Merge "rbd: Only log import failures when the RbdDriver is used"
This commit is contained in:
commit
dc93e3b510
@ -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)
|
||||
|
@ -1337,9 +1337,11 @@ class TestRBDDownload(test.NoDBTestCase):
|
||||
self.pool_name = "images"
|
||||
self.snapshot_name = "snap"
|
||||
|
||||
@mock.patch('nova.storage.rbd_utils.RBDDriver._check_for_import_failure',
|
||||
new=mock.Mock())
|
||||
@mock.patch.object(rbd_utils.RBDDriver, 'export_image')
|
||||
@mock.patch.object(rbd_utils, 'rbd')
|
||||
def test_rbd_download_success(self, mock_rbd, mock_export_image):
|
||||
@mock.patch.object(rbd_utils, 'rbd', new=mock.Mock())
|
||||
def test_rbd_download_success(self, mock_export_image):
|
||||
client = mock.MagicMock()
|
||||
ctx = mock.sentinel.ctx
|
||||
service = glance.GlanceImageServiceV2(client)
|
||||
@ -1366,9 +1368,11 @@ class TestRBDDownload(test.NoDBTestCase):
|
||||
exception.InvalidParameterValue, service.rbd_download, ctx,
|
||||
wrong_url_parts, mock.sentinel.dst_path)
|
||||
|
||||
@mock.patch('nova.storage.rbd_utils.RBDDriver._check_for_import_failure',
|
||||
new=mock.Mock())
|
||||
@mock.patch('nova.storage.rbd_utils.RBDDriver.export_image')
|
||||
@mock.patch.object(rbd_utils, 'rbd')
|
||||
def test_rbd_download_export_failure(self, mock_rbd, mock_export_image):
|
||||
@mock.patch.object(rbd_utils, 'rbd', new=mock.Mock())
|
||||
def test_rbd_download_export_failure(self, mock_export_image):
|
||||
client = mock.MagicMock()
|
||||
ctx = mock.sentinel.ctx
|
||||
service = glance.GlanceImageServiceV2(client)
|
||||
|
@ -5350,10 +5350,12 @@ class LibvirtConnTestCase(test.NoDBTestCase,
|
||||
def test_get_guest_config_default_with_virtio_scsi_bus(self):
|
||||
self._test_get_guest_config_with_virtio_scsi_bus()
|
||||
|
||||
@mock.patch.object(rbd_utils.RBDDriver, '_check_for_import_failure',
|
||||
new=mock.Mock())
|
||||
@mock.patch.object(rbd_utils.RBDDriver, 'get_mon_addrs')
|
||||
@mock.patch.object(rbd_utils, 'rbd')
|
||||
@mock.patch.object(rbd_utils, 'rbd', new=mock.Mock())
|
||||
def test_get_guest_config_rbd_with_virtio_scsi_bus(
|
||||
self, mock_rdb, mock_get_mon_addrs):
|
||||
self, mock_get_mon_addrs):
|
||||
self.flags(images_type='rbd', group='libvirt')
|
||||
mock_get_mon_addrs.return_value = ("host", 9876)
|
||||
self._test_get_guest_config_with_virtio_scsi_bus()
|
||||
|
Loading…
x
Reference in New Issue
Block a user