Skip to content

Commit

Permalink
Merge "Support alternate 'public-keys' format for NoCloud service."
Browse files Browse the repository at this point in the history
  • Loading branch information
Zuul authored and openstack-gerrit committed May 21, 2024
2 parents 04c6424 + 14900bc commit 1adf31b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cloudbaseinit/metadata/services/nocloudservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,9 @@ def get_public_keys(self):
if not raw_ssh_keys:
return []

if isinstance(raw_ssh_keys, list):
return raw_ssh_keys

return [raw_ssh_keys[key].get('openssh-key') for key in raw_ssh_keys]

def get_network_details(self):
Expand Down
10 changes: 10 additions & 0 deletions cloudbaseinit/tests/metadata/services/test_nocloudservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,16 @@ def test_get_public_keys(self, mock_get_metadata):
result = self._config_drive.get_public_keys()
self.assertEqual(result, expected_result)

@mock.patch(MODULE_PATH + '.NoCloudConfigDriveService._get_meta_data')
def test_get_public_keys_alt_fmt(self, mock_get_metadata):
fake_key = 'fake key'
expected_result = [fake_key]
mock_get_metadata.return_value = {
'public-keys': [fake_key]
}
result = self._config_drive.get_public_keys()
self.assertEqual(result, expected_result)

@ddt.data(('', ('V2 network metadata is empty', None)),
('1', ('V2 network metadata is not a dictionary', None)),
('{}', ('V2 network metadata is empty', None)),
Expand Down

0 comments on commit 1adf31b

Please sign in to comment.