summaryrefslogtreecommitdiff
path: root/tests/unittests/test_datasource
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unittests/test_datasource')
-rw-r--r--tests/unittests/test_datasource/test_configdrive.py7
-rw-r--r--tests/unittests/test_datasource/test_digitalocean.py14
-rw-r--r--tests/unittests/test_datasource/test_gce.py14
-rw-r--r--tests/unittests/test_datasource/test_opennebula.py9
4 files changed, 36 insertions, 8 deletions
diff --git a/tests/unittests/test_datasource/test_configdrive.py b/tests/unittests/test_datasource/test_configdrive.py
index 55153357..337be667 100644
--- a/tests/unittests/test_datasource/test_configdrive.py
+++ b/tests/unittests/test_datasource/test_configdrive.py
@@ -645,7 +645,7 @@ class TestConvertNetworkData(TestCase):
routes)
eni_renderer = eni.Renderer()
eni_renderer.render_network_state(
- self.tmp, network_state.parse_net_config_data(ncfg))
+ network_state.parse_net_config_data(ncfg), self.tmp)
with open(os.path.join(self.tmp, "etc",
"network", "interfaces"), 'r') as f:
eni_rendering = f.read()
@@ -665,8 +665,9 @@ class TestConvertNetworkData(TestCase):
ncfg = openstack.convert_net_json(NETWORK_DATA_BOND,
known_macs=KNOWN_MACS)
eni_renderer = eni.Renderer()
+
eni_renderer.render_network_state(
- self.tmp, network_state.parse_net_config_data(ncfg))
+ network_state.parse_net_config_data(ncfg), self.tmp)
with open(os.path.join(self.tmp, "etc",
"network", "interfaces"), 'r') as f:
eni_rendering = f.read()
@@ -697,7 +698,7 @@ class TestConvertNetworkData(TestCase):
known_macs=KNOWN_MACS)
eni_renderer = eni.Renderer()
eni_renderer.render_network_state(
- self.tmp, network_state.parse_net_config_data(ncfg))
+ network_state.parse_net_config_data(ncfg), self.tmp)
with open(os.path.join(self.tmp, "etc",
"network", "interfaces"), 'r') as f:
eni_rendering = f.read()
diff --git a/tests/unittests/test_datasource/test_digitalocean.py b/tests/unittests/test_datasource/test_digitalocean.py
index 9be6bc19..61d6e001 100644
--- a/tests/unittests/test_datasource/test_digitalocean.py
+++ b/tests/unittests/test_datasource/test_digitalocean.py
@@ -194,7 +194,12 @@ class TestDataSourceDigitalOcean(TestCase):
class TestNetworkConvert(TestCase):
- def _get_networking(self):
+ @mock.patch('cloudinit.net.get_interfaces_by_mac')
+ def _get_networking(self, m_get_by_mac):
+ m_get_by_mac.return_value = {
+ '04:01:57:d1:9e:01': 'ens1', '04:01:57:d1:9e:02': 'ens2',
+ 'b8:ae:ed:75:5f:9a': 'enp0s25',
+ 'ae:cc:08:7c:88:00': 'meta2p1'}
netcfg = digitalocean.convert_network_configuration(
DO_META['interfaces'], DO_META['dns']['nameservers'])
self.assertIn('config', netcfg)
@@ -302,10 +307,15 @@ class TestNetworkConvert(TestCase):
self.assertEqual(ipv4_def.get('netmask'), subn_def.get('netmask'))
self.assertNotIn('gateway', subn_def)
- def test_convert_without_private(self):
+ @mock.patch('cloudinit.net.get_interfaces_by_mac')
+ def test_convert_without_private(self, m_get_by_mac):
+ m_get_by_mac.return_value = {
+ 'b8:ae:ed:75:5f:9a': 'enp0s25',
+ 'ae:cc:08:7c:88:00': 'meta2p1'}
netcfg = digitalocean.convert_network_configuration(
DO_META_2['interfaces'], DO_META_2['dns']['nameservers'])
+ # print(netcfg)
byname = {}
for i in netcfg['config']:
if 'name' in i:
diff --git a/tests/unittests/test_datasource/test_gce.py b/tests/unittests/test_datasource/test_gce.py
index 4f83454e..3eaa58e3 100644
--- a/tests/unittests/test_datasource/test_gce.py
+++ b/tests/unittests/test_datasource/test_gce.py
@@ -5,6 +5,7 @@
# This file is part of cloud-init. See LICENSE file for license information.
import httpretty
+import mock
import re
from base64 import b64encode, b64decode
@@ -71,6 +72,11 @@ class TestDataSourceGCE(test_helpers.HttprettyTestCase):
self.ds = DataSourceGCE.DataSourceGCE(
settings.CFG_BUILTIN, None,
helpers.Paths({}))
+ self.m_platform_reports_gce = mock.patch(
+ 'cloudinit.sources.DataSourceGCE.platform_reports_gce',
+ return_value=True)
+ self.m_platform_reports_gce.start()
+ self.addCleanup(self.m_platform_reports_gce.stop)
super(TestDataSourceGCE, self).setUp()
def test_connection(self):
@@ -153,7 +159,13 @@ class TestDataSourceGCE(test_helpers.HttprettyTestCase):
def test_only_last_part_of_zone_used_for_availability_zone(self):
_set_mock_metadata()
- self.ds.get_data()
+ r = self.ds.get_data()
+ self.assertEqual(True, r)
self.assertEqual('bar', self.ds.availability_zone)
+ def test_get_data_returns_false_if_not_on_gce(self):
+ self.m_platform_reports_gce.return_value = False
+ self.assertEqual(False, self.ds.get_data())
+
+
# vi: ts=4 expandtab
diff --git a/tests/unittests/test_datasource/test_opennebula.py b/tests/unittests/test_datasource/test_opennebula.py
index a266e952..bce66125 100644
--- a/tests/unittests/test_datasource/test_opennebula.py
+++ b/tests/unittests/test_datasource/test_opennebula.py
@@ -195,7 +195,9 @@ class TestOpenNebulaDataSource(TestCase):
self.assertTrue('userdata' in results)
self.assertEqual(USER_DATA, results['userdata'])
- def test_hostname(self):
+ @mock.patch(DS_PATH + ".get_physical_nics_by_mac")
+ def test_hostname(self, m_get_phys_by_mac):
+ m_get_phys_by_mac.return_value = {'02:00:0a:12:01:01': 'eth0'}
for k in ('HOSTNAME', 'PUBLIC_IP', 'IP_PUBLIC', 'ETH0_IP'):
my_d = os.path.join(self.tmp, k)
populate_context_dir(my_d, {k: PUBLIC_IP})
@@ -205,11 +207,14 @@ class TestOpenNebulaDataSource(TestCase):
self.assertTrue('local-hostname' in results['metadata'])
self.assertEqual(PUBLIC_IP, results['metadata']['local-hostname'])
- def test_network_interfaces(self):
+ @mock.patch(DS_PATH + ".get_physical_nics_by_mac")
+ def test_network_interfaces(self, m_get_phys_by_mac):
+ m_get_phys_by_mac.return_value = {'02:00:0a:12:01:01': 'eth0'}
populate_context_dir(self.seed_dir, {'ETH0_IP': '1.2.3.4'})
results = ds.read_context_disk_dir(self.seed_dir)
self.assertTrue('network-interfaces' in results)
+ self.assertTrue('1.2.3.4' in results['network-interfaces'])
def test_find_candidates(self):
def my_devs_with(criteria):