From 81fa117dce054849aee8b347df72a238fea5b2bc Mon Sep 17 00:00:00 2001 From: Anton Arefiev Date: Fri, 17 Oct 2014 15:03:54 +0300 Subject: [PATCH] Handle DBConnectionError instead of Exception Handle database connection error exception instead of general during reporting Cinder service status to database. Change-Id: Id292f2ac92c45aa070727890f8d1472b3bb9357d --- cinder/service.py | 4 ++-- cinder/tests/test_service.py | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cinder/service.py b/cinder/service.py index 272ab7be4..2378c5917 100644 --- a/cinder/service.py +++ b/cinder/service.py @@ -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')) diff --git a/cinder/tests/test_service.py b/cinder/tests/test_service.py index 1b8109012..d731e619f 100644 --- a/cinder/tests/test_service.py +++ b/cinder/tests/test_service.py @@ -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, -- 2.45.2