Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sources/azure: set ovf_is_accessible when OVF is read successfully #1193

Merged
merged 1 commit into from
Jan 18, 2022
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
5 changes: 2 additions & 3 deletions cloudinit/sources/DataSourceAzure.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ def crawl_metadata(self):
# the candidate list determines the path to take in order to get the
# metadata we need.
reprovision = False
ovf_is_accessible = True
ovf_is_accessible = False
reprovision_after_nic_attach = False
metadata_source = None
ret = None
Expand Down Expand Up @@ -370,9 +370,9 @@ def crawl_metadata(self):
ret = util.mount_cb(src, load_azure_ds_dir)
# save the device for ejection later
self.iso_dev = src
ovf_is_accessible = True
else:
ret = load_azure_ds_dir(src)
ovf_is_accessible = True
metadata_source = src
break
except NonAzureDataSource:
Expand All @@ -385,7 +385,6 @@ def crawl_metadata(self):
report_diagnostic_event(
"%s was not mountable" % src, logger_func=LOG.debug
)
ovf_is_accessible = False
empty_md = {"local-hostname": ""}
empty_cfg = dict(
system_info=dict(default_user=dict(name=""))
Expand Down
41 changes: 39 additions & 2 deletions tests/unittests/sources/test_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,13 @@ def _get_mockds(self):
return dsaz

def _get_ds(
self, data, distro="ubuntu", apply_network=None, instance_id=None
self,
data,
distro="ubuntu",
apply_network=None,
instance_id=None,
write_ovf_to_data_dir: bool = False,
write_ovf_to_seed_dir: bool = True,
):
def _wait_for_files(flist, _maxwait=None, _naplen=None):
data["waited"] = flist
Expand All @@ -789,9 +795,12 @@ def _load_possible_azure_ds(seed_dir, cache_dir):
yield cache_dir

seed_dir = os.path.join(self.paths.seed_dir, "azure")
if data.get("ovfcontent") is not None:
if write_ovf_to_seed_dir and data.get("ovfcontent") is not None:
populate_dir(seed_dir, {"ovf-env.xml": data["ovfcontent"]})

if write_ovf_to_data_dir and data.get("ovfcontent") is not None:
populate_dir(self.waagent_d, {"ovf-env.xml": data["ovfcontent"]})

dsaz.BUILTIN_DS_CONFIG["data_dir"] = self.waagent_d

self.m_is_platform_viable = mock.MagicMock(autospec=True)
Expand Down Expand Up @@ -1005,6 +1014,34 @@ def test_basic_seed_dir(self):
"seed-dir (%s/seed/azure)" % self.tmp, dsrc.subplatform
)

def test_data_dir_without_imds_data(self):
odata = {"HostName": "myhost", "UserName": "myuser"}
data = {
"ovfcontent": construct_valid_ovf_env(data=odata),
"sys_cfg": {},
}
dsrc = self._get_ds(
data, write_ovf_to_data_dir=True, write_ovf_to_seed_dir=False
)

self.m_get_metadata_from_imds.return_value = {}
with mock.patch(MOCKPATH + "util.mount_cb") as m_mount_cb:
m_mount_cb.side_effect = [
MountFailedError("fail"),
({"local-hostname": "me"}, "ud", {"cfg": ""}, {}),
]
ret = dsrc.get_data()

self.assertTrue(ret)
self.assertEqual(dsrc.userdata_raw, "")
self.assertEqual(dsrc.metadata["local-hostname"], odata["HostName"])
self.assertTrue(
os.path.isfile(os.path.join(self.waagent_d, "ovf-env.xml"))
)
self.assertEqual("azure", dsrc.cloud_name)
self.assertEqual("azure", dsrc.platform_type)
self.assertEqual("seed-dir (%s)" % self.waagent_d, dsrc.subplatform)

def test_basic_dev_file(self):
"""When a device path is used, present that in subplatform."""
data = {"sys_cfg": {}, "dsdevs": ["/dev/cd0"]}
Expand Down