summaryrefslogtreecommitdiff
path: root/tests/unittests/test_net.py
diff options
context:
space:
mode:
authorKurt Stieger <kurt@easygo.at>2019-03-04 15:54:25 +0000
committerServer Team CI Bot <josh.powers+server-team-bot@canonical.com>2019-03-04 15:54:25 +0000
commitbd35300ba36bd63686715fa9661516a518781f6d (patch)
tree9a2a0f4d5b8ec44575418269fb3e1b547c6ad506 /tests/unittests/test_net.py
parentf2f530e5960ce8afd33e7f62a9b5d8898a6d0d79 (diff)
downloadvyos-cloud-init-bd35300ba36bd63686715fa9661516a518781f6d.tar.gz
vyos-cloud-init-bd35300ba36bd63686715fa9661516a518781f6d.zip
net: append type:dhcp[46] only if dhcp[46] is True in v2 netconfig
When providing netplan configuration to cloud-init, the internal network state would enable DHCP if the 'dhcp' key was present in the source config. In netplan, dhcp[46] is a boolean and the value of the boolean should control whether DHCP is enabled rather than the presence of the key. This issue leaded to inconsistant sysconfig/network-scripts on fedora. 'BOOTPROTO' was always 'dhcp', even if the address config was static. After this change a dhcp subnet is added only if the 'dhcp' setting in source cfg dict is True. LP: #1818032
Diffstat (limited to 'tests/unittests/test_net.py')
-rw-r--r--tests/unittests/test_net.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/unittests/test_net.py b/tests/unittests/test_net.py
index f001ae5a..e3b9e02b 100644
--- a/tests/unittests/test_net.py
+++ b/tests/unittests/test_net.py
@@ -406,6 +406,23 @@ network:
- maas
"""
+NETPLAN_DHCP_FALSE = """
+version: 2
+ethernets:
+ ens3:
+ match:
+ macaddress: 52:54:00:ab:cd:ef
+ dhcp4: false
+ dhcp6: false
+ addresses:
+ - 192.168.42.100/24
+ - 2001:db8::100/32
+ gateway4: 192.168.42.1
+ gateway6: 2001:db8::1
+ nameservers:
+ search: [example.com]
+ addresses: [192.168.42.53, 1.1.1.1]
+"""
# Examples (and expected outputs for various renderers).
OS_SAMPLES = [
@@ -2590,6 +2607,50 @@ USERCTL=no
config = sysconfig.ConfigObj(nm_cfg)
self.assertIn('ifcfg-rh', config['main']['plugins'])
+ def test_netplan_dhcp_false_disable_dhcp_in_state(self):
+ """netplan config with dhcp[46]: False should not add dhcp in state"""
+ net_config = yaml.load(NETPLAN_DHCP_FALSE)
+ ns = network_state.parse_net_config_data(net_config,
+ skip_broken=False)
+
+ dhcp_found = [snet for iface in ns.iter_interfaces()
+ for snet in iface['subnets'] if 'dhcp' in snet['type']]
+
+ self.assertEqual([], dhcp_found)
+
+ def test_netplan_dhcp_false_no_dhcp_in_sysconfig(self):
+ """netplan cfg with dhcp[46]: False should not have bootproto=dhcp"""
+
+ entry = {
+ 'yaml': NETPLAN_DHCP_FALSE,
+ 'expected_sysconfig': {
+ 'ifcfg-ens3': textwrap.dedent("""\
+ BOOTPROTO=none
+ DEFROUTE=yes
+ DEVICE=ens3
+ DNS1=192.168.42.53
+ DNS2=1.1.1.1
+ DOMAIN=example.com
+ GATEWAY=192.168.42.1
+ HWADDR=52:54:00:ab:cd:ef
+ IPADDR=192.168.42.100
+ IPV6ADDR=2001:db8::100/32
+ IPV6INIT=yes
+ IPV6_DEFAULTGW=2001:db8::1
+ NETMASK=255.255.255.0
+ NM_CONTROLLED=no
+ ONBOOT=yes
+ STARTMODE=auto
+ TYPE=Ethernet
+ USERCTL=no
+ """),
+ }
+ }
+
+ found = self._render_and_read(network_config=yaml.load(entry['yaml']))
+ self._compare_files_to_expected(entry['expected_sysconfig'], found)
+ self._assert_headers(found)
+
class TestOpenSuseSysConfigRendering(CiTestCase):