summaryrefslogtreecommitdiff
path: root/cloudinit
diff options
context:
space:
mode:
authorChris Patterson <cpatterson@microsoft.com>2022-02-04 14:17:38 -0500
committerGitHub <noreply@github.com>2022-02-04 13:17:38 -0600
commit6d817e94beb404d3917bf973bcb728aa6cc22ffe (patch)
treeca01446c8dfac1b6b429bd04187d6973255c2d35 /cloudinit
parenta1cfd1b48993ce912986204f5249eb67724636d5 (diff)
downloadvyos-cloud-init-6d817e94beb404d3917bf973bcb728aa6cc22ffe.tar.gz
vyos-cloud-init-6d817e94beb404d3917bf973bcb728aa6cc22ffe.zip
sources/azure: fix metadata check in _check_if_nic_is_primary() (#1232)
Currently _check_if_nic_is_primary() checks for imds_md is None, but imds_md is returned as an empty dictionary on error fetching metdata. Fix this check and the tests that are incorrectly vetting IMDS polling code. Additionally, use response.contents instead of str(response) when loding the JSON data returned from readurl. This helps simplify the mocking and avoids an unncessary conversion. Signed-off-by: Chris Patterson <cpatterson@microsoft.com>
Diffstat (limited to 'cloudinit')
-rwxr-xr-xcloudinit/sources/DataSourceAzure.py6
1 files changed, 3 insertions, 3 deletions
diff --git a/cloudinit/sources/DataSourceAzure.py b/cloudinit/sources/DataSourceAzure.py
index f3c24497..222f99f2 100755
--- a/cloudinit/sources/DataSourceAzure.py
+++ b/cloudinit/sources/DataSourceAzure.py
@@ -994,10 +994,10 @@ class DataSourceAzure(sources.DataSource):
)
finally:
# If we are not the primary nic, then clean the dhcp context.
- if imds_md is None:
+ if not imds_md:
dhcp_ctx.clean_network()
- if imds_md is not None:
+ if imds_md:
# Only primary NIC will get a response from IMDS.
LOG.info("%s is the primary nic", ifname)
is_primary = True
@@ -2291,7 +2291,7 @@ def _get_metadata_from_imds(
json_decode_error = ValueError
try:
- return util.load_json(str(response))
+ return util.load_json(response.contents)
except json_decode_error as e:
report_diagnostic_event(
"Ignoring non-json IMDS instance metadata response: %s. "