From 059d049c57cac02cdeaca832233a19712e0b4ded Mon Sep 17 00:00:00 2001 From: Ryan Harper Date: Tue, 17 Sep 2019 10:11:00 +0000 Subject: net: add is_master check for filtering device list Some network devices are transformed into a bond via kernel magic and do not have the 'bonding' sysfs attribute, but like a bond they have a duplicate MAC of other bond members. On Azure Advanced Networking SRIOV devices are auto bonded and will have the same MAC as the HyperV nic. We can detect this via the 'master' sysfs attribute in the device sysfs path and this patch adds this to the list of devices we ignore when enumerating device lists. LP: #1844191 --- cloudinit/net/tests/test_init.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'cloudinit/net/tests') diff --git a/cloudinit/net/tests/test_init.py b/cloudinit/net/tests/test_init.py index 7259dbe3..999db986 100644 --- a/cloudinit/net/tests/test_init.py +++ b/cloudinit/net/tests/test_init.py @@ -157,6 +157,12 @@ class TestReadSysNet(CiTestCase): ensure_file(os.path.join(self.sysdir, 'eth0', 'bonding')) self.assertTrue(net.is_bond('eth0')) + def test_has_master(self): + """has_master is True when /sys/net/devname/master exists.""" + self.assertFalse(net.has_master('enP1s1')) + ensure_file(os.path.join(self.sysdir, 'enP1s1', 'master')) + self.assertTrue(net.has_master('enP1s1')) + def test_is_vlan(self): """is_vlan is True when /sys/net/devname/uevent has DEVTYPE=vlan.""" ensure_file(os.path.join(self.sysdir, 'eth0', 'uevent')) @@ -424,6 +430,17 @@ class TestGetInterfaceMAC(CiTestCase): expected = [('eth2', 'aa:bb:cc:aa:bb:cc', None, None)] self.assertEqual(expected, net.get_interfaces()) + def test_get_interfaces_by_mac_skips_master_devs(self): + """Ignore interfaces with a master device which would have dup mac.""" + mac1 = mac2 = 'aa:bb:cc:aa:bb:cc' + write_file(os.path.join(self.sysdir, 'eth1', 'addr_assign_type'), '0') + write_file(os.path.join(self.sysdir, 'eth1', 'address'), mac1) + write_file(os.path.join(self.sysdir, 'eth1', 'master'), "blah") + write_file(os.path.join(self.sysdir, 'eth2', 'addr_assign_type'), '0') + write_file(os.path.join(self.sysdir, 'eth2', 'address'), mac2) + expected = [('eth2', mac2, None, None)] + self.assertEqual(expected, net.get_interfaces()) + @mock.patch('cloudinit.net.is_netfailover') def test_get_interfaces_by_mac_skips_netfailvoer(self, m_netfail): """Ignore interfaces if netfailover primary or standby.""" -- cgit v1.2.3