add with_detail parameter in heat resource-list request
DocImpact Change-Id: Ia8fad976819902c50df183925f410156395719db Closes-Bug: #1473086
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
from heatclient.common import utils
|
||||
|
||||
from heatclient.v1 import resources
|
||||
from six.moves.urllib import parse
|
||||
|
||||
from mox3 import mox
|
||||
import testtools
|
||||
@@ -106,25 +107,27 @@ class ResourceManagerTest(testtools.TestCase):
|
||||
self.m.VerifyAll()
|
||||
|
||||
def test_list(self):
|
||||
fields = {'stack_id': 'teststack'}
|
||||
expect = ('/stacks/teststack/resources')
|
||||
key = 'resources'
|
||||
|
||||
class FakeResponse(object):
|
||||
def json(self):
|
||||
return {key: {}}
|
||||
|
||||
class FakeClient(object):
|
||||
def get(self, *args, **kwargs):
|
||||
assert args[0] == expect
|
||||
return FakeResponse()
|
||||
|
||||
manager = resources.ResourceManager(FakeClient())
|
||||
manager.list(**fields)
|
||||
self._test_list(
|
||||
fields={'stack_id': 'teststack'},
|
||||
expect='/stacks/teststack/resources')
|
||||
|
||||
def test_list_nested(self):
|
||||
fields = {'stack_id': 'teststack', 'nested_depth': '99'}
|
||||
expect = ('/stacks/teststack/resources?nested_depth=99')
|
||||
self._test_list(
|
||||
fields={'stack_id': 'teststack', 'nested_depth': '99'},
|
||||
expect='/stacks/teststack/resources?%s' % parse.urlencode({
|
||||
'nested_depth': 99,
|
||||
}, True)
|
||||
)
|
||||
|
||||
def test_list_detail(self):
|
||||
self._test_list(
|
||||
fields={'stack_id': 'teststack', 'with_detail': 'True'},
|
||||
expect='/stacks/teststack/resources?%s' % parse.urlencode({
|
||||
'with_detail': True,
|
||||
}, True)
|
||||
)
|
||||
|
||||
def _test_list(self, fields, expect):
|
||||
key = 'resources'
|
||||
|
||||
class FakeResponse(object):
|
||||
|
@@ -3271,6 +3271,41 @@ class ShellTestResources(ShellBase):
|
||||
for field in required:
|
||||
self.assertRegexpMatches(resource_list_text, field)
|
||||
|
||||
def test_resource_list_detail(self):
|
||||
self.register_keystone_auth_fixture()
|
||||
resp_dict = {"resources": [{
|
||||
"resource_name": "foobar",
|
||||
"links": [{
|
||||
"href": "http://heat.example.com:8004/foo/12/resources/foobar",
|
||||
"rel": "self"
|
||||
}, {
|
||||
"href": "http://heat.example.com:8004/foo/12",
|
||||
"rel": "stack"
|
||||
}],
|
||||
}]}
|
||||
resp = fakes.FakeHTTPResponse(
|
||||
200,
|
||||
'OK',
|
||||
{'content-type': 'application/json'},
|
||||
jsonutils.dumps(resp_dict))
|
||||
stack_id = 'teststack/1'
|
||||
http.SessionClient.request('/stacks/%s/resources?%s' % (
|
||||
stack_id,
|
||||
parse.urlencode({'with_detail': True}, True)
|
||||
), 'GET').AndReturn(resp)
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
shell_cmd = 'resource-list {0} --with-detail'.format(stack_id)
|
||||
resource_list_text = self.shell(shell_cmd)
|
||||
|
||||
required = [
|
||||
'resource_name', 'foobar',
|
||||
'stack_name', 'foo',
|
||||
]
|
||||
for field in required:
|
||||
self.assertRegexpMatches(resource_list_text, field)
|
||||
|
||||
def test_resource_show_with_attrs(self):
|
||||
self.register_keystone_auth_fixture()
|
||||
resp_dict = {"resource":
|
||||
|
@@ -15,6 +15,7 @@
|
||||
from heatclient.common import utils
|
||||
|
||||
from oslo_utils import encodeutils
|
||||
import six
|
||||
from six.moves.urllib import parse
|
||||
|
||||
from heatclient.openstack.common.apiclient import base
|
||||
@@ -48,13 +49,19 @@ class Resource(base.Resource):
|
||||
class ResourceManager(stacks.StackChildManager):
|
||||
resource_class = Resource
|
||||
|
||||
def list(self, stack_id, nested_depth=0):
|
||||
def list(self, stack_id, **kwargs):
|
||||
"""Get a list of resources.
|
||||
:rtype: list of :class:`Resource`
|
||||
"""
|
||||
params = {}
|
||||
|
||||
for key, value in six.iteritems(kwargs):
|
||||
if value:
|
||||
params[key] = value
|
||||
url = '/stacks/%s/resources' % stack_id
|
||||
if nested_depth:
|
||||
url += '?nested_depth=%s' % nested_depth
|
||||
if params:
|
||||
url += '?%s' % parse.urlencode(params, True)
|
||||
|
||||
return self._list(url, "resources")
|
||||
|
||||
def get(self, stack_id, resource_name, with_attr=None):
|
||||
|
@@ -736,11 +736,15 @@ def do_template_validate(hc, args):
|
||||
help=_('Name or ID of stack to show the resources for.'))
|
||||
@utils.arg('-n', '--nested-depth', metavar='<DEPTH>',
|
||||
help=_('Depth of nested stacks from which to display resources.'))
|
||||
@utils.arg('--with-detail', default=False, action="store_true",
|
||||
help=_('Enable detail information presented for each resource'
|
||||
'in resources list.'))
|
||||
def do_resource_list(hc, args):
|
||||
'''Show list of resources belonging to a stack.'''
|
||||
fields = {
|
||||
'stack_id': args.id,
|
||||
'nested_depth': args.nested_depth,
|
||||
'with_detail': args.with_detail,
|
||||
}
|
||||
try:
|
||||
resources = hc.resources.list(**fields)
|
||||
@@ -754,7 +758,7 @@ def do_resource_list(hc, args):
|
||||
else:
|
||||
fields.insert(0, 'resource_name')
|
||||
|
||||
if args.nested_depth:
|
||||
if args.nested_depth or args.with_detail:
|
||||
fields.append('stack_name')
|
||||
|
||||
utils.print_list(resources, fields, sortby_index=4)
|
||||
|
Reference in New Issue
Block a user