From d767878219c2ee0496f6394a8e08b2ffed01f58f Mon Sep 17 00:00:00 2001 From: huangtianhua Date: Sat, 20 Sep 2014 16:50:18 +0800 Subject: Client supports check action Support stack check action. Change-Id: I652136fb20dfa06ac49b9addf85c4f226aa66107 --- heatclient/tests/test_shell.py | 28 ++++++++++++++++++++++++++++ heatclient/tests/test_stacks.py | 3 ++- heatclient/v1/actions.py | 7 +++++++ heatclient/v1/shell.py | 13 +++++++++++++ 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/heatclient/tests/test_shell.py b/heatclient/tests/test_shell.py index 701bb65..3a4ac10 100644 --- a/heatclient/tests/test_shell.py +++ b/heatclient/tests/test_shell.py @@ -1622,6 +1622,34 @@ class ShellTestUserPass(ShellBase): for r in required: self.assertRegexpMatches(update_text, r) + @httpretty.activate + def test_stack_check(self): + self.register_keystone_auth_fixture() + expected_data = {'check': None} + resp = fakes.FakeHTTPResponse( + 202, + 'Accepted', + {}, + 'The request is accepted for processing.') + http.HTTPClient.json_request( + 'POST', '/stacks/teststack2/actions', + data=expected_data + ).AndReturn((resp, None)) + fakes.script_heat_list() + + self.m.ReplayAll() + + check_text = self.shell('action-check teststack2') + + required = [ + 'stack_name', + 'id', + 'teststack2', + '1' + ] + for r in required: + self.assertRegexpMatches(check_text, r) + @httpretty.activate def test_stack_delete(self): self.register_keystone_auth_fixture() diff --git a/heatclient/tests/test_stacks.py b/heatclient/tests/test_stacks.py index 4886342..e5042c2 100644 --- a/heatclient/tests/test_stacks.py +++ b/heatclient/tests/test_stacks.py @@ -44,7 +44,8 @@ class StackStatusActionTest(testtools.TestCase): ('UPDATE', dict(action='UPDATE')), ('ROLLBACK', dict(action='ROLLBACK')), ('SUSPEND', dict(action='SUSPEND')), - ('RESUME', dict(action='RESUME')) + ('RESUME', dict(action='RESUME')), + ('CHECK', dict(action='CHECK')) ], [ ('IN_PROGRESS', dict(status='IN_PROGRESS')), ('FAILED', dict(status='FAILED')), diff --git a/heatclient/v1/actions.py b/heatclient/v1/actions.py index 9c7028f..4ecd2b6 100644 --- a/heatclient/v1/actions.py +++ b/heatclient/v1/actions.py @@ -53,3 +53,10 @@ class ActionManager(stacks.StackChildManager): resp, body = self.client.json_request('POST', '/stacks/%s/actions' % stack_id, data=body) + + def check(self, stack_id): + """Check a stack.""" + body = {'check': None} + resp, body = self.client.json_request('POST', + '/stacks/%s/actions' % stack_id, + data=body) diff --git a/heatclient/v1/shell.py b/heatclient/v1/shell.py index 5f728f4..63d438e 100644 --- a/heatclient/v1/shell.py +++ b/heatclient/v1/shell.py @@ -306,6 +306,19 @@ def do_action_resume(hc, args): do_stack_list(hc) +@utils.arg('id', metavar='', + help='Name or ID of stack to check.') +def do_action_check(hc, args): + '''Check that stack resources are in expected states.''' + fields = {'stack_id': args.id} + try: + hc.actions.check(**fields) + except exc.HTTPNotFound: + raise exc.CommandError('Stack not found: %s' % args.id) + else: + do_stack_list(hc) + + @utils.arg('id', metavar='', help='Name or ID of stack to describe.') def do_describe(hc, args): -- cgit v1.2.1