Add AuthCloudName to export data

Add the AuthCloudName parameter to the export data. If the parameter is
already set in the stack being exported, use that value, otherwise use
the name of the stack being exported.

Change-Id: Ie9b78d11c816d234853d454ab76da8750def9bba
Signed-off-by: James Slagle <jslagle@redhat.com>
(cherry picked from commit 2bfb6f2bc8)
This commit is contained in:
James Slagle 2022-02-22 14:01:51 -05:00
parent 884d3d52f1
commit 3fb4646fdd
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'}}