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

Proposed by Scott Moser
Status: Merged
Approved by: Scott Moser
Approved revision: 3d91eaade62a6f427c948c40b6d0a618e6351311
Merge reported by: Server Team CI bot
Merged at revision: not available
Proposed branch: ~smoser/cloud-init:fix/1796917-ignore-all-zero-macs
Merge into: cloud-init:master
Diff against target: 52 lines (+18/-2)
2 files modified
cloudinit/net/__init__.py (+4/-2)
tests/unittests/test_net.py (+14/-0)
Reviewer Review Type Date Requested Status
Server Team CI bot continuous-integration Approve
Chad Smith Approve
Ryan Harper Approve
Review via email: mp+356342@code.launchpad.net

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

Description of the change

see commit message

To post a comment you must log in.
Revision history for this message
Ryan Harper (raharper) wrote :

Interesting, I was wondering why the output in the bug showed a "truncated" MAC. And I figured we would have already ignored empty MAC as well.

This looks good plus unittest!

review: Approve
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:935d2de80d5847f5aee4e59a882179bbdd350489
https://jenkins.ubuntu.com/server/job/cloud-init-ci/377/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/377/rebuild

review: Approve (continuous-integration)
0206d10... by Scott Moser

rharper feedback: consistent use of tick or double quote on single line.

3d91eaa... by Scott Moser

change the comparison.

This should be slightly faster. Compute the string once and then
just do substring matching rather than computing the "zero mac"
for the given length each time.

Revision history for this message
Chad Smith (chad.smith) wrote :

Ahh my brain parsed that tunl mac as 6 bytes, not 4. Thanks for this fix and the inline comments to shed light on this issue in the future.
+1

review: Approve
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:0206d1067345cfa531133e27582a1236b245f318
https://jenkins.ubuntu.com/server/job/cloud-init-ci/378/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/378/rebuild

review: Approve (continuous-integration)
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:3d91eaade62a6f427c948c40b6d0a618e6351311
https://jenkins.ubuntu.com/server/job/cloud-init-ci/379/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/379/rebuild

review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/cloudinit/net/__init__.py b/cloudinit/net/__init__.py
2index f83d368..ad98a59 100644
3--- a/cloudinit/net/__init__.py
4+++ b/cloudinit/net/__init__.py
5@@ -612,7 +612,8 @@ def get_interfaces():
6 Bridges and any devices that have a 'stolen' mac are excluded."""
7 ret = []
8 devs = get_devicelist()
9- empty_mac = '00:00:00:00:00:00'
10+ # 16 somewhat arbitrarily chosen. Normally a mac is 6 '00:' tokens.
11+ zero_mac = ':'.join(('00',) * 16)
12 for name in devs:
13 if not interface_has_own_mac(name):
14 continue
15@@ -624,7 +625,8 @@ def get_interfaces():
16 # some devices may not have a mac (tun0)
17 if not mac:
18 continue
19- if mac == empty_mac and name != 'lo':
20+ # skip nics that have no mac (00:00....)
21+ if name != 'lo' and mac == zero_mac[:len(mac)]:
22 continue
23 ret.append((name, mac, device_driver(name), device_devid(name)))
24 return ret
25diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
26index 5d9c7d9..8e38373 100644
27--- a/tests/unittests/test_net.py
28+++ b/tests/unittests/test_net.py
29@@ -3339,9 +3339,23 @@ class TestGetInterfacesByMac(CiTestCase):
30 addnics = ('greptap1', 'lo', 'greptap2')
31 self.data['macs'].update(dict((k, empty_mac) for k in addnics))
32 self.data['devices'].update(set(addnics))
33+ self.data['own_macs'].extend(list(addnics))
34 ret = net.get_interfaces_by_mac()
35 self.assertEqual('lo', ret[empty_mac])
36
37+ def test_skip_all_zeros(self):
38+ """Any mac of 00:... should be skipped."""
39+ self._mock_setup()
40+ emac1, emac2, emac4, emac6 = (
41+ '00', '00:00', '00:00:00:00', '00:00:00:00:00:00')
42+ addnics = {'empty1': emac1, 'emac2a': emac2, 'emac2b': emac2,
43+ 'emac4': emac4, 'emac6': emac6}
44+ self.data['macs'].update(addnics)
45+ self.data['devices'].update(set(addnics))
46+ self.data['own_macs'].extend(addnics.keys())
47+ ret = net.get_interfaces_by_mac()
48+ self.assertEqual('lo', ret['00:00:00:00:00:00'])
49+
50 def test_ib(self):
51 ib_addr = '80:00:00:28:fe:80:00:00:00:00:00:00:00:11:22:03:00:33:44:56'
52 ib_addr_eth_format = '00:11:22:33:44:56'

Subscribers

People subscribed via source and target branches