summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorScott Moser <smoser@brickies.net>2016-11-08 20:59:23 -0500
committerScott Moser <smoser@brickies.net>2016-11-22 16:31:43 -0500
commit6e92c5f2fccaad24afb89f79f260cb496fb8d67f (patch)
treec2a106a958086e7a4a5538846475313346355782 /tests
parent11b1aba4597379051e6b934e2b8f5a455e26ef14 (diff)
downloadvyos-cloud-init-6e92c5f2fccaad24afb89f79f260cb496fb8d67f.tar.gz
vyos-cloud-init-6e92c5f2fccaad24afb89f79f260cb496fb8d67f.zip
net/cmdline: Consider ip= or ip6= on command line not only ip=
The previous behavior would miss ip6= on the command line and would not pay attention to the written net-* or net6-* files if only ip6= was found. The fix here enables parsing the files if either ip= or ip6= is found, and adds some tests as well. LP: #1639930
Diffstat (limited to 'tests')
-rw-r--r--tests/unittests/test_net.py72
1 files changed, 53 insertions, 19 deletions
diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
index 78c080ca..77e4013b 100644
--- a/tests/unittests/test_net.py
+++ b/tests/unittests/test_net.py
@@ -8,6 +8,8 @@ from cloudinit import util
from .helpers import dir2dict
from .helpers import mock
+from .helpers import populate_dir
+from .helpers import TempDirTestCase
from .helpers import TestCase
import base64
@@ -54,22 +56,9 @@ DHCP_EXPECTED_1 = {
}
DHCP6_CONTENT_1 = """
-DEVICE=eno1
+DEVICE6=eno1
HOSTNAME=
DNSDOMAIN=
-reason='PREINIT'
-interface='eno1'
-DEVICE=eno1
-HOSTNAME=
-DNSDOMAIN=
-reason='FAIL'
-interface='eno1'
-DEVICE=eno1
-HOSTNAME=
-DNSDOMAIN=
-reason='PREINIT6'
-interface='eno1'
-DEVICE=eno1
IPV6PROTO=dhcp6
IPV6ADDR=2001:67c:1562:8010:0:1::
IPV6NETMASK=64
@@ -77,11 +66,6 @@ IPV6DNS0=2001:67c:1562:8010::2:1
IPV6DOMAINSEARCH=
HOSTNAME=
DNSDOMAIN=
-reason='BOUND6'
-interface='eno1'
-new_ip6_address='2001:67c:1562:8010:0:1::'
-new_ip6_prefixlen='64'
-new_dhcp6_name_servers='2001:67c:1562:8010::2:1'
"""
DHCP6_EXPECTED_1 = {
@@ -677,6 +661,56 @@ class TestCmdlineConfigParsing(TestCase):
self.assertEqual(found, self.simple_cfg)
+class TestCmdlineReadKernelConfig(TempDirTestCase):
+ def test_ip_cmdline_read_kernel_cmdline_ip(self):
+ content = {'net-eth0.conf': DHCP_CONTENT_1}
+ populate_dir(self.tmp, content)
+ files = [os.path.join(self.tmp, k) for k in content.keys()]
+ found = cmdline.read_kernel_cmdline_config(
+ files=files, cmdline='foo ip=dhcp')
+ self.assertEqual(found['version'], 1)
+ self.assertEqual(found['config'], [DHCP_EXPECTED_1])
+
+ def test_ip_cmdline_read_kernel_cmdline_ip6(self):
+ content = {'net6-eno1.conf': DHCP6_CONTENT_1}
+ populate_dir(self.tmp, content)
+ files = [os.path.join(self.tmp, k) for k in content.keys()]
+ found = cmdline.read_kernel_cmdline_config(
+ files=files, cmdline='foo ip6=dhcp root=/dev/sda')
+ self.assertEqual(
+ found,
+ {'version': 1, 'config': [
+ {'type': 'physical', 'name': 'eno1',
+ 'subnets': [
+ {'dns_nameservers': ['2001:67c:1562:8010::2:1'],
+ 'control': 'manual', 'type': 'dhcp6', 'netmask': '64'}]}]})
+
+ def test_ip_cmdline_read_kernel_cmdline_none(self):
+ # if there is no ip= or ip6= on cmdline, return value should be None
+ content = {'net6-eno1.conf': DHCP6_CONTENT_1}
+ populate_dir(self.tmp, content)
+ files = [os.path.join(self.tmp, k) for k in content.keys()]
+ found = cmdline.read_kernel_cmdline_config(
+ files=files, cmdline='foo root=/dev/sda')
+ self.assertEqual(found, None)
+
+ def test_ip_cmdline_both_ip_ip6(self):
+ content = {'net-eth0.conf': DHCP_CONTENT_1,
+ 'net6-eth0.conf': DHCP6_CONTENT_1.replace('eno1', 'eth0')}
+ populate_dir(self.tmp, content)
+ files = [os.path.join(self.tmp, k) for k in sorted(content.keys())]
+ found = cmdline.read_kernel_cmdline_config(
+ files=files, cmdline='foo ip=dhcp ip6=dhcp')
+
+ eth0 = copy.deepcopy(DHCP_EXPECTED_1)
+ eth0['subnets'].append(
+ {'control': 'manual', 'type': 'dhcp6',
+ 'netmask': '64', 'dns_nameservers': ['2001:67c:1562:8010::2:1']})
+ expected = [eth0]
+ self.assertEqual(found['version'], 1)
+ self.assertEqual(found['config'], expected)
+
+
class TestEniRoundTrip(TestCase):
def setUp(self):
super(TestCase, self).setUp()