From 396a0e42755af96d8b96d42ae1bcf4ae4604443d Mon Sep 17 00:00:00 2001 From: Eugene Nikanorov Date: Fri, 20 Sep 2013 07:15:38 +0400 Subject: [PATCH] Fix usage of _fields method in provider_configuration.py Apply _fields() method to each dict in the list. Change-Id: I9357212e203843ffa4a05216d9c79fe8831971a5 Closes-Bug: #1227971 --- neutron/services/provider_configuration.py | 14 +++++++------- .../tests/unit/test_provider_configuration.py | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/neutron/services/provider_configuration.py b/neutron/services/provider_configuration.py index 85c2424d9..88a64b72b 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 e665c9a88..b8ee47796 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']}])