From e0e8a2e9e81c2f6293eaa8556c5ecdac910358cb Mon Sep 17 00:00:00 2001 From: Eugene Nikanorov Date: Mon, 17 Nov 2014 20:49:09 +0400 Subject: [PATCH] Catch DBReferenceError exception during binding a router In some cases (Concurrent API tests) router can be deleted before it is bound to an agent by scheduler. That may lead to traces on L3 agent side returned via RPC. Need to handle this case in more graceful way. Change-Id: Ic52c26ace7f32a615150bd6098b244ae0b98250c Closes-Bug: #1385257 --- neutron/scheduler/l3_agent_scheduler.py | 4 ++++ neutron/tests/unit/test_l3_schedulers.py | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/neutron/scheduler/l3_agent_scheduler.py b/neutron/scheduler/l3_agent_scheduler.py index c9b1efafb..e86a9c2fc 100644 --- a/neutron/scheduler/l3_agent_scheduler.py +++ b/neutron/scheduler/l3_agent_scheduler.py @@ -220,6 +220,10 @@ class L3Scheduler(object): {'agent_id': chosen_agent.id, 'router_id': router_id}) return + except db_exc.DBReferenceError: + LOG.debug('Router %s has already been removed ' + 'by concurrent operation', router_id) + return LOG.debug('Router %(router_id)s is scheduled to L3 agent ' '%(agent_id)s', {'router_id': router_id, diff --git a/neutron/tests/unit/test_l3_schedulers.py b/neutron/tests/unit/test_l3_schedulers.py index 09346758e..e9af85d49 100644 --- a/neutron/tests/unit/test_l3_schedulers.py +++ b/neutron/tests/unit/test_l3_schedulers.py @@ -482,6 +482,12 @@ class L3SchedulerTestBaseMixin(object): args, kwargs = flog.call_args self.assertIn('is scheduled', args[0]) + def test_bind_absent_router(self): + scheduler = l3_agent_scheduler.ChanceScheduler() + # checking that bind_router() is not throwing + # when supplied with router_id of non-existing router + scheduler.bind_router(self.adminContext, "dummyID", self.agent1) + def test_bind_existing_router(self): router = self._make_router(self.fmt, tenant_id=str(uuid.uuid4()), -- 2.45.2