From f2249bad214d64c7570a0cba559e80fa0bab488d Mon Sep 17 00:00:00 2001 From: Kevin Zhao Date: Mon, 3 Aug 2020 11:50:46 +0800 Subject: [PATCH] Handle the rbd image not found error Signed-off-by: Kevin Zhao --- ceph_iscsi_config/lun.py | 67 +++++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/ceph_iscsi_config/lun.py b/ceph_iscsi_config/lun.py index 8b910144..76bddada 100644 --- a/ceph_iscsi_config/lun.py +++ b/ceph_iscsi_config/lun.py @@ -1231,38 +1231,41 @@ def define_luns(logger, config, target): for disk_key in pool_disks: pool, image_name = disk_key.split('/') - with rbd.Image(ioctx, image_name) as rbd_image: - - disk_config = config.config['disks'][disk_key] - backstore = disk_config['backstore'] - backstore_object_name = disk_config['backstore_object_name'] - - lun = LUN(logger, pool, image_name, - rbd_image.size(), local_gw, backstore, - backstore_object_name) - - if lun.error: - raise CephiSCSIError("Error defining rbd image {}" - .format(disk_key)) - - so = lun.allocate() - if lun.error: - raise CephiSCSIError("Unable to register {} " - "with LIO: {}" - .format(disk_key, - lun.error_msg)) - - # If not in use by another target on this gw - # clean up stale locks. - if so.status != 'activated': - RBDDev.rbd_lock_cleanup(logger, ips, - rbd_image) - - target._map_lun(config, so, target_disks[disk_key]) - if target.error: - raise CephiSCSIError("Mapping for {} failed: {}" - .format(disk_key, - target.error_msg)) + try: + with rbd.Image(ioctx, image_name) as rbd_image: + + disk_config = config.config['disks'][disk_key] + backstore = disk_config['backstore'] + backstore_object_name = disk_config['backstore_object_name'] + + lun = LUN(logger, pool, image_name, + rbd_image.size(), local_gw, backstore, + backstore_object_name) + + if lun.error: + raise CephiSCSIError("Error defining rbd image {}" + .format(disk_key)) + + so = lun.allocate() + if lun.error: + raise CephiSCSIError("Unable to register {} " + "with LIO: {}" + .format(disk_key, + lun.error_msg)) + + # If not in use by another target on this gw + # clean up stale locks. + if so.status != 'activated': + RBDDev.rbd_lock_cleanup(logger, ips, + rbd_image) + + target._map_lun(config, so, target_disks[disk_key]) + if target.error: + raise CephiSCSIError("Mapping for {} failed: {}" + .format(disk_key, + target.error_msg)) + except rbd.ImageNotFound: + logger.debug("Rbd image not found: '{}' ".format(image_name)) def rados_pool(conf=None, pool=None):