summaryrefslogtreecommitdiff
path: root/tests/unittests/test_datasource/test_nocloud.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2016-08-11 06:43:17 -0600
committerScott Moser <smoser@ubuntu.com>2016-08-11 09:15:51 -0600
commitcdcac86848a570eb657af428fe4d2bd4ce3bceb1 (patch)
treed3316457e0797ffb786987f42632a7add0e9dd1a /tests/unittests/test_datasource/test_nocloud.py
parentdb72092b65ecc57bafe1ac6e81c99115f6bd1936 (diff)
downloadvyos-cloud-init-cdcac86848a570eb657af428fe4d2bd4ce3bceb1.tar.gz
vyos-cloud-init-cdcac86848a570eb657af428fe4d2bd4ce3bceb1.zip
NoCloud: fix bug providing network-interfaces via meta-data.
This fixes an issue with the NoCloud datasource where it would not recognize the 'network-interfaces' key provided in meta-data. LP: 1577982
Diffstat (limited to 'tests/unittests/test_datasource/test_nocloud.py')
-rw-r--r--tests/unittests/test_datasource/test_nocloud.py85
1 files changed, 84 insertions, 1 deletions
diff --git a/tests/unittests/test_datasource/test_nocloud.py b/tests/unittests/test_datasource/test_nocloud.py
index b0fa1130..f6a46ce9 100644
--- a/tests/unittests/test_datasource/test_nocloud.py
+++ b/tests/unittests/test_datasource/test_nocloud.py
@@ -6,7 +6,7 @@ from ..helpers import TestCase, populate_dir, mock, ExitStack
import os
import shutil
import tempfile
-
+import textwrap
import yaml
@@ -129,6 +129,89 @@ class TestNoCloudDataSource(TestCase):
self.assertFalse(dsrc.vendordata)
self.assertTrue(ret)
+ def test_metadata_network_interfaces(self):
+ gateway = "103.225.10.1"
+ md = {
+ 'instance-id': 'i-abcd',
+ 'local-hostname': 'hostname1',
+ 'network-interfaces': textwrap.dedent("""\
+ auto eth0
+ iface eth0 inet static
+ hwaddr 00:16:3e:70:e1:04
+ address 103.225.10.12
+ netmask 255.255.255.0
+ gateway """ + gateway + """
+ dns-servers 8.8.8.8""")}
+
+ populate_dir(
+ os.path.join(self.paths.seed_dir, "nocloud"),
+ {'user-data': b"ud",
+ 'meta-data': yaml.dump(md) + "\n"})
+
+ sys_cfg = {'datasource': {'NoCloud': {'fs_label': None}}}
+
+ ds = DataSourceNoCloud.DataSourceNoCloud
+
+ dsrc = ds(sys_cfg=sys_cfg, distro=None, paths=self.paths)
+ ret = dsrc.get_data()
+ self.assertTrue(ret)
+ # very simple check just for the strings above
+ self.assertIn(gateway, str(dsrc.network_config))
+
+ def test_metadata_network_config(self):
+ # network-config needs to get into network_config
+ netconf = {'version': 1,
+ 'config': [{'type': 'physical', 'name': 'interface0',
+ 'subnets': [{'type': 'dhcp'}]}]}
+ populate_dir(
+ os.path.join(self.paths.seed_dir, "nocloud"),
+ {'user-data': b"ud",
+ 'meta-data': "instance-id: IID\n",
+ 'network-config': yaml.dump(netconf) + "\n"})
+
+ sys_cfg = {'datasource': {'NoCloud': {'fs_label': None}}}
+
+ ds = DataSourceNoCloud.DataSourceNoCloud
+
+ dsrc = ds(sys_cfg=sys_cfg, distro=None, paths=self.paths)
+ ret = dsrc.get_data()
+ self.assertTrue(ret)
+ self.assertEqual(netconf, dsrc.network_config)
+
+ def test_metadata_network_config_over_interfaces(self):
+ # network-config should override meta-data/network-interfaces
+ gateway = "103.225.10.1"
+ md = {
+ 'instance-id': 'i-abcd',
+ 'local-hostname': 'hostname1',
+ 'network-interfaces': textwrap.dedent("""\
+ auto eth0
+ iface eth0 inet static
+ hwaddr 00:16:3e:70:e1:04
+ address 103.225.10.12
+ netmask 255.255.255.0
+ gateway """ + gateway + """
+ dns-servers 8.8.8.8""")}
+
+ netconf = {'version': 1,
+ 'config': [{'type': 'physical', 'name': 'interface0',
+ 'subnets': [{'type': 'dhcp'}]}]}
+ populate_dir(
+ os.path.join(self.paths.seed_dir, "nocloud"),
+ {'user-data': b"ud",
+ 'meta-data': yaml.dump(md) + "\n",
+ 'network-config': yaml.dump(netconf) + "\n"})
+
+ sys_cfg = {'datasource': {'NoCloud': {'fs_label': None}}}
+
+ ds = DataSourceNoCloud.DataSourceNoCloud
+
+ dsrc = ds(sys_cfg=sys_cfg, distro=None, paths=self.paths)
+ ret = dsrc.get_data()
+ self.assertTrue(ret)
+ self.assertEqual(netconf, dsrc.network_config)
+ self.assertNotIn(gateway, str(dsrc.network_config))
+
class TestParseCommandLineData(TestCase):