Add query parameters to listing heat stacks

Fix query parameters for listing heat stacks. This is also required for
corresponding Ansible module.

Change-Id: Ie9e27ad67061528cacbef8fa06658b4f61bfba33
This commit is contained in:
Artem Goncharov 2021-01-06 11:08:29 +01:00
parent eefd1609ac
commit e5e7c607c1
4 changed files with 49 additions and 4 deletions

View File

@ -209,15 +209,16 @@ class OrchestrationCloudMixin(_normalize.Normalizer):
return _utils._filter_list(stacks, name_or_id, filters)
@_utils.cache_on_arguments(should_cache_fn=_no_pending_stacks)
def list_stacks(self):
def list_stacks(self, **query):
"""List all stacks.
:param dict query: Query parameters to limit stacks.
:returns: a list of ``munch.Munch`` containing the stack description.
:raises: ``OpenStackCloudException`` if something goes wrong during the
OpenStack API call.
"""
data = self.orchestration.stacks()
data = self.orchestration.stacks(**query)
return self._normalize_stacks(data)
def get_stack(self, name_or_id, filters=None, resolve_outputs=True):

View File

@ -29,7 +29,10 @@ class Stack(resource.Resource):
allow_delete = True
_query_mapping = resource.QueryParameters(
'resolve_outputs'
'action', 'name', 'status',
'project_id', 'owner_id', 'username',
project_id='tenant_id',
**resource.TagMixin._tag_query_parameters
)
# Properties
@ -84,7 +87,7 @@ class Stack(resource.Resource):
#: A text explaining how the stack transits to its current status.
status_reason = resource.Body('stack_status_reason')
#: A list of strings used as tags on the stack
tags = resource.Body('tags')
tags = resource.Body('tags', type=list, default=[])
#: A dict containing the template use for stack creation.
template = resource.Body('template', type=dict)
#: Stack template description text. Currently contains the same text

View File

@ -51,6 +51,30 @@ class TestStack(base.TestCase):
self.assert_calls()
def test_list_stacks_filters(self):
fake_stacks = [
self.stack,
fakes.make_fake_stack(
self.getUniqueString('id'),
self.getUniqueString('name'))
]
self.register_uris([
dict(method='GET',
uri=self.get_mock_url(
'orchestration', 'public',
append=['stacks'],
qs_elements=['name=a', 'status=b'],
),
json={"stacks": fake_stacks}),
])
stacks = self.cloud.list_stacks(name='a', status='b')
self.assertEqual(
[f.toDict() for f in self.cloud._normalize_stacks(
stack.Stack(**st) for st in fake_stacks)],
[f.toDict() for f in stacks])
self.assert_calls()
def test_list_stacks_exception(self):
self.register_uris([
dict(method='GET',

View File

@ -135,6 +135,23 @@ class TestStack(base.TestCase):
self.assertTrue(sot.allow_delete)
self.assertTrue(sot.allow_list)
self.assertDictEqual(
{
'action': 'action',
'any_tags': 'tags-any',
'limit': 'limit',
'marker': 'marker',
'name': 'name',
'not_any_tags': 'not-tags-any',
'not_tags': 'not-tags',
'owner_id': 'owner_id',
'project_id': 'tenant_id',
'status': 'status',
'tags': 'tags',
'username': 'username',
},
sot._query_mapping._mapping)
def test_make_it(self):
sot = stack.Stack(**FAKE)
self.assertEqual(FAKE['capabilities'], sot.capabilities)