Fix usage of _fields method in provider_configuration.py

Apply _fields() method to each dict in the list.

Change-Id: I9357212e203843ffa4a05216d9c79fe8831971a5
Closes-Bug: #1227971
This commit is contained in:
Eugene Nikanorov 2013-09-20 07:15:38 +04:00
parent 1540cd3727
commit 534b062c82
2 changed files with 25 additions and 7 deletions

View File

@ -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)]

View File

@ -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']}])