diff --git a/neutron/services/provider_configuration.py b/neutron/services/provider_configuration.py index 85c2424d91..88a64b72b2 100644 --- a/neutron/services/provider_configuration.py +++ b/neutron/services/provider_configuration.py @@ -153,10 +153,10 @@ class ProviderConfiguration(object): return resource def get_service_providers(self, filters=None, fields=None): - res = [{'service_type': k[0], - 'name': k[1], - 'driver': v['driver'], - 'default': v['default']} - for k, v in self.providers.items() - if self._check_entry(k, v, filters)] - return self._fields(res, fields) + return [self._fields({'service_type': k[0], + 'name': k[1], + 'driver': v['driver'], + 'default': v['default']}, + fields) + for k, v in self.providers.items() + if self._check_entry(k, v, filters)] diff --git a/neutron/tests/unit/test_provider_configuration.py b/neutron/tests/unit/test_provider_configuration.py index e665c9a88d..b8ee47796b 100644 --- a/neutron/tests/unit/test_provider_configuration.py +++ b/neutron/tests/unit/test_provider_configuration.py @@ -181,3 +181,21 @@ class ProviderConfigurationTestCase(base.BaseTestCase): 'service_type': prov['service_type']} ) self.assertEqual(p, [prov]) + + def test_get_service_providers_with_fields(self): + provs = [{'service_type': constants.LOADBALANCER, + 'name': 'name', + 'driver': 'path', + 'default': False}, + {'service_type': constants.LOADBALANCER, + 'name': 'name2', + 'driver': 'path2', + 'default': False}] + pconf = provconf.ProviderConfiguration(provs) + for prov in provs: + p = pconf.get_service_providers( + filters={'name': [prov['name']], + 'service_type': prov['service_type']}, + fields=['name'] + ) + self.assertEqual(p, [{'name': prov['name']}])