From 6ef54ff3790f2641443a0f632a585e9edfa9373b Mon Sep 17 00:00:00 2001 From: Manjeet Singh Bhatia Date: Wed, 12 Sep 2018 22:18:28 +0000 Subject: [PATCH] Refactor l3hamode for ha migration. Reduce the check requested_ha_state to one by adding old_owner and new_owner to make it simple. Change-Id: I7ae2a6862d9020ba527229fb46e0b889237ace26 --- neutron/db/l3_hamode_db.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/neutron/db/l3_hamode_db.py b/neutron/db/l3_hamode_db.py index 4ef1daa79d3..c63663637b8 100644 --- a/neutron/db/l3_hamode_db.py +++ b/neutron/db/l3_hamode_db.py @@ -434,7 +434,11 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin, # This will throw HANotEnoughAvailableAgents if there aren't # enough l3 agents to handle this router. self.get_number_of_agents_for_scheduling(payload.context) + old_owner = constants.DEVICE_OWNER_ROUTER_INTF + new_owner = constants.DEVICE_OWNER_HA_REPLICATED_INT else: + old_owner = constants.DEVICE_OWNER_HA_REPLICATED_INT + new_owner = constants.DEVICE_OWNER_ROUTER_INTF ha_network = self.get_ha_network(payload.context, payload.desired_state.tenant_id) @@ -447,16 +451,9 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin, self.set_extra_attr_value(payload.context, payload.desired_state, 'ha', requested_ha_state) return - if requested_ha_state: - self._migrate_router_ports( - payload.context, payload.desired_state, - old_owner=constants.DEVICE_OWNER_ROUTER_INTF, - new_owner=constants.DEVICE_OWNER_HA_REPLICATED_INT) - else: - self._migrate_router_ports( - payload.context, payload.desired_state, - old_owner=constants.DEVICE_OWNER_HA_REPLICATED_INT, - new_owner=constants.DEVICE_OWNER_ROUTER_INTF) + self._migrate_router_ports( + payload.context, payload.desired_state, + old_owner=old_owner, new_owner=new_owner) self.set_extra_attr_value( payload.context, payload.desired_state, 'ha', requested_ha_state)