]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Catch DBReferenceError exception during binding a router
authorEugene Nikanorov <enikanorov@mirantis.com>
Mon, 17 Nov 2014 16:49:09 +0000 (20:49 +0400)
committerEugene Nikanorov <enikanorov@mirantis.com>
Wed, 19 Nov 2014 07:55:28 +0000 (11:55 +0400)
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
neutron/tests/unit/test_l3_schedulers.py

index c9b1efafb09d0351a42ab1b542691dd39a0ee7e0..e86a9c2fccf7a4450efa775a5bf8fe41fe893cef 100644 (file)
@@ -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,
index 09346758e057136cc296735ee0162cfc4d9e2c18..e9af85d4995a19ef5740e546e1cb11a7c35eeed9 100644 (file)
@@ -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()),