summaryrefslogtreecommitdiff
path: root/tests/unittests/test_datasource/test_altcloud.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unittests/test_datasource/test_altcloud.py')
-rw-r--r--tests/unittests/test_datasource/test_altcloud.py66
1 files changed, 26 insertions, 40 deletions
diff --git a/tests/unittests/test_datasource/test_altcloud.py b/tests/unittests/test_datasource/test_altcloud.py
index c74562d7..e9cd2fa5 100644
--- a/tests/unittests/test_datasource/test_altcloud.py
+++ b/tests/unittests/test_datasource/test_altcloud.py
@@ -26,6 +26,7 @@ import shutil
import tempfile
from cloudinit import helpers
+from cloudinit import util
from unittest import TestCase
# Get the cloudinit.sources.DataSourceAltCloud import items needed.
@@ -98,6 +99,16 @@ def _remove_user_data_files(mount_dir,
pass
+def _dmi_data(expected):
+ '''
+ Spoof the data received over DMI
+ '''
+ def _data(key):
+ return expected
+
+ return _data
+
+
class TestGetCloudType(TestCase):
'''
Test to exercise method: DataSourceAltCloud.get_cloud_type()
@@ -106,24 +117,22 @@ class TestGetCloudType(TestCase):
def setUp(self):
'''Set up.'''
self.paths = helpers.Paths({'cloud_dir': '/tmp'})
+ self.dmi_data = util.read_dmi_data
# 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
+ util.read_dmi_data = self.dmi_data
force_arch()
def test_rhev(self):
'''
Test method get_cloud_type() for RHEVm systems.
- Forcing dmidecode return to match a RHEVm system: RHEV Hypervisor
+ Forcing read_dmi_data return to match a RHEVm system: RHEV Hypervisor
'''
- cloudinit.sources.DataSourceAltCloud.CMD_DMI_SYSTEM = \
- ['echo', 'RHEV Hypervisor']
+ util.read_dmi_data = _dmi_data('RHEV')
dsrc = DataSourceAltCloud({}, None, self.paths)
self.assertEquals('RHEV', \
dsrc.get_cloud_type())
@@ -131,10 +140,9 @@ class TestGetCloudType(TestCase):
def test_vsphere(self):
'''
Test method get_cloud_type() for vSphere systems.
- Forcing dmidecode return to match a vSphere system: RHEV Hypervisor
+ Forcing read_dmi_data return to match a vSphere system: RHEV Hypervisor
'''
- cloudinit.sources.DataSourceAltCloud.CMD_DMI_SYSTEM = \
- ['echo', 'VMware Virtual Platform']
+ util.read_dmi_data = _dmi_data('VMware Virtual Platform')
dsrc = DataSourceAltCloud({}, None, self.paths)
self.assertEquals('VSPHERE', \
dsrc.get_cloud_type())
@@ -142,30 +150,9 @@ class TestGetCloudType(TestCase):
def test_unknown(self):
'''
Test method get_cloud_type() for unknown systems.
- Forcing dmidecode return to match an unrecognized return.
- '''
- cloudinit.sources.DataSourceAltCloud.CMD_DMI_SYSTEM = \
- ['echo', 'Unrecognized Platform']
- dsrc = DataSourceAltCloud({}, None, self.paths)
- self.assertEquals('UNKNOWN', \
- dsrc.get_cloud_type())
-
- def test_exception1(self):
- '''
- Test method get_cloud_type() where command dmidecode fails.
- '''
- cloudinit.sources.DataSourceAltCloud.CMD_DMI_SYSTEM = \
- ['ls', 'bad command']
- dsrc = DataSourceAltCloud({}, None, self.paths)
- self.assertEquals('UNKNOWN', \
- dsrc.get_cloud_type())
-
- def test_exception2(self):
- '''
- Test method get_cloud_type() where command dmidecode is not available.
+ Forcing read_dmi_data return to match an unrecognized return.
'''
- cloudinit.sources.DataSourceAltCloud.CMD_DMI_SYSTEM = \
- ['bad command']
+ util.read_dmi_data = _dmi_data('Unrecognized Platform')
dsrc = DataSourceAltCloud({}, None, self.paths)
self.assertEquals('UNKNOWN', \
dsrc.get_cloud_type())
@@ -180,6 +167,7 @@ class TestGetDataCloudInfoFile(TestCase):
'''Set up.'''
self.paths = helpers.Paths({'cloud_dir': '/tmp'})
self.cloud_info_file = tempfile.mkstemp()[1]
+ self.dmi_data = util.read_dmi_data
cloudinit.sources.DataSourceAltCloud.CLOUD_INFO_FILE = \
self.cloud_info_file
@@ -192,6 +180,7 @@ class TestGetDataCloudInfoFile(TestCase):
except OSError:
pass
+ util.read_dmi_data = self.dmi_data
cloudinit.sources.DataSourceAltCloud.CLOUD_INFO_FILE = \
'/etc/sysconfig/cloud-info'
@@ -243,6 +232,7 @@ class TestGetDataNoCloudInfoFile(TestCase):
def setUp(self):
'''Set up.'''
self.paths = helpers.Paths({'cloud_dir': '/tmp'})
+ self.dmi_data = util.read_dmi_data
cloudinit.sources.DataSourceAltCloud.CLOUD_INFO_FILE = \
'no such file'
# We have a different code path for arm to deal with LP1243287
@@ -253,16 +243,14 @@ class TestGetDataNoCloudInfoFile(TestCase):
# Reset
cloudinit.sources.DataSourceAltCloud.CLOUD_INFO_FILE = \
'/etc/sysconfig/cloud-info'
- cloudinit.sources.DataSourceAltCloud.CMD_DMI_SYSTEM = \
- ['dmidecode', '--string', 'system-product-name']
+ util.read_dmi_data = self.dmi_data
# Return back to original arch
force_arch()
def test_rhev_no_cloud_file(self):
'''Test No cloud info file module get_data() forcing RHEV.'''
- cloudinit.sources.DataSourceAltCloud.CMD_DMI_SYSTEM = \
- ['echo', 'RHEV Hypervisor']
+ util.read_dmi_data = _dmi_data('RHEV Hypervisor')
dsrc = DataSourceAltCloud({}, None, self.paths)
dsrc.user_data_rhevm = lambda: True
self.assertEquals(True, dsrc.get_data())
@@ -270,8 +258,7 @@ class TestGetDataNoCloudInfoFile(TestCase):
def test_vsphere_no_cloud_file(self):
'''Test No cloud info file module get_data() forcing VSPHERE.'''
- cloudinit.sources.DataSourceAltCloud.CMD_DMI_SYSTEM = \
- ['echo', 'VMware Virtual Platform']
+ util.read_dmi_data = _dmi_data('VMware Virtual Platform')
dsrc = DataSourceAltCloud({}, None, self.paths)
dsrc.user_data_vsphere = lambda: True
self.assertEquals(True, dsrc.get_data())
@@ -279,8 +266,7 @@ class TestGetDataNoCloudInfoFile(TestCase):
def test_failure_no_cloud_file(self):
'''Test No cloud info file module get_data() forcing unrecognized.'''
- cloudinit.sources.DataSourceAltCloud.CMD_DMI_SYSTEM = \
- ['echo', 'Unrecognized Platform']
+ util.read_dmi_data = _dmi_data('Unrecognized Platform')
dsrc = DataSourceAltCloud({}, None, self.paths)
self.assertEquals(False, dsrc.get_data())