From c0334858d1a71f22b86d4badcfc86a46294f795f Mon Sep 17 00:00:00 2001 From: Ramana Raja Date: Tue, 13 May 2025 12:37:52 -0400 Subject: [PATCH] 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 (cherry picked from commit 0a705115337d11231c21209c056c6c588c1bc8eb) --- src/pybind/mgr/dashboard/controllers/rbd.py | 7 +++++-- .../mgr/dashboard/controllers/rbd_mirroring.py | 8 +++++++- src/pybind/mgr/dashboard/services/rbd.py | 17 +++++++++-------- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/pybind/mgr/dashboard/controllers/rbd.py b/src/pybind/mgr/dashboard/controllers/rbd.py index 767d23577b655..abcbb111a6dfd 100644 --- a/src/pybind/mgr/dashboard/controllers/rbd.py +++ b/src/pybind/mgr/dashboard/controllers/rbd.py @@ -235,8 +235,11 @@ class RbdSnapshot(RESTController): def _create_snapshot(ioctx, img, snapshot_name): mirror_info = img.mirror_image_get_info() - mirror_mode = img.mirror_image_get_mode() - 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 + mirror_mode = None + if mirror_info['state'] == rbd.RBD_MIRROR_IMAGE_ENABLED: + mirror_mode = img.mirror_image_get_mode() + + if (mirror_mode == rbd.RBD_MIRROR_IMAGE_MODE_SNAPSHOT) and mirrorImageSnapshot: img.mirror_image_create_snapshot() else: img.create_snap(snapshot_name) diff --git a/src/pybind/mgr/dashboard/controllers/rbd_mirroring.py b/src/pybind/mgr/dashboard/controllers/rbd_mirroring.py index 413ccb8dde4c3..2b081051fe413 100644 --- a/src/pybind/mgr/dashboard/controllers/rbd_mirroring.py +++ b/src/pybind/mgr/dashboard/controllers/rbd_mirroring.py @@ -241,8 +241,14 @@ class ReplayingData(NamedTuple): def _get_mirror_mode(ioctx, image_name): with rbd.Image(ioctx, image_name) as img: - mirror_mode = img.mirror_image_get_mode() + mirror_mode = None mirror_mode_str = 'Disabled' + try: + mirror_mode = img.mirror_image_get_mode() + except rbd.InvalidArgument: + # Suppress exception raised when mirroring is disabled + pass + if mirror_mode == rbd.RBD_MIRROR_IMAGE_MODE_JOURNAL: mirror_mode_str = 'journal' elif mirror_mode == rbd.RBD_MIRROR_IMAGE_MODE_SNAPSHOT: diff --git a/src/pybind/mgr/dashboard/services/rbd.py b/src/pybind/mgr/dashboard/services/rbd.py index 31fdb7c9818e3..812774ba438db 100644 --- a/src/pybind/mgr/dashboard/services/rbd.py +++ b/src/pybind/mgr/dashboard/services/rbd.py @@ -305,8 +305,13 @@ class RbdService(object): with rbd.Image(ioctx, image_name) as img: stat = img.stat() mirror_info = img.mirror_image_get_info() - mirror_mode = img.mirror_image_get_mode() - 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 + mirror_mode = None + if mirror_info['state'] != rbd.RBD_MIRROR_IMAGE_DISABLED: + mirror_mode = img.mirror_image_get_mode() + else: + stat['mirror_mode'] = 'Disabled' + + if mirror_mode == rbd.RBD_MIRROR_IMAGE_MODE_JOURNAL: stat['mirror_mode'] = 'journal' elif mirror_mode == rbd.RBD_MIRROR_IMAGE_MODE_SNAPSHOT: stat['mirror_mode'] = 'snapshot' @@ -315,8 +320,6 @@ class RbdService(object): for scheduled_image in schedule_status['scheduled_images']: if scheduled_image['image'] == get_image_spec(pool_name, namespace, image_name): stat['schedule_info'] = scheduled_image - else: - stat['mirror_mode'] = 'Disabled' stat['name'] = image_name @@ -364,10 +367,8 @@ class RbdService(object): if snap['namespace'] == rbd.RBD_SNAP_NAMESPACE_TYPE_TRASH: continue - try: - snap['mirror_mode'] = MIRROR_IMAGE_MODE(img.mirror_image_get_mode()).name - except ValueError as ex: - raise DashboardException(f'Unknown RBD Mirror mode: {ex}') + if mirror_mode: + snap['mirror_mode'] = mirror_mode snap['timestamp'] = "{}Z".format( img.get_snap_timestamp(snap['id']).isoformat()) -- 2.39.5