]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
pybind/mgr/dashboard: fetch image's mirror mode 64100/head
authorRamana Raja <rraja@redhat.com>
Tue, 13 May 2025 16:37:52 +0000 (12:37 -0400)
committerIlya Dryomov <idryomov@gmail.com>
Mon, 23 Jun 2025 07:36:07 +0000 (09:36 +0200)
... 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 <rraja@redhat.com>
(cherry picked from commit 0a705115337d11231c21209c056c6c588c1bc8eb)

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

index 767d23577b655f95f577bcabb6666c06cf0c72fb..abcbb111a6dfd28287972abcb46e4ca30419d099 100644 (file)
@@ -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)
index 413ccb8dde4c386d594d2bf8770eba76054ed772..2b081051fe413e975cfbe7bbee6a0f6b0ee62d14 100644 (file)
@@ -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:
index 31fdb7c9818e3f684eb8c0c39b84cb22f8541276..812774ba438db5093f07202cb59020ca7c4610e2 100644 (file)
@@ -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())