Fix filtering by admin_state_up
Filtering list calls by admin_state_up would fail with values other than 1 or 0. The boolean conversion code was being skipped because the field key was already translated from 'admin_state_up' to 'enabled' and the code was expecting 'admin_state_up'. Change-Id: I17b2569603a4d33c37a8a06c8cff6db4357b6099 Story: 2001555 Task: 6497
This commit is contained in:

committed by
Jacky Hu

parent
8cca5deab3
commit
a6896f2633
@@ -107,10 +107,10 @@ class OctaviaBase(models.ModelBase):
|
||||
def apply_filter(query, model, filters):
|
||||
translated_filters = {}
|
||||
child_map = {}
|
||||
# Convert admin_state_up to proper type
|
||||
if 'admin_state_up' in filters:
|
||||
filters['admin_state_up'] = strutils.bool_from_string(
|
||||
filters['admin_state_up'])
|
||||
# Convert enabled to proper type
|
||||
if 'enabled' in filters:
|
||||
filters['enabled'] = strutils.bool_from_string(
|
||||
filters['enabled'])
|
||||
for attr, name_map in model.__v2_wsme__._child_map.items():
|
||||
for k, v in name_map.items():
|
||||
if v in filters:
|
||||
|
@@ -1038,6 +1038,21 @@ class TestLoadBalancer(base.BaseAPITest):
|
||||
self.assertIn(u'project_id', lb.keys())
|
||||
self.assertNotIn(u'description', lb.keys())
|
||||
|
||||
def test_get_all_admin_state_up_filter(self):
|
||||
self.create_load_balancer(uuidutils.generate_uuid(),
|
||||
admin_state_up=True,
|
||||
name='lb1',
|
||||
project_id=self.project_id)
|
||||
self.create_load_balancer(uuidutils.generate_uuid(),
|
||||
admin_state_up=False,
|
||||
name='lb2',
|
||||
project_id=self.project_id)
|
||||
|
||||
lbs = self.get(self.LBS_PATH, params={'admin_state_up': 'false'}).json
|
||||
self.assertEqual(1, len(lbs['loadbalancers']))
|
||||
self.assertFalse(lbs['loadbalancers'][0]['admin_state_up'])
|
||||
self.assertEqual('lb2', lbs['loadbalancers'][0]['name'])
|
||||
|
||||
def test_get_all_filter(self):
|
||||
lb1 = self.create_load_balancer(
|
||||
uuidutils.generate_uuid(),
|
||||
|
Reference in New Issue
Block a user