From 10ce8e3c27b7839ae79709586a59a88d28182963 Mon Sep 17 00:00:00 2001 From: Ramana Raja Date: Thu, 12 Dec 2024 16:38:29 -0500 Subject: [PATCH] mgr/rbd_support: disallow scheduling mirror snapshots ... of images that are part of a group. Creating a global, pool or namespace level mirror snapshot schedule shouldn't schedule mirror snapshots of images that are part of a group and reside in the pool or namespace. Also disallow directly scheduling mirror image snapshots on images that are part of a group. Signed-off-by: Ramana Raja --- qa/workunits/rbd/cli_generic.sh | 25 +++++++++++++++++++ .../rbd_support/mirror_snapshot_schedule.py | 6 +++++ 2 files changed, 31 insertions(+) diff --git a/qa/workunits/rbd/cli_generic.sh b/qa/workunits/rbd/cli_generic.sh index 3f210d440fc4e..cb74dd5c0958a 100755 --- a/qa/workunits/rbd/cli_generic.sh +++ b/qa/workunits/rbd/cli_generic.sh @@ -1403,6 +1403,7 @@ test_mirror_snapshot_schedule() { done rbd mirror snapshot schedule status | grep 'rbd2/ns1/test1' + # set a global level mirror image snapshot schedule rbd mirror snapshot schedule add 1h 00:15 test "$(rbd mirror snapshot schedule ls)" = 'every 1h starting at 00:15:00' rbd mirror snapshot schedule ls -R | grep 'every 1h starting at 00:15:00' @@ -1427,6 +1428,30 @@ test_mirror_snapshot_schedule() { test "$(rbd mirror snapshot schedule ls)" = 'every 1h starting at 00:15:00' test "$(rbd mirror snapshot schedule ls -p rbd2/ns1 --image test1)" = 'every 1m' + rbd create $RBD_CREATE_ARGS -s 1 rbd2/ns1/img1 + rbd create $RBD_CREATE_ARGS -s 1 rbd2/ns1/img2 + rbd group create rbd2/ns1/gp1 + rbd group image add rbd2/ns1/gp1 rbd2/ns1/img1 + # enabling snapshot on the group sets the snapshot mirror mode of the + # group's member image 'img1' + rbd mirror group enable rbd2/ns1/gp1 snapshot + rbd mirror image enable rbd2/ns1/img2 snapshot + # can't schedule mirror-snapshot on image 'img1' that is part of a group + expect_fail rbd mirror snapshot schedule add -p rbd2/ns1 --image img1 1m + # global level snapshot schedule does not create a schedule for the image + # 'img1' that is part of a group, but creates a schedule for the standalone + # image 'img2' + for i in `seq 12`; do + rbd mirror snapshot schedule status | grep 'rbd2/ns1/img1' || break + sleep 10 + done + rbd mirror snapshot schedule status | expect_fail grep 'rbd2/ns1/img1' + for i in `seq 12`; do + rbd mirror snapshot schedule status | grep 'rbd2/ns1/img2' && break + sleep 10 + done + rbd mirror snapshot schedule status | grep 'rbd2/ns1/img2' + rbd rm rbd2/ns1/test1 for i in `seq 12`; do rbd mirror snapshot schedule status | grep 'rbd2/ns1/test1' || break diff --git a/src/pybind/mgr/rbd_support/mirror_snapshot_schedule.py b/src/pybind/mgr/rbd_support/mirror_snapshot_schedule.py index e5b19f36228d3..a54845ece6b4c 100644 --- a/src/pybind/mgr/rbd_support/mirror_snapshot_schedule.py +++ b/src/pybind/mgr/rbd_support/mirror_snapshot_schedule.py @@ -24,6 +24,9 @@ def image_validator(image: rbd.Image) -> None: if mode != rbd.RBD_MIRROR_IMAGE_MODE_SNAPSHOT: raise rbd.InvalidArgument("Invalid mirror image mode") + if image.group()['pool'] != -1: + raise ValueError("image {} is part of a group".format(image.get_name())) + class ImageSpec(NamedTuple): pool_id: str @@ -451,6 +454,9 @@ class MirrorSnapshotScheduleHandler: image_name = image_names.get(image_id) if not image_name: continue + with rbd.Image(ioctx, image_name, read_only=True) as img: + if img.group()['pool'] != -1: + continue if namespace: name = "{}/{}/{}".format(pool_name, namespace, image_name) -- 2.39.5