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
This commit is contained in:
huangtianhua 2016-12-24 11:28:35 +08:00
parent 17dd3068e4
commit 3ee70cf4e8
4 changed files with 53 additions and 24 deletions

View File

@ -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 (

View File

@ -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)

View File

@ -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',

View File

@ -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)