diff options
author | Scott Moser <smoser@ubuntu.com> | 2018-03-16 15:43:27 -0600 |
---|---|---|
committer | Chad Smith <chad.smith@canonical.com> | 2018-03-16 15:43:27 -0600 |
commit | de34dc7c467b318b2d04d065f8d752c7a530e155 (patch) | |
tree | 768e0401dcdb4d6c428b516abe853bfbd8a3086a /tests/unittests | |
parent | 7ce839f846de705980839f9c7851bd0fd7353aad (diff) | |
download | vyos-cloud-init-de34dc7c467b318b2d04d065f8d752c7a530e155.tar.gz vyos-cloud-init-de34dc7c467b318b2d04d065f8d752c7a530e155.zip |
net: recognize iscsi root cases without ip= on kernel command line.
When 'ip=' or 'ip6=' is found on the kernel command line,
cloud-init will consider read network config from /run/net-*.conf files.
There are some iscsi-root scenarios where initramfs configures networking
but the ip= parameter is not present. 2 such cases are:
a.) static config in /etc/iscsi/iscsi.initramfs (copied into the
initramfs)
b.) iBft
This changes cloud-init to consider initramfs provided networking
information if:
* there are /run/net-* files and
* (ip= or ip6 is on the command line) or open-iscsi.interface file
exists.
LP: #1752391
Diffstat (limited to 'tests/unittests')
-rw-r--r-- | tests/unittests/test_net.py | 61 |
1 files changed, 43 insertions, 18 deletions
diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py index 9cf11f2e..84a0eabf 100644 --- a/tests/unittests/test_net.py +++ b/tests/unittests/test_net.py @@ -12,10 +12,8 @@ from cloudinit.sources.helpers import openstack from cloudinit import temp_utils from cloudinit import util -from cloudinit.tests.helpers import CiTestCase -from cloudinit.tests.helpers import dir2dict -from cloudinit.tests.helpers import mock -from cloudinit.tests.helpers import populate_dir +from cloudinit.tests.helpers import ( + CiTestCase, FilesystemMockingTestCase, dir2dict, mock, populate_dir) import base64 import copy @@ -2186,27 +2184,49 @@ class TestCmdlineConfigParsing(CiTestCase): self.assertEqual(found, self.simple_cfg) -class TestCmdlineReadKernelConfig(CiTestCase): +class TestCmdlineReadKernelConfig(FilesystemMockingTestCase): macs = { 'eth0': '14:02:ec:42:48:00', 'eno1': '14:02:ec:42:48:01', } - def test_ip_cmdline_read_kernel_cmdline_ip(self): - content = {'net-eth0.conf': DHCP_CONTENT_1} - files = sorted(populate_dir(self.tmp_dir(), content)) + def test_ip_cmdline_without_ip(self): + content = {'/run/net-eth0.conf': DHCP_CONTENT_1, + cmdline._OPEN_ISCSI_INTERFACE_FILE: "eth0\n"} + exp1 = copy.deepcopy(DHCP_EXPECTED_1) + exp1['mac_address'] = self.macs['eth0'] + + root = self.tmp_dir() + populate_dir(root, content) + self.reRoot(root) + found = cmdline.read_kernel_cmdline_config( - files=files, cmdline='foo ip=dhcp', mac_addrs=self.macs) + cmdline='foo root=/root/bar', mac_addrs=self.macs) + self.assertEqual(found['version'], 1) + self.assertEqual(found['config'], [exp1]) + + def test_ip_cmdline_read_kernel_cmdline_ip(self): + content = {'/run/net-eth0.conf': DHCP_CONTENT_1} exp1 = copy.deepcopy(DHCP_EXPECTED_1) exp1['mac_address'] = self.macs['eth0'] + + root = self.tmp_dir() + populate_dir(root, content) + self.reRoot(root) + + found = cmdline.read_kernel_cmdline_config( + cmdline='foo ip=dhcp', mac_addrs=self.macs) self.assertEqual(found['version'], 1) self.assertEqual(found['config'], [exp1]) def test_ip_cmdline_read_kernel_cmdline_ip6(self): - content = {'net6-eno1.conf': DHCP6_CONTENT_1} - files = sorted(populate_dir(self.tmp_dir(), content)) + content = {'/run/net6-eno1.conf': DHCP6_CONTENT_1} + root = self.tmp_dir() + populate_dir(root, content) + self.reRoot(root) + found = cmdline.read_kernel_cmdline_config( - files=files, cmdline='foo ip6=dhcp root=/dev/sda', + cmdline='foo ip6=dhcp root=/dev/sda', mac_addrs=self.macs) self.assertEqual( found, @@ -2226,18 +2246,23 @@ class TestCmdlineReadKernelConfig(CiTestCase): self.assertIsNone(found) def test_ip_cmdline_both_ip_ip6(self): - content = {'net-eth0.conf': DHCP_CONTENT_1, - 'net6-eth0.conf': DHCP6_CONTENT_1.replace('eno1', 'eth0')} - files = sorted(populate_dir(self.tmp_dir(), content)) - found = cmdline.read_kernel_cmdline_config( - files=files, cmdline='foo ip=dhcp ip6=dhcp', mac_addrs=self.macs) - + content = { + '/run/net-eth0.conf': DHCP_CONTENT_1, + '/run/net6-eth0.conf': DHCP6_CONTENT_1.replace('eno1', 'eth0')} eth0 = copy.deepcopy(DHCP_EXPECTED_1) eth0['mac_address'] = self.macs['eth0'] eth0['subnets'].append( {'control': 'manual', 'type': 'dhcp6', 'netmask': '64', 'dns_nameservers': ['2001:67c:1562:8010::2:1']}) expected = [eth0] + + root = self.tmp_dir() + populate_dir(root, content) + self.reRoot(root) + + found = cmdline.read_kernel_cmdline_config( + cmdline='foo ip=dhcp ip6=dhcp', mac_addrs=self.macs) + self.assertEqual(found['version'], 1) self.assertEqual(found['config'], expected) |