Fix deleting stacks by id when waiting for result

When we want to wait for the result (wait=True), deleting a stack by
name works as expected. However, if deleting by id the stack is still
deleted but we get an error while polling events because no event is
ever found. This happens because the poller always compares the
resource_name attribute, which will never match the id.

This also required updating the tests as the fake events are always
created with the id as the resource_name and they assume that the
function is always called with the stack id and never the stack name.

Change-Id: Icd3a831faf14a45b1e492a0088160e519b5c6a02
Task: 30189
Story: 2005301
This commit is contained in:
João Vale 2020-04-04 02:56:15 +01:00
parent 128f6b3bc3
commit 6cab3a619b
2 changed files with 61 additions and 3 deletions

View File

@ -60,7 +60,8 @@ def poll_for_events(
msg_template = "\n Stack %(name)s %(status)s \n"
def is_stack_event(event):
if event.get('resource_name', '') != stack_name:
if (event.get('resource_name', '') != stack_name
and event.get('physical_resource_id', '') != stack_name):
return False
phys_id = event.get('physical_resource_id', '')

View File

@ -183,9 +183,66 @@ class TestStack(base.TestCase):
self.cloud.delete_stack(self.stack_id)
self.assert_calls()
def test_delete_stack_wait(self):
def test_delete_stack_by_name_wait(self):
marker_event = fakes.make_fake_stack_event(
self.stack_id, self.stack_name, status='CREATE_COMPLETE')
self.stack_id, self.stack_name, status='CREATE_COMPLETE',
resource_name='name')
marker_qs = 'marker={e_id}&sort_dir=asc'.format(
e_id=marker_event['id'])
resolve = 'resolve_outputs=False'
self.register_uris([
dict(method='GET',
uri='{endpoint}/stacks/{name}?{resolve}'.format(
endpoint=fakes.ORCHESTRATION_ENDPOINT,
name=self.stack_name,
resolve=resolve),
status_code=302,
headers=dict(
location='{endpoint}/stacks/{name}/{id}?{resolve}'.format(
endpoint=fakes.ORCHESTRATION_ENDPOINT,
id=self.stack_id, name=self.stack_name,
resolve=resolve))),
dict(method='GET',
uri='{endpoint}/stacks/{name}/{id}?{resolve}'.format(
endpoint=fakes.ORCHESTRATION_ENDPOINT,
id=self.stack_id, name=self.stack_name, resolve=resolve),
json={"stack": self.stack}),
dict(method='GET',
uri='{endpoint}/stacks/{name}/events?{qs}'.format(
endpoint=fakes.ORCHESTRATION_ENDPOINT,
name=self.stack_name,
qs='limit=1&sort_dir=desc'),
complete_qs=True,
json={"events": [marker_event]}),
dict(method='DELETE',
uri='{endpoint}/stacks/{id}'.format(
endpoint=fakes.ORCHESTRATION_ENDPOINT,
id=self.stack_id)),
dict(method='GET',
uri='{endpoint}/stacks/{name}/events?{qs}'.format(
endpoint=fakes.ORCHESTRATION_ENDPOINT,
name=self.stack_name,
qs=marker_qs),
complete_qs=True,
json={"events": [
fakes.make_fake_stack_event(
self.stack_id, self.stack_name,
status='DELETE_COMPLETE', resource_name='name'),
]}),
dict(method='GET',
uri='{endpoint}/stacks/{name}?{resolve}'.format(
endpoint=fakes.ORCHESTRATION_ENDPOINT,
id=self.stack_id, name=self.stack_name, resolve=resolve),
status_code=404),
])
self.assertTrue(self.cloud.delete_stack(self.stack_name, wait=True))
self.assert_calls()
def test_delete_stack_by_id_wait(self):
marker_event = fakes.make_fake_stack_event(
self.stack_id, self.stack_name, status='CREATE_COMPLETE',
resource_name='name')
marker_qs = 'marker={e_id}&sort_dir=asc'.format(
e_id=marker_event['id'])
resolve = 'resolve_outputs=False'