Merge "Catch PortNotFound after HA router race condition"

This commit is contained in:
Jenkins 2016-02-28 13:13:26 +00:00 committed by Gerrit Code Review
commit f8ecd2b1c3
2 changed files with 26 additions and 1 deletions

View File

@ -687,6 +687,7 @@ class L3_HA_NAT_db_mixin(l3_dvr_db.L3_NAT_with_dvr_db_mixin,
try:
self._core_plugin.update_port(admin_ctx, port['id'],
{attributes.PORT: port})
except (orm.exc.StaleDataError, orm.exc.ObjectDeletedError):
except (orm.exc.StaleDataError, orm.exc.ObjectDeletedError,
n_exc.PortNotFound):
# Take concurrently deleted interfaces in to account
pass

View File

@ -642,6 +642,19 @@ class L3HATestCase(L3HATestFramework):
self.admin_ctx, self.agent1['host'], self.agent1)
self.assertEqual('active', routers[0][constants.HA_ROUTER_STATE_KEY])
def test_update_routers_states_port_not_found(self):
router1 = self._create_router()
self._bind_router(router1['id'])
port = {'id': 'foo', 'device_id': router1['id']}
with mock.patch.object(self.core_plugin, 'get_ports',
return_value=[port]):
with mock.patch.object(
self.core_plugin, 'update_port',
side_effect=n_exc.PortNotFound(port_id='foo')):
states = {router1['id']: 'active'}
self.plugin.update_routers_states(
self.admin_ctx, states, self.agent1['host'])
def test_exclude_dvr_agents_for_ha_candidates(self):
"""Test dvr agents configured with "dvr" only, as opposed to "dvr_snat",
are excluded.
@ -774,6 +787,17 @@ class L3HATestCase(L3HATestFramework):
self.assertNotIn('HA network tenant %s' % tenant_id,
nets_after)
def test_update_port_status_port_bingding_deleted_concurrently(self):
router1 = self._create_router()
self._bind_router(router1['id'])
states = {router1['id']: 'active'}
with mock.patch.object(self.plugin, 'get_ha_router_port_bindings'):
(self.admin_ctx.session.query(
l3_hamode_db.L3HARouterAgentPortBinding).
filter_by(router_id=router1['id']).delete())
self.plugin.update_routers_states(
self.admin_ctx, states, self.agent1['host'])
class L3HAModeDbTestCase(L3HATestFramework):