def test_tftp_service(self): # A TFTP service is configured and added to the top-level service. interfaces = [ factory.getRandomIPAddress(), factory.getRandomIPAddress(), ] self.patch( plugin, "get_all_interface_addresses", lambda: interfaces) config = { "tftp": { "generator": "http://candlemass/solitude", "root": self.tempdir, "port": factory.getRandomPort(), }, } options = Options() options["config-file"] = self.write_config(config) service_maker = ProvisioningServiceMaker("Harry", "Hill") service = service_maker.makeService(options) tftp_services = service.getServiceNamed("tftp") # The "tftp" service is a multi-service containing UDP servers for # each interface defined by get_all_interface_addresses(). self.assertIsInstance(tftp_services, MultiService) services = [ tftp_services.getServiceNamed(interface) for interface in interfaces ] expected_backend = MatchesAll( IsInstance(TFTPBackend), AfterPreprocessing( lambda backend: backend.base.path, Equals(config["tftp"]["root"])), AfterPreprocessing( lambda backend: backend.generator_url.geturl(), Equals(config["tftp"]["generator"]))) expected_protocol = MatchesAll( IsInstance(TFTP), AfterPreprocessing( lambda protocol: protocol.backend, expected_backend)) expected_service = MatchesAll( IsInstance(UDPServer), AfterPreprocessing( lambda service: len(service.args), Equals(2)), AfterPreprocessing( lambda service: service.args[0], # port Equals(config["tftp"]["port"])), AfterPreprocessing( lambda service: service.args[1], # protocol expected_protocol)) self.assertThat(services, AllMatch(expected_service)) # Only the interface used for each service differs. self.assertEqual( [svc.kwargs for svc in services], [{"interface": interface} for interface in interfaces])
def test_makeService(self): """ Only the site service is created when no options are given. """ options = Options() options["config-file"] = self.write_config({}) service_maker = ProvisioningServiceMaker("Harry", "Hill") service = service_maker.makeService(options) self.assertIsInstance(service, MultiService) self.assertSequenceEqual( ["log", "oops", "tftp"], sorted(service.namedServices)) self.assertEqual( len(service.namedServices), len(service.services), "Not all services are named.")
def test_makeService_with_broker(self): """ The log, oops, site, and amqp services are created when the broker user and password options are given. """ options = Options() options["config-file"] = self.write_config( {"broker": {"username": "******", "password": "******"}}) service_maker = ProvisioningServiceMaker("Harry", "Hill") service = service_maker.makeService(options) self.assertIsInstance(service, MultiService) self.assertSequenceEqual( ["amqp", "log", "oops", "tftp"], sorted(service.namedServices)) self.assertEqual( len(service.namedServices), len(service.services), "Not all services are named.")
def test_rpc_ping_service(self): options = Options() service_maker = ProvisioningServiceMaker("Harry", "Hill") service = service_maker.makeService(options, clock=None) rpc_ping = service.getServiceNamed("rpc-ping") self.assertIsInstance(rpc_ping, ClusterClientCheckerService)
def test_external_service(self): options = Options() service_maker = ProvisioningServiceMaker("Harry", "Hill") service = service_maker.makeService(options, clock=None) external_service = service.getServiceNamed("external") self.assertIsInstance(external_service, RackExternalService)
def test_dhcp_probe_service(self): options = Options() service_maker = ProvisioningServiceMaker("Spike", "Milligan") service = service_maker.makeService(options, clock=None) dhcp_probe = service.getServiceNamed("dhcp_probe") self.assertIsInstance(dhcp_probe, DHCPProbeService)
def test_service_monitor_service(self): options = Options() service_maker = ProvisioningServiceMaker("Harry", "Hill") service = service_maker.makeService(options, clock=None) service_monitor = service.getServiceNamed("service_monitor") self.assertIsInstance(service_monitor, ServiceMonitorService)
def test_networks_monitor_service(self): options = Options() service_maker = ProvisioningServiceMaker("Spike", "Milligan") service = service_maker.makeService(options, clock=None) networks_monitor = service.getServiceNamed("networks_monitor") self.assertIsInstance(networks_monitor, RackNetworksMonitoringService)
def test_image_download_service(self): options = Options() service_maker = ProvisioningServiceMaker("Harry", "Hill") service = service_maker.makeService(options, clock=None) image_service = service.getServiceNamed("image_download") self.assertIsInstance(image_service, ImageDownloadService)
def test_makeService_patches_tftp_service(self): mock_tftp_patch = (self.patch(plugin_module, 'add_patches_to_txtftp')) options = Options() service_maker = ProvisioningServiceMaker("Harry", "Hill") service_maker.makeService(options, clock=None) self.assertThat(mock_tftp_patch, MockCalledOnceWith())
def test_lease_socket_service(self): options = Options() service_maker = ProvisioningServiceMaker("Harry", "Hill") service = service_maker.makeService(options, clock=None) lease_socket_service = service.getServiceNamed("lease_socket_service") self.assertIsInstance(lease_socket_service, LeaseSocketService)
def test_http_service(self): options = Options() service_maker = ProvisioningServiceMaker("Harry", "Hill") service = service_maker.makeService(options, clock=None) http_service = service.getServiceNamed("http_service") self.assertIsInstance(http_service, StreamServerEndpointService)