def test__run_via_probe_interface_returns_servers(self): mock_send_and_await = self.patch(DHCPRequestMonitor, "send_requests_and_await_replies") mock_send_and_await.return_value = { DHCPServer("127.0.0.1", "127.0.0.1"), DHCPServer("127.1.1.1", "127.2.2.2"), } result = yield probe_interface("lo") self.assertThat(mock_send_and_await, MockCallsMatch(call())) self.assertThat(result, Equals({"127.0.0.1", "127.1.1.1"}))
def test__run_logs_result_and_makes_properties_available(self): logger = self.useFixture(TwistedLoggerFixture()) monitor = DHCPRequestMonitor('lo') mock_send_and_await = self.patch(monitor, 'send_requests_and_await_replies') mock_send_and_await.return_value = { DHCPServer('127.0.0.1', '127.0.0.1'), DHCPServer('127.1.1.1', '127.2.2.2'), } yield monitor.run() self.assertThat(mock_send_and_await, MockCallsMatch(call())) self.assertThat( logger.output, DocTestMatches( "External DHCP server(s) discovered on interface 'lo': 127.0.0.1, " "127.1.1.1 (via 127.2.2.2)")) self.assertThat(monitor.dhcp_servers, Equals({"127.0.0.1", "127.1.1.1"})) self.assertThat(monitor.dhcp_addresses, Equals({"127.0.0.1", "127.2.2.2"}))
def test_get_sys_info_empty(self): hostname = factory.make_hostname() architecture = factory.make_name('architecture') self.patch(refresh.socket, 'gethostname').return_value = hostname self.patch_autospec(refresh, 'get_os_release').return_value = {} self.patch_autospec( refresh, 'get_architecture').return_value = architecture self.assertThat({ 'hostname': hostname, 'architecture': architecture, 'osystem': '', 'distro_series': '', 'interfaces': {}, }, Equals(refresh.get_sys_info()))
def test__cancelAll(self): self.errbacks_called = 0 def mock_errback(result: Failure): self.assertTrue(result.check(CancelledError)) self.errbacks_called += 1 a = deferLater(reactor, 6, lambda: "a") b = deferLater(reactor, 6, lambda: "b") a.addBoth(mock_errback) b.addBoth(mock_errback) deferreds = [a, b] DHCPRequestMonitor.cancelAll(deferreds) deferredList = DeferredList(deferreds) yield deferredList self.assertThat(self.errbacks_called, Equals(2))
def test_get_sys_info_empty(self): hostname = factory.make_hostname() architecture = factory.make_name("architecture") self.patch(refresh.socket, "gethostname").return_value = hostname self.patch_autospec(refresh, "get_os_release").return_value = {} self.patch_autospec(refresh, "get_architecture").return_value = architecture self.assertThat( { "hostname": hostname, "architecture": architecture, "osystem": "", "distro_series": "", "maas_version": get_maas_version(), "interfaces": {}, }, Equals(refresh.get_sys_info()), )
def test_get_sys_info_alt(self): hostname = factory.make_hostname() osystem = factory.make_name('name') distro_series = factory.make_name('version_id') architecture = factory.make_name('architecture') self.patch(refresh.socket, 'gethostname').return_value = hostname self.patch_autospec(refresh, 'get_os_release').return_value = { 'NAME': osystem, 'VERSION_ID': distro_series, } self.patch_autospec( refresh, 'get_architecture').return_value = architecture self.assertThat({ 'hostname': hostname, 'architecture': architecture, 'osystem': osystem, 'distro_series': distro_series, 'interfaces': {}, }, Equals(refresh.get_sys_info()))
def test_get_sys_info(self): hostname = factory.make_hostname() osystem = factory.make_name('id') distro_series = factory.make_name('ubuntu_codename') architecture = factory.make_name('architecture') self.patch(refresh.socket, 'gethostname').return_value = hostname self.patch_autospec(refresh, 'get_os_release').return_value = { 'ID': osystem, 'UBUNTU_CODENAME': distro_series, } self.patch_autospec( refresh, 'get_architecture').return_value = architecture self.assertThat({ 'hostname': hostname, 'architecture': architecture, 'osystem': osystem, 'distro_series': distro_series, 'maas_version': get_maas_version(), 'interfaces': {}, }, Equals(refresh.get_sys_info()))
def test_get_sys_info_alt(self): hostname = factory.make_hostname() osystem = factory.make_name("name") distro_series = factory.make_name("version_id") architecture = factory.make_name("architecture") self.patch(refresh.socket, "gethostname").return_value = hostname self.patch_autospec(refresh, "get_os_release").return_value = { "NAME": osystem, "VERSION_ID": distro_series, } self.patch_autospec(refresh, "get_architecture").return_value = architecture self.assertThat( { "hostname": hostname, "architecture": architecture, "osystem": osystem, "distro_series": distro_series, "maas_version": get_maas_version(), "interfaces": {}, }, Equals(refresh.get_sys_info()), )