diff --git a/neutron/db/l3_hamode_db.py b/neutron/db/l3_hamode_db.py index 5dc92a8233f..e32616381a8 100644 --- a/neutron/db/l3_hamode_db.py +++ b/neutron/db/l3_hamode_db.py @@ -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 diff --git a/neutron/tests/unit/db/test_l3_hamode_db.py b/neutron/tests/unit/db/test_l3_hamode_db.py index c1902645004..15d899c39b9 100644 --- a/neutron/tests/unit/db/test_l3_hamode_db.py +++ b/neutron/tests/unit/db/test_l3_hamode_db.py @@ -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. @@ -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):