summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcloudinit/sources/DataSourceAzure.py5
-rw-r--r--tests/unittests/sources/test_azure.py41
2 files changed, 41 insertions, 5 deletions
diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py
index 22435284..7134c95a 100755
--- a/cloudinit/sources/DataSourceAzure.py
+++ b/cloudinit/sources/DataSourceAzure.py
@@ -335,7 +335,7 @@ class DataSourceAzure(sources.DataSource):
# 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
@@ -368,9 +368,9 @@ class DataSourceAzure(sources.DataSource):
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:
@@ -383,7 +383,6 @@ class DataSourceAzure(sources.DataSource):
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=""))
diff --git a/tests/unittests/sources/test_azure.py b/tests/unittests/sources/test_azure.py
index df1c289b..02083184 100644
--- a/tests/unittests/sources/test_azure.py
+++ b/tests/unittests/sources/test_azure.py
@@ -784,7 +784,13 @@ scbus-1 on xpt0 bus 0
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
@@ -798,9 +804,12 @@ scbus-1 on xpt0 bus 0
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)
@@ -1006,6 +1015,34 @@ scbus-1 on xpt0 bus 0
"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"]}