diff --git a/murano/common/config.py b/murano/common/config.py index 9d9078dd..3947208e 100644 --- a/murano/common/config.py +++ b/murano/common/config.py @@ -74,7 +74,11 @@ heat_opts = [ 'communicate with Heat API.'), cfg.StrOpt('endpoint_type', default='publicURL', - help='Heat endpoint type.') + help='Heat endpoint type.'), + + cfg.ListOpt('stack_tags', default=['murano'], + help='List of tags to be assigned to heat stacks created ' + 'during environment deployment.') ] mistral_opts = [ diff --git a/murano/engine/system/heat_stack.py b/murano/engine/system/heat_stack.py index 35a825a4..7fd62698 100644 --- a/murano/engine/system/heat_stack.py +++ b/murano/engine/system/heat_stack.py @@ -17,6 +17,7 @@ import copy import eventlet import heatclient.exc as heat_exc +from oslo_config import cfg from oslo_log import log as logging from murano.common.i18n import _LW @@ -25,6 +26,7 @@ from murano.dsl import dsl from murano.dsl import helpers LOG = logging.getLogger(__name__) +CONF = cfg.CONF HEAT_TEMPLATE_VERSION = '2013-05-23' @@ -45,6 +47,7 @@ class HeatStack(object): self._description = description self._clients = helpers.get_environment().clients self._last_stack_timestamps = (None, None) + self._tags = '' def current(self): client = self._clients.get_heat_client() @@ -175,6 +178,7 @@ class HeatStack(object): if self._applied or self._template is None: return + self._tags = ','.join(CONF.heat.stack_tags) if 'heat_template_version' not in self._template: self._template['heat_template_version'] = HEAT_TEMPLATE_VERSION @@ -195,7 +199,8 @@ class HeatStack(object): template=template, files=self._files, environment=self._hot_environment, - disable_rollback=True) + disable_rollback=True, + tags=self._tags) self._wait_state(lambda status: status == 'CREATE_COMPLETE') else: @@ -208,7 +213,8 @@ class HeatStack(object): files=self._files, environment=self._hot_environment, template=template, - disable_rollback=True) + disable_rollback=True, + tags=self._tags) self._wait_state( lambda status: status == 'UPDATE_COMPLETE', True) else: diff --git a/murano/tests/unit/test_heat_stack.py b/murano/tests/unit/test_heat_stack.py index cc5e5962..23dade4d 100644 --- a/murano/tests/unit/test_heat_stack.py +++ b/murano/tests/unit/test_heat_stack.py @@ -15,6 +15,7 @@ from heatclient.v1 import stacks import mock +from oslo_config import cfg from murano.dsl import constants from murano.dsl import helpers @@ -26,6 +27,7 @@ from murano.engine.system import heat_stack from murano.tests.unit import base MOD_NAME = 'murano.engine.system.heat_stack' +CONF = cfg.CONF class TestHeatStack(base.MuranoTestCase): @@ -43,6 +45,8 @@ class TestHeatStack(base.MuranoTestCase): client_manager_mock.get_heat_client.return_value = \ self.heat_client_mock self.environment_mock.clients = client_manager_mock + CONF.set_override('stack_tags', ['test-murano'], 'heat') + self.mock_tag = ','.join(CONF.heat.stack_tags) @mock.patch(MOD_NAME + '.HeatStack._wait_state') @mock.patch(MOD_NAME + '.HeatStack._get_status') @@ -51,7 +55,6 @@ class TestHeatStack(base.MuranoTestCase): status_get.return_value = 'NOT_FOUND' wait_st.return_value = {} - context = {constants.CTX_ENVIRONMENT: self.environment_mock} with helpers.contextual(context): @@ -84,7 +87,8 @@ class TestHeatStack(base.MuranoTestCase): parameters={}, template=expected_template, files={}, - environment='' + environment='', + tags=self.mock_tag ) self.assertTrue(hs._applied) @@ -116,7 +120,8 @@ class TestHeatStack(base.MuranoTestCase): parameters={}, template=expected_template, files={}, - environment='' + environment='', + tags=self.mock_tag ) self.assertTrue(hs._applied) @@ -149,7 +154,8 @@ class TestHeatStack(base.MuranoTestCase): parameters={}, template=expected_template, files={"heatFile": "file"}, - environment='' + environment='', + tags=self.mock_tag ) self.assertTrue(hs._applied) @@ -183,6 +189,7 @@ class TestHeatStack(base.MuranoTestCase): template=expected_template, files={"heatFile": "file"}, environment='environments', + tags=self.mock_tag ) self.assertTrue(hs._applied) @@ -218,3 +225,41 @@ class TestHeatStack(base.MuranoTestCase): hs.update_template({'heat_template_version': '2013-05-23'}) expected['heat_template_version'] = '2013-05-23' self.assertEqual(expected, hs._template) + + @mock.patch(MOD_NAME + '.HeatStack._wait_state') + @mock.patch(MOD_NAME + '.HeatStack._get_status') + def test_heat_stack_tags_are_sent(self, status_get, wait_st): + """Assert that heat_stack `tags` parameter get push & with + value from config parameter `stack_tags`. + """ + + status_get.return_value = 'NOT_FOUND' + wait_st.return_value = {} + CONF.set_override('stack_tags', ['test-murano', 'murano-tag'], 'heat') + context = {constants.CTX_ENVIRONMENT: self.environment_mock} + + with helpers.contextual(context): + hs = heat_stack.HeatStack('test-stack', None) + hs._description = None + hs._template = {'resources': {'test': 1}} + hs._files = {} + hs._hot_environment = '' + hs._parameters = {} + hs._applied = False + hs._tags = ','.join(CONF.heat.stack_tags) + hs.push() + + expected_template = { + 'heat_template_version': '2013-05-23', + 'resources': {'test': 1} + } + self.heat_client_mock.stacks.create.assert_called_with( + stack_name='test-stack', + disable_rollback=True, + parameters={}, + template=expected_template, + files={}, + environment='', + tags=','.join(CONF.heat.stack_tags) + ) + self.assertTrue(hs._applied) diff --git a/releasenotes/notes/tag-heat-stacks-3345eb1bda531a6f.yaml b/releasenotes/notes/tag-heat-stacks-3345eb1bda531a6f.yaml new file mode 100644 index 00000000..fa0dac72 --- /dev/null +++ b/releasenotes/notes/tag-heat-stacks-3345eb1bda531a6f.yaml @@ -0,0 +1,5 @@ +--- +features: + - Heat stacks created by murano during environment deployment now + have 'murano' tag by default. This is controlled by ``stack_tags`` + config parameter. \ No newline at end of file