← Back to team overview

cloud-init-dev team mailing list archive

[Merge] ~smoser/cloud-init:fix/1796917-ignore-all-zero-macs into cloud-init:master

 

Scott Moser has proposed merging ~smoser/cloud-init:fix/1796917-ignore-all-zero-macs into cloud-init:master.

Commit message:
net: ignore nics that have "zero" mac address.

Previously we explicitly excluded mac address '00:00:00:00:00:00'.
But then some nics (tunl0 and sit0) ended up having a mac address like
'00:00:00:00'.

The change here just ignores all 00[:00[:00...]].

LP: #1796917

Requested reviews:
  cloud-init commiters (cloud-init-dev)
Related bugs:
  Bug #1796917 in cloud-images: "cloud-init fails to run on latest cosmic minimal image"
  https://bugs.launchpad.net/cloud-images/+bug/1796917

For more details, see:
https://code.launchpad.net/~smoser/cloud-init/+git/cloud-init/+merge/356342

see commit message
-- 
Your team cloud-init commiters is requested to review the proposed merge of ~smoser/cloud-init:fix/1796917-ignore-all-zero-macs into cloud-init:master.
diff --git a/cloudinit/net/__init__.py b/cloudinit/net/__init__.py
index f83d368..e7aad35 100644
--- a/cloudinit/net/__init__.py
+++ b/cloudinit/net/__init__.py
@@ -612,7 +612,6 @@ def get_interfaces():
     Bridges and any devices that have a 'stolen' mac are excluded."""
     ret = []
     devs = get_devicelist()
-    empty_mac = '00:00:00:00:00:00'
     for name in devs:
         if not interface_has_own_mac(name):
             continue
@@ -624,7 +623,8 @@ def get_interfaces():
         # some devices may not have a mac (tun0)
         if not mac:
             continue
-        if mac == empty_mac and name != 'lo':
+        # skip nics that have no mac (00:00....)
+        if name != 'lo' and mac == ':'.join(('00',) * len(mac.split(":"))):
             continue
         ret.append((name, mac, device_driver(name), device_devid(name)))
     return ret
diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
index 5d9c7d9..8e38373 100644
--- a/tests/unittests/test_net.py
+++ b/tests/unittests/test_net.py
@@ -3339,9 +3339,23 @@ class TestGetInterfacesByMac(CiTestCase):
         addnics = ('greptap1', 'lo', 'greptap2')
         self.data['macs'].update(dict((k, empty_mac) for k in addnics))
         self.data['devices'].update(set(addnics))
+        self.data['own_macs'].extend(list(addnics))
         ret = net.get_interfaces_by_mac()
         self.assertEqual('lo', ret[empty_mac])
 
+    def test_skip_all_zeros(self):
+        """Any mac of 00:... should be skipped."""
+        self._mock_setup()
+        emac1, emac2, emac4, emac6 = (
+            '00', '00:00', '00:00:00:00', '00:00:00:00:00:00')
+        addnics = {'empty1': emac1, 'emac2a': emac2, 'emac2b': emac2,
+                   'emac4': emac4, 'emac6': emac6}
+        self.data['macs'].update(addnics)
+        self.data['devices'].update(set(addnics))
+        self.data['own_macs'].extend(addnics.keys())
+        ret = net.get_interfaces_by_mac()
+        self.assertEqual('lo', ret['00:00:00:00:00:00'])
+
     def test_ib(self):
         ib_addr = '80:00:00:28:fe:80:00:00:00:00:00:00:00:11:22:03:00:33:44:56'
         ib_addr_eth_format = '00:11:22:33:44:56'