diff options
author | Anh Vo <anhvo@microsoft.com> | 2021-04-27 13:40:59 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-27 12:40:59 -0500 |
commit | ba82b3ef70d0f8de7471aea8fcc89923d9b07235 (patch) | |
tree | 2a6aef48badaca003945ae9ffebb7349af740805 /tests/unittests | |
parent | 5c740dcf6f278a180c32863d2b4225b6db925ef0 (diff) | |
download | vyos-cloud-init-ba82b3ef70d0f8de7471aea8fcc89923d9b07235.tar.gz vyos-cloud-init-ba82b3ef70d0f8de7471aea8fcc89923d9b07235.zip |
Azure: adding support for consuming userdata from IMDS (#884)
Diffstat (limited to 'tests/unittests')
-rw-r--r-- | tests/unittests/test_datasource/test_azure.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tests/unittests/test_datasource/test_azure.py b/tests/unittests/test_datasource/test_azure.py index c4a8e08d..f8433690 100644 --- a/tests/unittests/test_datasource/test_azure.py +++ b/tests/unittests/test_datasource/test_azure.py @@ -1899,6 +1899,56 @@ scbus-1 on xpt0 bus 0 dsrc.get_data() self.assertTrue(dsrc.metadata["disable_password"]) + @mock.patch(MOCKPATH + 'get_metadata_from_imds') + def test_userdata_from_imds(self, m_get_metadata_from_imds): + sys_cfg = {'datasource': {'Azure': {'apply_network_config': True}}} + odata = {'HostName': "myhost", 'UserName': "myuser"} + data = { + 'ovfcontent': construct_valid_ovf_env(data=odata), + 'sys_cfg': sys_cfg + } + userdata = "userdataImds" + imds_data = copy.deepcopy(NETWORK_METADATA) + imds_data["compute"]["osProfile"] = dict( + adminUsername="username1", + computerName="hostname1", + disablePasswordAuthentication="true", + ) + imds_data["compute"]["userData"] = b64e(userdata) + m_get_metadata_from_imds.return_value = imds_data + dsrc = self._get_ds(data) + ret = dsrc.get_data() + self.assertTrue(ret) + self.assertEqual(dsrc.userdata_raw, userdata.encode('utf-8')) + + @mock.patch(MOCKPATH + 'get_metadata_from_imds') + def test_userdata_from_imds_with_customdata_from_OVF( + self, m_get_metadata_from_imds): + userdataOVF = "userdataOVF" + odata = { + 'HostName': "myhost", 'UserName': "myuser", + 'UserData': {'text': b64e(userdataOVF), 'encoding': 'base64'} + } + sys_cfg = {'datasource': {'Azure': {'apply_network_config': True}}} + data = { + 'ovfcontent': construct_valid_ovf_env(data=odata), + 'sys_cfg': sys_cfg + } + + userdataImds = "userdataImds" + imds_data = copy.deepcopy(NETWORK_METADATA) + imds_data["compute"]["osProfile"] = dict( + adminUsername="username1", + computerName="hostname1", + disablePasswordAuthentication="true", + ) + imds_data["compute"]["userData"] = b64e(userdataImds) + m_get_metadata_from_imds.return_value = imds_data + dsrc = self._get_ds(data) + ret = dsrc.get_data() + self.assertTrue(ret) + self.assertEqual(dsrc.userdata_raw, userdataOVF.encode('utf-8')) + class TestAzureBounce(CiTestCase): |