From 73776facdcc9611b00410c43bd16e09bdfc7a7e7 Mon Sep 17 00:00:00 2001 From: Kevin Benton Date: Thu, 15 Jun 2017 00:25:36 -0700 Subject: [PATCH] Use super to make _build_routers_list safer This switches _build_routers_list to call 'super' in both of the override cases so we aren't sensitive to class ordering. Change-Id: I2f8b54826918280cf63d69a6d34bfc4b358b3b6a Related-Bug: #1695101 --- neutron/db/l3_dvr_db.py | 12 ++---------- neutron/db/l3_gwmode_db.py | 2 ++ 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/neutron/db/l3_dvr_db.py b/neutron/db/l3_dvr_db.py index 3189e6667fc..8d9e1bb068c 100644 --- a/neutron/db/l3_dvr_db.py +++ b/neutron/db/l3_dvr_db.py @@ -591,22 +591,18 @@ class _DVRAgentInterfaceMixin(object): def _build_routers_list(self, context, routers, gw_ports): # Perform a single query up front for all routers + routers = super(_DVRAgentInterfaceMixin, self)._build_routers_list( + context, routers, gw_ports) if not routers: return [] router_ids = [r['id'] for r in routers] binding_objs = rb_obj.RouterL3AgentBinding.get_objects( context, router_id=router_ids) bindings = dict((b.router_id, b) for b in binding_objs) - for rtr in routers: gw_port_id = rtr['gw_port_id'] # Collect gw ports only if available if gw_port_id and gw_ports.get(gw_port_id): - rtr['gw_port'] = gw_ports[gw_port_id] - if 'enable_snat' in rtr[l3.EXTERNAL_GW_INFO]: - rtr['enable_snat'] = ( - rtr[l3.EXTERNAL_GW_INFO]['enable_snat']) - binding = bindings.get(rtr['id']) if not binding: rtr['gw_port_host'] = None @@ -963,10 +959,6 @@ class _DVRAgentInterfaceMixin(object): return update_port -# NOTE: The order in which the parent classes are inherited sometimes -# determines the functions defined in those classes to be executed. -# So any new classes that overrides a function in the parent class should -# be added before the parent class. class L3_NAT_with_dvr_db_mixin(_DVRAgentInterfaceMixin, DVRResourceOperationHandler, l3_attrs_db.ExtraAttributesMixin, diff --git a/neutron/db/l3_gwmode_db.py b/neutron/db/l3_gwmode_db.py index 8987dd133ba..50fa94d46f7 100644 --- a/neutron/db/l3_gwmode_db.py +++ b/neutron/db/l3_gwmode_db.py @@ -79,6 +79,8 @@ class L3_NAT_dbonly_mixin(l3_db.L3_NAT_dbonly_mixin): return cfg.CONF.enable_snat_by_default def _build_routers_list(self, context, routers, gw_ports): + routers = super(L3_NAT_dbonly_mixin, self)._build_routers_list( + context, routers, gw_ports) for rtr in routers: gw_port_id = rtr['gw_port_id'] # Collect gw ports only if available