Implement method in openstack metadata service

- Implement `get_kms_host` method

Change-Id: I62fdfbd3f99bdcad096911bd34bb363cfc15d4ef
This commit is contained in:
do-gyun
2024-10-29 16:38:05 +09:00
committed by do-gyun kim
parent e17488c239
commit 1f97a21bb7
3 changed files with 38 additions and 0 deletions

View File

@@ -308,3 +308,16 @@ class BaseOpenStackService(base.BaseMetadataService):
LOG.debug("user_data metadata not present")
return list(set((cert.strip() for cert in certs)))
def get_kms_host(self):
meta_data = self._get_meta_data()
meta = meta_data.get("meta")
if meta and "kms_host" in meta:
kms_host = meta["kms_host"]
elif "kms_host" in meta_data:
kms_host = meta_data["kms_host"]
else:
kms_host = None
return kms_host

View File

@@ -528,3 +528,26 @@ class TestBaseOpenStackService(unittest.TestCase):
self.assertIsNone(network_details)
self.assertTrue(mock_log_exception.called)
@mock.patch(MODPATH +
".BaseOpenStackService._get_meta_data")
def _test_get_kms_host(self, mock_get_meta_data, meta_data):
mock_get_meta_data.return_value = meta_data
response = self._service.get_kms_host()
mock_get_meta_data.assert_called_once_with()
if meta_data and 'kms_host' in meta_data:
self.assertEqual(meta_data['kms_host'], response)
elif meta_data and 'kms_host' in meta_data.get('meta'):
self.assertEqual(meta_data.get('meta')['kms_host'], response)
else:
self.assertIsNone(response)
def test_get_kms_host(self):
self._test_get_kms_host(meta_data={'kms_host': 'fake host'})
def test_get_kms_host_in_meta(self):
self._test_get_kms_host(
meta_data={'meta': {'kms_host': 'fake host'}})
def test_get_kms_host_no_pass(self):
self._test_get_kms_host(meta_data={})

View File

@@ -53,6 +53,7 @@ Capabilities:
* admin user password
* post admin user password (only once)
* user data
* kms host
Config options for `openstack` section:
@@ -105,6 +106,7 @@ Capabilities:
* admin user name
* admin user password
* user data
* kms host
Config options for `config_drive` section: