Commit 5188a187 authored by Elena Grandi's avatar Elena Grandi

When using the ip as a name, keep it up to date with changes

parent 2f63ea2a
......@@ -130,6 +130,9 @@ class Machine:
# better as soon as possible.
if self.name == self.mac and self.ip is not None:
self.name = self.ip
# When using the ip as a name, keep it up to date with changes
if "ip" in changes and self.name == changes["ip"][0]:
self.name = self.ip
return changes
@classmethod
......
......@@ -196,6 +196,24 @@ class TestMockMachineStore(AsyncTestCase):
self.assertEqual(self.store.machines[mac].name, ip)
self.assertFalse(self.store.machines[mac].registered)
@gen_test
async def test_add_machine_by_ip_no_name_then_change_ip(self):
mac = '52:54:00:f2:f7:64'
ip = '192.168.6.102'
gathered = await self.post_host_seen(mac=mac, ip=ip)
self.assertIsInstance(gathered[1], events.HostNewEvent)
self.assertIn(mac, self.store.machines)
self.assertEqual(self.store.machines[mac].ip, ip)
self.assertEqual(self.store.machines[mac].name, ip)
self.assertFalse(self.store.machines[mac].registered)
new_ip = '192.168.6.103'
gathered = await self.post_host_seen(mac=mac, ip=new_ip)
self.assertIsInstance(gathered[1], events.HostChangedEvent)
self.assertIn(mac, self.store.machines)
self.assertEqual(self.store.machines[mac].ip, new_ip)
self.assertEqual(self.store.machines[mac].name, new_ip)
self.assertFalse(self.store.machines[mac].registered)
@gen_test
async def test_add_machine_w_timestamp(self):
mac = self.machine['mac']
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment