Skip to content

Commit 0a70511

Browse files
committed
pybind/mgr/dashboard: fetch image's mirror mode
... only if the image is not disabled for mirroring. If the image is disabled for mirroring, fetching the image's mirroring mode is invalid. So validate that the image is not disabled for mirroring before fetching the mirroring mode. Signed-off-by: Ramana Raja <[email protected]>
1 parent b3f1d2d commit 0a70511

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

src/pybind/mgr/dashboard/controllers/rbd.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,11 @@ def create(self, image_spec, snapshot_name, mirrorImageSnapshot):
235235

236236
def _create_snapshot(ioctx, img, snapshot_name):
237237
mirror_info = img.mirror_image_get_info()
238-
mirror_mode = img.mirror_image_get_mode()
239-
if (mirror_info['state'] == rbd.RBD_MIRROR_IMAGE_ENABLED and mirror_mode == rbd.RBD_MIRROR_IMAGE_MODE_SNAPSHOT) and mirrorImageSnapshot: # noqa E501 #pylint: disable=line-too-long
238+
mirror_mode = None
239+
if mirror_info['state'] == rbd.RBD_MIRROR_IMAGE_ENABLED:
240+
mirror_mode = img.mirror_image_get_mode()
241+
242+
if (mirror_mode == rbd.RBD_MIRROR_IMAGE_MODE_SNAPSHOT) and mirrorImageSnapshot:
240243
img.mirror_image_create_snapshot()
241244
else:
242245
img.create_snap(snapshot_name)

src/pybind/mgr/dashboard/controllers/rbd_mirroring.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,14 @@ class ReplayingData(NamedTuple):
241241

242242
def _get_mirror_mode(ioctx, image_name):
243243
with rbd.Image(ioctx, image_name) as img:
244-
mirror_mode = img.mirror_image_get_mode()
244+
mirror_mode = None
245245
mirror_mode_str = 'Disabled'
246+
try:
247+
mirror_mode = img.mirror_image_get_mode()
248+
except rbd.InvalidArgument:
249+
# Suppress exception raised when mirroring is disabled
250+
pass
251+
246252
if mirror_mode == rbd.RBD_MIRROR_IMAGE_MODE_JOURNAL:
247253
mirror_mode_str = 'journal'
248254
elif mirror_mode == rbd.RBD_MIRROR_IMAGE_MODE_SNAPSHOT:

src/pybind/mgr/dashboard/services/rbd.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,13 @@ def _rbd_image(cls, ioctx, pool_name, namespace, image_name, # pylint: disable=
305305
with rbd.Image(ioctx, image_name) as img:
306306
stat = img.stat()
307307
mirror_info = img.mirror_image_get_info()
308-
mirror_mode = img.mirror_image_get_mode()
309-
if mirror_mode == rbd.RBD_MIRROR_IMAGE_MODE_JOURNAL and mirror_info['state'] != rbd.RBD_MIRROR_IMAGE_DISABLED: # noqa E501 #pylint: disable=line-too-long
308+
mirror_mode = None
309+
if mirror_info['state'] != rbd.RBD_MIRROR_IMAGE_DISABLED:
310+
mirror_mode = img.mirror_image_get_mode()
311+
else:
312+
stat['mirror_mode'] = 'Disabled'
313+
314+
if mirror_mode == rbd.RBD_MIRROR_IMAGE_MODE_JOURNAL:
310315
stat['mirror_mode'] = 'journal'
311316
elif mirror_mode == rbd.RBD_MIRROR_IMAGE_MODE_SNAPSHOT:
312317
stat['mirror_mode'] = 'snapshot'
@@ -315,8 +320,6 @@ def _rbd_image(cls, ioctx, pool_name, namespace, image_name, # pylint: disable=
315320
for scheduled_image in schedule_status['scheduled_images']:
316321
if scheduled_image['image'] == get_image_spec(pool_name, namespace, image_name):
317322
stat['schedule_info'] = scheduled_image
318-
else:
319-
stat['mirror_mode'] = 'Disabled'
320323

321324
stat['name'] = image_name
322325

@@ -364,10 +367,8 @@ def _rbd_image(cls, ioctx, pool_name, namespace, image_name, # pylint: disable=
364367
if snap['namespace'] == rbd.RBD_SNAP_NAMESPACE_TYPE_TRASH:
365368
continue
366369

367-
try:
368-
snap['mirror_mode'] = MIRROR_IMAGE_MODE(img.mirror_image_get_mode()).name
369-
except ValueError as ex:
370-
raise DashboardException(f'Unknown RBD Mirror mode: {ex}')
370+
if mirror_mode:
371+
snap['mirror_mode'] = mirror_mode
371372

372373
snap['timestamp'] = "{}Z".format(
373374
img.get_snap_timestamp(snap['id']).isoformat())

0 commit comments

Comments
 (0)