]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Handle DBConnectionError instead of Exception
authorAnton Arefiev <aarefiev@mirantis.com>
Fri, 17 Oct 2014 12:03:54 +0000 (15:03 +0300)
committerAnton Arefiev <aarefiev@mirantis.com>
Tue, 21 Oct 2014 11:45:06 +0000 (14:45 +0300)
Handle database connection error exception instead of
general during reporting Cinder service status to database.

Change-Id: Id292f2ac92c45aa070727890f8d1472b3bb9357d

cinder/service.py
cinder/tests/test_service.py

index 272ab7be473d26c56d0fa1f2aa76c73ef41467c1..2378c59177775cdb58f608fe3f4d45151654ddf8 100644 (file)
@@ -23,6 +23,7 @@ import os
 import random
 
 from oslo.config import cfg
+from oslo.db import exception as db_exc
 from oslo import messaging
 import osprofiler.notifier
 from osprofiler import profiler
@@ -304,8 +305,7 @@ class Service(service.Service):
                 self.model_disconnected = False
                 LOG.error(_('Recovered model server connection!'))
 
-        # TODO(vish): this should probably only catch connection errors
-        except Exception:  # pylint: disable=W0702
+        except db_exc.DBConnectionError:
             if not getattr(self, 'model_disconnected', False):
                 self.model_disconnected = True
                 LOG.exception(_('model server went away'))
index 1b8109012db804fa038a4e8bcf36689b7a59a44c..d731e619f13baa36d53ca9ee33fca54d2b08a4c2 100644 (file)
@@ -23,6 +23,7 @@ Unit Tests for remote procedure calls using queue
 import mock
 import mox
 from oslo.config import cfg
+from oslo.db import exception as db_exc
 
 from cinder import context
 from cinder import db
@@ -148,8 +149,9 @@ class ServiceTestCase(test.TestCase):
                                        binary).AndRaise(exception.NotFound())
         service.db.service_create(mox.IgnoreArg(),
                                   service_create).AndReturn(service_ref)
-        service.db.service_get(mox.IgnoreArg(),
-                               mox.IgnoreArg()).AndRaise(Exception())
+        service.db.service_get(
+            mox.IgnoreArg(),
+            mox.IgnoreArg()).AndRaise(db_exc.DBConnectionError())
 
         self.mox.ReplayAll()
         serv = service.Service(host,