Skip to content

Commit

Permalink
Display stack owner info on stack-list
Browse files Browse the repository at this point in the history
When listing stacks using the --global-tenant flag, the user is not able
to tell who each stack belongs to.  Furthermore, the problem may also
happen if there are multiple users within the same project.

This adds a --show-owner flag to stack-list to display the stack_owner
information when doing a normal stack list.  This flag is also set to
true when using --global-tenant, including an extra project field as
well, since the username is not unique across all projects.

Closes-Bug: #1359898
Change-Id: Id517be1d147f0b3a72ef7c3f8e4d16c7460477f8
  • Loading branch information
andersonvom committed Sep 16, 2014
1 parent 3a05689 commit c29f12a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
4 changes: 4 additions & 0 deletions heatclient/tests/fakes.py
Expand Up @@ -24,12 +24,16 @@ def script_heat_list(url=None, show_nested=False):
{
"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"
}]
Expand Down
18 changes: 18 additions & 0 deletions heatclient/tests/test_shell.py
Expand Up @@ -553,6 +553,9 @@ def test_stack_list_with_args(self):
' --show-deleted')

required = [
'stack_owner',
'project',
'testproject',
'teststack',
'teststack2',
]
Expand Down Expand Up @@ -583,6 +586,21 @@ def test_stack_list_show_nested(self):
for r in required:
self.assertRegexpMatches(list_text, r)

@httpretty.activate
def test_stack_list_show_owner(self):
self.register_keystone_auth_fixture()
fakes.script_heat_list()
self.m.ReplayAll()

list_text = self.shell('stack-list --show-owner')

required = [
'stack_owner',
'testowner',
]
for r in required:
self.assertRegexpMatches(list_text, r)

@httpretty.activate
def test_parsable_error(self):
self.register_keystone_auth_fixture()
Expand Down
12 changes: 9 additions & 3 deletions heatclient/v1/shell.py
Expand Up @@ -460,11 +460,12 @@ def do_list(hc):
help='Limit the number of stacks returned.')
@utils.arg('-m', '--marker', metavar='<ID>',
help='Only return stacks that appear after the given stack ID.')
@utils.arg('-g', '--global-tenant',
action='store_true',
default=False,
@utils.arg('-g', '--global-tenant', action='store_true', default=False,
help='Display stacks from all tenants. Operation only authorized '
'for users who match the policy in heat\'s policy.json.')
@utils.arg('-o', '--show-owner', action='store_true', default=False,
help='Display stack owner information. This is automatically '
'enabled when using --global-tenant.')
def do_stack_list(hc, args=None):
'''List the user's stacks.'''
kwargs = {}
Expand All @@ -479,6 +480,11 @@ def do_stack_list(hc, args=None):
fields.append('parent')
kwargs['show_nested'] = True

if args.global_tenant or args.show_owner:
fields.insert(2, 'stack_owner')
if args.global_tenant:
fields.insert(2, 'project')

stacks = hc.stacks.list(**kwargs)
utils.print_list(stacks, fields, sortby_index=3)

Expand Down

0 comments on commit c29f12a

Please sign in to comment.