Use region_id filter for List Endpoints

The old region filter didn't work, it was not available
in Keystone.

Change-Id: Ic4d60a046df1f231d02a45998c8a0ef7c5b7b107
Closes-bug: #1482772
This commit is contained in:
lin-hua-cheng 2015-08-24 19:43:31 -07:00
parent 28138b5882
commit 03d5d8effc
2 changed files with 18 additions and 2 deletions

View File

@ -89,3 +89,16 @@ class EndpointTests(utils.TestCase, utils.CrudTests):
expected_path = 'v3/%s?interface=%s' % (self.collection_key, interface)
self.assertRaises(exceptions.ValidationError, self.manager.list,
expected_path=expected_path, interface=interface)
def test_list_filtered_by_region(self):
region_id = uuid.uuid4().hex
ref_list = [self.new_ref(region=region_id),
self.new_ref(region=region_id)]
expected_path = 'v3/%s?region_id=%s' % (self.collection_key, region_id)
expected_query = {'region_id': region_id}
# Validate passing either region or region_id result to the API call.
self.test_list(ref_list=ref_list, expected_path=expected_path,
expected_query=expected_query, region=region_id)
self.test_list(ref_list=ref_list, expected_path=expected_path,
expected_query=expected_query, region_id=region_id)

View File

@ -68,17 +68,20 @@ class EndpointManager(base.CrudManager):
@utils.positional(enforcement=utils.positional.WARN)
def list(self, service=None, interface=None, region=None, enabled=None,
**kwargs):
region_id=None, **kwargs):
"""List endpoints.
If ``**kwargs`` are provided, then filter endpoints with
attributes matching ``**kwargs``.
"""
# NOTE(lhcheng): region filter is not supported by keystone,
# region_id should be used instead. Consider removing the
# region argument in the next release.
self._validate_interface(interface)
return super(EndpointManager, self).list(
service_id=base.getid(service),
interface=interface,
region=region,
region_id=region_id or base.getid(region),
enabled=enabled,
**kwargs)