summaryrefslogtreecommitdiff
path: root/tests/unittests
diff options
context:
space:
mode:
authorScott Moser <smoser@brickies.net>2017-07-19 09:28:52 -0400
committerScott Moser <smoser@brickies.net>2017-07-19 09:51:55 -0400
commitc0060fe4892197179a5cfbfd3239cf3b6c3e5029 (patch)
treecd1ae5e0f2f4cd889d9565f1f450e9a5673aa51f /tests/unittests
parent865e941f3f88c7daeafbf1eab856e02ce2b6a5f7 (diff)
downloadvyos-cloud-init-c0060fe4892197179a5cfbfd3239cf3b6c3e5029.tar.gz
vyos-cloud-init-c0060fe4892197179a5cfbfd3239cf3b6c3e5029.zip
net: fix renaming of nics to support mac addresses written in upper case.
The network device renaming code previously required the case of the mac address input to match that of the data read from the system. For example, if user provided network config with mac address in upper case, then cloud-init would not rename the device correctly as /sys/class/net/address stores lower case values. The fix here is to always compare lower case mac addresses. LP: #1705147
Diffstat (limited to 'tests/unittests')
-rw-r--r--tests/unittests/test_net.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
index 71c9c457..76721bab 100644
--- a/tests/unittests/test_net.py
+++ b/tests/unittests/test_net.py
@@ -2176,5 +2176,32 @@ class TestRenameInterfaces(CiTestCase):
capture=True),
])
+ @mock.patch('cloudinit.util.subp')
+ def test_rename_macs_case_insensitive(self, mock_subp):
+ """_rename_interfaces must support upper or lower case macs."""
+ renames = [
+ ('aa:aa:aa:aa:aa:aa', 'en0', None, None),
+ ('BB:BB:BB:BB:BB:BB', 'en1', None, None),
+ ('cc:cc:cc:cc:cc:cc', 'en2', None, None),
+ ('DD:DD:DD:DD:DD:DD', 'en3', None, None),
+ ]
+ current_info = {
+ 'eth0': {'downable': True, 'mac': 'AA:AA:AA:AA:AA:AA',
+ 'name': 'eth0', 'up': False},
+ 'eth1': {'downable': True, 'mac': 'bb:bb:bb:bb:bb:bb',
+ 'name': 'eth1', 'up': False},
+ 'eth2': {'downable': True, 'mac': 'cc:cc:cc:cc:cc:cc',
+ 'name': 'eth2', 'up': False},
+ 'eth3': {'downable': True, 'mac': 'DD:DD:DD:DD:DD:DD',
+ 'name': 'eth3', 'up': False},
+ }
+ net._rename_interfaces(renames, current_info=current_info)
+
+ expected = [
+ mock.call(['ip', 'link', 'set', 'eth%d' % i, 'name', 'en%d' % i],
+ capture=True)
+ for i in range(len(renames))]
+ mock_subp.assert_has_calls(expected)
+
# vi: ts=4 expandtab