summaryrefslogtreecommitdiff
path: root/tests/unittests
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2018-12-20 17:22:45 +0000
committerKim Hagen <kim.sidney@gmail.com>2019-01-23 13:22:33 +0100
commitd7952d075666122f480f0a5820ac01dfbaa7da1a (patch)
treee77a3057f3b90bb032dd2cc386b61d7a3978fd71 /tests/unittests
parentc4da1a5cddacaa7c2a15df9170f21c3fce78fb15 (diff)
downloadvyos-cloud-init-d7952d075666122f480f0a5820ac01dfbaa7da1a.tar.gz
vyos-cloud-init-d7952d075666122f480f0a5820ac01dfbaa7da1a.zip
Vmware: Add support for the com.vmware.guestInfo OVF transport.
This adds support for reading OVF information over the 'com.vmware.guestInfo' tranport. The current implementation requires vmware-rpctool be installed in the system. LP: #1807466
Diffstat (limited to 'tests/unittests')
-rw-r--r--tests/unittests/test_datasource/test_ovf.py72
-rw-r--r--tests/unittests/test_ds_identify.py15
2 files changed, 81 insertions, 6 deletions
diff --git a/tests/unittests/test_datasource/test_ovf.py b/tests/unittests/test_datasource/test_ovf.py
index a226c032..e4af0fa3 100644
--- a/tests/unittests/test_datasource/test_ovf.py
+++ b/tests/unittests/test_datasource/test_ovf.py
@@ -17,6 +17,8 @@ from cloudinit.sources import DataSourceOVF as dsovf
from cloudinit.sources.helpers.vmware.imc.config_custom_script import (
CustomScriptNotFound)
+MPATH = 'cloudinit.sources.DataSourceOVF.'
+
OVF_ENV_CONTENT = """<?xml version="1.0" encoding="UTF-8"?>
<Environment xmlns="http://schemas.dmtf.org/ovf/environment/1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
@@ -126,7 +128,7 @@ class TestDatasourceOVF(CiTestCase):
'cloudinit.sources.DataSourceOVF',
{'util.read_dmi_data': None,
'transport_iso9660': (False, None, None),
- 'transport_vmware_guestd': (False, None, None)},
+ 'transport_vmware_guestinfo': (False, None, None)},
ds.get_data)
self.assertFalse(retcode, 'Expected False return from ds.get_data')
self.assertIn(
@@ -142,7 +144,7 @@ class TestDatasourceOVF(CiTestCase):
'cloudinit.sources.DataSourceOVF',
{'util.read_dmi_data': 'vmware',
'transport_iso9660': (False, None, None),
- 'transport_vmware_guestd': (False, None, None)},
+ 'transport_vmware_guestinfo': (False, None, None)},
ds.get_data)
self.assertFalse(retcode, 'Expected False return from ds.get_data')
self.assertIn(
@@ -189,9 +191,8 @@ class TestDatasourceOVF(CiTestCase):
self.assertEqual('ovf', ds.cloud_name)
self.assertEqual('ovf', ds.platform_type)
- MPATH = 'cloudinit.sources.DataSourceOVF.'
with mock.patch(MPATH + 'util.read_dmi_data', return_value='!VMware'):
- with mock.patch(MPATH + 'transport_vmware_guestd') as m_guestd:
+ with mock.patch(MPATH + 'transport_vmware_guestinfo') as m_guestd:
with mock.patch(MPATH + 'transport_iso9660') as m_iso9660:
m_iso9660.return_value = (None, 'ignored', 'ignored')
m_guestd.return_value = (None, 'ignored', 'ignored')
@@ -211,9 +212,8 @@ class TestDatasourceOVF(CiTestCase):
self.assertEqual('ovf', ds.cloud_name)
self.assertEqual('ovf', ds.platform_type)
- MPATH = 'cloudinit.sources.DataSourceOVF.'
with mock.patch(MPATH + 'util.read_dmi_data', return_value='VMWare'):
- with mock.patch(MPATH + 'transport_vmware_guestd') as m_guestd:
+ with mock.patch(MPATH + 'transport_vmware_guestinfo') as m_guestd:
with mock.patch(MPATH + 'transport_iso9660') as m_iso9660:
m_iso9660.return_value = (None, 'ignored', 'ignored')
m_guestd.return_value = (None, 'ignored', 'ignored')
@@ -384,5 +384,65 @@ class TestTransportIso9660(CiTestCase):
self.assertTrue(dsovf.maybe_cdrom_device('/dev/xvda1'))
self.assertTrue(dsovf.maybe_cdrom_device('xvdza1'))
+
+@mock.patch(MPATH + "util.which")
+@mock.patch(MPATH + "util.subp")
+class TestTransportVmwareGuestinfo(CiTestCase):
+ """Test the com.vmware.guestInfo transport implemented in
+ transport_vmware_guestinfo."""
+
+ rpctool = 'vmware-rpctool'
+ with_logs = True
+ not_found = (False, None, None)
+ rpctool_path = '/not/important/vmware-rpctool'
+
+ def test_without_vmware_rpctool_returns_notfound(self, m_subp, m_which):
+ m_which.return_value = None
+ self.assertEqual(self.not_found, dsovf.transport_vmware_guestinfo())
+ self.assertEqual(0, m_subp.call_count,
+ "subp should not be called if no rpctool in path.")
+
+ def test_notfound_on_exit_code_1(self, m_subp, m_which):
+ """If vmware-rpctool exits 1, then must return not found."""
+ m_which.return_value = self.rpctool_path
+ m_subp.side_effect = util.ProcessExecutionError(
+ stdout="", stderr="No value found", exit_code=1, cmd=["unused"])
+ self.assertEqual(self.not_found, dsovf.transport_vmware_guestinfo())
+ self.assertEqual(1, m_subp.call_count)
+ self.assertNotIn("WARNING", self.logs.getvalue(),
+ "exit code of 1 by rpctool should not cause warning.")
+
+ def test_notfound_if_no_content_but_exit_zero(self, m_subp, m_which):
+ """If vmware-rpctool exited 0 with no stdout is normal not-found.
+
+ This isn't actually a case I've seen. normally on "not found",
+ rpctool would exit 1 with 'No value found' on stderr. But cover
+ the case where it exited 0 and just wrote nothing to stdout.
+ """
+ m_which.return_value = self.rpctool_path
+ m_subp.return_value = ('', '')
+ self.assertEqual(self.not_found, dsovf.transport_vmware_guestinfo())
+ self.assertEqual(1, m_subp.call_count)
+
+ def test_notfound_and_warns_on_unexpected_exit_code(self, m_subp, m_which):
+ """If vmware-rpctool exits non zero or 1, warnings should be logged."""
+ m_which.return_value = self.rpctool_path
+ m_subp.side_effect = util.ProcessExecutionError(
+ stdout=None, stderr="No value found", exit_code=2, cmd=["unused"])
+ self.assertEqual(self.not_found, dsovf.transport_vmware_guestinfo())
+ self.assertEqual(1, m_subp.call_count)
+ self.assertIn("WARNING", self.logs.getvalue(),
+ "exit code of 2 by rpctool should log WARNING.")
+
+ def test_found_when_guestinfo_present(self, m_subp, m_which):
+ """When there is a ovf info, transport should return it."""
+ m_which.return_value = self.rpctool_path
+ content = fill_properties({})
+ m_subp.return_value = (content, '')
+ self.assertEqual(
+ (content, self.rpctool, "guestinfo.ovfEnv"),
+ dsovf.transport_vmware_guestinfo())
+ self.assertEqual(1, m_subp.call_count)
+
#
# vi: ts=4 expandtab
diff --git a/tests/unittests/test_ds_identify.py b/tests/unittests/test_ds_identify.py
index 80640f19..756b4fb4 100644
--- a/tests/unittests/test_ds_identify.py
+++ b/tests/unittests/test_ds_identify.py
@@ -138,6 +138,9 @@ class DsIdentifyBase(CiTestCase):
{'name': 'detect_virt', 'RET': 'none', 'ret': 1},
{'name': 'uname', 'out': UNAME_MYSYS},
{'name': 'blkid', 'out': BLKID_EFI_ROOT},
+ {'name': 'ovf_vmware_transport_guestinfo',
+ 'out': 'No value found', 'ret': 1},
+
]
written = [d['name'] for d in mocks]
@@ -475,6 +478,10 @@ class TestDsIdentify(DsIdentifyBase):
"""OVF is identified when iso9660 cdrom path contains ovf schema."""
self._test_ds_found('OVF')
+ def test_ovf_on_vmware_guestinfo_found(self):
+ """OVF guest info is found on vmware."""
+ self._test_ds_found('OVF-guestinfo')
+
def test_ovf_on_vmware_iso_found_when_vmware_customization(self):
"""OVF is identified when vmware customization is enabled."""
self._test_ds_found('OVF-vmware-customization')
@@ -773,6 +780,14 @@ VALID_CFG = {
'dev/sr0': 'pretend ovf iso has ' + OVF_MATCH_STRING + '\n',
}
},
+ 'OVF-guestinfo': {
+ 'ds': 'OVF',
+ 'mocks': [
+ {'name': 'ovf_vmware_transport_guestinfo', 'ret': 0,
+ 'out': '<?xml version="1.0" encoding="UTF-8"?>\n<Environment'},
+ MOCK_VIRT_IS_VMWARE,
+ ],
+ },
'ConfigDrive': {
'ds': 'ConfigDrive',
'mocks': [