Browse Source

Merge "Rollback stack with correct tags"

changes/11/494811/3
Jenkins 5 years ago committed by Gerrit Code Review
parent
commit
c423e5d202
  1. 9
      heat/engine/stack.py
  2. 25
      heat/tests/test_stack.py
  3. 13
      heat/tests/test_stack_update.py

9
heat/engine/stack.py

@ -592,7 +592,8 @@ class Stack(collections.Mapping):
nested_depth=stack.nested_depth,
deleted_time=stack.deleted_at)
def get_kwargs_for_cloning(self, keep_status=False, only_db=False):
def get_kwargs_for_cloning(self, keep_status=False, only_db=False,
keep_tags=False):
"""Get common kwargs for calling Stack() for cloning.
The point of this method is to reduce the number of places that we
@ -633,6 +634,8 @@ class Stack(collections.Mapping):
stack['tenant_id'] = self.tenant_id
stack['timeout_mins'] = self.timeout_mins
stack['strict_validate'] = self.strict_validate
if keep_tags:
stack['tags'] = self.tags
return stack
@ -1196,7 +1199,7 @@ class Stack(collections.Mapping):
LOG.debug('Loaded existing backup stack')
return self.load(self.context, stack=s)
elif create_if_missing:
kwargs = self.get_kwargs_for_cloning()
kwargs = self.get_kwargs_for_cloning(keep_tags=True)
kwargs['owner_id'] = self.id
del(kwargs['prev_raw_template_id'])
prev = type(self)(self.context, self._backup_name(),
@ -1512,7 +1515,7 @@ class Stack(collections.Mapping):
if action == self.UPDATE:
# Oldstack is useless when the action is not UPDATE , so we don't
# need to build it, this can avoid some unexpected errors.
kwargs = self.get_kwargs_for_cloning()
kwargs = self.get_kwargs_for_cloning(keep_tags=True)
self._ensure_encrypted_param_names_valid()
oldstack = Stack(self.context, self.name, copy.deepcopy(self.t),
**kwargs)

25
heat/tests/test_stack.py

@ -2924,15 +2924,18 @@ class StackTest(common.HeatTestCase):
class StackKwargsForCloningTest(common.HeatTestCase):
scenarios = [
('default', dict(keep_status=False, only_db=False,
not_included=['action', 'status', 'status_reason'])),
('only_db', dict(keep_status=False, only_db=True,
('default', dict(keep_status=False, only_db=False, keep_tags=False,
not_included=['action', 'status', 'status_reason',
'strict_validate'])),
('keep_status', dict(keep_status=True, only_db=False,
not_included=[])),
('status_db', dict(keep_status=True, only_db=True,
not_included=['strict_validate'])),
'tags'])),
('only_db', dict(keep_status=False, only_db=True, keep_tags=False,
not_included=['action', 'status', 'status_reason',
'strict_validate', 'tags'])),
('keep_status', dict(keep_status=True, only_db=False, keep_tags=False,
not_included=['tags'])),
('status_db', dict(keep_status=True, only_db=True, keep_tags=False,
not_included=['strict_validate', 'tags'])),
('keep_tags', dict(keep_status=False, only_db=False, keep_tags=True,
not_included=['action', 'status', 'status_reason']))
]
def test_kwargs(self):
@ -2945,7 +2948,8 @@ class StackKwargsForCloningTest(common.HeatTestCase):
user_creds_id=123, tenant_id='some-uuid',
username='jo', nested_depth=3,
strict_validate=True, convergence=False,
current_traversal=45)
current_traversal=45,
tags=['tag1', 'tag2'])
db_map = {'parent_resource': 'parent_resource_name',
'tenant_id': 'tenant', 'timeout_mins': 'timeout'}
test_db_data = {}
@ -2956,7 +2960,8 @@ class StackKwargsForCloningTest(common.HeatTestCase):
self.stack = stack.Stack(ctx, utils.random_name(), tmpl,
**test_data)
res = self.stack.get_kwargs_for_cloning(keep_status=self.keep_status,
only_db=self.only_db)
only_db=self.only_db,
keep_tags=self.keep_tags)
for key in self.not_included:
self.assertNotIn(key, res)

13
heat/tests/test_stack_update.py

@ -856,21 +856,24 @@ class StackUpdateTest(common.HeatTestCase):
cancel_message=rpc_api.THREAD_CANCEL):
tmpl = {'HeatTemplateFormatVersion': '2012-12-12',
'Resources': {'AResource': {'Type': 'GenericResourceType'}}}
old_tags = ['tag1', 'tag2']
self.stack = stack.Stack(self.ctx, 'update_test_stack',
template.Template(tmpl))
template.Template(tmpl), tags=old_tags)
self.stack.store()
self.stack.create()
self.assertEqual((stack.Stack.CREATE, stack.Stack.COMPLETE),
self.stack.state)
self.assertEqual(old_tags, self.stack.tags)
tmpl2 = {'HeatTemplateFormatVersion': '2012-12-12',
'Resources': {
'AResource': {'Type': 'GenericResourceType'},
'BResource': {'Type': 'MultiStepResourceType'}}}
new_tags = ['tag3', 'tag4']
updated_stack = stack.Stack(self.ctx, 'updated_stack',
template.Template(tmpl2),
disable_rollback=disable_rollback)
disable_rollback=disable_rollback,
tags=new_tags)
msgq_mock = mock.MagicMock()
msgq_mock.get_nowait.return_value = cancel_message
@ -878,6 +881,10 @@ class StackUpdateTest(common.HeatTestCase):
self.stack.update(updated_stack, msg_queue=msgq_mock)
self.assertEqual(state, self.stack.state)
if disable_rollback:
self.assertEqual(new_tags, self.stack.tags)
else:
self.assertEqual(old_tags, self.stack.tags)
msgq_mock.get_nowait.assert_called_once_with()
def test_update_force_cancel_no_rollback(self):

Loading…
Cancel
Save