Added check for emptyness where in_ is being used
All the Neutron code was scanned for places where in_ is being used and added checks to ensure that the input is not an empty sequence. Change-Id: I1e27f94ea350ce1dfabdd7eb14e4397ca29e8eb7 Closes-Bug:1264579
This commit is contained in:
parent
ddb546443f
commit
949256d3f7
|
@ -134,6 +134,9 @@ class CommonDbMixin(object):
|
|||
for key, value in filters.iteritems():
|
||||
column = getattr(model, key, None)
|
||||
if column:
|
||||
if not value:
|
||||
query = query.filter(sql.false())
|
||||
return query
|
||||
query = query.filter(column.in_(value))
|
||||
for _name, hooks in self._model_query_hooks.get(model,
|
||||
{}).iteritems():
|
||||
|
|
|
@ -360,6 +360,8 @@ class L3AgentSchedulerDbMixin(l3agentscheduler.L3AgentSchedulerPluginBase,
|
|||
for key, value in filters.iteritems():
|
||||
column = getattr(agents_db.Agent, key, None)
|
||||
if column:
|
||||
if not value:
|
||||
return []
|
||||
query = query.filter(column.in_(value))
|
||||
|
||||
agent_modes = filters.get('agent_modes', [])
|
||||
|
@ -481,6 +483,8 @@ class L3AgentSchedulerDbMixin(l3agentscheduler.L3AgentSchedulerPluginBase,
|
|||
|
||||
def get_l3_agent_with_min_routers(self, context, agent_ids):
|
||||
"""Return l3 agent with the least number of routers."""
|
||||
if not agent_ids:
|
||||
return None
|
||||
query = context.session.query(
|
||||
agents_db.Agent,
|
||||
func.count(
|
||||
|
|
|
@ -365,6 +365,8 @@ class L3_NAT_with_dvr_db_mixin(l3_db.L3_NAT_db_mixin,
|
|||
|
||||
def _build_routers_list(self, context, routers, gw_ports):
|
||||
# Perform a single query up front for all routers
|
||||
if not routers:
|
||||
return []
|
||||
router_ids = [r['id'] for r in routers]
|
||||
snat_binding = l3_dvrsched_db.CentralizedSnatL3AgentBinding
|
||||
query = (context.session.query(snat_binding).
|
||||
|
|
|
@ -435,6 +435,8 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin):
|
|||
self._delete_ha_interfaces(context, router_db.id)
|
||||
|
||||
def get_ha_router_port_bindings(self, context, router_ids, host=None):
|
||||
if not router_ids:
|
||||
return []
|
||||
query = context.session.query(L3HARouterAgentPortBinding)
|
||||
|
||||
if host:
|
||||
|
|
|
@ -49,6 +49,8 @@ class L3_HA_scheduler_db_mixin(l3_sch_db.L3AgentSchedulerDbMixin):
|
|||
return query
|
||||
|
||||
def get_l3_agents_ordered_by_num_routers(self, context, agent_ids):
|
||||
if not agent_ids:
|
||||
return []
|
||||
query = (context.session.query(agents_db.Agent, func.count(
|
||||
l3_sch_db.RouterL3AgentBinding.router_id).label('count')).
|
||||
outerjoin(l3_sch_db.RouterL3AgentBinding).
|
||||
|
|
|
@ -1004,7 +1004,9 @@ class NetworkProfile_db_mixin(object):
|
|||
net_profile_ids = (db_session.query(n1kv_models_v2.ProfileBinding.
|
||||
profile_id).
|
||||
filter_by(tenant_id=tenant_id).
|
||||
filter_by(profile_type=c_const.NETWORK))
|
||||
filter_by(profile_type=c_const.NETWORK).all())
|
||||
if not net_profile_ids:
|
||||
return []
|
||||
network_profiles = (db_session.query(model).filter(model.id.in_(
|
||||
pid[0] for pid in net_profile_ids)))
|
||||
return [self._make_network_profile_dict(p) for p in network_profiles]
|
||||
|
@ -1464,6 +1466,8 @@ class PolicyProfile_db_mixin(object):
|
|||
ProfileBinding.profile_id)
|
||||
.filter_by(tenant_id=tenant_id).
|
||||
filter_by(profile_type=c_const.POLICY).all())
|
||||
if not profile_ids:
|
||||
return []
|
||||
profiles = db_session.query(model).filter(model.id.in_(
|
||||
pid[0] for pid in profile_ids))
|
||||
return [self._make_policy_profile_dict(p) for p in profiles]
|
||||
|
@ -1637,12 +1641,13 @@ class PolicyProfile_db_mixin(object):
|
|||
n1kv_models_v2.ProfileBinding.
|
||||
profile_type == c_const.POLICY)))
|
||||
b_set = set(i.profile_id for i in b_set_q)
|
||||
(db_session.query(n1kv_models_v2.ProfileBinding).
|
||||
filter(sql.and_(n1kv_models_v2.ProfileBinding.profile_id.
|
||||
in_(a_set & b_set),
|
||||
n1kv_models_v2.ProfileBinding.tenant_id ==
|
||||
c_const.TENANT_ID_NOT_SET)).
|
||||
delete(synchronize_session="fetch"))
|
||||
if a_set & b_set:
|
||||
(db_session.query(n1kv_models_v2.ProfileBinding).
|
||||
filter(sql.and_(n1kv_models_v2.ProfileBinding.profile_id.
|
||||
in_(a_set & b_set),
|
||||
n1kv_models_v2.ProfileBinding.tenant_id ==
|
||||
c_const.TENANT_ID_NOT_SET)).
|
||||
delete(synchronize_session="fetch"))
|
||||
|
||||
def _add_policy_profile(self,
|
||||
policy_profile_name,
|
||||
|
|
|
@ -120,9 +120,10 @@ class VxlanTypeDriver(type_tunnel.TunnelTypeDriver):
|
|||
chunked_vnis = (vnis_to_remove[i:i + bulk_size] for i in
|
||||
range(0, len(vnis_to_remove), bulk_size))
|
||||
for vni_list in chunked_vnis:
|
||||
session.query(VxlanAllocation).filter(
|
||||
VxlanAllocation.vxlan_vni.in_(vni_list)).delete(
|
||||
synchronize_session=False)
|
||||
if vni_list:
|
||||
session.query(VxlanAllocation).filter(
|
||||
VxlanAllocation.vxlan_vni.in_(vni_list)).delete(
|
||||
synchronize_session=False)
|
||||
# collect vnis that need to be added
|
||||
vnis = list(vxlan_vnis - existing_vnis)
|
||||
chunked_vnis = (vnis[i:i + bulk_size] for i in
|
||||
|
|
Loading…
Reference in New Issue