← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~raharper/cloud-init:fix/net-get-devices-ignore-devs-with-master into cloud-init:master


Ryan Harper has proposed merging ~raharper/cloud-init:fix/net-get-devices-ignore-devs-with-master into cloud-init:master.

Commit message:
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

Requested reviews:
  cloud-init Commiters (cloud-init-dev)
Related bugs:
  Bug #1844191 in cloud-init: "azure advanced networking sometimes triggers duplicate mac detection"

For more details, see:
Your team cloud-init Commiters is requested to review the proposed merge of ~raharper/cloud-init:fix/net-get-devices-ignore-devs-with-master into cloud-init:master.
diff --git a/cloudinit/net/__init__.py b/cloudinit/net/__init__.py
index 0eb952f..2e1c333 100644
--- a/cloudinit/net/__init__.py
+++ b/cloudinit/net/__init__.py
@@ -109,6 +109,10 @@ def is_bond(devname):
     return os.path.exists(sys_dev_path(devname, "bonding"))
+def is_master(devname):
+    return os.path.exists(sys_dev_path(devname, path="master"))
 def is_netfailover(devname, driver=None):
     """ netfailover driver uses 3 nics, master, primary and standby.
         this returns True if the device is either the primary or standby
@@ -154,7 +158,7 @@ def is_netfail_master(devname, driver=None):
         Return True if all of the above is True.
-    if os.path.exists(sys_dev_path(devname, path='master')):
+    if is_master(devname):
         return False
     if driver is None:
@@ -211,7 +215,7 @@ def is_netfail_standby(devname, driver=None):
         Return True if all of the above is True.
-    if not os.path.exists(sys_dev_path(devname, path='master')):
+    if not is_master(devname):
         return False
     if driver is None:
@@ -786,6 +790,8 @@ def get_interfaces():
         if is_bond(name):
+        if is_master(name):
+            continue
         if is_netfailover(name):
         mac = get_interface_mac(name)
diff --git a/cloudinit/net/tests/test_init.py b/cloudinit/net/tests/test_init.py
index 7259dbe..3834aa0 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'))
+    def test_is_master(self):
+        """is_master is True when /sys/net/devname/master exists."""
+        self.assertFalse(net.is_master('enP1s1'))
+        ensure_file(os.path.join(self.sysdir, 'enP1s1', 'master'))
+        self.assertTrue(net.is_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'))

Follow ups