Skip to content

Commit

Permalink
Fix: API returns 503 if one of the store is mis-configured
Browse files Browse the repository at this point in the history
If user mis-configures one of the multiple stores defined in glance-api
configuratio file, then service returns 503 for all API requests.

Made provision to exclude faulty store and resume service normally
to function wiht other configured stores.

Closes-Bug: #1875281
Change-Id: I685a0ecbfba7cf7dbce3fd2eb84f97bd8ffbfcf3
(cherry picked from commit 98b9091)
(cherry picked from commit 17b66ab)
  • Loading branch information
konan-abhi committed May 11, 2020
1 parent d052ce5 commit a622766
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
14 changes: 10 additions & 4 deletions glance_store/_drivers/rbd.py
Expand Up @@ -271,10 +271,16 @@ def get_connection(self, conffile, rados_id):

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:
Expand Down
6 changes: 5 additions & 1 deletion glance_store/tests/unit/test_multistore_rbd.py
Expand Up @@ -35,6 +35,9 @@ class MockRados(object):
class Error(Exception):
pass

class ObjectNotFound(Exception):
pass

class ioctx(object):
def __init__(self, *args, **kwargs):
pass
Expand Down Expand Up @@ -442,11 +445,12 @@ def test_rados_connect_timeout(self, mock_rados_connect):
@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.
Expand Down
4 changes: 4 additions & 0 deletions glance_store/tests/unit/test_rbd_store.py
Expand Up @@ -34,6 +34,9 @@ class MockRados(object):
class Error(Exception):
pass

class ObjectNotFound(Exception):
pass

class ioctx(object):
def __init__(self, *args, **kwargs):
pass
Expand Down Expand Up @@ -450,6 +453,7 @@ def test_rados_connect_timeout(self, mock_rados_connect):
@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'):
Expand Down

0 comments on commit a622766

Please sign in to comment.