Fix bugs on network and port query

1. What is the problem
After running tempest test test_networks and test_ports, we find
some bugs on network and port query:
(1) Querying port with fields specified is not supported
(2) Querying port with ip address filter is not supported
(3) Querying network without id in the returned fields causes error

2. What is the solution to the problem
(1) Remove unnecessary fields before returning result
(2) If ip address filter is specified, join IPAllocation table to
    filter ports
(3) If id is not in the specified field list, do not extend result
    with segmentation information because network id is required to
    retrieve segmentation information

3. What the features need to be implemented to the Tricircle
   to realize the solution
Tempest test test_networks can be passed, to pass test_ports, we stil
need to support security group update and binding profile update.

Change-Id: Iec498fc72cd0dba74c908823f2d429537d52e0e2
This commit is contained in:
zhiyuan_cai 2016-08-27 16:58:02 +08:00 committed by joehuang
parent b556ae5615
commit a20a6b0ebe
1 changed files with 35 additions and 6 deletions

View File

@ -312,15 +312,17 @@ class TricirclePlugin(db_base_plugin_v2.NeutronDbPluginV2,
def get_network(self, context, network_id, fields=None):
net = super(TricirclePlugin, self).get_network(context, network_id,
fields)
self.type_manager.extend_network_dict_provider(context, net)
if not fields or 'id' in fields:
self.type_manager.extend_network_dict_provider(context, net)
return net
def get_networks(self, context, filters=None, fields=None,
sorts=None, limit=None, marker=None, page_reverse=False):
nets = super(TricirclePlugin,
self).get_networks(context, filters, None, sorts,
self).get_networks(context, filters, fields, sorts,
limit, marker, page_reverse)
self.type_manager.extend_networks_dict_provider(context, nets)
if not fields or 'id' in fields:
self.type_manager.extend_networks_dict_provider(context, nets)
return nets
def create_subnet(self, context, subnet):
@ -373,7 +375,8 @@ class TricirclePlugin(db_base_plugin_v2.NeutronDbPluginV2,
context, subnet_id, subnet)
def create_port(self, context, port):
return super(TricirclePlugin, self).create_port(context, port)
db_port = super(TricirclePlugin, self).create_port_db(context, port)
return self._make_port_dict(db_port)
def update_port(self, context, port_id, port):
# TODO(zhiyuan) handle bottom port update
@ -447,6 +450,19 @@ class TricirclePlugin(db_base_plugin_v2.NeutronDbPluginV2,
def _apply_ports_filters(query, model, filters):
if not filters:
return query
fixed_ips = filters.pop('fixed_ips', {})
ip_addresses = fixed_ips.get('ip_address')
subnet_ids = fixed_ips.get('subnet_id')
if ip_addresses or subnet_ids:
query = query.join(models_v2.Port.fixed_ips)
if ip_addresses:
query = query.filter(
models_v2.IPAllocation.ip_address.in_(ip_addresses))
if subnet_ids:
query = query.filter(
models_v2.IPAllocation.subnet_id.in_(subnet_ids))
for key, value in filters.iteritems():
column = getattr(model, key, None)
if column is not None:
@ -558,6 +574,10 @@ class TricirclePlugin(db_base_plugin_v2.NeutronDbPluginV2,
if filters:
_filters = dict(filters)
for key, value in _filters:
if key == 'fixed_ips':
if 'ip_address' in value:
_filters[key] = 'ip_address=%s' % value['ip_address']
continue
id_list = self._get_map_filter_ids(
key, value, current_pod['pod_id'], top_bottom_map)
if id_list:
@ -660,7 +680,8 @@ class TricirclePlugin(db_base_plugin_v2.NeutronDbPluginV2,
# _get_ports_from_pod_with_number already traverses all the pods
# to try to get ports equal to limit, so pod is transparent for
# controller.
return res['ports']
return [super(TricirclePlugin,
self)._fields(p, fields) for p in res['ports']]
else:
ret = []
pods = db_api.list_pods(t_ctx)
@ -670,6 +691,13 @@ class TricirclePlugin(db_base_plugin_v2.NeutronDbPluginV2,
_filters = []
if filters:
for key, value in filters.iteritems():
if key == 'fixed_ips':
if 'ip_address' in value:
_filters.append(
{'key': key, 'comparator': 'eq',
'value': 'ip_address=%s' % value[
'ip_address']})
continue
id_list = self._get_map_filter_ids(
key, value, pod['pod_id'], top_bottom_map)
if id_list:
@ -685,7 +713,8 @@ class TricirclePlugin(db_base_plugin_v2.NeutronDbPluginV2,
ret = self._map_ports_from_bottom_to_top(ret, bottom_top_map)
ret.extend(self._get_ports_from_top(context, top_bottom_map,
filters))
return ret
return [super(TricirclePlugin,
self)._fields(p, fields) for p in ret]
def create_router(self, context, router):
return super(TricirclePlugin, self).create_router(context, router)