summaryrefslogtreecommitdiff
path: root/tests/unittests/sources/test_azure_helper.py
diff options
context:
space:
mode:
authorChris Patterson <cpatterson@microsoft.com>2022-02-10 15:03:10 -0500
committerGitHub <noreply@github.com>2022-02-10 14:03:10 -0600
commit50de985bc4e47dff1a8fc52abb7679032bb40cae (patch)
treeeec039c570ff733a202c6c7ef341fda3873b1c4f /tests/unittests/sources/test_azure_helper.py
parentc3482971f0f155475f367d6dec00bae25b79cfff (diff)
downloadvyos-cloud-init-50de985bc4e47dff1a8fc52abb7679032bb40cae.tar.gz
vyos-cloud-init-50de985bc4e47dff1a8fc52abb7679032bb40cae.zip
sources/azure: refactor ssh key handling (#1248)
Split _get_public_ssh_keys_and_source() into _get_public_keys_from_imds() and _get_public_keys_from_ovf(). Set _get_public_keys_from_imds() to take a parameter of the IMDS metadata rather than assuming it is already set in self.metadata. This will allow us to move negotation into local phase where self.metadata may not be set yet. Update this method to raise KeyError if IMDS metadata is missing/malformed, and ValueError if SSH key format is not supported. Update get_public_ssh_keys() to catch these errors and fall back to the OVF/Wireserver keys as needed. To improve clarity, update register_with_azure_and_fetch_data() to return the list of SSH keys, rather than bundling them into a dictionary for updating against the metadata dictionary. There should be no change in behavior with this refactor. Signed-off-by: Chris Patterson <cpatterson@microsoft.com>
Diffstat (limited to 'tests/unittests/sources/test_azure_helper.py')
-rw-r--r--tests/unittests/sources/test_azure_helper.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/tests/unittests/sources/test_azure_helper.py b/tests/unittests/sources/test_azure_helper.py
index 6f7f2890..98143bc3 100644
--- a/tests/unittests/sources/test_azure_helper.py
+++ b/tests/unittests/sources/test_azure_helper.py
@@ -1204,16 +1204,16 @@ class TestWALinuxAgentShim(CiTestCase):
[mock.call(self.GoalState.return_value.certificates_xml)],
sslmgr.parse_certificates.call_args_list,
)
- self.assertIn("expected-key", data["public-keys"])
- self.assertIn("expected-no-value-key", data["public-keys"])
- self.assertNotIn("should-not-be-found", data["public-keys"])
+ self.assertIn("expected-key", data)
+ self.assertIn("expected-no-value-key", data)
+ self.assertNotIn("should-not-be-found", data)
def test_absent_certificates_produces_empty_public_keys(self):
mypk = [{"fingerprint": "fp1", "path": "path1"}]
self.GoalState.return_value.certificates_xml = None
shim = wa_shim()
data = shim.register_with_azure_and_fetch_data(pubkey_info=mypk)
- self.assertEqual([], data["public-keys"])
+ self.assertEqual([], data)
def test_correct_url_used_for_report_ready(self):
self.find_endpoint.return_value = "test_endpoint"