Пример #1
0
 def test_disables_database_connections_in_reactor(self):
     self.assertConnectionsEnabled()
     service_maker = RegionWorkerServiceMaker("Harry", "Hill")
     # Disable _configureThreads() as it's too invasive right now.
     self.patch_autospec(service_maker, "_configureThreads")
     service_maker.makeService(Options())
     self.assertConnectionsDisabled()
Пример #2
0
 def test_makeService_without_import_services(self):
     options = Options()
     service_maker = RegionWorkerServiceMaker("Harry", "Hill")
     # Disable _configureThreads() as it's too invasive right now.
     self.patch_autospec(service_maker, "_configureThreads")
     service = service_maker.makeService(options)
     self.assertIsInstance(service, MultiService)
     expected_services = [
         "database-tasks",
         "postgres-listener-worker",
         "rack-controller",
         "rpc",
         "status-worker",
         "web",
         "ipc-worker",
     ]
     self.assertItemsEqual(expected_services, service.namedServices.keys())
     self.assertEqual(
         len(service.namedServices),
         len(service.services),
         "Not all services are named.",
     )
     self.assertThat(
         logger.configure,
         MockCalledOnceWith(
             options["verbosity"], logger.LoggingMode.TWISTD
         ),
     )
     self.assertThat(crochet.no_setup, MockCalledOnceWith())
Пример #3
0
 def test_makeService_with_import_services(self):
     options = Options()
     service_maker = RegionWorkerServiceMaker("Harry", "Hill")
     # Disable _configureThreads() as it's too invasive right now.
     self.patch_autospec(service_maker, "_configureThreads")
     # Set the environment variable to create the import services.
     self.useFixture(
         EnvironmentVariableFixture(
             'MAAS_REGIOND_RUN_IMPORTER_SERVICE', 'true'))
     service = service_maker.makeService(options)
     self.assertIsInstance(service, MultiService)
     expected_services = [
         "database-tasks",
         "postgres-listener-worker",
         "rack-controller",
         "rpc",
         "status-worker",
         "web",
         "ipc-worker",
         "import-resources",
         "import-resources-progress",
     ]
     self.assertItemsEqual(expected_services, service.namedServices.keys())
     self.assertEqual(
         len(service.namedServices), len(service.services),
         "Not all services are named.")
     self.assertThat(
         logger.configure, MockCalledOnceWith(
             options["verbosity"], logger.LoggingMode.TWISTD))
     self.assertThat(crochet.no_setup, MockCalledOnceWith())
Пример #4
0
 def test_makeService_configures_pserv_debug(self):
     options = Options()
     service_maker = RegionWorkerServiceMaker("Harry", "Hill")
     mock_pserv = self.patch(service_maker, "_configurePservSettings")
     # Disable _configureThreads() as it's too invasive right now.
     self.patch_autospec(service_maker, "_configureThreads")
     service_maker.makeService(options)
     self.assertThat(mock_pserv, MockCalledOnceWith())
Пример #5
0
 def test_configures_thread_pool(self):
     # Patch and restore where it's visible because patching a running
     # reactor is potentially fairly harmful.
     patcher = monkey.MonkeyPatcher()
     patcher.add_patch(reactor, "threadpool", None)
     patcher.add_patch(reactor, "threadpoolForDatabase", None)
     patcher.patch()
     try:
         service_maker = RegionWorkerServiceMaker("Harry", "Hill")
         service_maker.makeService(Options())
         threadpool = reactor.getThreadPool()
         self.assertThat(threadpool, IsInstance(ThreadPool))
     finally:
         patcher.restore()
Пример #6
0
 def test_init(self):
     service_maker = RegionWorkerServiceMaker("Harry", "Hill")
     self.assertEqual("Harry", service_maker.tapname)
     self.assertEqual("Hill", service_maker.description)
Пример #7
0
try:
    from maasserver.plugin import (
        RegionAllInOneServiceMaker,
        RegionMasterServiceMaker,
        RegionWorkerServiceMaker,
    )
except ImportError:
    pass
else:
    # Regiond services that twisted could spawn.
    twistd_plugins.append(
        RegionMasterServiceMaker("maas-regiond-master",
                                 "The MAAS Region Controller master process."))
    twistd_plugins.append(
        RegionWorkerServiceMaker("maas-regiond-worker",
                                 "The MAAS Region Controller worker process."))
    twistd_plugins.append(
        RegionAllInOneServiceMaker(
            "maas-regiond-all",
            "The MAAS Region Controller all-in-one process."))


class Options(ServerOptions):
    """Override the plugins path for the server options."""
    @staticmethod
    def _getPlugins(interface):
        return twistd_plugins


def runService(service):
    """Run the `service`."""