Optimize Heat stack check when processing roles
When checking for compatibility when upgrading networks, we check if the stack exists for every single network. Including on initial deployment. This makes the check once, and pass on the result. Change-Id: I2ed9dcac8f7bc212f55571eedee7572d8f0becf7
This commit is contained in:
@@ -150,11 +150,9 @@ class ProcessTemplatesAction(base.TripleOAction):
|
|||||||
"the J2 excludes list to: %s" % j2_excl_data)
|
"the J2 excludes list to: %s" % j2_excl_data)
|
||||||
return j2_excl_data
|
return j2_excl_data
|
||||||
|
|
||||||
def _heat_resource_exists(self, nested_stack_name, resource_name, context):
|
def _heat_resource_exists(self, heatclient, stack, nested_stack_name,
|
||||||
heatclient = self.get_orchestration_client(context)
|
resource_name, context):
|
||||||
try:
|
if stack is None:
|
||||||
stack = heatclient.stacks.get(self.container)
|
|
||||||
except heat_exc.HTTPNotFound:
|
|
||||||
LOG.debug("Resource does not exist because stack does not exist")
|
LOG.debug("Resource does not exist because stack does not exist")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@@ -217,6 +215,14 @@ class ProcessTemplatesAction(base.TripleOAction):
|
|||||||
r_map[r.get('name')] = r
|
r_map[r.get('name')] = r
|
||||||
excl_templates = j2_excl_data.get('name')
|
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 = {}
|
n_map = {}
|
||||||
for n in network_data:
|
for n in network_data:
|
||||||
if n.get('enabled') is not False:
|
if n.get('enabled') is not False:
|
||||||
@@ -228,7 +234,8 @@ class ProcessTemplatesAction(base.TripleOAction):
|
|||||||
# Check to see if legacy named API network exists
|
# Check to see if legacy named API network exists
|
||||||
# and if so we need to set compat_name
|
# and if so we need to set compat_name
|
||||||
api_net = "{}Network".format(constants.LEGACY_API_NETWORK)
|
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'
|
n['compat_name'] = 'Internal'
|
||||||
LOG.info("Upgrade compatibility enabled for legacy "
|
LOG.info("Upgrade compatibility enabled for legacy "
|
||||||
"network resource Internal.")
|
"network resource Internal.")
|
||||||
|
@@ -221,7 +221,9 @@ class ProcessTemplatesActionTest(base.TestCase):
|
|||||||
'process_multiple_environments_and_files')
|
'process_multiple_environments_and_files')
|
||||||
@mock.patch('heatclient.common.template_utils.get_template_contents')
|
@mock.patch('heatclient.common.template_utils.get_template_contents')
|
||||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
@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_get_template_contents,
|
||||||
mock_process_multiple_environments_and_files):
|
mock_process_multiple_environments_and_files):
|
||||||
|
|
||||||
@@ -289,8 +291,10 @@ class ProcessTemplatesActionTest(base.TestCase):
|
|||||||
@mock.patch('tripleo_common.actions.templates.ProcessTemplatesAction'
|
@mock.patch('tripleo_common.actions.templates.ProcessTemplatesAction'
|
||||||
'._heat_resource_exists')
|
'._heat_resource_exists')
|
||||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
||||||
def test_process_custom_roles(self, get_obj_client_mock,
|
@mock.patch('tripleo_common.actions.base.TripleOAction.'
|
||||||
resource_exists_mock):
|
'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
|
resource_exists_mock.return_value = False
|
||||||
swift = self._custom_roles_mock_objclient(
|
swift = self._custom_roles_mock_objclient(
|
||||||
'foo.j2.yaml', JINJA_SNIPPET)
|
'foo.j2.yaml', JINJA_SNIPPET)
|
||||||
@@ -323,8 +327,11 @@ class ProcessTemplatesActionTest(base.TestCase):
|
|||||||
@mock.patch('tripleo_common.actions.templates.ProcessTemplatesAction'
|
@mock.patch('tripleo_common.actions.templates.ProcessTemplatesAction'
|
||||||
'._heat_resource_exists')
|
'._heat_resource_exists')
|
||||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
@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(
|
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
|
resource_exists_mock.return_value = False
|
||||||
swift = self._custom_roles_mock_objclient(
|
swift = self._custom_roles_mock_objclient(
|
||||||
'disable-constraints.role.j2.yaml', snippet,
|
'disable-constraints.role.j2.yaml', snippet,
|
||||||
@@ -363,8 +370,10 @@ class ProcessTemplatesActionTest(base.TestCase):
|
|||||||
@mock.patch('tripleo_common.actions.templates.ProcessTemplatesAction'
|
@mock.patch('tripleo_common.actions.templates.ProcessTemplatesAction'
|
||||||
'._heat_resource_exists')
|
'._heat_resource_exists')
|
||||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
||||||
def test_custom_roles_networks(self, get_obj_client_mock,
|
@mock.patch('tripleo_common.actions.base.TripleOAction'
|
||||||
resource_exists_mock):
|
'.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
|
resource_exists_mock.return_value = False
|
||||||
swift = self._custom_roles_mock_objclient(
|
swift = self._custom_roles_mock_objclient(
|
||||||
'role-networks.role.j2.yaml', JINJA_SNIPPET_ROLE_NETWORKS,
|
'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):
|
def test_heat_resource_exists(self, client_mock):
|
||||||
mock_ctx = mock.MagicMock()
|
mock_ctx = mock.MagicMock()
|
||||||
heat_client = mock.MagicMock()
|
heat_client = mock.MagicMock()
|
||||||
heat_client.stacks.get.return_value = mock.MagicMock(
|
stack = mock.MagicMock(stack_name='overcloud')
|
||||||
stack_name='overcloud')
|
|
||||||
heat_client.resources.get.return_value = mock.MagicMock(
|
heat_client.resources.get.return_value = mock.MagicMock(
|
||||||
links=[{'rel': 'stack',
|
links=[{'rel': 'stack',
|
||||||
'href': 'http://192.0.2.1:8004/v1/'
|
'href': 'http://192.0.2.1:8004/v1/'
|
||||||
@@ -525,15 +533,14 @@ class ProcessTemplatesActionTest(base.TestCase):
|
|||||||
action = templates.ProcessTemplatesAction()
|
action = templates.ProcessTemplatesAction()
|
||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
action._heat_resource_exists(
|
action._heat_resource_exists(
|
||||||
'Networks', 'InternalNetwork', mock_ctx))
|
heat_client, stack, 'Networks', 'InternalNetwork', mock_ctx))
|
||||||
|
|
||||||
@mock.patch('tripleo_common.actions.base.TripleOAction.'
|
@mock.patch('tripleo_common.actions.base.TripleOAction.'
|
||||||
'get_orchestration_client')
|
'get_orchestration_client')
|
||||||
def test_no_heat_resource_exists(self, client_mock):
|
def test_no_heat_resource_exists(self, client_mock):
|
||||||
mock_ctx = mock.MagicMock()
|
mock_ctx = mock.MagicMock()
|
||||||
heat_client = mock.MagicMock()
|
heat_client = mock.MagicMock()
|
||||||
heat_client.stacks.get.return_value = mock.MagicMock(
|
stack = mock.MagicMock(stack_name='overcloud')
|
||||||
stack_name='overcloud')
|
|
||||||
|
|
||||||
def return_not_found(*args):
|
def return_not_found(*args):
|
||||||
raise heat_exc.HTTPNotFound()
|
raise heat_exc.HTTPNotFound()
|
||||||
@@ -543,14 +550,17 @@ class ProcessTemplatesActionTest(base.TestCase):
|
|||||||
action = templates.ProcessTemplatesAction()
|
action = templates.ProcessTemplatesAction()
|
||||||
self.assertFalse(
|
self.assertFalse(
|
||||||
action._heat_resource_exists(
|
action._heat_resource_exists(
|
||||||
'Networks', 'InternalNetwork', mock_ctx))
|
heat_client, stack, 'Networks', 'InternalNetwork', mock_ctx))
|
||||||
|
|
||||||
@mock.patch('tripleo_common.actions.templates.ProcessTemplatesAction'
|
@mock.patch('tripleo_common.actions.templates.ProcessTemplatesAction'
|
||||||
'._heat_resource_exists')
|
'._heat_resource_exists')
|
||||||
@mock.patch('tripleo_common.actions.templates.ProcessTemplatesAction'
|
@mock.patch('tripleo_common.actions.templates.ProcessTemplatesAction'
|
||||||
'._j2_render_and_put')
|
'._j2_render_and_put')
|
||||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
@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):
|
||||||
resource_exists_mock.return_value = True
|
resource_exists_mock.return_value = True
|
||||||
swift = self._custom_roles_mock_objclient(
|
swift = self._custom_roles_mock_objclient(
|
||||||
@@ -576,7 +586,10 @@ class ProcessTemplatesActionTest(base.TestCase):
|
|||||||
@mock.patch('tripleo_common.actions.templates.ProcessTemplatesAction'
|
@mock.patch('tripleo_common.actions.templates.ProcessTemplatesAction'
|
||||||
'._j2_render_and_put')
|
'._j2_render_and_put')
|
||||||
@mock.patch('tripleo_common.actions.base.TripleOAction.get_object_client')
|
@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):
|
||||||
resource_exists_mock.return_value = False
|
resource_exists_mock.return_value = False
|
||||||
swift = self._custom_roles_mock_objclient(
|
swift = self._custom_roles_mock_objclient(
|
||||||
|
Reference in New Issue
Block a user