@@ -95,18 +95,15 @@ def _wait_for_clone_to_be_in_progress(self, clone, clone_group=None, timo=120):
9595 def _check_clone_canceled (self , clone , clone_group = None ):
9696 self .__check_clone_state ("canceled" , clone , clone_group , timo = 1 )
9797
98- def _get_subvolume_snapshot_path (self , subvolume , snapshot , source_group , subvol_path , source_version ):
99- if source_version == 2 :
100- # v2
101- if subvol_path is not None :
102- (base_path , uuid_str ) = os .path .split (subvol_path )
103- else :
104- (base_path , uuid_str ) = os .path .split (self ._get_subvolume_path (self .volname , subvolume , group_name = source_group ))
105- return os .path .join (base_path , ".snap" , snapshot , uuid_str )
98+ def _get_subvolume_snapshot_path (self , subvol_name , snap_name , group_name ):
99+ cmd = (f'fs subvolume snapshot getpath { self .volname } { subvol_name } '
100+ f'{ snap_name } ' )
101+ if group_name :
102+ cmd += f' { group_name } '
106103
107- # v1
108- base_path = self . _get_subvolume_path ( self . volname , subvolume , group_name = source_group )
109- return os .path .join (base_path , ".snap" , snapshot )
104+ cephfs_snap_path = self . get_ceph_cmd_stdout ( cmd ). strip ()
105+ # remove leading '/' from cephfs_snap_path
106+ return os .path .join (self . mount_a . hostfs_mntpt , cephfs_snap_path [ 1 :] )
110107
111108 def _verify_clone_attrs (self , source_path , clone_path ):
112109 path1 = source_path
@@ -168,7 +165,7 @@ def _verify_clone(self, subvolume, snapshot, clone,
168165 subvol_path = None , source_version = 2 , timo = 120 ):
169166 # pass in subvol_path (subvolume path when snapshot was taken) when subvolume is removed
170167 # but snapshots are retained for clone verification
171- path1 = self ._get_subvolume_snapshot_path (subvolume , snapshot , source_group , subvol_path , source_version )
168+ path1 = self ._get_subvolume_snapshot_path (subvolume , snapshot , source_group )
172169 path2 = self ._get_subvolume_path (self .volname , clone , group_name = clone_group )
173170
174171 check = 0
@@ -5214,123 +5211,6 @@ def test_subvolume_snapshot_create_idempotence(self):
52145211 # verify trash dir is clean
52155212 self ._wait_for_trash_empty ()
52165213
5217- def get_subvol_uuid (self , subvol_name , group_name = None ):
5218- '''
5219- Return the UUID directory component obtained from the path of
5220- subvolume.
5221- '''
5222- if group_name :
5223- cmd = (f'fs subvolume getpath { self .volname } { subvol_name } '
5224- f'{ group_name } ' )
5225- else :
5226- cmd = f'fs subvolume getpath { self .volname } { subvol_name } '
5227-
5228- subvol_path = self .get_ceph_cmd_stdout (cmd ).strip ()
5229-
5230- subvol_uuid = os .path .basename (subvol_path )
5231- return subvol_uuid
5232-
5233- def test_snapshot_getpath (self ):
5234- '''
5235- Test that "ceph fs subvolume snapshot getpath" command returns path to
5236- the specified snapshot in the specified subvolume.
5237- '''
5238- subvol_name = self ._gen_subvol_name ()
5239- snap_name = self ._gen_subvol_snap_name ()
5240-
5241- self .run_ceph_cmd (f'fs subvolume create { self .volname } { subvol_name } ' )
5242- sv_uuid = self .get_subvol_uuid (subvol_name )
5243- self .run_ceph_cmd (f'fs subvolume snapshot create { self .volname } '
5244- f'{ subvol_name } { snap_name } ' )
5245-
5246- snap_path = self .get_ceph_cmd_stdout (f'fs subvolume snapshot getpath '
5247- f'{ self .volname } { subvol_name } '
5248- f'{ snap_name } ' ).strip ()
5249- # expected snapshot path
5250- exp_snap_path = os .path .join ('/volumes' , '_nogroup' , subvol_name ,
5251- '.snap' , snap_name , sv_uuid )
5252- self .assertEqual (snap_path , exp_snap_path )
5253-
5254- def test_snapshot_getpath_in_group (self ):
5255- '''
5256- Test that "ceph fs subvolume snapshot getpath" command returns path to
5257- the specified snapshot in the specified subvolume in the specified
5258- group.
5259- '''
5260- subvol_name = self ._gen_subvol_name ()
5261- group_name = self ._gen_subvol_grp_name ()
5262- snap_name = self ._gen_subvol_snap_name ()
5263-
5264- self .run_ceph_cmd (f'fs subvolumegroup create { self .volname } { group_name } ' )
5265- self .run_ceph_cmd (f'fs subvolume create { self .volname } { subvol_name } '
5266- f'{ group_name } ' )
5267- sv_uuid = self .get_subvol_uuid (subvol_name , group_name )
5268- self .run_ceph_cmd (f'fs subvolume snapshot create { self .volname } '
5269- f'{ subvol_name } { snap_name } { group_name } ' )
5270-
5271- snap_path = self .get_ceph_cmd_stdout (f'fs subvolume snapshot getpath '
5272- f'{ self .volname } { subvol_name } '
5273- f'{ snap_name } { group_name } ' )\
5274- .strip ()
5275- # expected snapshot path
5276- exp_snap_path = os .path .join ('/volumes' , group_name , subvol_name ,
5277- '.snap' , snap_name , sv_uuid )
5278- self .assertEqual (snap_path , exp_snap_path )
5279-
5280- def test_snapshot_getpath_on_retained_subvol (self ):
5281- '''
5282- Test that "ceph fs subvolume snapshot getpath" command returns path to
5283- the specified snapshot in the specified subvolume that was deleted but
5284- snapshots on which is retained.
5285- '''
5286- subvol_name = self ._gen_subvol_name ()
5287- snap_name = self ._gen_subvol_snap_name ()
5288-
5289- self .run_ceph_cmd (f'fs subvolume create { self .volname } { subvol_name } ' )
5290- sv_uuid = self .get_subvol_uuid (subvol_name )
5291- self .run_ceph_cmd (f'fs subvolume snapshot create { self .volname } '
5292- f'{ subvol_name } { snap_name } ' )
5293- self .run_ceph_cmd (f'fs subvolume rm { self .volname } { subvol_name } '
5294- '--retain-snapshots' )
5295-
5296- snap_path = self .get_ceph_cmd_stdout (f'fs subvolume snapshot getpath '
5297- f'{ self .volname } { subvol_name } '
5298- f'{ snap_name } ' ).strip ()
5299-
5300- # expected snapshot path
5301- exp_snap_path = os .path .join ('/volumes' , '_nogroup' , subvol_name ,
5302- '.snap' , snap_name , sv_uuid )
5303- self .assertEqual (snap_path , exp_snap_path )
5304-
5305- def test_snapshot_getpath_on_retained_subvol_in_group (self ):
5306- '''
5307- Test that "ceph fs subvolume snapshot getpath" command returns path to
5308- the specified snapshot in the specified subvolume that was deleted but
5309- snapshots on which is retained. And the deleted subvolume is located on
5310- a non-default group.
5311- '''
5312- subvol_name = self ._gen_subvol_name ()
5313- group_name = self ._gen_subvol_grp_name ()
5314- snap_name = self ._gen_subvol_snap_name ()
5315-
5316- self .run_ceph_cmd (f'fs subvolumegroup create { self .volname } { group_name } ' )
5317- self .run_ceph_cmd (f'fs subvolume create { self .volname } { subvol_name } '
5318- f'{ group_name } ' )
5319- sv_uuid = self .get_subvol_uuid (subvol_name , group_name )
5320- self .run_ceph_cmd (f'fs subvolume snapshot create { self .volname } '
5321- f'{ subvol_name } { snap_name } { group_name } ' )
5322- self .run_ceph_cmd (f'fs subvolume rm { self .volname } { subvol_name } '
5323- f'{ group_name } --retain-snapshots' )
5324-
5325- snap_path = self .get_ceph_cmd_stdout (f'fs subvolume snapshot getpath '
5326- f'{ self .volname } { subvol_name } '
5327- f'{ snap_name } { group_name } ' )\
5328- .strip ()
5329- # expected snapshot path
5330- exp_snap_path = os .path .join ('/volumes' , group_name , subvol_name ,
5331- '.snap' , snap_name , sv_uuid )
5332- self .assertEqual (snap_path , exp_snap_path )
5333-
53345214 def test_subvolume_snapshot_info (self ):
53355215
53365216 """
@@ -6603,6 +6483,224 @@ def test_clean_stale_subvolume_snapshot_metadata(self):
66036483 self .mount_a .run_shell (['sudo' , 'rm' , '-f' , tmp_meta_path ], omit_sudo = False )
66046484
66056485
6486+ class TestSubvolumeSnapshotGetpath (TestVolumesHelper ):
6487+
6488+ def get_subvol_uuid (self , subvol_name , group_name = None ):
6489+ '''
6490+ Return the UUID directory component obtained from the path of
6491+ subvolume.
6492+ '''
6493+ if group_name :
6494+ cmd = (f'fs subvolume getpath { self .volname } { subvol_name } '
6495+ f'{ group_name } ' )
6496+ else :
6497+ cmd = f'fs subvolume getpath { self .volname } { subvol_name } '
6498+
6499+ subvol_path = self .get_ceph_cmd_stdout (cmd ).strip ()
6500+
6501+ subvol_uuid = os .path .basename (subvol_path )
6502+ return subvol_uuid
6503+
6504+ def construct_snap_path_for_v2 (self , subvol_name , snap_name , uuid ,
6505+ group_name = '_nogroup' ):
6506+ return os .path .join ('/volumes' , group_name , subvol_name , '.snap' ,
6507+ snap_name , uuid )
6508+
6509+ def construct_snap_path_for_v1 (self , subvol_name , snap_name , uuid ,
6510+ group_name = '_nogroup' ):
6511+ return os .path .join ('/volumes' , group_name , subvol_name , uuid ,
6512+ '.snap' , snap_name )
6513+
6514+ def construct_snap_path_for_legacy (self , subvol_name , snap_name ,
6515+ group_name = '_nogroup' ):
6516+ return os .path .join ('/volumes' , group_name , subvol_name , '.snap' ,
6517+ snap_name )
6518+
6519+ def test_snapshot_getpath (self ):
6520+ '''
6521+ Test that "ceph fs subvolume snapshot getpath" command returns path to
6522+ the specified snapshot in the specified subvolume.
6523+ '''
6524+ subvol_name = self ._gen_subvol_name ()
6525+ snap_name = self ._gen_subvol_snap_name ()
6526+
6527+ self .run_ceph_cmd (f'fs subvolume create { self .volname } { subvol_name } ' )
6528+ sv_uuid = self .get_subvol_uuid (subvol_name )
6529+ self .run_ceph_cmd (f'fs subvolume snapshot create { self .volname } '
6530+ f'{ subvol_name } { snap_name } ' )
6531+
6532+ snap_path = self .get_ceph_cmd_stdout (f'fs subvolume snapshot getpath '
6533+ f'{ self .volname } { subvol_name } '
6534+ f'{ snap_name } ' ).strip ()
6535+ exp_snap_path = self .construct_snap_path_for_v2 (subvol_name , snap_name ,
6536+ sv_uuid )
6537+ self .assertEqual (snap_path , exp_snap_path )
6538+
6539+ def test_snapshot_getpath_in_group (self ):
6540+ '''
6541+ Test that "ceph fs subvolume snapshot getpath" command returns path to
6542+ the specified snapshot in the specified subvolume in the specified
6543+ group.
6544+ '''
6545+ subvol_name = self ._gen_subvol_name ()
6546+ group_name = self ._gen_subvol_grp_name ()
6547+ snap_name = self ._gen_subvol_snap_name ()
6548+
6549+ self .run_ceph_cmd (f'fs subvolumegroup create { self .volname } { group_name } ' )
6550+ self .run_ceph_cmd (f'fs subvolume create { self .volname } { subvol_name } '
6551+ f'{ group_name } ' )
6552+ sv_uuid = self .get_subvol_uuid (subvol_name , group_name )
6553+ self .run_ceph_cmd (f'fs subvolume snapshot create { self .volname } '
6554+ f'{ subvol_name } { snap_name } { group_name } ' )
6555+
6556+ snap_path = self .get_ceph_cmd_stdout (f'fs subvolume snapshot getpath '
6557+ f'{ self .volname } { subvol_name } '
6558+ f'{ snap_name } { group_name } ' )\
6559+ .strip ()
6560+ exp_snap_path = self .construct_snap_path_for_v2 (subvol_name , snap_name ,
6561+ sv_uuid , group_name )
6562+ self .assertEqual (snap_path , exp_snap_path )
6563+
6564+ def test_snapshot_getpath_on_retained_subvol (self ):
6565+ '''
6566+ Test that "ceph fs subvolume snapshot getpath" command returns path to
6567+ the specified snapshot in the specified subvolume that was deleted but
6568+ snapshots on which is retained.
6569+ '''
6570+ subvol_name = self ._gen_subvol_name ()
6571+ snap_name = self ._gen_subvol_snap_name ()
6572+
6573+ self .run_ceph_cmd (f'fs subvolume create { self .volname } { subvol_name } ' )
6574+ sv_uuid = self .get_subvol_uuid (subvol_name )
6575+ self .run_ceph_cmd (f'fs subvolume snapshot create { self .volname } '
6576+ f'{ subvol_name } { snap_name } ' )
6577+ self .run_ceph_cmd (f'fs subvolume rm { self .volname } { subvol_name } '
6578+ '--retain-snapshots' )
6579+
6580+ snap_path = self .get_ceph_cmd_stdout (f'fs subvolume snapshot getpath '
6581+ f'{ self .volname } { subvol_name } '
6582+ f'{ snap_name } ' ).strip ()
6583+ exp_snap_path = self .construct_snap_path_for_v2 (subvol_name , snap_name ,
6584+ sv_uuid )
6585+ self .assertEqual (snap_path , exp_snap_path )
6586+
6587+ def test_snapshot_getpath_on_retained_subvol_in_group (self ):
6588+ '''
6589+ Test that "ceph fs subvolume snapshot getpath" command returns path to
6590+ the specified snapshot in the specified subvolume that was deleted but
6591+ snapshots on which is retained. And the deleted subvolume is located on
6592+ a non-default group.
6593+ '''
6594+ subvol_name = self ._gen_subvol_name ()
6595+ group_name = self ._gen_subvol_grp_name ()
6596+ snap_name = self ._gen_subvol_snap_name ()
6597+
6598+ self .run_ceph_cmd (f'fs subvolumegroup create { self .volname } { group_name } ' )
6599+ self .run_ceph_cmd (f'fs subvolume create { self .volname } { subvol_name } '
6600+ f'{ group_name } ' )
6601+ sv_uuid = self .get_subvol_uuid (subvol_name , group_name )
6602+ self .run_ceph_cmd (f'fs subvolume snapshot create { self .volname } '
6603+ f'{ subvol_name } { snap_name } { group_name } ' )
6604+ self .run_ceph_cmd (f'fs subvolume rm { self .volname } { subvol_name } '
6605+ f'{ group_name } --retain-snapshots' )
6606+
6607+ snap_path = self .get_ceph_cmd_stdout (f'fs subvolume snapshot getpath '
6608+ f'{ self .volname } { subvol_name } '
6609+ f'{ snap_name } { group_name } ' )\
6610+ .strip ()
6611+ exp_snap_path = self .construct_snap_path_for_v2 (subvol_name , snap_name ,
6612+ sv_uuid , group_name )
6613+ self .assertEqual (snap_path , exp_snap_path )
6614+
6615+ def test_snapshot_getpath_for_v1 (self ):
6616+ subvol_name = self ._gen_subvol_name ()
6617+ snap_name = self ._gen_subvol_snap_name ()
6618+
6619+ self ._create_v1_subvolume (subvol_name )
6620+ sv_uuid = self .get_subvol_uuid (subvol_name )
6621+ self .run_ceph_cmd (f'fs subvolume snapshot create { self .volname } '
6622+ f'{ subvol_name } { snap_name } ' )
6623+
6624+ snap_path = self .get_ceph_cmd_stdout (
6625+ f'fs subvolume snapshot getpath { self .volname } { subvol_name } '
6626+ f'{ snap_name } ' ).strip ()
6627+ exp_snap_path = self .construct_snap_path_for_v1 (subvol_name , snap_name ,
6628+ sv_uuid )
6629+ self .assertEqual (snap_path , exp_snap_path )
6630+
6631+ def test_snapshot_getpath_in_group_for_v1 (self ):
6632+ subvol_name = self ._gen_subvol_name ()
6633+ group_name = self ._gen_subvol_grp_name ()
6634+ snap_name = self ._gen_subvol_snap_name ()
6635+
6636+ self .run_ceph_cmd (f'fs subvolumegroup create { self .volname } '
6637+ f'{ group_name } ' )
6638+ self ._create_v1_subvolume (subvol_name , group_name )
6639+ sv_uuid = self .get_subvol_uuid (subvol_name , group_name )
6640+ self .run_ceph_cmd (f'fs subvolume snapshot create { self .volname } '
6641+ f'{ subvol_name } { snap_name } { group_name } ' )
6642+
6643+ snap_path = self .get_ceph_cmd_stdout (
6644+ f'fs subvolume snapshot getpath { self .volname } { subvol_name } '
6645+ f'{ snap_name } { group_name } ' ).strip ()
6646+ exp_snap_path = self .construct_snap_path_for_v1 (subvol_name , snap_name ,
6647+ sv_uuid , group_name )
6648+ self .assertEqual (snap_path , exp_snap_path )
6649+
6650+ def test_snapshot_getpath_for_upgraded_legacy (self ):
6651+ subvol_name = self ._gen_subvol_name ()
6652+ snap_name = self ._gen_subvol_snap_name ()
6653+
6654+ sv_path = os .path .join ('.' , 'volumes' , '_nogroup' , subvol_name )
6655+ self .mount_a .run_shell (f'sudo mkdir -p { sv_path } ' , omit_sudo = False )
6656+
6657+ sv_getpath = self .get_ceph_cmd_stdout (
6658+ f'fs subvolume getpath { self .volname } { subvol_name } ' ).strip ()
6659+ self .assertNotEqual (sv_getpath , None )
6660+ # remove '/' at the beginning
6661+ self .assertEqual (sv_path [1 :], sv_getpath )
6662+ self ._assert_meta_location_and_version (self .volname , subvol_name ,
6663+ version = 1 , legacy = True )
6664+
6665+ self .run_ceph_cmd (f'fs subvolume snapshot create { self .volname } '
6666+ f'{ subvol_name } { snap_name } ' )
6667+
6668+ snap_path = self .get_ceph_cmd_stdout (
6669+ f'fs subvolume snapshot getpath { self .volname } { subvol_name } '
6670+ f'{ snap_name } ' ).strip ()
6671+ exp_snap_path = self .construct_snap_path_for_legacy (subvol_name ,
6672+ snap_name )
6673+ self .assertEqual (snap_path , exp_snap_path )
6674+
6675+ def test_snapshot_getpath_in_group_for_upgraded_legacy (self ):
6676+ subvol_name = self ._gen_subvol_name ()
6677+ group_name = self ._gen_subvol_grp_name ()
6678+ snap_name = self ._gen_subvol_snap_name ()
6679+
6680+ sv_path = os .path .join ('.' , 'volumes' , group_name , subvol_name )
6681+ self .mount_a .run_shell (f'sudo mkdir -p { sv_path } ' , omit_sudo = False )
6682+
6683+ sv_getpath = self .get_ceph_cmd_stdout (
6684+ f'fs subvolume getpath { self .volname } { subvol_name } '
6685+ f'{ group_name } ' ).strip ()
6686+ self .assertNotEqual (sv_getpath , None )
6687+ # remove '/' at the beginning
6688+ self .assertEqual (sv_path [1 :], sv_getpath )
6689+ self ._assert_meta_location_and_version (self .volname , subvol_name ,
6690+ subvol_group = group_name ,
6691+ version = 1 , legacy = True )
6692+
6693+ self .run_ceph_cmd (f'fs subvolume snapshot create { self .volname } '
6694+ f'{ subvol_name } { snap_name } { group_name } ' )
6695+
6696+ snap_path = self .get_ceph_cmd_stdout (
6697+ f'fs subvolume snapshot getpath { self .volname } { subvol_name } '
6698+ f'{ snap_name } { group_name } ' ).strip ()
6699+ exp_snap_path = self .construct_snap_path_for_legacy (subvol_name , snap_name ,
6700+ group_name )
6701+ self .assertEqual (snap_path , exp_snap_path )
6702+
6703+
66066704class TestSubvolumeSnapshotClones (TestVolumesHelper ):
66076705 """ Tests for FS subvolume snapshot clone operations."""
66086706 def test_clone_subvolume_info (self ):
0 commit comments