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()
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())
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())
def test_makeService(self): options = Options() service_maker = RegionMasterServiceMaker("Harry", "Hill") # Disable _ensureConnection() its not allowed in the reactor. self.patch_autospec(service_maker, "_ensureConnection") # 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 = [ "region-controller", "nonce-cleanup", "dns-publication-cleanup", "service-monitor", "status-monitor", "stats", "postgres-listener-master", "networks-monitor", "active-discovery", "reverse-dns", "ntp", "workers", "ipc-master", ] 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())
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())
def test_disables_database_connections_in_reactor(self): self.assertConnectionsEnabled() service_maker = RegionAllInOneServiceMaker("Harry", "Hill") # Disable _ensureConnection() its not allowed in the reactor. self.patch_autospec(service_maker, "_ensureConnection") # Disable _configureThreads() as it's too invasive right now. self.patch_autospec(service_maker, "_configureThreads") service_maker.makeService(Options()) self.assertConnectionsDisabled()
def test_makeService_configures_pserv_debug(self): options = Options() service_maker = RegionAllInOneServiceMaker("Harry", "Hill") mock_pserv = self.patch(service_maker, "_configurePservSettings") # Disable _ensureConnection() its not allowed in the reactor. self.patch_autospec(service_maker, "_ensureConnection") # Disable _configureThreads() as it's too invasive right now. self.patch_autospec(service_maker, "_configureThreads") service_maker.makeService(options) self.assertThat(mock_pserv, MockCalledOnceWith())
def test_runs_start_up(self): service_maker = RegionServiceMaker("Harry", "Hill") # Disable _ensureConnection() its not allowed in the reactor. self.patch_autospec(service_maker, "_ensureConnection") # Disable _configureThreads() as it's too invasive right now. self.patch_autospec(service_maker, "_configureThreads") # Disable _preformStartUp() as it performs operations we don't want # in the testing environment. mock_performStartUp = self.patch_autospec(service_maker, "_performStartUp") service_maker.makeService(Options()) self.assertThat(mock_performStartUp, MockCalledOnceWith())
def test_disables_database_connections_in_reactor(self): self.assertConnectionsEnabled() service_maker = RegionServiceMaker("Harry", "Hill") # Disable _ensureConnection() its not allowed in the reactor. self.patch_autospec(service_maker, "_ensureConnection") # Disable _configureThreads() as it's too invasive right now. self.patch_autospec(service_maker, "_configureThreads") # Disable _preformStartUp() as it performs operations we don't want # in the testing environment. self.patch_autospec(service_maker, "_performStartUp") service_maker.makeService(Options()) self.assertConnectionsDisabled()
def test_makeService(self): options = Options() service_maker = RegionAllInOneServiceMaker("Harry", "Hill") # Disable _ensureConnection() its not allowed in the reactor. self.patch_autospec(service_maker, "_ensureConnection") # 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 = [ # Worker services. "database-tasks", "postgres-listener-worker", "rack-controller", "rpc", "service-monitor", "status-worker", "version-check", "web", "ipc-worker", # Master services. "region-controller", "nonce-cleanup", "dns-publication-cleanup", "status-monitor", "stats", "prometheus", "prometheus-exporter", "import-resources", "import-resources-progress", "postgres-listener-master", "networks-monitor", "active-discovery", "reverse-dns", "ntp", "syslog", # "workers", Prevented in all-in-one. "ipc-master", ] 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())
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()
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 = RegionAllInOneServiceMaker("Harry", "Hill") # Disable _ensureConnection() its not allowed in the reactor. self.patch_autospec(service_maker, "_ensureConnection") service_maker.makeService(Options()) threadpool = reactor.getThreadPool() self.assertThat(threadpool, IsInstance(ThreadPool)) finally: patcher.restore()
def test_makeService_cleanup_prometheus_dir(self): tmpdir = Path(self.useFixture(TempDirectory()).path) self.useFixture( EnvironmentVariableFixture("prometheus_multiproc_dir", str(tmpdir)) ) pid = os.getpid() file1 = tmpdir / "histogram_{}.db".format(pid) file1.touch() file2 = tmpdir / "histogram_{}.db".format(self.get_unused_pid()) file2.touch() service_maker = RegionMasterServiceMaker("Harry", "Hill") # Disable _ensureConnection() its not allowed in the reactor. self.patch_autospec(service_maker, "_ensureConnection") # Disable _configureThreads() as it's too invasive right now. self.patch_autospec(service_maker, "_configureThreads") service_maker.makeService(Options()) self.assertTrue(file1.exists()) self.assertFalse(file2.exists())
def test_makeService(self): options = Options() service_maker = RegionServiceMaker("Harry", "Hill") # Look like the master process. self.patch(eventloop, "is_master_process").return_value = True # Disable _ensureConnection() its not allowed in the reactor. self.patch_autospec(service_maker, "_ensureConnection") # Disable _configureThreads() as it's too invasive right now. self.patch_autospec(service_maker, "_configureThreads") # Disable _preformStartUp() as it performs operations we don't want # in the testing environment. self.patch_autospec(service_maker, "_performStartUp") service = service_maker.makeService(options) self.assertIsInstance(service, MultiService) expected_services = [ "active-discovery", "database-tasks", "dns-publication-cleanup", "import-resources", "import-resources-progress", "networks-monitor", "nonce-cleanup", "ntp", "postgres-listener", "rack-controller", "region-controller", "reverse-dns", "rpc", "rpc-advertise", "service-monitor", "status-monitor", "status-worker", "web", ] 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())
def test_parse_minimal_options(self): options = Options() # The minimal set of options that must be provided. arguments = [] options.parseOptions(arguments) # No error.
def test_defaults(self): options = Options() self.assertEqual({}, options.defaults)