]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mgr/vol: fix test_subvolume_retain_snapshot_recreate
authorRishabh Dave <ridave@redhat.com>
Sat, 12 Apr 2025 16:45:29 +0000 (22:15 +0530)
committerRishabh Dave <ridave@redhat.com>
Wed, 3 Dec 2025 07:51:56 +0000 (13:21 +0530)
2 issues had to be in fixed this test -

1. list_snapshots() needs to be re-defined in v3 since snapshots from
   previous incarnations can also have retained snapshots and those
   too needs to be listed.

2. snapshot_data_path() needs to be re-defined to cover the case where
   the snapshot doesn't belong to currrent incarnation but to one of the
   previous incarnation.

These issues were triggered by the part of the test that re-creates a
subvolume from its own snapshot that was retained during previous
deletion. Thus, snapshot doesn't belong to current incarnation and
therefore caused these methods to fail.

Signed-off-by: Rishabh Dave <ridave@redhat.com>
src/pybind/mgr/volumes/fs/operations/versions/subvolume_v3.py

index 0152eedac250900c7418272d8be10e8889316a1c..6f564d53d25783048e9ad14d3869c88978e519f7 100644 (file)
@@ -310,7 +310,16 @@ class SubvolumeV3(SubvolumeV2):
 
 
     def snapshot_data_path(self, snap_name):
-        snap_path = join(self.snapshot_path(snap_name), b'mnt')
+        uuid = self.get_incar_uuid_for_snap(snap_name)
+        if uuid == None:
+            raise VolumeException(-errno.ENOENT,
+                                  f'snapshot \'{snap_name}\' does not exist')
+        elif uuid == self.uuid:
+            snap_path = join(self.snapshot_path(snap_name), b'mnt')
+        else:
+            snap_path = join(self.roots_dir, uuid,
+                             self.vol_spec.snapshot_dir_prefix.encode('utf-8'),
+                             snap_name.encode('utf-8'), b'mnt')
 
         # v2 raises exception if the snapshot path do not exist so do the same
         # to prevent any bugs due to difference in behaviour.
@@ -330,3 +339,19 @@ class SubvolumeV3(SubvolumeV2):
             raise VolumeException(-e.args[0], e.args[1])
 
         return snap_path
+
+    def list_snapshots(self):
+        '''
+        Return list of name of all snapshots from all the incarnations.
+        '''
+        all_snap_names = []
+
+        # list of all incarnations/UUID dirs of this subvolume.
+        incars = listdir(self.fs, self.roots_dir)
+
+        for incar_uuid in incars:
+            # construct path to ".snap" directory for given UUID.
+            snap_dir = join(self.roots_dir, incar_uuid,
+                            self.vol_spec.snapshot_dir_prefix.encode('utf-8'))
+            all_snap_names.extend(listdir(self.fs, snap_dir))
+        return all_snap_names