Merge "Add AuthCloudName to export data" into stable/wallaby

This commit is contained in:
Zuul 2022-03-21 21:33:44 +00:00 committed by Gerrit Code Review
commit 2909e00222
2 changed files with 43 additions and 0 deletions

View File

@ -113,6 +113,16 @@ def export_stack(heat, stack, should_filter=False,
raise RuntimeError(
"No data returned to export %s from." % param)
# Check if AuthCloudName is in the stack environment, and if so add it to
# the export data. Otherwise set it to the exported stack's name.
auth_cloud_name = heat_stack.environment().get(
'parameter_defaults').get(
'AuthCloudName', None)
if auth_cloud_name:
data['AuthCloudName'] = auth_cloud_name
else:
data['AuthCloudName'] = stack
return data

View File

@ -40,6 +40,11 @@ class TestExport(TestCase):
self.mock_stack.to_dict.return_value = dict(outputs=outputs)
self.mock_open = mock.mock_open(read_data='{"an_key":"an_value"}')
mock_environment = mock.Mock()
self.mock_stack.environment = mock_environment
mock_environment.return_value = dict(
parameter_defaults=dict())
ceph_inv = {
'DistributedComputeHCI': {
'hosts': {
@ -86,6 +91,33 @@ class TestExport(TestCase):
expected = \
{'AllNodesExtraMapData': {u'an_key': u'an_value'},
'AuthCloudName': 'overcloud',
'EndpointMapOverride': {'em_key': 'em_value'},
'ExtraHostFileEntries': 'hosts entry',
'GlobalConfigExtraMapData': {'gc_key': 'gc_value'}}
self.assertEqual(expected, data)
self.mock_open.assert_called_once_with(
os.path.join(
os.environ.get('HOME'),
'config-download/overcloud/group_vars/overcloud.json'),
'r')
@mock.patch('tripleoclient.utils.os.path.exists',
autospec=True, reutrn_value=True)
@mock.patch('tripleoclient.utils.get_stack')
def test_export_stack_auth_cloud_name_set(
self, mock_get_stack, mock_exists):
heat = mock.Mock()
mock_get_stack.return_value = self.mock_stack
self.mock_stack.environment.return_value['parameter_defaults'] = (
dict(AuthCloudName='central'))
with mock.patch('tripleoclient.utils.open', self.mock_open):
data = export.export_stack(heat, "overcloud")
expected = \
{'AllNodesExtraMapData': {u'an_key': u'an_value'},
'AuthCloudName': 'central',
'EndpointMapOverride': {'em_key': 'em_value'},
'ExtraHostFileEntries': 'hosts entry',
'GlobalConfigExtraMapData': {'gc_key': 'gc_value'}}
@ -110,6 +142,7 @@ class TestExport(TestCase):
expected = \
{'AllNodesExtraMapData': {u'ovn_dbs_vip': u'vip'},
'AuthCloudName': 'overcloud',
'EndpointMapOverride': {'em_key': 'em_value'},
'ExtraHostFileEntries': 'hosts entry',
'GlobalConfigExtraMapData': {'gc_key': 'gc_value'}}