diff --git a/tripleo_common/actions/templates.py b/tripleo_common/actions/templates.py index 44d497864..d7373bb3f 100644 --- a/tripleo_common/actions/templates.py +++ b/tripleo_common/actions/templates.py @@ -150,11 +150,9 @@ class ProcessTemplatesAction(base.TripleOAction): "the J2 excludes list to: %s" % j2_excl_data) return j2_excl_data - def _heat_resource_exists(self, nested_stack_name, resource_name, context): - heatclient = self.get_orchestration_client(context) - try: - stack = heatclient.stacks.get(self.container) - except heat_exc.HTTPNotFound: + def _heat_resource_exists(self, heatclient, stack, nested_stack_name, + resource_name, context): + if stack is None: LOG.debug("Resource does not exist because stack does not exist") return False @@ -217,6 +215,14 @@ class ProcessTemplatesAction(base.TripleOAction): r_map[r.get('name')] = r excl_templates = j2_excl_data.get('name') + heatclient = self.get_orchestration_client(context) + stack = None + try: + stack = heatclient.stacks.get(self.container, + resolve_outputs=False) + except heat_exc.HTTPNotFound: + LOG.debug("Stack does not exist") + n_map = {} for n in network_data: if n.get('enabled') is not False: @@ -228,7 +234,8 @@ class ProcessTemplatesAction(base.TripleOAction): # Check to see if legacy named API network exists # and if so we need to set compat_name api_net = "{}Network".format(constants.LEGACY_API_NETWORK) - if self._heat_resource_exists('Networks', api_net, context): + if self._heat_resource_exists(heatclient, stack, 'Networks', + api_net, context): n['compat_name'] = 'Internal' LOG.info("Upgrade compatibility enabled for legacy " "network resource Internal.") diff --git a/tripleo_common/tests/actions/test_templates.py b/tripleo_common/tests/actions/test_templates.py index b45c6a8ec..7959fd6fb 100644 --- a/tripleo_common/tests/actions/test_templates.py +++ b/tripleo_common/tests/actions/test_templates.py @@ -221,7 +221,9 @@ class ProcessTemplatesActionTest(base.TestCase): 'process_multiple_environments_and_files') @mock.patch('heatclient.common.template_utils.get_template_contents') @mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client') - def test_run(self, mock_get_object_client, + @mock.patch('tripleo_common.actions.base.TripleOAction.' + 'get_orchestration_client') + def test_run(self, mock_get_heat_client, mock_get_object_client, mock_get_template_contents, mock_process_multiple_environments_and_files): @@ -289,8 +291,10 @@ class ProcessTemplatesActionTest(base.TestCase): @mock.patch('tripleo_common.actions.templates.ProcessTemplatesAction' '._heat_resource_exists') @mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client') - def test_process_custom_roles(self, get_obj_client_mock, - resource_exists_mock): + @mock.patch('tripleo_common.actions.base.TripleOAction.' + 'get_orchestration_client') + def test_process_custom_roles(self, get_heat_client_mock, + get_obj_client_mock, resource_exists_mock): resource_exists_mock.return_value = False swift = self._custom_roles_mock_objclient( 'foo.j2.yaml', JINJA_SNIPPET) @@ -323,8 +327,11 @@ class ProcessTemplatesActionTest(base.TestCase): @mock.patch('tripleo_common.actions.templates.ProcessTemplatesAction' '._heat_resource_exists') @mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client') + @mock.patch('tripleo_common.actions.base.TripleOAction.' + 'get_orchestration_client') def _process_custom_roles_disable_constraints( - self, snippet, get_obj_client_mock, resource_exists_mock): + self, snippet, get_heat_client_mock, get_obj_client_mock, + resource_exists_mock): resource_exists_mock.return_value = False swift = self._custom_roles_mock_objclient( 'disable-constraints.role.j2.yaml', snippet, @@ -363,8 +370,10 @@ class ProcessTemplatesActionTest(base.TestCase): @mock.patch('tripleo_common.actions.templates.ProcessTemplatesAction' '._heat_resource_exists') @mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client') - def test_custom_roles_networks(self, get_obj_client_mock, - resource_exists_mock): + @mock.patch('tripleo_common.actions.base.TripleOAction' + '.get_orchestration_client') + def test_custom_roles_networks(self, get_heat_client_mock, + get_obj_client_mock, resource_exists_mock): resource_exists_mock.return_value = False swift = self._custom_roles_mock_objclient( 'role-networks.role.j2.yaml', JINJA_SNIPPET_ROLE_NETWORKS, @@ -509,8 +518,7 @@ class ProcessTemplatesActionTest(base.TestCase): def test_heat_resource_exists(self, client_mock): mock_ctx = mock.MagicMock() heat_client = mock.MagicMock() - heat_client.stacks.get.return_value = mock.MagicMock( - stack_name='overcloud') + stack = mock.MagicMock(stack_name='overcloud') heat_client.resources.get.return_value = mock.MagicMock( links=[{'rel': 'stack', 'href': 'http://192.0.2.1:8004/v1/' @@ -525,15 +533,14 @@ class ProcessTemplatesActionTest(base.TestCase): action = templates.ProcessTemplatesAction() self.assertTrue( action._heat_resource_exists( - 'Networks', 'InternalNetwork', mock_ctx)) + heat_client, stack, 'Networks', 'InternalNetwork', mock_ctx)) @mock.patch('tripleo_common.actions.base.TripleOAction.' 'get_orchestration_client') def test_no_heat_resource_exists(self, client_mock): mock_ctx = mock.MagicMock() heat_client = mock.MagicMock() - heat_client.stacks.get.return_value = mock.MagicMock( - stack_name='overcloud') + stack = mock.MagicMock(stack_name='overcloud') def return_not_found(*args): raise heat_exc.HTTPNotFound() @@ -543,14 +550,17 @@ class ProcessTemplatesActionTest(base.TestCase): action = templates.ProcessTemplatesAction() self.assertFalse( action._heat_resource_exists( - 'Networks', 'InternalNetwork', mock_ctx)) + heat_client, stack, 'Networks', 'InternalNetwork', mock_ctx)) @mock.patch('tripleo_common.actions.templates.ProcessTemplatesAction' '._heat_resource_exists') @mock.patch('tripleo_common.actions.templates.ProcessTemplatesAction' '._j2_render_and_put') @mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client') - def test_legacy_api_network_exists(self, get_obj_client_mock, j2_mock, + @mock.patch('tripleo_common.actions.base.TripleOAction.' + 'get_orchestration_client') + def test_legacy_api_network_exists(self, get_heat_client_mock, + get_obj_client_mock, j2_mock, resource_exists_mock): resource_exists_mock.return_value = True swift = self._custom_roles_mock_objclient( @@ -576,7 +586,10 @@ class ProcessTemplatesActionTest(base.TestCase): @mock.patch('tripleo_common.actions.templates.ProcessTemplatesAction' '._j2_render_and_put') @mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client') - def test_no_legacy_api_network_exists(self, get_obj_client_mock, j2_mock, + @mock.patch('tripleo_common.actions.base.TripleOAction.' + 'get_orchestration_client') + def test_no_legacy_api_network_exists(self, get_heat_client_mock, + get_obj_client_mock, j2_mock, resource_exists_mock): resource_exists_mock.return_value = False swift = self._custom_roles_mock_objclient(