def test_reports_lack_of_foreign_dhcp_servers_to_region(self): clock = Clock() interface_name = factory.make_name("eth") interfaces = { interface_name: { "enabled": True, "links": [{ "address": "10.0.0.1/24" }] } } protocol, connecting = self.patch_rpc_methods() self.addCleanup((yield connecting)) deferToThread = self.patch(dhcp_probe_service, 'deferToThread') deferToThread.side_effect = [ defer.succeed(interfaces), ] probe_interface = self.patch(dhcp_probe_service, 'probe_interface') probe_interface.return_value = [] client = getRegionClient() rpc_service = Mock() rpc_service.getClientNow.return_value = defer.succeed(client) service = DHCPProbeService(rpc_service, clock) yield service.startService() yield service.stopService() self.assertThat( protocol.ReportForeignDHCPServer, MockCalledOnceWith(protocol, system_id=client.localIdent, interface_name=interface_name, dhcp_ip=None))
def test_skips_unconfigured_interfaces(self): clock = Clock() interface_name = factory.make_name("eth") interfaces = {interface_name: {"enabled": True, "links": []}} mock_interfaces = self.patch(dhcp_probe_service, "get_all_interfaces_definition") mock_interfaces.return_value = interfaces service = DHCPProbeService(sentinel.service, clock) try_get_client = self.patch(service, "_tryGetClient") try_get_client.getClientNow = Mock() probe_interface = self.patch(dhcp_probe_service, "probe_interface") yield service.startService() yield service.stopService() self.assertThat(probe_interface, MockNotCalled())
def test_probes_ipv4_interfaces(self): clock = Clock() interface_name = factory.make_name("eth") interfaces = { interface_name: { "enabled": True, "links": [{"address": "10.0.0.1/24"}], } } mock_interfaces = self.patch( dhcp_probe_service, "get_all_interfaces_definition" ) mock_interfaces.return_value = interfaces service = DHCPProbeService(sentinel.service, clock) try_get_client = self.patch(service, "_tryGetClient") try_get_client.getClientNow = Mock() probe_interface = self.patch(dhcp_probe_service, "probe_interface") yield service.startService() yield service.stopService() self.assertThat(probe_interface, MockCalledOnce())
def test_skips_ipv6_interfaces(self): clock = Clock() interface_name = factory.make_name("eth") interfaces = { interface_name: { "enabled": True, "links": [{ "address": "2001:db8::1/64" }] } } mock_interfaces = self.patch(dhcp_probe_service, 'get_all_interfaces_definition') mock_interfaces.return_value = interfaces service = DHCPProbeService(sentinel.service, clock) try_get_client = self.patch(service, '_tryGetClient') try_get_client.getClientNow = Mock() probe_interface = self.patch(dhcp_probe_service, 'probe_interface') yield service.startService() yield service.stopService() self.assertThat(probe_interface, MockNotCalled())
def test_exits_gracefully_if_cant_report_foreign_dhcp_server(self): clock = Clock() interface_name = factory.make_name("eth") interfaces = { interface_name: { "enabled": True, "links": [{ "address": "10.0.0.1/24" }] } } maaslog = self.patch(dhcp_probe_service, 'maaslog') deferToThread = self.patch(dhcp_probe_service, 'deferToThread') deferToThread.side_effect = [ defer.succeed(interfaces), ] probe_interface = self.patch(dhcp_probe_service, 'probe_interface') probe_interface.return_value = ['192.168.0.100'] protocol, connecting = self.patch_rpc_methods() self.addCleanup((yield connecting)) del protocol._commandDispatch[ region.ReportForeignDHCPServer.commandName] rpc_service = Mock() rpc_service.getClientNow.return_value = defer.succeed( getRegionClient()) service = DHCPProbeService(rpc_service, clock) yield service.startService() yield service.stopService() self.assertThat( maaslog.error, MockCalledOnceWith( "Unable to inform region of DHCP server: the region " "does not yet support the ReportForeignDHCPServer RPC " "method."))