[DEBUG] Add functional tests for stack cancel

This adds tests for user initiated stack cancel operations
w/ or w/o rollback.

Change-Id: I8ff787dc02dd76f99e9ece073b2f700c1922104d
Related-Bug: #1709041
(cherry picked from commit 6c7d059689)
This commit is contained in:
rabi 2017-08-31 10:55:13 +05:30 committed by Rodrigo Barbieri
parent 9b1ab5e152
commit a6525426a0
2 changed files with 109 additions and 5 deletions

View File

@ -286,11 +286,15 @@ class HeatIntegrationTest(testscenarios.WithScenarios,
return False
return res.resource_status == status
def _verify_status(self, stack, stack_identifier, status, fail_regexp):
def _verify_status(self, stack, stack_identifier, status,
fail_regexp, is_action_cancelled=False):
if stack.stack_status == status:
# Handle UPDATE_COMPLETE/FAILED case: Make sure we don't
# wait for a stale UPDATE_COMPLETE/FAILED status.
if status in ('UPDATE_FAILED', 'UPDATE_COMPLETE'):
if is_action_cancelled:
return True
if self.updated_time.get(
stack_identifier) != stack.updated_time:
self.updated_time[stack_identifier] = stack.updated_time
@ -324,7 +328,8 @@ class HeatIntegrationTest(testscenarios.WithScenarios,
failure_pattern=None,
success_on_not_found=False,
signal_required=False,
resources_to_signal=None):
resources_to_signal=None,
is_action_cancelled=False):
"""Waits for a Stack to reach a given status.
Note this compares the full $action_$status, e.g
@ -354,7 +359,7 @@ class HeatIntegrationTest(testscenarios.WithScenarios,
# been created yet
else:
if self._verify_status(stack, stack_identifier, status,
fail_regexp):
fail_regexp, is_action_cancelled):
return
if signal_required:
self.signal_resources(resources_to_signal)
@ -425,7 +430,7 @@ class HeatIntegrationTest(testscenarios.WithScenarios,
self._wait_for_stack_status(**kwargs)
def cancel_update_stack(self, stack_identifier,
def cancel_update_stack(self, stack_identifier, rollback=True,
expected_status='ROLLBACK_COMPLETE'):
stack_name = stack_identifier.split('/')[0]
@ -433,10 +438,16 @@ class HeatIntegrationTest(testscenarios.WithScenarios,
self.updated_time[stack_identifier] = self.client.stacks.get(
stack_identifier, resolve_outputs=False).updated_time
self.client.actions.cancel_update(stack_name)
if rollback:
self.client.actions.cancel_update(stack_name)
else:
self.client.actions.cancel_without_rollback(stack_name)
kwargs = {'stack_identifier': stack_identifier,
'status': expected_status}
if expected_status == 'UPDATE_FAILED':
kwargs['is_action_cancelled'] = True
if expected_status in ['ROLLBACK_COMPLETE']:
# To trigger rollback you would intentionally fail the stack
# Hence check for rollback failures

View File

@ -0,0 +1,93 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import copy
import eventlet
from heat_integrationtests.common import test
from heat_integrationtests.functional import functional_base
template = {
'heat_template_version': 'pike',
'resources': {
'test1': {
'type': 'OS::Heat::TestResource',
'properties': {
'value': 'Test1',
'action_wait_secs': {
'update': 30,
}
}
},
'test2': {
'type': 'OS::Heat::TestResource',
'properties': {
'value': 'Test1',
},
'depends_on': ['test1']
},
}
}
def get_templates(delay_s=None):
before = copy.deepcopy(template)
after = copy.deepcopy(before)
for r in after['resources'].values():
r['properties']['value'] = 'Test2'
if delay_s:
before_props = before['resources']['test1']['properties']
before_props['action_wait_secs']['create'] = delay_s
return before, after
class StackCancelTest(functional_base.FunctionalTestsBase):
def _test_cancel_update(self, rollback=True,
expected_status='ROLLBACK_COMPLETE'):
before, after = get_templates()
stack_id = self.stack_create(template=before)
self.update_stack(stack_id, template=after,
expected_status='UPDATE_IN_PROGRESS')
self._wait_for_resource_status(stack_id, 'test1', 'UPDATE_IN_PROGRESS')
self.cancel_update_stack(stack_id, rollback, expected_status)
return stack_id
def test_cancel_update_with_rollback(self):
self._test_cancel_update()
# def test_cancel_update_without_rollback(self):
# stack_id = self._test_cancel_update(rollback=False,
# expected_status='UPDATE_FAILED')
# self.assertTrue(test.call_until_true(
# 60, 2, self.verify_resource_status,
# stack_id, 'test1', 'UPDATE_COMPLETE'))
# eventlet.sleep(2)
# self.assertTrue(self.verify_resource_status(stack_id, 'test2',
# 'CREATE_COMPLETE'))
# def test_cancel_create_without_rollback(self):
# before, after = get_templates(delay_s=30)
# stack_id = self.stack_create(template=before,
# expected_status='CREATE_IN_PROGRESS')
# self._wait_for_resource_status(stack_id, 'test1', 'CREATE_IN_PROGRESS')
# self.cancel_update_stack(stack_id, rollback=False,
# expected_status='CREATE_FAILED')
# self.assertTrue(test.call_until_true(
# 60, 2, self.verify_resource_status,
# stack_id, 'test1', 'CREATE_COMPLETE'))
# eventlet.sleep(2)
# self.assertTrue(self.verify_resource_status(stack_id, 'test2',
# 'INIT_COMPLETE'))