summaryrefslogtreecommitdiff
path: root/nova/storage
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2020-11-09 23:51:46 +0000
committerGerrit Code Review <review@openstack.org>2020-11-09 23:51:46 +0000
commitdc93e3b510f53d5b2198c8edd22528f0c899617e (patch)
treed1727dc08e472089202d6a4b0d74e57abc0f335c /nova/storage
parent4f2540a7a69d52390011adb1e74b20f0f1333361 (diff)
parent4916ab7a4cb67edc0b54a8ee67c58b1302769792 (diff)
downloadnova-dc93e3b510f53d5b2198c8edd22528f0c899617e.tar.gz
Merge "rbd: Only log import failures when the RbdDriver is used"
Diffstat (limited to 'nova/storage')
-rw-r--r--nova/storage/rbd_utils.py49
1 files changed, 28 insertions, 21 deletions
diff --git a/nova/storage/rbd_utils.py b/nova/storage/rbd_utils.py
index d4197271e9..d6fc6b8317 100644
--- a/nova/storage/rbd_utils.py
+++ b/nova/storage/rbd_utils.py
@@ -29,6 +29,12 @@ import nova.conf
from nova import exception
from nova.i18n import _
+try:
+ import rados
+ import rbd
+except ImportError:
+ rados = None
+ rbd = None
CONF = nova.conf.CONF
@@ -36,25 +42,6 @@ LOG = logging.getLogger(__name__)
RESIZE_SNAPSHOT_NAME = 'nova-resize'
-# NOTE(lyarwood): Log exceptions if we fail to import rbd or rados in order to
-# provide context later if we end up attempting to use the RbdDriver and
-# raising RuntimeError
-try:
- import rados
-except ImportError:
- rados = None
- LOG.exception(
- "Unable to import the rados module, this can be ignored if Ceph is "
- "not used within this environment")
-
-try:
- import rbd
-except ImportError:
- rbd = None
- LOG.exception(
- "Unable to import the rbd module, this can be ignored if Ceph is not "
- "used within this environment")
-
class RbdProxy(object):
"""A wrapper around rbd.RBD class instance to avoid blocking of process.
@@ -137,8 +124,11 @@ class RBDDriver(object):
def __init__(self, pool=None, user=None, ceph_conf=None,
connect_timeout=None):
- if rbd is None:
- raise RuntimeError(_('rbd python libraries not found'))
+
+ # NOTE(lyarwood): Ensure the rbd and rados modules have been imported
+ # correctly before continuing, this is done in a seperate private
+ # method to allow us to skip this check in unit tests etc.
+ self._check_for_import_failure()
self.pool = pool or CONF.libvirt.images_rbd_pool
self.rbd_user = user or CONF.libvirt.rbd_user
@@ -146,6 +136,23 @@ class RBDDriver(object):
connect_timeout or CONF.libvirt.rbd_connect_timeout)
self.ceph_conf = ceph_conf or CONF.libvirt.images_rbd_ceph_conf
+ def _check_for_import_failure(self):
+ # NOTE(lyarwood): If the original import of the required rbd or rados
+ # modules failed then repeat the imports at runtime within this driver
+ # to log the full exception in order to provide context to anyone
+ # debugging the failure in the logs.
+ global rados, rbd
+ if rbd is None or rados is None:
+ try:
+ # NOTE(lyarwood): noqa is required on both imports here as they
+ # are unused (F401) even if successful.
+ import rados # noqa: F401
+ import rbd # noqa: F401
+ except ImportError:
+ LOG.exception("Unable to import the rados or rbd modules")
+
+ raise RuntimeError(_('rbd python libraries not found'))
+
def _connect_to_rados(self, pool=None):
client = rados.Rados(rados_id=self.rbd_user,
conffile=self.ceph_conf)