1322
1323
self.assertEqual("192.168.0.1", ip_address_observed)
1326
class TestFindMACViaARP(MAASTestCase):
1328
def patch_call(self, output):
1329
"""Replace `call_capture_and_check` with one that returns `output`."""
1330
fake = self.patch(provisioningserver.utils, 'call_capture_and_check')
1331
fake.return_value = output
1334
def test__resolves_IP_address_to_MAC(self):
1336
Address HWtype HWaddress Flags Mask Iface
1337
192.168.100.20 (incomplete) virbr1
1338
192.168.0.104 (incomplete) eth0
1339
192.168.0.5 (incomplete) eth0
1340
192.168.0.2 (incomplete) eth0
1341
192.168.0.100 (incomplete) eth0
1342
192.168.122.20 ether 52:54:00:02:86:4b C virbr0
1343
192.168.0.4 (incomplete) eth0
1344
192.168.0.1 ether 90:f6:52:f6:17:92 C eth0
1347
call_capture_and_check = self.patch_call(sample)
1348
mac_address_observed = find_mac_via_arp("192.168.122.20")
1350
call_capture_and_check,
1351
MockCalledOnceWith(['arp', '-n']))
1352
self.assertEqual("52:54:00:02:86:4b", mac_address_observed)
1354
def test__returns_consistent_output(self):
1355
ip = factory.getRandomIPAddress()
1357
'52:54:00:02:86:4b',
1358
'90:f6:52:f6:17:92',
1360
lines = ['%s ether %s C eth0' % (ip, mac) for mac in macs]
1361
self.patch_call('\n'.join(lines))
1362
one_result = find_mac_via_arp(ip)
1363
self.patch_call('\n'.join(reversed(lines)))
1364
other_result = find_mac_via_arp(ip)
1366
self.assertIn(one_result, macs)
1367
self.assertEqual(one_result, other_result)
1325
1370
class TestAsynchronousDecorator(MAASTestCase):
1327
1372
run_tests_with = AsynchronousDeferredRunTest.make_factory(timeout=5)