summaryrefslogtreecommitdiff
path: root/tests/unittests
diff options
context:
space:
mode:
authorThomas Berger <loki@lokis-chaos.de>2018-09-18 07:16:40 +0000
committerServer Team CI Bot <josh.powers+server-team-bot@canonical.com>2018-09-18 07:16:40 +0000
commit98d18c31c8759add858096dea53bc093c7cc9caa (patch)
treeed4403e191ebbde628007c6f88d984a0dfa6481e /tests/unittests
parentc714651c1988a17f457426de63cdb8514d5a81b4 (diff)
downloadvyos-cloud-init-98d18c31c8759add858096dea53bc093c7cc9caa.tar.gz
vyos-cloud-init-98d18c31c8759add858096dea53bc093c7cc9caa.zip
net_util: ensure static configs have netmask in translate_network result
If a DataSource provides a network configuration in version 2 and runs on a distro which does not have a network renderer class in use, then the conversion of V2 to eni results in static ip configurations with subnet prefix-length (192.168.23.1/24) rather than explicit netmask value. When sending such a config to net_util.translate_network the resulting dictionary is missing the 'netmask' key for static configured addresses breaking network configurations on multiple distributions. This patch detects static ip configurations using prefix-length and converts the format into the previous 'address' and 'netmask' parts to keep compatibility for these distribtuions until they move to the v2 network configuration. LP: #1792454
Diffstat (limited to 'tests/unittests')
-rw-r--r--tests/unittests/test_distros/test_netconfig.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/unittests/test_distros/test_netconfig.py b/tests/unittests/test_distros/test_netconfig.py
index 740fb76c..9bbff451 100644
--- a/tests/unittests/test_distros/test_netconfig.py
+++ b/tests/unittests/test_distros/test_netconfig.py
@@ -34,6 +34,19 @@ auto eth1
iface eth1 inet dhcp
'''
+BASE_NET_CFG_FROM_V2 = '''
+auto lo
+iface lo inet loopback
+
+auto eth0
+iface eth0 inet static
+ address 192.168.1.5/24
+ gateway 192.168.1.254
+
+auto eth1
+iface eth1 inet dhcp
+'''
+
BASE_NET_CFG_IPV6 = '''
auto lo
iface lo inet loopback
@@ -262,6 +275,32 @@ hn0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
'''), results[rc_conf])
self.assertEqual(0o644, get_mode(rc_conf, tmpd))
+ def test_simple_write_freebsd_from_v2eni(self):
+ fbsd_distro = self._get_distro('freebsd')
+
+ rc_conf = '/etc/rc.conf'
+ read_bufs = {
+ rc_conf: 'initial-rc-conf-not-validated',
+ '/etc/resolv.conf': 'initial-resolv-conf-not-validated',
+ }
+
+ tmpd = self.tmp_dir()
+ populate_dir(tmpd, read_bufs)
+ with self.reRooted(tmpd):
+ with mock.patch("cloudinit.distros.freebsd.util.subp",
+ return_value=('vtnet0', '')):
+ fbsd_distro.apply_network(BASE_NET_CFG_FROM_V2, False)
+ results = dir2dict(tmpd)
+
+ self.assertIn(rc_conf, results)
+ self.assertCfgEquals(
+ dedent('''\
+ ifconfig_vtnet0="192.168.1.5 netmask 255.255.255.0"
+ ifconfig_vtnet1="DHCP"
+ defaultrouter="192.168.1.254"
+ '''), results[rc_conf])
+ self.assertEqual(0o644, get_mode(rc_conf, tmpd))
+
def test_apply_network_config_fallback_freebsd(self):
fbsd_distro = self._get_distro('freebsd')