Add tagging fuctionality for heat stacks

Heat provides tagging fuctionality for stacks, now tagging is
possible for stacks generated via murano also. To implement it,
added new config parameter `stack_tags` with default value 'murano'
and tagged heat stacks created during environment deployment with
`stack_tags` parameter's value.

Change-Id: Ib3f4027b78616c02cf3bbb210578df23d7e536d3
Implements: blueprint tag-murano-heat-stacks
This commit is contained in:
enthurohini 2015-12-17 02:22:23 +05:30 committed by Kirill Zaitsev
parent 10d8593003
commit a1d69bb515
4 changed files with 67 additions and 7 deletions

View File

@ -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 = [

View File

@ -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:

View File

@ -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)

View File

@ -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.