def verifyDirectoryComparison(self, before, after, reverify=False):
        """
        Verify that the hierarchy described by "before", when upgraded, matches
        the hierarchy described by "after".

        @param before: a dictionary of the format accepted by L{TestCase.createHierarchy}

        @param after: a dictionary of the format accepted by L{TestCase.createHierarchy}

        @param reverify: if C{True}, re-verify the hierarchy by upgrading a
            second time and re-verifying the root again.

        @raise twisted.trial.unittest.FailTest: if the test fails.

        @return: C{None}
        """
        root = self.createHierarchy(before)

        config.DocumentRoot = root
        config.DataRoot = root

        upgradeData(config)
        self.assertTrue(self.verifyHierarchy(root, after))

        if reverify:
            # Ensure that repeating the process doesn't change anything
            upgradeData(config)
            self.assertTrue(self.verifyHierarchy(root, after))
    def test_migrateResourceInfo(self):
        # Fake getResourceInfo( )

        assignments = {
            'guid1' : (False, None, None),
            'guid2' : (True, 'guid1', None),
            'guid3' : (False, 'guid1', 'guid2'),
            'guid4' : (True, None, 'guid3'),
        }

        def _getResourceInfo(ignored):
            results = []
            for guid, info in assignments.iteritems():
                results.append( (guid, info[0], info[1], info[2]) )
            return results

        self.setUpInitialStates()
        # Override the normal getResourceInfo method with our own:
        XMLDirectoryService.getResourceInfo = _getResourceInfo

        before = { }
        after = {
            ".calendarserver_version" :
            {
                "@contents" : "1",
            },
#            CalendarUserProxyDatabase.dbFilename :
#            {
#                "@contents" : None,
#            },
            MailGatewayTokensDatabase.dbFilename :
            {
                "@contents" : None,
            },
#            ResourceInfoDatabase.dbFilename :
#            {
#                "@contents" : None,
#            }
        }
        root = self.createHierarchy(before)
        config.DocumentRoot = root
        config.DataRoot = root

        upgradeData(config)
        self.assertTrue(self.verifyHierarchy(root, after))
    def test_noUpgrade(self):
        """
        Test the behavior of running on a new server (i.e. no upgrade needed).
        """

        self.setUpInitialStates()

        config.DocumentRoot = self.newdocroot
        config.DataRoot = self.existingdataroot
        
        # Check pre-conditions
        self.assertFalse(os.path.exists(os.path.join(config.DocumentRoot, "principals")))
        self.assertTrue(os.path.exists(os.path.join(config.DataRoot, CalendarUserProxyDatabase.dbFilename)))

        upgradeData(config)
        
        # Check post-conditions
        self.assertFalse(os.path.exists(os.path.join(config.DocumentRoot, "principals",)))
        self.assertTrue(os.path.exists(os.path.join(config.DataRoot, CalendarUserProxyDatabase.dbFilename)))
    def test_normalUpgrade(self):
        """
        Test the behavior of normal upgrade from old server to new.
        """

        self.setUpInitialStates()

        config.DocumentRoot = self.olddocroot
        config.DataRoot = self.newdataroot

        
        # Check pre-conditions
        self.assertTrue(os.path.exists(os.path.join(config.DocumentRoot, "principals")))
        self.assertTrue(os.path.isdir(os.path.join(config.DocumentRoot, "principals")))
        self.assertTrue(os.path.exists(os.path.join(config.DocumentRoot, "principals", CalendarUserProxyDatabase.dbOldFilename)))
        self.assertFalse(os.path.exists(os.path.join(config.DataRoot, CalendarUserProxyDatabase.dbFilename)))

        upgradeData(config)
        
        # Check post-conditions
        self.assertFalse(os.path.exists(os.path.join(config.DocumentRoot, "principals",)))
        self.assertTrue(os.path.exists(os.path.join(config.DataRoot, CalendarUserProxyDatabase.dbFilename)))
    def makeService(self, options):
        self.log_info("%s %s starting %s process..." % (self.description, version, config.ProcessType))

        serviceMethod = getattr(self, "makeService_%s" % (config.ProcessType,), None)

        if not serviceMethod:
            raise UsageError(
                "Unknown server type %s. "
                "Please choose: Slave, Single or Combined"
                % (config.ProcessType,)
            )
        else:

            if config.ProcessType in ('Combined', 'Single'):

                # Memcached is not needed for the "master" process
                if config.ProcessType in ('Combined',):
                    config.Memcached.Pools.Default.ClientEnabled = False

                # Note: if the master process ever needs access to memcached
                # we'll either have to start memcached prior to the
                # updateProxyDB call below, or disable memcached
                # client config only while updateProxyDB is running.

                # Process localization string files
                processLocalizationFiles(config.Localization)

                # Now do any on disk upgrades we might need.
                upgradeData(config)

                # Make sure proxies get initialized
                if config.ProxyLoadFromFile:
                    def _doProxyUpdate():
                        proxydbClass = namedClass(config.ProxyDBService.type)
                        calendaruserproxy.ProxyDBService = proxydbClass(**config.ProxyDBService.params)
                        loader = XMLCalendarUserProxyLoader(config.ProxyLoadFromFile)
                        return loader.updateProxyDB()
                    addSystemEventTrigger("after", "startup", _doProxyUpdate)



            try:
                service = serviceMethod(options)
            except ConfigurationError, e:
                sys.stderr.write("Configuration error: %s\n" % (e,))
                sys.exit(1)

            #
            # Note: if there is a stopped process in the same session
            # as the calendar server and the calendar server is the
            # group leader then when twistd forks to drop privileges a
            # SIGHUP may be sent by the kernel, which can cause the
            # process to exit. This SIGHUP should be, at a minimum,
            # ignored.
            #

            def location(frame):
                if frame is None:
                    return "Unknown"
                else:
                    return "%s: %s" % (frame.f_code.co_name, frame.f_lineno)

            import signal
            def sighup_handler(num, frame):
                self.log_info("SIGHUP recieved at %s" % (location(frame),))

                # Reload the config file
                try:
                    config.reload()
                except ConfigurationError, e:
                    self.log_error("Invalid configuration: {0}".format(e))

                # If combined service send signal to all caldavd children
                if hasattr(service, "processMonitor"):
                    service.processMonitor.signalAll(signal.SIGHUP, "caldav")
Beispiel #6
0
    configFileName = None

    for opt, arg in optargs:
        if opt in ("-h", "--help"):
            usage()

        elif opt in ("-f", "--config"):
            configFileName = arg

    if args:
        usage("Too many arguments: %s" % (" ".join(args), ))

    try:
        config = loadConfig(configFileName)
    except ConfigurationError, e:
        sys.stdout.write("%s\n" % (e, ))
        sys.exit(1)

    profiling = False

    if profiling:
        import cProfile
        cProfile.runctx("upgradeData(c)", globals(), {"c": config},
                        "/tmp/upgrade.prof")
    else:
        upgradeData(config)


if __name__ == "__main__":
    main()
Beispiel #7
0
        usage(e)

    configFileName = None

    for opt, arg in optargs:
        if opt in ("-h", "--help"):
            usage()

        elif opt in ("-f", "--config"):
            configFileName = arg

    if args:
        usage("Too many arguments: %s" % (" ".join(args),))

    try:
        config = loadConfig(configFileName)
    except ConfigurationError, e:
        sys.stdout.write("%s\n" % (e,))
        sys.exit(1)

    profiling = False

    if profiling:
        import cProfile
        cProfile.runctx("upgradeData(c)", globals(), {"c": config}, "/tmp/upgrade.prof")
    else:
        upgradeData(config)

if __name__ == "__main__":
    main()