Fix fields translation on filtering

Filtering load balancers by VIP data would raise an internal server
error (500 HTTP) in octavia-api. This patch fixes that as well as pool
filtering by healthmonitor_id.

The patch also adds vip.qos_policy_id to the load balancer filtering
capabilities.

Story: 2001944
Task: 15061

Change-Id: Iaa4877f71e98689b7e92b3e2abb9d7da2c5ca521
This commit is contained in:
Carlos Goncalves 2018-06-29 23:55:37 +02:00
parent 16cb3603b8
commit fd20d06896
5 changed files with 19 additions and 8 deletions

View File

@ -31,7 +31,8 @@ class BaseLoadBalancerType(types.BaseType):
'ip_address': 'vip_address',
'subnet_id': 'vip_subnet_id',
'port_id': 'vip_port_id',
'network_id': 'vip_network_id'}}
'network_id': 'vip_network_id',
'qos_policy_id': 'vip_qos_policy_id'}}
class LoadBalancerResponse(BaseLoadBalancerType):

View File

@ -43,8 +43,10 @@ class SessionPersistencePUT(types.BaseType):
class BasePoolType(types.BaseType):
_type_to_model_map = {'admin_state_up': 'enabled',
'healthmonitor': 'health_monitor'}
_child_map = {}
'healthmonitor': 'health_monitor',
'healthmonitor_id': 'health_monitor.id'}
_child_map = {'health_monitor': {'id': 'healthmonitor_id'}}
class PoolResponse(BasePoolType):

View File

@ -113,8 +113,11 @@ class OctaviaBase(models.ModelBase):
filters['enabled'])
for attr, name_map in model.__v2_wsme__._child_map.items():
for k, v in name_map.items():
if v in filters:
child_map[attr] = {k: filters.pop(v)}
if attr in filters and k in filters[attr]:
child_map.setdefault(attr, {}).update(
{k: filters[attr].pop(k)})
filters.pop(attr, None)
for k, v in model.__v2_wsme__._type_to_model_map.items():
if k in filters:
translated_filters[v] = filters.pop(k)

View File

@ -1096,7 +1096,8 @@ class TestLoadBalancer(base.BaseAPITest):
lb1 = self.create_load_balancer(
uuidutils.generate_uuid(),
name='lb1',
project_id=self.project_id).get(self.root_tag)
project_id=self.project_id,
vip_address='10.0.0.1').get(self.root_tag)
self.create_load_balancer(
uuidutils.generate_uuid(),
name='lb2',
@ -1106,7 +1107,7 @@ class TestLoadBalancer(base.BaseAPITest):
name='lb3',
project_id=self.project_id).get(self.root_tag)
lbs = self.get(self.LBS_PATH, params={
'id': lb1['id']}).json
'id': lb1['id'], 'vip_address': lb1['vip_address']}).json
self.assertEqual(1, len(lbs['loadbalancers']))
self.assertEqual(lb1['id'],
lbs['loadbalancers'][0]['id'])

View File

@ -510,6 +510,10 @@ class TestPool(base.BaseAPITest):
constants.LB_ALGORITHM_ROUND_ROBIN,
name='pool1').get(self.root_tag)
self.set_lb_status(lb_id=self.lb_id)
hm = self.create_health_monitor(po1['id'],
constants.HEALTH_MONITOR_HTTP,
1, 1, 1, 1).get('healthmonitor')
self.set_lb_status(lb_id=self.lb_id)
self.create_pool(
self.lb_id,
constants.PROTOCOL_HTTP,
@ -524,7 +528,7 @@ class TestPool(base.BaseAPITest):
self.set_lb_status(lb_id=self.lb_id)
pools = self.get(self.POOLS_PATH, params={
'id': po1['id']}).json
'id': po1['id'], 'healthmonitor_id': hm['id']}).json
self.assertEqual(1, len(pools['pools']))
self.assertEqual(po1['id'],
pools['pools'][0]['id'])