Skip to content

Commit

Permalink
Merge "Catch PortNotFound after HA router race condition"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Feb 28, 2016
2 parents 544b85b + 472d84d commit f8ecd2b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion neutron/db/l3_hamode_db.py
Expand Up @@ -687,6 +687,7 @@ def _update_router_port_bindings(self, context, states, host):
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
24 changes: 24 additions & 0 deletions neutron/tests/unit/db/test_l3_hamode_db.py
Expand Up @@ -642,6 +642,19 @@ def test_set_router_states_handles_concurrently_deleted_router(self):
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.
Expand Down Expand Up @@ -774,6 +787,17 @@ def test_ha_router_create_failed_no_ha_network_delete(self):
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):

Expand Down

0 comments on commit f8ecd2b

Please sign in to comment.