diff options
author | huangtianhua <huangtianhua@huawei.com> | 2016-12-24 11:28:35 +0800 |
---|---|---|
committer | huangtianhua <huangtianhua@huawei.com> | 2017-01-24 07:09:58 +0000 |
commit | 3ee70cf4e8c2d8505230f73ef0b6b44185567dc2 (patch) | |
tree | 5ad65b9d93c7921ca48de7bc5861fc5d89494b99 /heatclient | |
parent | 17dd3068e4d6fc10236290cc082908c439bcfead (diff) | |
download | python-heatclient-3ee70cf4e8c2d8505230f73ef0b6b44185567dc2.tar.gz |
Show 'project' info if heat server returns
Show 'project'/'Project' info in heatclient
if heat server returns 'project' info of stacks.
Change-Id: I7d95ae96a678ef41bcd3d5379f204db83e4b585c
Closes-Bug: #1652412
Diffstat (limited to 'heatclient')
-rw-r--r-- | heatclient/osc/v1/stack.py | 7 | ||||
-rw-r--r-- | heatclient/tests/unit/osc/v1/test_stack.py | 21 | ||||
-rw-r--r-- | heatclient/tests/unit/test_shell.py | 42 | ||||
-rw-r--r-- | heatclient/v1/shell.py | 7 |
4 files changed, 53 insertions, 24 deletions
diff --git a/heatclient/osc/v1/stack.py b/heatclient/osc/v1/stack.py index cf03cec..4b04dff 100644 --- a/heatclient/osc/v1/stack.py +++ b/heatclient/osc/v1/stack.py @@ -623,8 +623,6 @@ def _list(client, args=None): columns.pop() if args.long: columns.insert(2, 'Stack Owner') - if args.long or args.all_projects: - columns.insert(2, 'Project') if args.nested: columns.append('Parent') @@ -634,6 +632,11 @@ def _list(client, args=None): columns.append('Deletion Time') data = client.stacks.list(**kwargs) + data = list(data) + for stk in data: + if hasattr(stk, 'project'): + columns.insert(2, 'Project') + break data = utils.sort_items(data, args.sort if args else None) return ( diff --git a/heatclient/tests/unit/osc/v1/test_stack.py b/heatclient/tests/unit/osc/v1/test_stack.py index c40bdf1..7481acb 100644 --- a/heatclient/tests/unit/osc/v1/test_stack.py +++ b/heatclient/tests/unit/osc/v1/test_stack.py @@ -453,6 +453,9 @@ class TestStackList(TestStack): 'deletion_time': '2015-10-21T07:50:00Z', } + data_with_project = copy.deepcopy(data) + data_with_project['project'] = 'test_project' + def setUp(self): super(TestStackList, self).setUp() self.cmd = stack.ListStack(self.app, None) @@ -495,6 +498,8 @@ class TestStackList(TestStack): self.assertEqual(cols, columns) def test_stack_list_all_projects(self): + self.stack_client.list.return_value = [ + stacks.Stack(None, self.data_with_project)] kwargs = copy.deepcopy(self.defaults) kwargs['global_tenant'] = True cols = copy.deepcopy(self.columns) @@ -507,7 +512,23 @@ class TestStackList(TestStack): self.stack_client.list.assert_called_with(**kwargs) self.assertEqual(cols, columns) + def test_stack_list_with_project(self): + self.stack_client.list.return_value = [ + stacks.Stack(None, self.data_with_project)] + kwargs = copy.deepcopy(self.defaults) + cols = copy.deepcopy(self.columns) + cols.insert(2, 'Project') + arglist = [] + parsed_args = self.check_parser(self.cmd, arglist, []) + + columns, data = self.cmd.take_action(parsed_args) + + self.stack_client.list.assert_called_with(**kwargs) + self.assertEqual(cols, columns) + def test_stack_list_long(self): + self.stack_client.list.return_value = [ + stacks.Stack(None, self.data_with_project)] kwargs = copy.deepcopy(self.defaults) kwargs['global_tenant'] = True cols = copy.deepcopy(self.columns) diff --git a/heatclient/tests/unit/test_shell.py b/heatclient/tests/unit/test_shell.py index 18173de..abb5845 100644 --- a/heatclient/tests/unit/test_shell.py +++ b/heatclient/tests/unit/test_shell.py @@ -126,25 +126,25 @@ class TestCase(testtools.TestCase): mockfixture = self.useFixture(mockpatch.Patch(target, **kwargs)) return mockfixture.mock - def stack_list_resp_dict(self, show_nested=False): - resp_dict = {"stacks": [ - { - "id": "1", - "stack_name": "teststack", - "stack_owner": "testowner", - "project": "testproject", - "stack_status": 'CREATE_COMPLETE', - "creation_time": "2012-10-25T01:58:47Z" - }, - { - "id": "2", - "stack_name": "teststack2", - "stack_owner": "testowner", - "project": "testproject", - "stack_status": 'IN_PROGRESS', - "creation_time": "2012-10-25T01:58:47Z" - }] - } + def stack_list_resp_dict(self, show_nested=False, include_project=False): + stack1 = { + "id": "1", + "stack_name": "teststack", + "stack_owner": "testowner", + "stack_status": 'CREATE_COMPLETE', + "creation_time": "2012-10-25T01:58:47Z"} + stack2 = { + "id": "2", + "stack_name": "teststack2", + "stack_owner": "testowner", + "stack_status": 'IN_PROGRESS', + "creation_time": "2012-10-25T01:58:47Z" + } + if include_project: + stack1['project'] = 'testproject' + stack1['project'] = 'testproject' + + resp_dict = {"stacks": [stack1, stack2]} if show_nested: nested = { "id": "3", @@ -153,6 +153,8 @@ class TestCase(testtools.TestCase): "creation_time": "2012-10-25T01:58:47Z", "parent": "theparentof3" } + if include_project: + nested['project'] = 'testproject' resp_dict["stacks"].append(nested) return resp_dict @@ -4209,7 +4211,7 @@ class MockShellTestUserPass(MockShellBase): def test_stack_list_with_args(self): self.register_keystone_auth_fixture() - resp_dict = self.stack_list_resp_dict() + resp_dict = self.stack_list_resp_dict(include_project=True) resp = fakes.FakeHTTPResponse( 200, 'success, you', diff --git a/heatclient/v1/shell.py b/heatclient/v1/shell.py index a3179b3..a38c32a 100644 --- a/heatclient/v1/shell.py +++ b/heatclient/v1/shell.py @@ -689,13 +689,16 @@ def do_stack_list(hc, args=None): if args.global_tenant or args.show_owner: fields.append('stack_owner') - if args.global_tenant: - fields.append('project') if args.show_deleted: fields.append('deletion_time') stacks = hc.stacks.list(**kwargs) + stacks = list(stacks) + for stk in stacks: + if hasattr(stk, 'project'): + fields.append('project') + break utils.print_list(stacks, fields, sortby_index=sortby_index) |