summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelipe Reyes <felipe.reyes@canonical.com>2017-05-19 17:13:52 -0400
committerFelipe Reyes <felipe.reyes@canonical.com>2017-06-01 18:31:04 -0400
commitf6b3d25c6ef335ff891030b8e34c1d27f45b896c (patch)
tree762071496142e084882768a8aec3bc3dbfa424a1
parent59c6530990f0a375d390add49dad79b9089b1231 (diff)
Update the host_id for network:router_gateway interfaces
The ports owned by a router_gateway need to get its host_id property updated during the failover of a router. Otherwise the port connected to the external network will always have its host_id set to the value obtained during creation. Change-Id: I5eca20e3cc64d7a9e52b0556a3cadd29eb4c821d Closes-Bug: 1694337 (cherry picked from commit d8334b41d2c5bcd4916347d20008b1538d48b0ef)
Notes
Notes (review): Code-Review+1: Reedip <reedip.banerjee@gmail.com> Code-Review-1: Tovin Seven <vinhnt@vn.fujitsu.com> Code-Review+2: Brian Haley <haleyb.dev@gmail.com> Code-Review+2: Kevin Benton <kevin@benton.pub> Workflow+1: Kevin Benton <kevin@benton.pub> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Fri, 02 Jun 2017 16:19:39 +0000 Reviewed-on: https://review.openstack.org/470045 Project: openstack/neutron Branch: refs/heads/stable/newton
-rw-r--r--neutron/db/l3_hamode_db.py3
-rw-r--r--neutron/tests/unit/db/test_l3_hamode_db.py24
2 files changed, 22 insertions, 5 deletions
diff --git a/neutron/db/l3_hamode_db.py b/neutron/db/l3_hamode_db.py
index 16f1ef1..f395801 100644
--- a/neutron/db/l3_hamode_db.py
+++ b/neutron/db/l3_hamode_db.py
@@ -776,7 +776,8 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin,
776 device_filter = {'device_id': list(states.keys()), 776 device_filter = {'device_id': list(states.keys()),
777 'device_owner': 777 'device_owner':
778 [constants.DEVICE_OWNER_HA_REPLICATED_INT, 778 [constants.DEVICE_OWNER_HA_REPLICATED_INT,
779 constants.DEVICE_OWNER_ROUTER_SNAT]} 779 constants.DEVICE_OWNER_ROUTER_SNAT,
780 constants.DEVICE_OWNER_ROUTER_GW]}
780 ports = self._core_plugin.get_ports(admin_ctx, filters=device_filter) 781 ports = self._core_plugin.get_ports(admin_ctx, filters=device_filter)
781 active_ports = (port for port in ports 782 active_ports = (port for port in ports
782 if states[port['device_id']] == n_const.HA_ROUTER_STATE_ACTIVE) 783 if states[port['device_id']] == n_const.HA_ROUTER_STATE_ACTIVE)
diff --git a/neutron/tests/unit/db/test_l3_hamode_db.py b/neutron/tests/unit/db/test_l3_hamode_db.py
index f7c2d30..b0dc8a4 100644
--- a/neutron/tests/unit/db/test_l3_hamode_db.py
+++ b/neutron/tests/unit/db/test_l3_hamode_db.py
@@ -84,6 +84,7 @@ class L3HATestFramework(testlib_api.SqlTestCase):
84 router['ha'] = ha 84 router['ha'] = ha
85 if distributed is not None: 85 if distributed is not None:
86 router['distributed'] = distributed 86 router['distributed'] = distributed
87
87 return self.plugin.create_router(ctx, {'router': router}) 88 return self.plugin.create_router(ctx, {'router': router})
88 89
89 def _migrate_router(self, router_id, ha): 90 def _migrate_router(self, router_id, ha):
@@ -1061,26 +1062,41 @@ class L3HAModeDbTestCase(L3HATestFramework):
1061 self.admin_ctx, 1062 self.admin_ctx,
1062 filters=device_filter)[0] 1063 filters=device_filter)[0]
1063 1064
1065 def _get_router_port_bindings(self, router_id):
1066 device_filter = {'device_id': [router_id],
1067 'device_owner':
1068 [constants.DEVICE_OWNER_HA_REPLICATED_INT,
1069 constants.DEVICE_OWNER_ROUTER_SNAT,
1070 constants.DEVICE_OWNER_ROUTER_GW]}
1071 return self.core_plugin.get_ports(
1072 self.admin_ctx,
1073 filters=device_filter)
1074
1064 def test_update_router_port_bindings_updates_host(self): 1075 def test_update_router_port_bindings_updates_host(self):
1076 ext_net = self._create_network(self.core_plugin, self.admin_ctx,
1077 external=True)
1065 network_id = self._create_network(self.core_plugin, self.admin_ctx) 1078 network_id = self._create_network(self.core_plugin, self.admin_ctx)
1066 subnet = self._create_subnet(self.core_plugin, self.admin_ctx, 1079 subnet = self._create_subnet(self.core_plugin, self.admin_ctx,
1067 network_id) 1080 network_id)
1068 interface_info = {'subnet_id': subnet['id']} 1081 interface_info = {'subnet_id': subnet['id']}
1069 1082
1070 router = self._create_router() 1083 router = self._create_router()
1084 self.plugin._update_router_gw_info(self.admin_ctx, router['id'],
1085 {'network_id': ext_net})
1071 self.plugin.add_router_interface(self.admin_ctx, 1086 self.plugin.add_router_interface(self.admin_ctx,
1072 router['id'], 1087 router['id'],
1073 interface_info) 1088 interface_info)
1074 self.plugin._update_router_port_bindings( 1089 self.plugin._update_router_port_bindings(
1075 self.admin_ctx, {router['id']: 'active'}, self.agent1['host']) 1090 self.admin_ctx, {router['id']: 'active'}, self.agent1['host'])
1076 1091
1077 port = self._get_first_interface(router['id']) 1092 for port in self._get_router_port_bindings(router['id']):
1078 self.assertEqual(self.agent1['host'], port[portbindings.HOST_ID]) 1093 self.assertEqual(self.agent1['host'], port[portbindings.HOST_ID])
1079 1094
1080 self.plugin._update_router_port_bindings( 1095 self.plugin._update_router_port_bindings(
1081 self.admin_ctx, {router['id']: 'active'}, self.agent2['host']) 1096 self.admin_ctx, {router['id']: 'active'}, self.agent2['host'])
1082 port = self._get_first_interface(router['id']) 1097
1083 self.assertEqual(self.agent2['host'], port[portbindings.HOST_ID]) 1098 for port in self._get_router_port_bindings(router['id']):
1099 self.assertEqual(self.agent2['host'], port[portbindings.HOST_ID])
1084 1100
1085 def test_ensure_host_set_on_ports_dvr_ha_binds_to_active(self): 1101 def test_ensure_host_set_on_ports_dvr_ha_binds_to_active(self):
1086 agent3 = helpers.register_l3_agent('host_3', 1102 agent3 = helpers.register_l3_agent('host_3',