Merge "Fix: API returns 503 if one of the store is mis-configured"

This commit is contained in:
Zuul 2020-05-08 08:41:58 +00:00 committed by Gerrit Code Review
commit 0f03d535f4
3 changed files with 19 additions and 5 deletions
glance_store

@ -271,10 +271,16 @@ class Store(driver.Store):
try:
client.connect(timeout=self.connect_timeout)
except rados.Error:
msg = _LE("Error connecting to ceph cluster.")
LOG.exception(msg)
raise exceptions.BackendException()
except (rados.Error, rados.ObjectNotFound) as e:
if self.backend_group and len(self.conf.enabled_backends) > 1:
reason = _("Error in store configuration: %s") % e
LOG.debug(reason)
raise exceptions.BadStoreConfiguration(
store_name=self.backend_group, reason=reason)
else:
msg = _LE("Error connecting to ceph cluster.")
LOG.exception(msg)
raise exceptions.BackendException()
try:
yield client
finally:

@ -36,6 +36,9 @@ class MockRados(object):
class Error(Exception):
pass
class ObjectNotFound(Exception):
pass
class ioctx(object):
def __init__(self, *args, **kwargs):
pass
@ -443,11 +446,12 @@ class TestMultiStore(base.MultiStoreBaseTest,
@mock.patch.object(MockRados.Rados, 'connect', side_effect=MockRados.Error)
def test_rados_connect_error(self, _):
rbd_store.rados.Error = MockRados.Error
rbd_store.rados.ObjectNotFound = MockRados.ObjectNotFound
def test():
with self.store.get_connection('conffile', 'rados_id'):
pass
self.assertRaises(exceptions.BackendException, test)
self.assertRaises(exceptions.BadStoreConfiguration, test)
def test_create_image_conf_features(self):
# Tests that we use non-0 features from ceph.conf and cast to int.

@ -35,6 +35,9 @@ class MockRados(object):
class Error(Exception):
pass
class ObjectNotFound(Exception):
pass
class ioctx(object):
def __init__(self, *args, **kwargs):
pass
@ -451,6 +454,7 @@ class TestStore(base.StoreBaseTest,
@mock.patch.object(MockRados.Rados, 'connect', side_effect=MockRados.Error)
def test_rados_connect_error(self, _):
rbd_store.rados.Error = MockRados.Error
rbd_store.rados.ObjectNotFound = MockRados.ObjectNotFound
def test():
with self.store.get_connection('conffile', 'rados_id'):