diff options
author | Ryan Harper <ryan.harper@canonical.com> | 2017-06-09 12:35:11 -0500 |
---|---|---|
committer | Scott Moser <smoser@brickies.net> | 2017-07-18 17:04:59 -0400 |
commit | d1e8eb73aca6a3f5cee415774dcf540e934ec250 (patch) | |
tree | 93fb353a830d3d27d8114052a8acb8f7d4bf0c84 /tests/unittests | |
parent | e80517ae6aea49c9ab3bd622a33fee44014f485f (diff) | |
download | vyos-cloud-init-d1e8eb73aca6a3f5cee415774dcf540e934ec250.tar.gz vyos-cloud-init-d1e8eb73aca6a3f5cee415774dcf540e934ec250.zip |
sysconfig: include GATEWAY value if set in subnet
Render the GATEWAY= value in interface files which have a gateway in the
subnet configuration.
LP: #1686856
Diffstat (limited to 'tests/unittests')
-rw-r--r-- | tests/unittests/test_distros/test_netconfig.py | 2 | ||||
-rw-r--r-- | tests/unittests/test_net.py | 38 |
2 files changed, 40 insertions, 0 deletions
diff --git a/tests/unittests/test_distros/test_netconfig.py b/tests/unittests/test_distros/test_netconfig.py index 83580cc0..dffe1781 100644 --- a/tests/unittests/test_distros/test_netconfig.py +++ b/tests/unittests/test_distros/test_netconfig.py @@ -479,6 +479,7 @@ BOOTPROTO=none DEVICE=eth0 IPADDR=192.168.1.5 NETMASK=255.255.255.0 +GATEWAY=192.168.1.254 NM_CONTROLLED=no ONBOOT=yes TYPE=Ethernet @@ -627,6 +628,7 @@ IPV6_AUTOCONF=no BOOTPROTO=none DEVICE=eth0 IPV6ADDR=2607:f0d0:1002:0011::2/64 +GATEWAY=2607:f0d0:1002:0011::1 IPV6INIT=yes NM_CONTROLLED=no ONBOOT=yes diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py index 06e8f094..71c9c457 100644 --- a/tests/unittests/test_net.py +++ b/tests/unittests/test_net.py @@ -828,6 +828,7 @@ pre-down route del -net 10.0.0.0 netmask 255.0.0.0 gw 11.0.0.1 metric 3 || true } } + CONFIG_V1_EXPLICIT_LOOPBACK = { 'version': 1, 'config': [{'name': 'eth0', 'type': 'physical', @@ -836,6 +837,18 @@ CONFIG_V1_EXPLICIT_LOOPBACK = { 'subnets': [{'control': 'auto', 'type': 'loopback'}]}, ]} + +CONFIG_V1_SIMPLE_SUBNET = { + 'version': 1, + 'config': [{'mac_address': '52:54:00:12:34:00', + 'name': 'interface0', + 'subnets': [{'address': '10.0.2.15', + 'gateway': '10.0.2.2', + 'netmask': '255.255.255.0', + 'type': 'static'}], + 'type': 'physical'}]} + + DEFAULT_DEV_ATTRS = { 'eth1000': { "bridge": False, @@ -1135,6 +1148,31 @@ USERCTL=no with open(os.path.join(render_dir, fn)) as fh: self.assertEqual(expected_content, fh.read()) + def test_network_config_v1_samples(self): + ns = network_state.parse_net_config_data(CONFIG_V1_SIMPLE_SUBNET) + render_dir = self.tmp_path("render") + os.makedirs(render_dir) + renderer = sysconfig.Renderer() + renderer.render_network_state(ns, render_dir) + found = dir2dict(render_dir) + nspath = '/etc/sysconfig/network-scripts/' + self.assertNotIn(nspath + 'ifcfg-lo', found.keys()) + expected = """\ +# Created by cloud-init on instance boot automatically, do not edit. +# +BOOTPROTO=none +DEVICE=interface0 +GATEWAY=10.0.2.2 +HWADDR=52:54:00:12:34:00 +IPADDR=10.0.2.15 +NETMASK=255.255.255.0 +NM_CONTROLLED=no +ONBOOT=yes +TYPE=Ethernet +USERCTL=no +""" + self.assertEqual(expected, found[nspath + 'ifcfg-interface0']) + def test_config_with_explicit_loopback(self): ns = network_state.parse_net_config_data(CONFIG_V1_EXPLICIT_LOOPBACK) render_dir = self.tmp_path("render") |