Fix filtering for provider capabilities list API
The "Show Provider Flavor Capabilities" would silently ignore filtering parameters passed into the API. This patch corrects this such that you can filter the providers capabilities list. Change-Id: I9a2aa4ed5b4ef60545c60a6d5bd06066ef361a56 Story: 2006817 Task: 37377
This commit is contained in:
parent
51425dcda6
commit
28c936ec71
@ -89,6 +89,25 @@ class FlavorCapabilitiesController(base.BaseController):
|
||||
'reported: %s', self.provider, e.operator_fault_string)
|
||||
raise exceptions.ProviderNotImplementedError(
|
||||
prov=self.provider, user_msg=e.user_fault_string)
|
||||
|
||||
# Apply any valid filters provided as URL parameters
|
||||
name_filter = None
|
||||
description_filter = None
|
||||
pagination_helper = pecan.request.context.get(
|
||||
constants.PAGINATION_HELPER)
|
||||
if pagination_helper:
|
||||
name_filter = pagination_helper.params.get(constants.NAME)
|
||||
description_filter = pagination_helper.params.get(
|
||||
constants.DESCRIPTION)
|
||||
if name_filter:
|
||||
metadata_dict = {
|
||||
key: value for key, value in six.iteritems(metadata_dict) if
|
||||
key == name_filter}
|
||||
if description_filter:
|
||||
metadata_dict = {
|
||||
key: value for key, value in six.iteritems(metadata_dict) if
|
||||
value == description_filter}
|
||||
|
||||
response_list = [
|
||||
provider_types.ProviderResponse(name=key, description=value) for
|
||||
key, value in six.iteritems(metadata_dict)]
|
||||
|
@ -308,10 +308,12 @@ CREATED_AT = 'created_at'
|
||||
CRL_CONTAINER_ID = 'crl_container_id'
|
||||
DELTA = 'delta'
|
||||
DELTAS = 'deltas'
|
||||
DESCRIPTION = 'description'
|
||||
ENABLED = 'enabled'
|
||||
FAILED_AMPHORA = 'failed_amphora'
|
||||
FAILOVER_AMPHORA = 'failover_amphora'
|
||||
FAILOVER_AMPHORA_ID = 'failover_amphora_id'
|
||||
FIELDS = 'fields'
|
||||
FLAVOR_ID = 'flavor_id'
|
||||
HEALTH_MON = 'health_mon'
|
||||
HEALTH_MONITOR = 'health_monitor'
|
||||
|
@ -132,3 +132,42 @@ class TestFlavorCapabilities(base.BaseAPITest):
|
||||
self.get(self.FLAVOR_CAPABILITIES_PATH.format(provider='noop_driver'),
|
||||
status=403)
|
||||
self.conf.config(group='api_settings', auth_strategy=auth_strategy)
|
||||
|
||||
def test_amphora_driver_one_filter(self):
|
||||
ref_description = ("The compute driver flavor ID.")
|
||||
result = self.get(
|
||||
self.FLAVOR_CAPABILITIES_PATH.format(provider=constants.AMPHORA),
|
||||
params={constants.NAME: 'compute_flavor'})
|
||||
capabilities = result.json.get(self.root_tag)
|
||||
self.assertEqual(1, len(capabilities))
|
||||
self.assertEqual(2, len(capabilities[0]))
|
||||
self.assertEqual(ref_description,
|
||||
capabilities[0][constants.DESCRIPTION])
|
||||
|
||||
def test_amphora_driver_two_filters(self):
|
||||
ref_description = ("The compute driver flavor ID.")
|
||||
result = self.get(
|
||||
self.FLAVOR_CAPABILITIES_PATH.format(provider=constants.AMPHORA),
|
||||
params={constants.NAME: 'compute_flavor',
|
||||
constants.DESCRIPTION: ref_description})
|
||||
capabilities = result.json.get(self.root_tag)
|
||||
self.assertEqual(1, len(capabilities))
|
||||
self.assertEqual(ref_description,
|
||||
capabilities[0][constants.DESCRIPTION])
|
||||
|
||||
def test_amphora_driver_filter_no_match(self):
|
||||
result = self.get(
|
||||
self.FLAVOR_CAPABILITIES_PATH.format(provider=constants.AMPHORA),
|
||||
params={constants.NAME: 'bogus'})
|
||||
capabilities = result.json.get(self.root_tag)
|
||||
self.assertEqual([], capabilities)
|
||||
|
||||
def test_amphora_driver_one_filter_one_field(self):
|
||||
result = self.get(
|
||||
self.FLAVOR_CAPABILITIES_PATH.format(provider=constants.AMPHORA),
|
||||
params={constants.NAME: 'compute_flavor',
|
||||
constants.FIELDS: constants.NAME})
|
||||
capabilities = result.json.get(self.root_tag)
|
||||
self.assertEqual(1, len(capabilities))
|
||||
self.assertEqual(1, len(capabilities[0]))
|
||||
self.assertEqual('compute_flavor', capabilities[0][constants.NAME])
|
||||
|
@ -0,0 +1,4 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
Fixes the ability to filter on the provider flavor capabilities API.
|
Loading…
Reference in New Issue
Block a user