Merge "Stack resource search"
This commit is contained in:
commit
413b5f2dbd
|
@ -115,7 +115,15 @@ class ResourceManagerTest(testtools.TestCase):
|
|||
self._test_list(
|
||||
fields={'stack_id': 'teststack', 'nested_depth': '99'},
|
||||
expect='/stacks/teststack/resources?%s' % parse.urlencode({
|
||||
'nested_depth': 99,
|
||||
'nested_depth': 99
|
||||
}, True)
|
||||
)
|
||||
|
||||
def test_list_filtering(self):
|
||||
self._test_list(
|
||||
fields={'stack_id': 'teststack', 'filters': {'name': 'rsc_1'}},
|
||||
expect='/stacks/teststack/resources?%s' % parse.urlencode({
|
||||
'name': 'rsc_1'
|
||||
}, True)
|
||||
)
|
||||
|
||||
|
|
|
@ -3791,7 +3791,8 @@ class ShellTestResources(ShellBase):
|
|||
--------------+
|
||||
''', resource_list_text)
|
||||
|
||||
def test_resource_list_nested(self):
|
||||
def _test_resource_list_more_args(self, query_args, cmd_args,
|
||||
response_args):
|
||||
self.register_keystone_auth_fixture()
|
||||
resp_dict = {"resources": [{
|
||||
"resource_name": "foobar",
|
||||
|
@ -3810,55 +3811,35 @@ class ShellTestResources(ShellBase):
|
|||
jsonutils.dumps(resp_dict))
|
||||
stack_id = 'teststack/1'
|
||||
http.SessionClient.request(
|
||||
'/stacks/%s/resources?nested_depth=99' % (
|
||||
stack_id), 'GET').AndReturn(resp)
|
||||
'/stacks/%s/resources?%s' % (
|
||||
stack_id, query_args), 'GET').AndReturn(resp)
|
||||
|
||||
self.m.ReplayAll()
|
||||
|
||||
shell_cmd = 'resource-list {0} --nested-depth {1}'.format(stack_id, 99)
|
||||
shell_cmd = 'resource-list %s %s' % (stack_id, cmd_args)
|
||||
|
||||
resource_list_text = self.shell(shell_cmd)
|
||||
|
||||
required = [
|
||||
'resource_name', 'foobar',
|
||||
'stack_name', 'foo',
|
||||
]
|
||||
for field in required:
|
||||
for field in response_args:
|
||||
self.assertRegexpMatches(resource_list_text, field)
|
||||
|
||||
def test_resource_list_nested(self):
|
||||
self._test_resource_list_more_args(
|
||||
query_args='nested_depth=99',
|
||||
cmd_args='--nested-depth 99',
|
||||
response_args=['resource_name', 'foobar', 'stack_name', 'foo'])
|
||||
|
||||
def test_resource_list_filter(self):
|
||||
self._test_resource_list_more_args(
|
||||
query_args='name=foobar',
|
||||
cmd_args='--filter name=foobar',
|
||||
response_args=['resource_name', 'foobar'])
|
||||
|
||||
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)
|
||||
self._test_resource_list_more_args(
|
||||
query_args=parse.urlencode({'with_detail': True}, True),
|
||||
cmd_args='--with-detail',
|
||||
response_args=['resource_name', 'foobar', 'stack_name', 'foo'])
|
||||
|
||||
def test_resource_show_with_attrs(self):
|
||||
self.register_keystone_auth_fixture()
|
||||
|
|
|
@ -56,9 +56,14 @@ class ResourceManager(stacks.StackChildManager):
|
|||
"""
|
||||
params = {}
|
||||
|
||||
if 'filters' in kwargs:
|
||||
filters = kwargs.pop('filters')
|
||||
params.update(filters)
|
||||
|
||||
for key, value in six.iteritems(kwargs):
|
||||
if value:
|
||||
params[key] = value
|
||||
|
||||
url = '/stacks/%s/resources' % stack_id
|
||||
if params:
|
||||
url += '?%s' % parse.urlencode(params, True)
|
||||
|
|
|
@ -850,12 +850,19 @@ def do_template_validate(hc, args):
|
|||
@utils.arg('--with-detail', default=False, action="store_true",
|
||||
help=_('Enable detail information presented for each resource '
|
||||
'in resources list.'))
|
||||
@utils.arg('-f', '--filter', metavar='<KEY=VALUE>',
|
||||
help=_('Filter parameters to apply on returned resources based on'
|
||||
' their name, status, type, action, id and'
|
||||
' physcial_resource_id. This can be specified multiple'
|
||||
' times.'),
|
||||
action='append')
|
||||
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,
|
||||
'filters': utils.format_parameters(args.filter)
|
||||
}
|
||||
try:
|
||||
resources = hc.resources.list(**fields)
|
||||
|
|
Loading…
Reference in New Issue