Fixed exceptions handling in stacks deleting
When you delete multiple stacks like 'stackA stackB stackC' and you dont have enough rights for deleting stackB, it throws 403. In result stackA is deleted, but stackC is still there. Change-Id: If2795a4a7a6987da15b5f3f23ee066000e1f2a65
This commit is contained in:
parent
b80d64703c
commit
7c1e7b05f4
@ -653,6 +653,9 @@ class DeleteStack(command.Command):
|
||||
except heat_exc.HTTPNotFound:
|
||||
failure_count += 1
|
||||
print(_('Stack not found: %s') % sid)
|
||||
except heat_exc.Forbidden:
|
||||
failure_count += 1
|
||||
print(_('Forbidden: %s') % sid)
|
||||
|
||||
if parsed_args.wait:
|
||||
for sid, marker in stacks_waiting:
|
||||
|
@ -569,6 +569,13 @@ class TestStackDelete(TestStack):
|
||||
|
||||
self.assertRaises(exc.CommandError, self.cmd.take_action, parsed_args)
|
||||
|
||||
def test_stack_delete_forbidden(self):
|
||||
arglist = ['my_stack']
|
||||
self.stack_client.delete.side_effect = heat_exc.Forbidden
|
||||
parsed_args = self.check_parser(self.cmd, arglist, [])
|
||||
|
||||
self.assertRaises(exc.CommandError, self.cmd.take_action, parsed_args)
|
||||
|
||||
def test_stack_delete_one_found_one_not_found(self):
|
||||
arglist = ['stack1', 'stack2']
|
||||
self.stack_client.delete.side_effect = [None, heat_exc.HTTPNotFound]
|
||||
|
@ -2607,7 +2607,7 @@ class ShellTestUserPass(ShellBase):
|
||||
for r in required:
|
||||
self.assertRegexpMatches(delete_text, r)
|
||||
|
||||
def test_stack_delete_failed(self):
|
||||
def test_stack_delete_failed_on_notfound(self):
|
||||
self.register_keystone_auth_fixture()
|
||||
|
||||
if self.client == http.SessionClient:
|
||||
@ -2623,6 +2623,22 @@ class ShellTestUserPass(ShellBase):
|
||||
self.assertIn('Unable to delete 1 of the 1 stacks.',
|
||||
str(error))
|
||||
|
||||
def test_stack_delete_failed_on_forbidden(self):
|
||||
self.register_keystone_auth_fixture()
|
||||
|
||||
if self.client == http.SessionClient:
|
||||
self.client.request(
|
||||
'/stacks/teststack1/1', 'DELETE').AndRaise(exc.Forbidden())
|
||||
else:
|
||||
http.HTTPClient.raw_request(
|
||||
'DELETE',
|
||||
'/stacks/teststack1/1').AndRaise(exc.Forbidden())
|
||||
self.m.ReplayAll()
|
||||
error = self.assertRaises(
|
||||
exc.CommandError, self.shell, 'stack-delete teststack1/1')
|
||||
self.assertIn('Unable to delete 1 of the 1 stacks.',
|
||||
str(error))
|
||||
|
||||
def test_build_info(self):
|
||||
self.register_keystone_auth_fixture()
|
||||
resp_dict = {
|
||||
|
@ -323,7 +323,7 @@ def do_stack_delete(hc, args):
|
||||
fields = {'stack_id': sid}
|
||||
try:
|
||||
hc.stacks.delete(**fields)
|
||||
except exc.HTTPNotFound as e:
|
||||
except (exc.HTTPNotFound, exc.Forbidden) as e:
|
||||
failure_count += 1
|
||||
print(e)
|
||||
if failure_count:
|
||||
|
Loading…
Reference in New Issue
Block a user