Allow to filter endpoint groups by name

While using the openstack client command, the list on endpoint filters
cannot be filtered by name. This adds an optional parameter on the query
to allow the name to be specified as filter. This fixes the behavior on
OSC to search.

Change-Id: Ia1cbc9f4ded8f2494b1bf7ba5e953be0dfaf11f5
Closes-Bug: #1828565
This commit is contained in:
Jose Castro Leon 2019-04-26 16:59:18 +02:00
parent ebac8330d8
commit 6cdb3a8374
8 changed files with 58 additions and 8 deletions

View File

@ -266,6 +266,16 @@ List all available endpoint groups.
Relationship: ``https://docs.openstack.org/api/openstack-identity/3/ext/OS-EP-FILTER/1.0/rel/endpoint_groups``
Request
-------
Parameters
~~~~~~~~~~
.. rest_parameters:: parameters.yaml
- name: request_endpoint_group_name_query_not_required
Response
--------
@ -782,4 +792,4 @@ Example
Status: 200 OK
.. literalinclude:: samples/OS-EP-FILTER/endpoint-groups-response.json
:language: javascript
:language: javascript

View File

@ -93,6 +93,13 @@ user_id_path:
type: string
# variables in query
request_endpoint_group_name_query_not_required:
description: |
Filters the response by an endpoint group name.
in: query
required: false
type: string
since_query:
description: |
A timestamp used to limit the list of results to events

View File

@ -66,9 +66,12 @@ class EndpointGroupsResource(ks_flask.ResourceBase):
PROVIDERS.catalog_api.get_endpoint_group(endpoint_group_id))
def _list_endpoint_groups(self):
ENFORCER.enforce_call(action='identity:list_endpoint_groups')
return self.wrap_collection(
PROVIDERS.catalog_api.list_endpoint_groups())
filters = ('name')
ENFORCER.enforce_call(action='identity:list_endpoint_groups',
filters=filters)
hints = self.build_driver_hints(filters)
refs = PROVIDERS.catalog_api.list_endpoint_groups(hints)
return self.wrap_collection(refs, hints=hints)
def get(self, endpoint_group_id=None):
if endpoint_group_id is not None:

View File

@ -441,7 +441,7 @@ class CatalogDriverBase(provider_api.ProviderAPIMixin, object):
raise exception.NotImplemented() # pragma: no cover
@abc.abstractmethod
def list_endpoint_groups(self):
def list_endpoint_groups(self, hints):
"""List all endpoint groups.
:returns: None.

View File

@ -548,10 +548,11 @@ class Catalog(base.CatalogDriverBase):
else:
return endpoint_group_project_ref
def list_endpoint_groups(self):
def list_endpoint_groups(self, hints):
with sql.session_for_read() as session:
query = session.query(EndpointGroup)
endpoint_group_refs = query.all()
endpoint_group_refs = sql.filter_limit_query(
EndpointGroup, query, hints)
return [e.to_dict() for e in endpoint_group_refs]
def list_endpoint_groups_for_project(self, project_id):

View File

@ -326,7 +326,7 @@ class Catalog(base.CatalogDriverBase):
def get_endpoint_group_in_project(self, endpoint_group_id, project_id):
raise exception.NotImplemented()
def list_endpoint_groups(self):
def list_endpoint_groups(self, hints):
raise exception.NotImplemented()
def list_endpoint_groups_for_project(self, project_id):

View File

@ -1046,6 +1046,29 @@ class EndpointGroupCRUDTestCase(EndpointFilterTestCase):
self.head(url, expected_status=http_client.OK)
def test_list_endpoint_groups_by_name(self):
"""GET & HEAD /OS-EP-FILTER/endpoint_groups."""
# create an endpoint group to work with
endpoint_group_id = self._create_valid_endpoint_group(
self.DEFAULT_ENDPOINT_GROUP_URL, self.DEFAULT_ENDPOINT_GROUP_BODY)
# retrieve the single endpointgroup by name
url = ('/OS-EP-FILTER/endpoint_groups?name=%(name)s' %
{'name': 'endpoint_group_name'})
r = self.get(url, expected_status=http_client.OK)
self.assertNotEmpty(r.result['endpoint_groups'])
self.assertEqual(1, len(r.result['endpoint_groups']))
self.assertEqual(endpoint_group_id,
r.result['endpoint_groups'][0].get('id'))
self.head(url, expected_status=http_client.OK)
# try to retrieve a non existant one
url = ('/OS-EP-FILTER/endpoint_groups?name=%(name)s' %
{'name': 'fake'})
r = self.get(url, expected_status=http_client.OK)
self.assertEqual(0, len(r.result['endpoint_groups']))
def test_list_projects_associated_with_endpoint_group(self):
"""GET & HEAD /OS-EP-FILTER/endpoint_groups/{endpoint_group}/projects.

View File

@ -0,0 +1,6 @@
---
fixes:
- |
[`bug 1828565 <https://bugs.launchpad.net/keystone/+bug/1828565>`_]
Fixes endpoint group listing by name. This allows the openstackclient
command to search endpoint groups by name.