summaryrefslogtreecommitdiff
path: root/heatclient
diff options
context:
space:
mode:
authorDmitriy Uvarenkov <duvarenkov@mirantis.com>2016-02-23 13:28:23 +0200
committerDmitriy Uvarenkov <duvarenkov@mirantis.com>2016-03-07 16:55:08 +0200
commit7c1e7b05f44657e8ed59e2ec7f95c3c09e845226 (patch)
tree112f25a29de93c95f72b539d3d42de9e09e956ec /heatclient
parentb80d64703c1310d2002fdf87cedaa72d6cdffc06 (diff)
downloadpython-heatclient-7c1e7b05f44657e8ed59e2ec7f95c3c09e845226.tar.gz
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
Diffstat (limited to 'heatclient')
-rw-r--r--heatclient/osc/v1/stack.py3
-rw-r--r--heatclient/tests/unit/osc/v1/test_stack.py7
-rw-r--r--heatclient/tests/unit/test_shell.py18
-rw-r--r--heatclient/v1/shell.py2
4 files changed, 28 insertions, 2 deletions
diff --git a/heatclient/osc/v1/stack.py b/heatclient/osc/v1/stack.py
index c256bb1..e60b6e2 100644
--- a/heatclient/osc/v1/stack.py
+++ b/heatclient/osc/v1/stack.py
@@ -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:
diff --git a/heatclient/tests/unit/osc/v1/test_stack.py b/heatclient/tests/unit/osc/v1/test_stack.py
index 4ab4818..788414b 100644
--- a/heatclient/tests/unit/osc/v1/test_stack.py
+++ b/heatclient/tests/unit/osc/v1/test_stack.py
@@ -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]
diff --git a/heatclient/tests/unit/test_shell.py b/heatclient/tests/unit/test_shell.py
index 82149bb..899f311 100644
--- a/heatclient/tests/unit/test_shell.py
+++ b/heatclient/tests/unit/test_shell.py
@@ -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 = {
diff --git a/heatclient/v1/shell.py b/heatclient/v1/shell.py
index acea3fc..a61c0bc 100644
--- a/heatclient/v1/shell.py
+++ b/heatclient/v1/shell.py
@@ -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: