diff options
author | Chris Patterson <cpatterson@microsoft.com> | 2022-01-20 16:34:22 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-20 15:34:22 -0600 |
commit | 6c8770f5336c8c74dc8208f50ab0a479363d1332 (patch) | |
tree | 7218c7560e900bd5693dfc1c3d9eae6c7279bd42 /cloudinit | |
parent | 78079374ac2b9cb8ae74975c2009fd21d59c130a (diff) | |
download | vyos-cloud-init-6c8770f5336c8c74dc8208f50ab0a479363d1332.tar.gz vyos-cloud-init-6c8770f5336c8c74dc8208f50ab0a479363d1332.zip |
sources/azure: unpack ret tuple in crawl_metadata() (#1194)
load_azure_ds_dir() always returns a tuple. Instead of saving this
tuple as ret, expand it immediately as md, userdata_raw, cfg, files.
This allows for more fine-grained passing of data before getting
expanded later.
- Update _should_reprovision methods to use cfg instead of tuple.
- Update _should_reprovision methods to remove the ovf_md guard.
This should be a safe refactor as the OVF is not required, and the
config is initialized to an empty dict. In practice, a mount failure
would have initialized ret anyways if the OVF was not found. If a
mount failure wasn't seen and ret was None, this guard could be
causing other failures by ignoring the PPS state that should be
available from IMDS metadata.
Signed-off-by: Chris Patterson <cpatterson@microsoft.com>
Diffstat (limited to 'cloudinit')
-rwxr-xr-x | cloudinit/sources/DataSourceAzure.py | 39 |
1 files changed, 17 insertions, 22 deletions
diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py index 7134c95a..9577355c 100755 --- a/cloudinit/sources/DataSourceAzure.py +++ b/cloudinit/sources/DataSourceAzure.py @@ -338,7 +338,10 @@ class DataSourceAzure(sources.DataSource): ovf_is_accessible = False reprovision_after_nic_attach = False metadata_source = None - ret = None + md = {} + userdata_raw = "" + cfg = {} + files = {} if os.path.isfile(REPROVISION_MARKER_FILE): reprovision = True metadata_source = "IMDS" @@ -361,15 +364,17 @@ class DataSourceAzure(sources.DataSource): try: if src.startswith("/dev/"): if util.is_FreeBSD(): - ret = util.mount_cb( + md, userdata_raw, cfg, files = util.mount_cb( src, load_azure_ds_dir, mtype="udf" ) else: - ret = util.mount_cb(src, load_azure_ds_dir) + md, userdata_raw, cfg, files = util.mount_cb( + src, load_azure_ds_dir + ) # save the device for ejection later self.iso_dev = src else: - ret = load_azure_ds_dir(src) + md, userdata_raw, cfg, files = load_azure_ds_dir(src) ovf_is_accessible = True metadata_source = src break @@ -383,11 +388,8 @@ class DataSourceAzure(sources.DataSource): report_diagnostic_event( "%s was not mountable" % src, logger_func=LOG.debug ) - empty_md = {"local-hostname": ""} - empty_cfg = dict( - system_info=dict(default_user=dict(name="")) - ) - ret = (empty_md, "", empty_cfg, {}) + md = {"local-hostname": ""} + cfg = {"system_info": {"default_user": {"name": ""}}} metadata_source = "IMDS" continue except BrokenAzureDataSource as exc: @@ -414,11 +416,11 @@ class DataSourceAzure(sources.DataSource): raise sources.InvalidMetaDataException(msg) perform_reprovision = reprovision or self._should_reprovision( - ret, imds_md + cfg, imds_md ) perform_reprovision_after_nic_attach = ( reprovision_after_nic_attach - or self._should_reprovision_after_nic_attach(ret, imds_md) + or self._should_reprovision_after_nic_attach(cfg, imds_md) ) if perform_reprovision or perform_reprovision_after_nic_attach: @@ -428,13 +430,12 @@ class DataSourceAzure(sources.DataSource): raise sources.InvalidMetaDataException(msg) if perform_reprovision_after_nic_attach: self._wait_for_all_nics_ready() - ret = self._reprovision() + md, userdata_raw, cfg, files = self._reprovision() # fetch metadata again as it has changed after reprovisioning imds_md = self.get_imds_data_with_api_fallback( self.fallback_interface, retries=10 ) - (md, userdata_raw, cfg, files) = ret self.seed = metadata_source crawled_data.update( { @@ -1408,7 +1409,7 @@ class DataSourceAzure(sources.DataSource): return None def _should_reprovision_after_nic_attach( - self, ovf_md, imds_md=None + self, cfg: dict, imds_md=None ) -> bool: """Whether or not we should wait for nic attach and then poll IMDS for reprovisioning data. Also sets a marker file to poll IMDS. @@ -1421,13 +1422,10 @@ class DataSourceAzure(sources.DataSource): the ISO, thus cloud-init needs to have a way of knowing that it should jump back into the waiting mode in order to retrieve the ovf_env. - @param ovf_md: Metadata obtained from reading ovf-env. + @param cfg: OVF cfg. @param imds_md: Metadata obtained from IMDS @return: Whether to reprovision after waiting for nics to be attached. """ - if not ovf_md: - return False - (_md, _userdata_raw, cfg, _files) = ovf_md path = REPROVISION_NIC_ATTACH_MARKER_FILE if ( cfg.get("PreprovisionedVMType", None) == "Savable" @@ -1445,7 +1443,7 @@ class DataSourceAzure(sources.DataSource): return True return False - def _should_reprovision(self, ovf_md, imds_md=None): + def _should_reprovision(self, cfg: dict, imds_md=None): """Whether or not we should poll IMDS for reprovisioning data. Also sets a marker file to poll IMDS. @@ -1456,9 +1454,6 @@ class DataSourceAzure(sources.DataSource): However, since the VM reports ready to the Fabric, we will not attach the ISO, thus cloud-init needs to have a way of knowing that it should jump back into the polling loop in order to retrieve the ovf_env.""" - if not ovf_md: - return False - (_md, _userdata_raw, cfg, _files) = ovf_md path = REPROVISION_MARKER_FILE if ( cfg.get("PreprovisionedVm") is True |