Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions cloudinit/sources/DataSourceOVF.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,20 @@ def _get_data(self):
found.append(seed)
elif system_type and 'vmware' in system_type.lower():
LOG.debug("VMware Virtualization Platform found")
allow_vmware_cust = False
allow_raw_data = False
if not self.vmware_customization_supported:
LOG.debug("Skipping the check for "
"VMware Customization support")
else:
allow_vmware_cust = not util.get_cfg_option_bool(
self.sys_cfg, "disable_vmware_customization", True)
allow_raw_data = util.get_cfg_option_bool(
self.ds_cfg, "allow_raw_data", True)

if not (allow_vmware_cust or allow_raw_data):
LOG.debug(
"Customization for VMware platform is disabled.")
else:
search_paths = (
"/usr/lib/vmware-tools", "/usr/lib64/vmware-tools",
Expand Down Expand Up @@ -148,19 +159,21 @@ def _get_data(self):
GuestCustEvent.GUESTCUST_EVENT_CUSTOMIZE_FAILED,
vmwareImcConfigFilePath,
self._vmware_cust_conf)
else:
LOG.debug("Did not find VMware Customization Config File")

# Honor disable_vmware_customization setting on metadata absent
if not md_path:
if util.get_cfg_option_bool(self.sys_cfg,
"disable_vmware_customization",
True):
# Don't handle the customization for below 2 cases:
# 1. meta data is found, allow_raw_data is False.
# 2. no meta data is found, allow_vmware_cust is False.
if md_path and not allow_raw_data:
LOG.debug(
"Customization for VMware platform is disabled.")
"Customization using raw data is disabled.")
# reset vmwareImcConfigFilePath to None to avoid
# customization for VMware platform
vmwareImcConfigFilePath = None
if md_path is None and not allow_vmware_cust:
LOG.debug(
"Customization using VMware config is disabled.")
vmwareImcConfigFilePath = None
else:
LOG.debug("Did not find VMware Customization Config File")

use_raw_data = bool(vmwareImcConfigFilePath and md_path)
if use_raw_data:
Expand Down Expand Up @@ -429,7 +442,7 @@ def get_max_wait_from_cfg(cfg):
LOG.warning("Failed to get '%s', using %s",
max_wait_cfg_option, default_max_wait)

if max_wait <= 0:
if max_wait < 0:
LOG.warning("Invalid value '%s' for '%s', using '%s' instead",
max_wait, max_wait_cfg_option, default_max_wait)
max_wait = default_max_wait
Expand All @@ -440,6 +453,8 @@ def get_max_wait_from_cfg(cfg):
def wait_for_imc_cfg_file(filename, maxwait=180, naplen=5,
dirpath="/var/run/vmware-imc"):
waited = 0
if maxwait <= naplen:
naplen = 1
Comment thread
TheRealFalcon marked this conversation as resolved.

while waited < maxwait:
fileFullPath = os.path.join(dirpath, filename)
Expand Down
4 changes: 4 additions & 0 deletions doc/rtd/topics/datasources/ovf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ configuration (in `/etc/cloud/cloud.cfg` or `/etc/cloud/cloud.cfg.d/`).

The settings that may be configured are:

* disable_vmware_customization: disable or enable the vmware customization
based on vmware customization files. (default: True)
* allow_raw_data: enable or disable the vmware customization based on raw
cloud-init data including metadata and userdata. (default: True)
* vmware_cust_file_max_wait: the maximum amount of clock time in seconds that
should be spent waiting for vmware customization files. (default: 15)

Expand Down
79 changes: 71 additions & 8 deletions tests/unittests/test_datasource/test_ovf.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,17 @@ def test_get_data_false_on_none_dmi_data(self):
self.assertIn(
'DEBUG: No system-product-name found', self.logs.getvalue())

def test_get_data_no_vmware_customization_disabled(self):
"""When cloud-init workflow for vmware is disabled via sys_cfg and
no meta data provided, log a message.
def test_get_data_vmware_customization_disabled(self):
"""When vmware customization is disabled via sys_cfg and
allow_raw_data is disabled via ds_cfg, log a message.
"""
paths = Paths({'cloud_dir': self.tdir})
ds = self.datasource(
sys_cfg={'disable_vmware_customization': True}, distro={},
paths=paths)
sys_cfg={'disable_vmware_customization': True,
'datasource': {'OVF': {'allow_raw_data': False}}},
distro={}, paths=paths)
conf_file = self.tmp_path('test-cust', self.tdir)
conf_content = dedent("""\
[CUSTOM-SCRIPT]
SCRIPT-NAME = test-script
[MISC]
MARKER-ID = 12345345
""")
Expand All @@ -168,7 +167,71 @@ def test_get_data_no_vmware_customization_disabled(self):
'DEBUG: Customization for VMware platform is disabled.',
self.logs.getvalue())

def test_get_data_vmware_customization_disabled(self):
def test_get_data_vmware_customization_sys_cfg_disabled(self):
"""When vmware customization is disabled via sys_cfg and
no meta data is found, log a message.
"""
paths = Paths({'cloud_dir': self.tdir})
ds = self.datasource(
sys_cfg={'disable_vmware_customization': True,
'datasource': {'OVF': {'allow_raw_data': True}}},
distro={}, paths=paths)
conf_file = self.tmp_path('test-cust', self.tdir)
conf_content = dedent("""\
[MISC]
MARKER-ID = 12345345
""")
util.write_file(conf_file, conf_content)
retcode = wrap_and_call(
'cloudinit.sources.DataSourceOVF',
{'dmi.read_dmi_data': 'vmware',
'transport_iso9660': NOT_FOUND,
'transport_vmware_guestinfo': NOT_FOUND,
'util.del_dir': True,
'search_file': self.tdir,
'wait_for_imc_cfg_file': conf_file},
ds.get_data)
self.assertFalse(retcode, 'Expected False return from ds.get_data')
self.assertIn(
'DEBUG: Customization using VMware config is disabled.',
self.logs.getvalue())

def test_get_data_allow_raw_data_disabled(self):
"""When allow_raw_data is disabled via ds_cfg and
meta data is found, log a message.
"""
paths = Paths({'cloud_dir': self.tdir})
ds = self.datasource(
sys_cfg={'disable_vmware_customization': False,
'datasource': {'OVF': {'allow_raw_data': False}}},
distro={}, paths=paths)

# Prepare the conf file
conf_file = self.tmp_path('test-cust', self.tdir)
conf_content = dedent("""\
[CLOUDINIT]
METADATA = test-meta
""")
util.write_file(conf_file, conf_content)
# Prepare the meta data file
metadata_file = self.tmp_path('test-meta', self.tdir)
util.write_file(metadata_file, "This is meta data")
retcode = wrap_and_call(
'cloudinit.sources.DataSourceOVF',
{'dmi.read_dmi_data': 'vmware',
'transport_iso9660': NOT_FOUND,
'transport_vmware_guestinfo': NOT_FOUND,
'util.del_dir': True,
'search_file': self.tdir,
'wait_for_imc_cfg_file': conf_file,
'collect_imc_file_paths': [self.tdir + '/test-meta', '', '']},
ds.get_data)
self.assertFalse(retcode, 'Expected False return from ds.get_data')
self.assertIn(
'DEBUG: Customization using raw data is disabled.',
self.logs.getvalue())

def test_get_data_vmware_customization_enabled(self):
"""When cloud-init workflow for vmware is enabled via sys_cfg log a
message.
"""
Expand Down