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_altcloud.py24
-rw-r--r--tests/unittests/test_datasource/test_azure.py4
-rw-r--r--tests/unittests/test_datasource/test_configdrive.py2
-rw-r--r--tests/unittests/test_datasource/test_nocloud.py1
-rw-r--r--tests/unittests/test_datasource/test_smartos.py33
5 files changed, 34 insertions, 30 deletions
diff --git a/tests/unittests/test_datasource/test_altcloud.py b/tests/unittests/test_datasource/test_altcloud.py
index bda61c7e..eaaa90e6 100644
--- a/tests/unittests/test_datasource/test_altcloud.py
+++ b/tests/unittests/test_datasource/test_altcloud.py
@@ -33,6 +33,8 @@ import cloudinit.sources.DataSourceAltCloud
from cloudinit.sources.DataSourceAltCloud import DataSourceAltCloud
from cloudinit.sources.DataSourceAltCloud import read_user_data_callback
+OS_UNAME_ORIG = getattr(os, 'uname')
+
def _write_cloud_info_file(value):
'''
@@ -104,11 +106,16 @@ class TestGetCloudType(TestCase):
def setUp(self):
'''Set up.'''
self.paths = helpers.Paths({'cloud_dir': '/tmp'})
+ # We have a different code path for arm to deal with LP1243287
+ # We have to switch arch to x86_64 to avoid test failure
+ force_arch('x86_64')
def tearDown(self):
# Reset
cloudinit.sources.DataSourceAltCloud.CMD_DMI_SYSTEM = \
['dmidecode', '--string', 'system-product-name']
+ # Return back to original arch
+ force_arch()
def test_rhev(self):
'''
@@ -238,6 +245,9 @@ class TestGetDataNoCloudInfoFile(TestCase):
self.paths = helpers.Paths({'cloud_dir': '/tmp'})
cloudinit.sources.DataSourceAltCloud.CLOUD_INFO_FILE = \
'no such file'
+ # We have a different code path for arm to deal with LP1243287
+ # We have to switch arch to x86_64 to avoid test failure
+ force_arch('x86_64')
def tearDown(self):
# Reset
@@ -245,6 +255,8 @@ class TestGetDataNoCloudInfoFile(TestCase):
'/etc/sysconfig/cloud-info'
cloudinit.sources.DataSourceAltCloud.CMD_DMI_SYSTEM = \
['dmidecode', '--string', 'system-product-name']
+ # Return back to original arch
+ force_arch()
def test_rhev_no_cloud_file(self):
'''Test No cloud info file module get_data() forcing RHEV.'''
@@ -442,4 +454,16 @@ class TestReadUserDataCallback(TestCase):
_remove_user_data_files(self.mount_dir)
self.assertEquals(None, read_user_data_callback(self.mount_dir))
+
+def force_arch(arch=None):
+
+ def _os_uname():
+ return ('LINUX', 'NODENAME', 'RELEASE', 'VERSION', arch)
+
+ if arch:
+ setattr(os, 'uname', _os_uname)
+ elif arch is None:
+ setattr(os, 'uname', OS_UNAME_ORIG)
+
+
# vi: ts=4 expandtab
diff --git a/tests/unittests/test_datasource/test_azure.py b/tests/unittests/test_datasource/test_azure.py
index 44c537f4..ccfd672a 100644
--- a/tests/unittests/test_datasource/test_azure.py
+++ b/tests/unittests/test_datasource/test_azure.py
@@ -352,13 +352,13 @@ class TestAzureDataSource(MockerTestCase):
ovf_env_path = os.path.join(self.waagent_d, 'ovf-env.xml')
self.assertTrue(os.path.exists(ovf_env_path))
self.assertEqual(xml, load_file(ovf_env_path))
-
+
def test_existing_ovf_same(self):
# waagent/SharedConfig left alone if found ovf-env.xml same as cached
odata = {'UserData': base64.b64encode("SOMEUSERDATA")}
data = {'ovfcontent': construct_valid_ovf_env(data=odata)}
- populate_dir(self.waagent_d,
+ populate_dir(self.waagent_d,
{'ovf-env.xml': data['ovfcontent'],
'otherfile': 'otherfile-content',
'SharedConfig.xml': 'mysharedconfig'})
diff --git a/tests/unittests/test_datasource/test_configdrive.py b/tests/unittests/test_datasource/test_configdrive.py
index 937b88c1..4404668e 100644
--- a/tests/unittests/test_datasource/test_configdrive.py
+++ b/tests/unittests/test_datasource/test_configdrive.py
@@ -166,7 +166,7 @@ class TestConfigDriveDataSource(MockerTestCase):
my_mock.replay()
device = cfg_ds.device_name_to_device(name)
self.assertEquals(dev_name, device)
-
+
def test_dev_ec2_map(self):
populate_dir(self.tmp, CFG_DRIVE_FILES_V2)
cfg_ds = ds.DataSourceConfigDrive(settings.CFG_BUILTIN,
diff --git a/tests/unittests/test_datasource/test_nocloud.py b/tests/unittests/test_datasource/test_nocloud.py
index af575a10..a65833eb 100644
--- a/tests/unittests/test_datasource/test_nocloud.py
+++ b/tests/unittests/test_datasource/test_nocloud.py
@@ -133,6 +133,7 @@ class TestNoCloudDataSource(MockerTestCase):
self.assertFalse(dsrc.vendordata)
self.assertTrue(ret)
+
class TestParseCommandLineData(MockerTestCase):
def test_parse_cmdline_data_valid(self):
diff --git a/tests/unittests/test_datasource/test_smartos.py b/tests/unittests/test_datasource/test_smartos.py
index 19282bac..8f9fa27d 100644
--- a/tests/unittests/test_datasource/test_smartos.py
+++ b/tests/unittests/test_datasource/test_smartos.py
@@ -158,6 +158,11 @@ class TestSmartOSDataSource(helpers.FilesystemMockingTestCase):
def _dmi_data():
return dmi_data
+ def _os_uname():
+ # LP: #1243287. tests assume this runs, but running test on
+ # arm would cause them all to fail.
+ return ('LINUX', 'NODENAME', 'RELEASE', 'VERSION', 'x86_64')
+
if sys_cfg is None:
sys_cfg = {}
@@ -168,6 +173,7 @@ class TestSmartOSDataSource(helpers.FilesystemMockingTestCase):
self.apply_patches([(mod, 'LEGACY_USER_D', self.legacy_user_d)])
self.apply_patches([(mod, 'get_serial', _get_serial)])
self.apply_patches([(mod, 'dmi_data', _dmi_data)])
+ self.apply_patches([(os, 'uname', _os_uname)])
dsrc = mod.DataSourceSmartOS(sys_cfg, distro=None,
paths=self.paths)
return dsrc
@@ -334,33 +340,6 @@ class TestSmartOSDataSource(helpers.FilesystemMockingTestCase):
shebang = f.readlines()[0].strip()
self.assertEquals(shebang, "#!/usr/bin/perl")
- def test_scripts_removed(self):
- """
- Since SmartOS requires that the user script is fetched
- each boot, we want to make sure that the information
- is backed-up for user-review later.
-
- This tests the behavior of when a script is removed. It makes
- sure that a) the previous script is backed-up; and 2) that
- there is no script remaining.
- """
-
- script_d = os.path.join(self.tmp, "instance", "data")
- os.makedirs(script_d)
-
- test_script_f = os.path.join(script_d, 'user-script')
- with open(test_script_f, 'w') as f:
- f.write("TEST DATA")
-
- my_returns = MOCK_RETURNS.copy()
- del my_returns['user-script']
-
- dsrc = self._get_ds(mockdata=my_returns)
- ret = dsrc.get_data()
- self.assertTrue(ret)
- self.assertFalse(dsrc.metadata['user-script'])
- self.assertFalse(os.path.exists(test_script_f))
-
def test_userdata_removed(self):
"""
User-data in the SmartOS world is supposed to be written to a file