Merge ~xnox/cloud-init:master into cloud-init:master

Proposed by Dimitri John Ledkov
Status: Merged
Merged at revision: df4ca453520342a0541ab9202305858bf39d4f48
Proposed branch: ~xnox/cloud-init:master
Merge into: cloud-init:master
Diff against target: 91 lines (+34/-3)
2 files modified
cloudinit/net/__init__.py (+7/-0)
tests/unittests/test_net.py (+27/-3)
Reviewer Review Type Date Requested Status
Scott Moser Approve
Server Team CI bot continuous-integration Approve
Ryan Harper Pending
Review via email: mp+322828@code.launchpad.net

Commit message

net: kernel lies about vlans not stealing mac addresses, when they do

Introduce is_vlan function and call that when building dictionary of
interfaces by mac address.

LP: #1682871

To post a comment you must log in.
Revision history for this message
Server Team CI bot (server-team-bot) wrote :

FAILED: Continuous integration, rev:9cff0a5689846ebb92219efbed3f7f8d7748dd06
No commit message was specified in the merge proposal. Click on the following link and set the commit message (if you want a jenkins rebuild you need to trigger it yourself):
https://code.launchpad.net/~xnox/cloud-init/+git/cloud-init/+merge/322828/+edit-commit-message

https://jenkins.ubuntu.com/server/job/cloud-init-ci/257/
Executed test runs:
    SUCCESS: https://jenkins.ubuntu.com/server/job/cloud-init-ci/nodes=metal-amd64/257
    SUCCESS: https://jenkins.ubuntu.com/server/job/cloud-init-ci/nodes=metal-arm64/257
    SUCCESS: https://jenkins.ubuntu.com/server/job/cloud-init-ci/nodes=metal-ppc64el/257
    SUCCESS: https://jenkins.ubuntu.com/server/job/cloud-init-ci/nodes=metal-s390x/257
    SUCCESS: https://jenkins.ubuntu.com/server/job/cloud-init-ci/nodes=vm-i386/257

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

review: Needs Fixing (continuous-integration)
Revision history for this message
Dimitri John Ledkov (xnox) wrote :

I did pass all the tests, and have set the commit message now.
I am unable to retrigger jenkins =(

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/cloudinit/net/__init__.py b/cloudinit/net/__init__.py
index 346be5d..a072a8d 100644
--- a/cloudinit/net/__init__.py
+++ b/cloudinit/net/__init__.py
@@ -86,6 +86,11 @@ def is_bridge(devname):
86 return os.path.exists(sys_dev_path(devname, "bridge"))86 return os.path.exists(sys_dev_path(devname, "bridge"))
8787
8888
89def is_vlan(devname):
90 uevent = str(read_sys_net_safe(devname, "uevent"))
91 return 'DEVTYPE=vlan' in uevent.splitlines()
92
93
89def is_connected(devname):94def is_connected(devname):
90 # is_connected isn't really as simple as that. 2 is95 # is_connected isn't really as simple as that. 2 is
91 # 'physically connected'. 3 is 'not connected'. but a wlan interface will96 # 'physically connected'. 3 is 'not connected'. but a wlan interface will
@@ -393,6 +398,8 @@ def get_interfaces_by_mac():
393 continue398 continue
394 if is_bridge(name):399 if is_bridge(name):
395 continue400 continue
401 if is_vlan(name):
402 continue
396 mac = get_interface_mac(name)403 mac = get_interface_mac(name)
397 # some devices may not have a mac (tun0)404 # some devices may not have a mac (tun0)
398 if not mac:405 if not mac:
diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
index 9cc5e4a..89e7536 100644
--- a/tests/unittests/test_net.py
+++ b/tests/unittests/test_net.py
@@ -1463,13 +1463,16 @@ class TestNetRenderers(CiTestCase):
14631463
1464class TestGetInterfacesByMac(CiTestCase):1464class TestGetInterfacesByMac(CiTestCase):
1465 _data = {'devices': ['enp0s1', 'enp0s2', 'bond1', 'bridge1',1465 _data = {'devices': ['enp0s1', 'enp0s2', 'bond1', 'bridge1',
1466 'bridge1-nic', 'tun0'],1466 'bridge1-nic', 'tun0', 'bond1.101'],
1467 'bonds': ['bond1'],1467 'bonds': ['bond1'],
1468 'bridges': ['bridge1'],1468 'bridges': ['bridge1'],
1469 'own_macs': ['enp0s1', 'enp0s2', 'bridge1-nic', 'bridge1'],1469 'vlans': ['bond1.101'],
1470 'own_macs': ['enp0s1', 'enp0s2', 'bridge1-nic', 'bridge1',
1471 'bond1.101'],
1470 'macs': {'enp0s1': 'aa:aa:aa:aa:aa:01',1472 'macs': {'enp0s1': 'aa:aa:aa:aa:aa:01',
1471 'enp0s2': 'aa:aa:aa:aa:aa:02',1473 'enp0s2': 'aa:aa:aa:aa:aa:02',
1472 'bond1': 'aa:aa:aa:aa:aa:01',1474 'bond1': 'aa:aa:aa:aa:aa:01',
1475 'bond1.101': 'aa:aa:aa:aa:aa:01',
1473 'bridge1': 'aa:aa:aa:aa:aa:03',1476 'bridge1': 'aa:aa:aa:aa:aa:03',
1474 'bridge1-nic': 'aa:aa:aa:aa:aa:03',1477 'bridge1-nic': 'aa:aa:aa:aa:aa:03',
1475 'tun0': None}}1478 'tun0': None}}
@@ -1484,13 +1487,16 @@ class TestGetInterfacesByMac(CiTestCase):
1484 def _se_is_bridge(self, name):1487 def _se_is_bridge(self, name):
1485 return name in self.data['bridges']1488 return name in self.data['bridges']
14861489
1490 def _se_is_vlan(self, name):
1491 return name in self.data['vlans']
1492
1487 def _se_interface_has_own_mac(self, name):1493 def _se_interface_has_own_mac(self, name):
1488 return name in self.data['own_macs']1494 return name in self.data['own_macs']
14891495
1490 def _mock_setup(self):1496 def _mock_setup(self):
1491 self.data = copy.deepcopy(self._data)1497 self.data = copy.deepcopy(self._data)
1492 mocks = ('get_devicelist', 'get_interface_mac', 'is_bridge',1498 mocks = ('get_devicelist', 'get_interface_mac', 'is_bridge',
1493 'interface_has_own_mac')1499 'interface_has_own_mac', 'is_vlan')
1494 self.mocks = {}1500 self.mocks = {}
1495 for n in mocks:1501 for n in mocks:
1496 m = mock.patch('cloudinit.net.' + n,1502 m = mock.patch('cloudinit.net.' + n,
@@ -1536,6 +1542,24 @@ class TestGetInterfacesByMac(CiTestCase):
1536 mock.call('b1')],1542 mock.call('b1')],
1537 any_order=True)1543 any_order=True)
15381544
1545 def test_excludes_vlans(self):
1546 self._mock_setup()
1547 # add a device 'b1', make all return they have their "own mac",
1548 # set everything other than 'b1' to be a vlan.
1549 # then expect b1 is the only thing left.
1550 self.data['macs']['b1'] = 'aa:aa:aa:aa:aa:b1'
1551 self.data['devices'].append('b1')
1552 self.data['bonds'] = []
1553 self.data['bridges'] = []
1554 self.data['own_macs'] = self.data['devices']
1555 self.data['vlans'] = [f for f in self.data['devices'] if f != "b1"]
1556 ret = net.get_interfaces_by_mac()
1557 self.assertEqual({'aa:aa:aa:aa:aa:b1': 'b1'}, ret)
1558 self.mocks['is_vlan'].assert_has_calls(
1559 [mock.call('bridge1'), mock.call('enp0s1'), mock.call('bond1'),
1560 mock.call('b1')],
1561 any_order=True)
1562
15391563
1540def _gzip_data(data):1564def _gzip_data(data):
1541 with io.BytesIO() as iobuf:1565 with io.BytesIO() as iobuf:

Subscribers

People subscribed via source and target branches