def test_copy_new_dir_dest_subvol_down(self): """ Case 4: - Copy dir ---> Bring down dht sub-volume where destination directory hashes to down sub-volume - Create directory from mount point. - Copy dir and make sure destination dir does not exist """ # pylint: disable=protected-access m_point = self.mounts[0].mountpoint # Get subvol list subvols = (get_subvols(self.mnode, self.volname))['volume_subvols'] self.assertIsNotNone(subvols, "Failed to get subvols") # Find out the destination dir name such that it hashes to # different subvol newdir = find_new_hashed(subvols, "/", "src_dir") dest_dir = str(newdir.newname) dest_count = newdir.subvol_count # Bring down the hashed-subvol for dest dir ret = bring_bricks_offline(self.volname, subvols[dest_count]) self.assertTrue( ret, ('Error in bringing down subvolume %s', subvols[dest_count])) g.log.info('DHT subvol %s is offline', subvols[dest_count]) # Create source dir ret = mkdir(self.mounts[0].client_system, "{}/src_dir".format(m_point)) self.assertTrue(ret, "mkdir of src_dir failed") g.log.info("Directory src_dir created successfully") # Copy src_dir to dest_dir (should fail as hash subvol for dest # dir is down) self._copy_when_dest_hash_down(m_point, dest_dir)
def test_dht_file_rename_dest_exists_src_and_dest_hash_diff(self): """ case 6 : - Destination file should exist - Source file is stored on hashed subvolume(s1) it self - Destination file should be hashed to some other subvolume(s2) - Destination file is stored on hashed subvolume mv <source_file> <destination_file> - Destination file is removed. - Source file should be renamed as destination file - Destination hashed file should be created on its hashed subvolume(s2) """ # pylint: disable=protected-access # pylint: disable=unsubscriptable-object # Create source file and Get hashed subvol (s1) _, src_count, source_file = ( self._create_file_and_get_hashed_subvol("test_source_file")) # Find a new file name for destination file, which hashes # to another subvol (s2) new_hashed = find_new_hashed(self.subvols, "/", "test_source_file") self.assertIsNotNone(new_hashed, "could'nt find new hashed for destination file") # create destination_file and get its hashed subvol (s2) dest_hashed_subvol, dest_count, dest_file = ( self._create_file_and_get_hashed_subvol(str(new_hashed.newname))) # Verify the subvols are not same for source and destination files self.assertNotEqual(src_count, dest_count, "The subvols for src and dest are same.") # Rename the source file to the destination file ret = move_file(self.mounts[0].client_system, source_file, dest_file) self.assertTrue( ret, "Failed to move files {} and {}".format(source_file, dest_file)) # Verify destination file is removed ret = self._verify_file_exists(dest_hashed_subvol, str(new_hashed.newname)) self.assertTrue(ret, ("Destination file : {} is not removed in subvol" " : {}".format(str(new_hashed.newname), dest_hashed_subvol._fqpath))) g.log.info("The destination file is removed as expected") # Verify the Destination link is found in new subvol (s2) ret = self._verify_link_file_exists(dest_hashed_subvol, str(new_hashed.newname)) self.assertTrue( ret, ("The New hashed volume {} doesn't have the " "expected linkto file {}".format(str( new_hashed.newname), dest_hashed_subvol._fqpath))) g.log.info("New hashed volume has the expected linkto file")
def test_copy_new_dir_dest_subvol_up(self): """ Case 3: - Copy dir ---> Bring down dht sub-volume where destination directory should not hash to down sub-volume - Create files and directories from mount point. - copy dir and make sure destination dir does not exist """ # pylint: disable=protected-access # pylint: disable=too-many-statements m_point = self.mounts[0].mountpoint # Get subvols subvols = (get_subvols(self.mnode, self.volname))['volume_subvols'] self.assertIsNotNone(subvols, "Failed to get subvols") # Find out hashed brick/subvol for src dir src_subvol, src_count = find_hashed_subvol(subvols, "/", "src_dir") self.assertIsNotNone(src_subvol, "Could not find srchashed") g.log.info("Hashed subvol for src_dir is %s", src_subvol._path) # Find out the destination dir name such that it hashes to # different subvol newdir = find_new_hashed(subvols, "/", "src_dir") dest_dir = str(newdir.newname) dest_count = newdir.subvol_count # Remove the hashed subvol for dest and src dir from the # subvol list for item in (subvols[src_count], subvols[dest_count]): subvols.remove(item) # Bring down a dht subvol ret = bring_bricks_offline(self.volname, subvols[0]) self.assertTrue(ret, ('Error in bringing down subvolume %s', subvols[0])) g.log.info('DHT subvol %s is offline', subvols[0]) # Create source dir and create files inside it self._create_src(m_point) # Create files on source dir and # perform copy of src_dir to dest_dir self._copy_files_check_contents(m_point, dest_dir)
def test_file_rename_when_source_and_dest_hash_diff_subvol(self): """ case 1 : - Destination file does not exist - Source file is stored on hashed subvolume(s1) it self - Destination file should be hashed to some other subvolume(s2) mv <source_file> <destination_file> - Source file should be renamed to to Destination file. - Destination link file should be created on its hashed subvolume(s2) """ # pylint: disable=protected-access # pylint: disable=unsubscriptable-object # Create soruce file and Get hashed subvol (s2) _, count, source_file = ( self._create_file_and_get_hashed_subvol("test_source_file")) # Rename the file such that the new name hashes to a new subvol (S1) new_hashed = find_new_hashed(self.subvols, "/", "test_source_file") self.assertIsNotNone( new_hashed, ("could'nt find new hashed for {}".format(source_file))) src_link_subvol = new_hashed.hashedbrickobject # Verify the subvols are not same for source and destination files self.assertNotEqual(count, new_hashed.subvol_count, "The subvols for src and dest are same.") # Rename the source file to the destination file dest_file = "{}/{}".format(self.mount_point, str(new_hashed.newname)) ret = move_file(self.clients[0], source_file, dest_file) self.assertTrue( ret, ("Failed to move files {} and {}".format(source_file, dest_file))) # Verify the link file is found in new subvol ret = self._verify_link_file_exists(src_link_subvol, str(new_hashed.newname)) self.assertTrue( ret, ("The hashed subvol {} doesn't have the " "expected linkto file: {}".format(src_link_subvol._fqpath, str(new_hashed.newname)))) g.log.info("New hashed volume has the expected linkto file")
def test_custom_xattr_with_subvol_down_dir_exists(self): """ Description: Steps: 1) Create directories from mount point. 2) Bring one or more(not all) dht sub-volume(s) down by killing processes on that server 3) Create a custom xattr for dir hashed to down sub-volume and also for another dir not hashing to down sub-volumes # setfattr -n user.foo -v bar2 <dir> 4) Verify that custom xattr for directory is displayed on mount point and bricks for both directories # getfattr -n user.foo <dir> # getfattr -n user.foo <brick_path>/<dir> 5) Modify custom xattr value and verify that custom xattr for directory is displayed on mount point and all up bricks # setfattr -n user.foo -v ABC <dir> 6) Verify that custom xattr is not displayed once you remove it on mount point and all up bricks 7) Verify that mount point shows pathinfo xattr for dir hashed to down sub-volume and also for dir not hashed to down sub-volumes # getfattr -n trusted.glusterfs.pathinfo <dir> 8) Again create a custom xattr for dir not hashing to down sub-volumes # setfattr -n user.foo -v star1 <dir> 9) Bring up the sub-volumes 10) Execute lookup on parent directory of both <dir> from mount point 11) Verify Custom extended attributes for dir1 on all bricks """ # pylint: disable=protected-access # Create dir1 on client0 self._create_dir(dir_name="dir1") # Get subvol list subvols = (get_subvols(self.mnode, self.volname))['volume_subvols'] self.assertIsNotNone(subvols, "Failed to get subvols") # Finding a dir name such that it hashes to a different subvol newhash = find_new_hashed(subvols, "/", "dir1") new_name = str(newhash.newname) new_subvol_count = newhash.subvol_count # Create a dir with the new name self._create_dir(dir_name=new_name) # Kill the brick/subvol to which the new dir hashes ret = bring_bricks_offline( self.volname, subvols[new_subvol_count]) self.assertTrue(ret, ('Error in bringing down subvolume %s', subvols[new_subvol_count])) g.log.info('DHT subvol %s is offline', subvols[new_subvol_count]) # Set the xattr on dir hashing to down subvol ret = set_fattr(self.client, '{}/{}'.format(self.m_point, new_name), 'user.foo', 'bar2') self.assertFalse(ret, "Unexpected: custom xattr set successfully" " for dir hashing to down subvol") g.log.info("Expected: Failed to set xattr on dir:%s" " which hashes to down subvol due to error: Transport" " endpoint not connected", new_name) # Check if the trusted.glusterfs.pathinfo is displayed # for dir hashing to down subvol on mointpoint ret = get_fattr(self.client, '{}/{}'.format( self.m_point, new_name), 'trusted.glusterfs.pathinfo') self.assertIsNotNone(ret, "Failed to get the xattr" " on:{}".format(self.client)) g.log.info("The xattr trusted.glusterfs.pathinfo" " is displayed on mointpoint for %s", new_name) # Set the xattr on dir hashing to down subvol ret = set_fattr(self.client, '{}/{}'.format(self.m_point, new_name), 'user.foo', 'star1') self.assertFalse(ret, "Unexpected: custom xattr set successfully" " for dir hashing to down subvol") g.log.info("Expected: Tansport endpoint not connected") # Calling the local function self._create_xattr_check_self_heal()
def test_file_rename_dest_exist_and_hash_to_srclink_subvol(self): """ Case 10: - Destination file should exist - Source file is hashed sub volume(s1) and cached on another subvolume(s2) - Destination file should be hashed to same subvolume(s1) where source file is hashed. mv <source_file> <destination_file> - Destination file is removed. - Source file(cached) should be renamed to destination file - Source file(hashed) should be removed. - Destination hahshed file should be created on its hashed subvolume(s1) """ # pylint: disable=protected-access # pylint: disable=unsubscriptable-object # Get hashed subvol s2) _, src_count, source_file = ( self._create_file_and_get_hashed_subvol("test_source_file")) # Rename the file to create link in another subvol - (s1) new_hashed = find_new_hashed(self.subvols, "/", "test_source_file") self.assertIsNotNone(new_hashed, ("could not find new hashed subvol " "for {}".format(source_file))) self.assertNotEqual(src_count, new_hashed.subvol_count, "New file should hash to different sub-volume") # Rename the source file to the new file name dest_file = "{}/{}".format(self.mount_point, str(new_hashed.newname)) ret = move_file(self.mounts[0].client_system, source_file, dest_file) self.assertTrue( ret, ("Failed to move file {} and {}".format(source_file, dest_file))) # Verify the Source link file is stored on hashed sub volume(s1) src_link_subvol = new_hashed.hashedbrickobject ret = self._verify_link_file_exists(src_link_subvol, str(new_hashed.newname)) self.assertTrue( ret, ("The New hashed volume {} doesn't have the " "expected linkto file {}".format(src_link_subvol._fqpath, str(new_hashed.newname)))) # Get a file name for dest to hash to the subvol s1 new_hashed2 = find_specific_hashed(self.subvols, "/", src_link_subvol, new_hashed.newname) self.assertIsNotNone(new_hashed2, ("Couldn't find a name hashed to the" " given subvol {}".format(src_link_subvol))) # Create destination file in the subvol (s2) dest_hashed_subvol, dest_count, dest_file = ( self._create_file_and_get_hashed_subvol(str(new_hashed2.newname))) # Verify the subvol is same as S1 self.assertEqual(new_hashed.subvol_count, dest_count, "The subvols for src and dest are not same.") # Move the source file to the new file name source_file = "{}/{}".format(self.mount_point, str(new_hashed.newname)) dest_file = "{}/{}".format(self.mount_point, str(new_hashed2.newname)) ret = move_file(self.mounts[0].client_system, source_file, dest_file) self.assertTrue(ret, "Failed to move file") # Verify destination file is removed ret = self._verify_file_exists(dest_hashed_subvol, str(new_hashed2.newname)) self.assertTrue(ret, ("Destination file : {} is not removed in subvol" " : {}".format(str(new_hashed.newname), dest_hashed_subvol._fqpath))) g.log.info("The destination file is removed as expected") # Check that the source link file is removed. ret = self._verify_link_file_exists(src_link_subvol, str(new_hashed.newname)) self.assertFalse( ret, ("The hashed volume {} still have the " "expected linkto file {}".format(src_link_subvol._fqpath, str(new_hashed.newname)))) g.log.info("The source link file is removed") # Check Destination link file is created on its hashed sub-volume(s1) ret = self._verify_link_file_exists(src_link_subvol, str(new_hashed2.newname)) self.assertTrue( ret, ("The New hashed volume {} doesn't have the " "expected linkto file {}".format(src_link_subvol._fqpath, str(new_hashed2.newname)))) g.log.info("Destinaion link is created in desired subvol")
def test_file_rename_dest_exist_and_not_hash_src_srclink_subvol(self): """ Case 8: - Destination file should exist - Source file is hashed sub volume(s1) and cached on another subvolume(s2) - Destination file should be hashed to some other subvolume(s3) (should not be same subvolumes mentioned in above condition) mv <source_file> <destination_file> - Destination file is removed. - Source file should be renamed as destination file - Souce hashed file should be removed - Destination hashed file should be created on its hashed subvolume(s3) """ # pylint: disable=protected-access # pylint: disable=too-many-locals # pylint: disable=unsubscriptable-object # Find a non hashed subvolume(or brick) # Create soruce file and Get hashed subvol (s2) _, count, source_file = ( self._create_file_and_get_hashed_subvol("test_source_file")) # Rename the file to create link in hashed subvol -(s1) new_hashed = find_new_hashed(self.subvols, "/", "test_source_file") self.assertIsNotNone(new_hashed, "could not find new hashed for dstfile") count2 = new_hashed.subvol_count # Rename the source file to the new file name dest_file = "{}/{}".format(self.mount_point, str(new_hashed.newname)) ret = move_file(self.mounts[0].client_system, source_file, dest_file) self.assertTrue( ret, ("Failed to move file {} and {}".format(source_file, dest_file))) # Verify the Source link file is stored on hashed sub volume(s1) src_link_subvol = new_hashed.hashedbrickobject ret = self._verify_link_file_exists(src_link_subvol, str(new_hashed.newname)) self.assertTrue( ret, ("The hashed subvol {} doesn't have the " "expected linkto file: {}".format(src_link_subvol._fqpath, str(new_hashed.newname)))) # Find a subvol (s3) other than S1 and S2 brickobject = create_brickobjectlist(self.subvols, "/") self.assertIsNotNone(brickobject, "Failed to get brick object list") br_count = -1 subvol_new = None for brickdir in brickobject: br_count += 1 if br_count not in (count, count2): subvol_new = brickdir break new_hashed2 = find_specific_hashed(self.subvols, "/", subvol_new) self.assertIsNotNone(new_hashed2, "could not find new hashed for dstfile") # Create destination file in a new subvol (s3) dest_hashed_subvol, dest_count, dest_file = ( self._create_file_and_get_hashed_subvol(str(new_hashed2.newname))) # Verify the subvol is not same as S1 or S2 self.assertNotEqual( count2, dest_count, ("The subvols for src :{} and dest : {} are same.".format( count2, dest_count))) # Verify the subvol is not same as S1 or S2 self.assertNotEqual( count, dest_count, ("The subvols for src :{} and dest : {} are same.".format( count, dest_count))) # Rename the source file to the destination file source_file = "{}/{}".format(self.mount_point, str(new_hashed.newname)) ret = move_file(self.mounts[0].client_system, source_file, dest_file) self.assertTrue( ret, ("Failed to move file {} and {}".format(source_file, dest_file))) # Verify destination file is removed ret = self._verify_file_exists(dest_hashed_subvol, str(new_hashed2.newname)) self.assertTrue(ret, ("Destination file : {} is not removed in subvol" " : {}".format(str(new_hashed.newname), dest_hashed_subvol._fqpath))) g.log.info("The destination file is removed as expected") # Check that the source link file is removed. ret = self._verify_link_file_exists(src_link_subvol, str(new_hashed.newname)) self.assertFalse( ret, ("The New hashed volume {} still have the " "expected linkto file {}".format(src_link_subvol._fqpath, str(new_hashed.newname)))) g.log.info("The source link file is removed") # Check Destination link file is created on its hashed sub-volume(s3) ret = self._verify_link_file_exists(dest_hashed_subvol, str(new_hashed2.newname)) self.assertTrue( ret, ("The New hashed volume {} doesn't have the " "expected linkto file {}".format(dest_hashed_subvol._fqpath, str(new_hashed2.newname)))) g.log.info("Destinaion link is created in desired subvol")
def test_file_rename_when_dest_neither_hash_cache_to_src_subvols(self): """ - Destination file should exist - Source file hashed on sub volume(s1) and cached on another subvolume(s2) - Destination file should be hased to some other subvolume(s3) (neither s1 nor s2) - Destination file hased on subvolume(s3) but cached on remaining subvolume(s4) mv <source_file> <destination_file> - Destination file is removed. - Source file should be renamed as destination file - Destination link file should be there on hashed subvolume and should link to new destination file - source link file should be removed """ # pylint: disable=protected-access # pylint: disable=too-many-locals # Create source file and Get hashed subvol (s2) _, src_count, source_file = ( self._create_file_and_get_hashed_subvol("test_source_file")) # Find a new file name for destination file, which hashes # to another subvol (s2) new_hashed = find_new_hashed(self.subvols, "/", "test_source_file") self.assertIsNotNone(new_hashed, "couldn't find new hashed for destination file") # Rename the source file to the new file name src_hashed = "{}/{}".format(self.mount_point, str(new_hashed.newname)) ret = move_file(self.mounts[0].client_system, source_file, src_hashed) self.assertTrue(ret, ("Failed to move file {} and {}" .format(source_file, src_hashed))) # Verify the Source link file is stored on hashed sub volume(s1) src_link_subvol = new_hashed.hashedbrickobject ret = self._verify_link_file_exists(src_link_subvol, str(new_hashed.newname)) self.assertTrue(ret, ("The hashed subvol {} doesn't have the " "expected linkto file: {}" .format(src_link_subvol._fqpath, str(new_hashed.newname)))) # Destination file cached on S4. # Find a subvol (s4) for dest file to linkto, other than S1 and S2 brickobject = create_brickobjectlist(self.subvols, "/") self.assertIsNotNone(brickobject, "Failed to get brick object list") br_count = -1 subvol_new = None for brickdir in brickobject: br_count += 1 if br_count not in (src_count, new_hashed.subvol_count): subvol_new = brickdir break dest_cached = find_specific_hashed(self.subvols, "/", subvol_new) self.assertIsNotNone(dest_cached, "could not find new hashed for dstfile") # Create a file in S3 _, _, dest_src = self._create_file_and_get_hashed_subvol( str(dest_cached.newname)) # Verify the subvol is not S2 and S1 self.assertNotEqual(dest_cached.subvol_count, new_hashed.subvol_count, ("The subvol found for destination is same as " "that of the source file hashed subvol")) self.assertNotEqual(dest_cached.subvol_count, src_count, ("The subvol found for destination is same as " "that of the source file cached subvol")) # Identify a name for dest that hashes to another subvol S3 # Find a subvol (s3) for dest file to linkto, other than S1 and S2 and # S4 brickobject = create_brickobjectlist(self.subvols, "/") self.assertIsNotNone(brickobject, "Failed to get brick object list") br_count = -1 subvol_new = None for brickdir in brickobject: br_count += 1 if br_count not in (src_count, new_hashed.subvol_count, dest_cached.subvol_count): subvol_new = brickdir break dest_hashed = find_specific_hashed(self.subvols, "/", subvol_new) # Move dest to new name dest = "{}/{}".format(self.mount_point, str(dest_hashed.newname)) ret = move_file(self.mounts[0].client_system, dest_src, dest) self.assertTrue(ret, ("Failed to move file {} and {}" .format(dest_src, dest))) # Move Source file to Dest src = "{}/{}".format(self.mount_point, str(new_hashed.newname)) ret = move_file(self.mounts[0].client_system, src, dest) self.assertTrue(ret, ("Failed to move file {} and {}" .format(src, dest))) # Verify Destination File is removed ret = self._verify_file_exists(dest_cached.hashedbrickobject, str(dest_cached.newname)) self.assertFalse(ret, "The Source file is still present in {}" .format(dest_cached.hashedbrickobject._fqpath)) # Verify Source link is removed ret = self._verify_link_file_exists(src_link_subvol, str(new_hashed.newname)) self.assertFalse(ret, "The source link file is still present in {}" .format(src_link_subvol._fqpath)) # Verify Destination Link is present and points to new dest file ret = self._verify_link_file_exists(dest_hashed.hashedbrickobject, str(dest_hashed.newname)) self.assertTrue(ret, "The Dest link file is not present in {}" .format(dest_hashed.hashedbrickobject._fqpath)) file_path = dest_hashed.hashedbrickobject._fqpath + str( dest_hashed.newname) ret = (self._verify_file_links_to_specified_destination( dest_hashed.hashedbrickobject._host, file_path, str(dest_hashed.newname))) self.assertTrue(ret, "The dest link file not pointing towards " "the desired file") g.log.info("The Destination link file is pointing to new file" " as expected")
def _find_hash_for_src_file(self): """Find a new hashsubvol which is different from hash of srcfile""" src_hash_subvol = find_new_hashed(self.subvols, "/", "srcfile") new_src_name = str(src_hash_subvol.newname) src_hash_subvol_count = src_hash_subvol.subvol_count return new_src_name, src_hash_subvol_count
def test_file_rename_when_src_file_and_dest_file_hash_same_subvol(self): """ Case 4: - Destination file does not exist - Source link file is stored on hashed sub volume(s1) and Source file is stored on another subvolume(s2) - Destination file should be hashed to same subvolume(s2) mv <source_file> <destination_file> - Source file should be ranamed to destination file - source link file should be removed. """ # pylint: disable=protected-access # pylint: disable=unsubscriptable-object # Get hashed subvol (S2) source_hashed_subvol, count, source_file = ( self._create_file_and_get_hashed_subvol("test_source_file")) # Rename the file to create link in hashed subvol -(s1) new_hashed = find_new_hashed(self.subvols, "/", "test_source_file") self.assertIsNotNone( new_hashed, ("could not find new hashed for {}".format(source_file))) # Rename the source file to the new file name dest_file = "{}/{}".format(self.mount_point, str(new_hashed.newname)) ret = move_file(self.clients[0], source_file, dest_file) self.assertTrue( ret, ("Failed to move file {} and {}".format(source_file, dest_file))) # Verify the Source link file is stored on hashed sub volume(s1) src_link_subvol = new_hashed.hashedbrickobject ret = self._verify_link_file_exists(src_link_subvol, str(new_hashed.newname)) self.assertTrue( ret, ("The New hashed volume {} doesn't have the " "expected linkto file {}".format(src_link_subvol._fqpath, str(new_hashed.newname)))) # Get a file name to hash to the subvol s2 new_hashed2 = find_specific_hashed(self.subvols, "/", source_hashed_subvol) self.assertIsNotNone( new_hashed2, "Could not find a name hashed" "to the given subvol") _, rename_count = (find_hashed_subvol(self.subvols, "/", str(new_hashed2.newname))) self.assertEqual(count, rename_count, "The subvols for src and dest are not same.") # Move the source file to the new file name source_file = "{}/{}".format(self.mount_point, str(new_hashed.newname)) dest_file = "{}/{}".format(self.mount_point, str(new_hashed2.newname)) ret = move_file(self.clients[0], source_file, dest_file) self.assertTrue( ret, ("Failed to move file {} and {}".format(source_file, dest_file))) # check that the source link file is removed. ret = self._verify_link_file_exists(src_link_subvol, str(new_hashed.newname)) self.assertFalse( ret, ("The New hashed volume {} still have the " "expected linkto file {}".format(src_link_subvol._fqpath, str(new_hashed.newname)))) g.log.info("The source link file is removed")
def test_file_access(self): """ Test file access. """ # pylint: disable=protected-access # pylint: disable=too-many-locals # pylint: disable=too-many-statements mount_obj = self.mounts[0] mountpoint = mount_obj.mountpoint # get subvol list subvols = (get_subvols(self.mnode, self.volname))['volume_subvols'] self.assertIsNotNone(subvols, "failed to get subvols") # create a file srcfile = mountpoint + '/testfile' ret, _, err = g.run(self.clients[0], ("touch %s" % srcfile)) self.assertEqual(ret, 0, ("File creation failed for %s err %s", srcfile, err)) g.log.info("testfile creation successful") # find hashed subvol srchashed, scount = find_hashed_subvol(subvols, "/", "testfile") self.assertIsNotNone(srchashed, "could not find srchashed") g.log.info("hashed subvol for srcfile %s subvol count %s", srchashed._host, str(scount)) # rename the file such that the new name hashes to a new subvol tmp = find_new_hashed(subvols, "/", "testfile") self.assertIsNotNone(tmp, "could not find new hashed for dstfile") g.log.info("dst file name : %s dst hashed_subvol : %s " "subvol count : %s", tmp.newname, tmp.hashedbrickobject._host, str(tmp.subvol_count)) dstname = str(tmp.newname) dstfile = mountpoint + "/" + dstname dsthashed = tmp.hashedbrickobject dcount = tmp.subvol_count ret, _, err = g.run(self.clients[0], ("mv %s %s" % (srcfile, dstfile))) self.assertEqual(ret, 0, ("rename failed for %s err %s", srcfile, err)) g.log.info("cmd: mv srcfile dstfile successful") # check that on dsthash_subvol the file is a linkto file filepath = dsthashed._fqpath + "/" + dstname file_stat = get_file_stat(dsthashed._host, filepath) self.assertEqual(file_stat['access'], "1000", ("Expected file " "permission to be 1000" " on subvol %s", dsthashed._host)) g.log.info("dsthash_subvol has the expected linkto file") # check on srchashed the file is a data file filepath = srchashed._fqpath + "/" + dstname file_stat = get_file_stat(srchashed._host, filepath) self.assertNotEqual(file_stat['access'], "1000", ("Expected file " "permission not to" "be 1000 on subvol" "%s", srchashed._host)) # Bring down the hashed subvol of dstfile(linkto file) ret = bring_bricks_offline(self.volname, subvols[dcount]) self.assertTrue(ret, ('Error in bringing down subvolume %s', subvols[dcount])) g.log.info('dst subvol %s is offline', subvols[dcount]) # Need to access the file through a fresh lookup through a new mount # create a new dir(choosing server to do a mount) ret, _, _ = g.run(self.mnode, ("mkdir -p /mnt")) self.assertEqual(ret, 0, ('mkdir of mount dir failed')) g.log.info("mkdir of mount dir succeeded") # do a temp mount ret = mount_volume(self.volname, self.mount_type, "/mnt", self.mnode, self.mnode) self.assertTrue(ret, ('temporary mount failed')) g.log.info("temporary mount succeeded") # check that file is accessible (stat) ret, _, _ = g.run(self.mnode, ("stat /mnt/%s" % dstname)) self.assertEqual(ret, 0, ('stat error on for dst file %s', dstname)) g.log.info("stat on /mnt/%s successful", dstname) # cleanup temporary mount ret = umount_volume(self.mnode, "/mnt") self.assertTrue(ret, ('temporary mount failed')) g.log.info("umount successful") # Bring up the hashed subvol ret = bring_bricks_online(self.mnode, self.volname, subvols[dcount], bring_bricks_online_methods=None) self.assertTrue(ret, "Error in bringing back subvol online") g.log.info('Subvol is back online') # now bring down the cached subvol ret = bring_bricks_offline(self.volname, subvols[scount]) self.assertTrue(ret, ('Error in bringing down subvolume %s', subvols[scount])) g.log.info('target subvol %s is offline', subvols[scount]) # file access should fail ret, _, _ = g.run(self.clients[0], ("stat %s" % dstfile)) self.assertEqual(ret, 1, ('stat error on for file %s', dstfile)) g.log.info("dstfile access failed as expected")
def test_file_rename_when_dest_hash_src_cached(self): """ - Destination file should exist - Source file hashed sub volume(s1) and cached on another subvolume(s2) - Destination file should be hased to subvolume where source file is stored(s2) - Destination file hased on subvolume(s2) but should be cached on some other subvolume(s3) than this two subvolume mv <source_file> <destination_file> - Destination file is removed. - Source file should be renamed as destination file - Destination link file should be removed - source link file should be removed """ # pylint: disable=protected-access # pylint: disable=too-many-locals # Create source file and Get hashed subvol (s2) src_subvol, src_count, source_file = ( self._create_file_and_get_hashed_subvol("test_source_file")) # Find a new file name for destination file, which hashes # to another subvol (s2) new_hashed = find_new_hashed(self.subvols, "/", "test_source_file") self.assertIsNotNone(new_hashed, "couldn't find new hashed for destination file") # Rename the source file to the new file name src_hashed = "{}/{}".format(self.mount_point, str(new_hashed.newname)) ret = move_file(self.mounts[0].client_system, source_file, src_hashed) self.assertTrue(ret, ("Failed to move file {} and {}" .format(source_file, src_hashed))) # Verify the Source link file is stored on hashed sub volume(s1) src_link_subvol = new_hashed.hashedbrickobject ret = self._verify_link_file_exists(src_link_subvol, str(new_hashed.newname)) self.assertTrue(ret, ("The hashed subvol {} doesn't have the " "expected linkto file: {}" .format(src_link_subvol._fqpath, str(new_hashed.newname)))) # Find a subvol (s3) for dest file to linkto, other than S1 and S2 brickobject = create_brickobjectlist(self.subvols, "/") self.assertIsNotNone(brickobject, "Failed to get brick object list") br_count = -1 subvol_new = None for brickdir in brickobject: br_count += 1 if br_count not in (src_count, new_hashed.subvol_count): subvol_new = brickdir break new_hashed2 = find_specific_hashed(self.subvols, "/", subvol_new) self.assertIsNotNone(new_hashed2, "could not find new hashed for dstfile") # Create a file in the subvol S3 dest_subvol, count, dest_file = ( self._create_file_and_get_hashed_subvol(str(new_hashed2.newname))) # Verify the subvol is not same as S1 and S2 self.assertNotEqual(count, src_count, ("The subvol found for destination is same as that" " of the source file cached subvol")) self.assertNotEqual(count, new_hashed.subvol_count, ("The subvol found for destination is same as that" " of the source file hashed subvol")) # Find a file name that hashes to S2 dest_hashed = find_specific_hashed(self.subvols, "/", src_subvol) self.assertIsNotNone(dest_hashed, "could not find new hashed for dstfile") # Rename destination to hash to S2 and verify dest = "{}/{}".format(self.mount_point, str(dest_hashed.newname)) ret = move_file(self.mounts[0].client_system, dest_file, dest) self.assertTrue(ret, ("Failed to move file {} and {}" .format(dest_file, dest))) # Rename Source File to Dest ret = move_file(self.mounts[0].client_system, src_hashed, dest) self.assertTrue(ret, ("Failed to move file {} and {}" .format(src_hashed, dest))) # Verify Destination File is removed ret = self._verify_file_exists(new_hashed2.hashedbrickobject, str(new_hashed2.newname)) self.assertFalse(ret, "The Destination file is still present in {}" .format(dest_subvol._fqpath)) # Verify Source link is removed ret = self._verify_link_file_exists(src_link_subvol, str(new_hashed.newname)) self.assertFalse(ret, "The source link file is still present in {}" .format(src_link_subvol._fqpath)) # Verify Destination Link is removed ret = self._verify_link_file_exists(dest_hashed.hashedbrickobject, str(dest_hashed.newname)) self.assertFalse(ret, "The Dest link file is still present in {}" .format(dest_hashed.hashedbrickobject._fqpath))
def test_delete_file_in_migration(self): """ Verify that if a file is picked for migration and then deleted, the file should be removed successfully. * First create a big data file of 10GB. * Rename that file, such that after rename a linkto file is created (we are doing this to make sure that file is picked for migration.) * Add bricks to the volume and trigger rebalance using force option. * When the file has been picked for migration, delete that file from the mount point. * Check whether the file has been deleted or not on the mount-point as well as the back-end bricks. """ # pylint: disable=too-many-statements # pylint: disable=too-many-locals # pylint: disable=protected-access mountpoint = self.mounts[0].mountpoint # Location of source file src_file = mountpoint + '/file1' # Finding a file name such that renaming source file to it will form a # linkto file subvols = (get_subvols(self.mnode, self.volname))['volume_subvols'] newhash = find_new_hashed(subvols, "/", "file1") new_name = str(newhash.newname) new_host = str(newhash.hashedbrickobject._host) new_name_path = str(newhash.hashedbrickobject._fqpath)[:-2] # Location of destination file to which source file will be renamed dst_file = '{}/{}'.format(mountpoint, new_name) # Create a 10GB file source file cmd = ( "dd if=/dev/urandom of={} bs=1024K count=10000".format(src_file)) ret, _, _ = g.run(self.clients[0], cmd) self.assertEqual(ret, 0, ("File {} creation failed".format(src_file))) # Move file such that it hashes to some other subvol and forms linkto # file ret = move_file(self.clients[0], src_file, dst_file) self.assertTrue(ret, "Rename failed") g.log.info('Renamed file %s to %s', src_file, dst_file) # Check if "file_two" is linkto file ret = is_linkto_file(new_host, '{}/{}'.format(new_name_path, new_name)) self.assertTrue(ret, "File is not a linkto file") g.log.info("File is linkto file") # Expanding volume by adding bricks to the volume ret, _, _ = add_brick(self.mnode, self.volname, self.add_brick_list, force=True) self.assertEqual(ret, 0, ("Volume {}: Add-brick failed".format(self.volname))) g.log.info("Volume %s: add-brick successful", self.volname) # Log Volume Info and Status after expanding the volume log_volume_info_and_status(self.mnode, self.volname) # Start Rebalance ret, _, _ = rebalance_start(self.mnode, self.volname, force=True) self.assertEqual( ret, 0, ("Volume {}: Failed to start rebalance".format(self.volname))) g.log.info("Volume %s : Rebalance started ", self.volname) # Check if rebalance is running and delete the file status_info = get_rebalance_status(self.mnode, self.volname) status = status_info['aggregate']['statusStr'] self.assertEqual(status, 'in progress', "Rebalance is not running") ret, _, _ = g.run(self.clients[0], (" rm -rf {}".format(dst_file))) self.assertEqual(ret, 0, ("Cannot delete file {}".format(dst_file))) g.log.info("File is deleted") # Check if the file is present on the mount point ret, _, _ = g.run(self.clients[0], ("ls -l {}".format(dst_file))) self.assertEqual(ret, 2, ("Failed to delete file {}".format(dst_file))) # Check if the file is present on the backend bricks bricks = get_all_bricks(self.mnode, self.volname) for brick in bricks: node, brick_path = brick.split(':') ret, _, _ = g.run(node, "ls -l {}/{}".format(brick_path, new_name)) self.assertEqual( ret, 2, "File is still present on" " back-end brick: {}".format(brick_path)) g.log.info("File is deleted from back-end brick: %s", brick_path) # Check if rebalance process is still running for server in self.servers: ret, _, _ = g.run(server, "pgrep rebalance") self.assertEqual(ret, 1, ("Rebalance process is still" " running on server {}".format(server))) g.log.info("Rebalance process is not running")
def test_file_rename_when_dest_cache_to_src_subvol(self): """ - Destination file should exist - Source file is stored on hashed subvolume it self - Destination file should be hased to some other subvolume(s2) - Destination file hashed on subvolume(s2) but cached on the subvolume(s1) where souce file is present mv <source_file> <destination_file> - Destination file is removed. - Source file should be renamed as destination file - Destination link file should be there on hashed subvolume and should link to new destination file """ # pylint: disable=protected-access # Create soruce file and Get hashed subvol (s1) source_hashed_subvol, src_count, _ = ( self._create_file_and_get_hashed_subvol("test_source_file")) # Find name for dest file to cache to S1 dest_subvol = find_specific_hashed(self.subvols, "/", source_hashed_subvol) dest_name = str(dest_subvol.newname) # Create destination file in subvol S1 _, dest_count, _ = self._create_file_and_get_hashed_subvol(dest_name) # Verify its subvol (s1) self.assertEqual(src_count, dest_count, ("The newly created file falls under subvol {} " "rather than {}".format(dest_count, src_count))) # Rename dest file such that it hashes to some other subvol S2 dest_hashed_subvol = find_new_hashed(self.subvols, "/", dest_name) self.assertIsNotNone(dest_hashed_subvol, "could not find new hashed for dstfile") # Rename/Move the file dest_file = "{}/{}".format(self.mount_point, dest_hashed_subvol.newname) src_file = "{}/{}".format(self.mount_point, dest_name) ret = move_file(self.mounts[0].client_system, src_file, dest_file) self.assertTrue( ret, "Failed to move files {} and {}".format(src_file, dest_file)) # Verify the Dest link file is stored on hashed sub volume(s2) dest_link_subvol = dest_hashed_subvol.hashedbrickobject ret = self._verify_link_file_exists(dest_link_subvol, str(dest_hashed_subvol.newname)) self.assertTrue( ret, ("The hashed subvol {} doesn't have the " "expected linkto file: {}".format( dest_link_subvol._fqpath, str(dest_hashed_subvol.newname)))) # Rename Source to Dest src = "{}/{}".format(self.mount_point, "test_source_file") dest_file = "{}/{}".format(self.mount_point, dest_hashed_subvol.newname) ret = move_file(self.mounts[0].client_system, src, dest_file) self.assertTrue( ret, "Failed to move files {} and {}".format(src, dest_file)) # Verify destination file is removed ret = self._verify_file_exists(dest_subvol.hashedbrickobject, dest_name) self.assertFalse(ret, ("Destination file : {} is not removed in subvol" " : {}".format(str(dest_hashed_subvol.newname), dest_link_subvol._fqpath))) g.log.info("The destination file is removed as expected") # Verify the Destination link is present ret = self._verify_link_file_exists(dest_link_subvol, str(dest_hashed_subvol.newname)) self.assertTrue( ret, ("The hashed subvol {} still have the " "expected linkto file: {}".format( dest_link_subvol._fqpath, str(dest_hashed_subvol.newname)))) g.log.info("The Destination link file is present as expected") # Verify the dest link file points to new destination file file_path = dest_link_subvol._fqpath + str(dest_hashed_subvol.newname) ret = (self._verify_file_links_to_specified_destination( dest_link_subvol._host, file_path, str(dest_hashed_subvol.newname))) self.assertTrue( ret, "The dest link file not pointing towards " "the desired file") g.log.info("The Destination link file is pointing to new file" " as expected")
def test_file_rename_when_dest_hash_to_src_subvol(self): """ - Destination file should exist - Source file is stored on hashed subvolume it self - Destination file should be hased to same subvolume(s1) where source file is - Destination file hased subvolume(s1) but cached onsubvolume(s2) mv <source_file> <destination_file> - Destination file is removed. - Source file should be renamed as destination file - Destination link file should be removed """ # pylint: disable=protected-access # Create soruce file and Get hashed subvol (s1) source_hashed_subvol, src_count, source_file = ( self._create_file_and_get_hashed_subvol("test_source_file")) # Find a file name that hashes to another subvol (s2) new_hashed = find_new_hashed(self.subvols, "/", "test_source_file") self.assertIsNotNone( new_hashed, ("could'nt find new hashed for {}".format(source_file))) # Create destination file in subvol S2 _, dest_count, dest_file = (self._create_file_and_get_hashed_subvol( str(new_hashed.newname))) # Rename dest file such that it hashes to S1 new_hashed2 = find_specific_hashed(self.subvols, "/", source_hashed_subvol) self.assertIsNotNone(new_hashed2, "could not find new hashed for dstfile") # Verify the subvol is S1 itself self.assertEqual( new_hashed2.subvol_count, src_count, "The destination file is not stored to desired " "subvol :{}".format(dest_count)) # Rename/Move the file dest_file2 = "{}/{}".format(self.mount_point, str(new_hashed2.newname)) ret = move_file(self.mounts[0].client_system, dest_file, dest_file2) self.assertTrue( ret, "Failed to move files {} and {}".format(source_file, dest_file)) # Verify the Dest link file is stored on hashed sub volume(s1) dest_link_subvol = new_hashed2.hashedbrickobject ret = self._verify_link_file_exists(dest_link_subvol, str(new_hashed2.newname)) self.assertTrue( ret, ("The hashed subvol {} doesn't have the " "expected linkto file: {}".format(dest_link_subvol._fqpath, str(new_hashed2.newname)))) # Rename Source to Dest src = "{}/{}".format(self.mount_point, "test_source_file") dest_file = "{}/{}".format(self.mount_point, str(new_hashed2.newname)) ret = move_file(self.mounts[0].client_system, src, dest_file) self.assertTrue( ret, "Failed to move files {} and {}".format(src, dest_file)) # Verify destination file is removed ret = self._verify_file_exists(new_hashed.hashedbrickobject, str(new_hashed.newname)) self.assertFalse( ret, ("Destination file : {} is not removed in subvol" " : {}".format(str(new_hashed.newname), new_hashed.hashedbrickobject._fqpath))) g.log.info("The destination file is removed as expected") # Verify the Destination link is removed ret = self._verify_link_file_exists(new_hashed2.hashedbrickobject, str(new_hashed2.newname)) self.assertFalse(ret, ("The hashed subvol {} still have the " "expected linkto file: {}".format( new_hashed2.hashedbrickobject._fqpath, str(new_hashed2.newname)))) g.log.info("The Destination link file is removed as expected")
def test_file_rename_when_source_and_dest_hash_same_subvol(self): """ - Destination file should exist - Source file is hashed sub volume(s1) and cached on another subvolume(s2) - Destination file should be hased to same subvolume(s1) where source file is hased - Destination hashed on subvolume(s1) but should be cached on subvolume(s2) where source file is stored mv <source_file> <destination_file> - Destination file is removed. - Source file should be renamed as destination file - Destination link file should be there on hashed subvolume and should link to new destination file - source link file should be removed """ # pylint: disable=protected-access # pylint: disable=too-many-locals # Create soruce file and Get hashed subvol (s2) source_hashed_subvol, src_count, source_file = ( self._create_file_and_get_hashed_subvol("test_source_file")) # Rename the file such that the new name hashes to a new subvol (S1) new_hashed = find_new_hashed(self.subvols, "/", "test_source_file") self.assertIsNotNone( new_hashed, ("could'nt find new hashed for {}".format(source_file))) # Verify the subvols are not same for source and destination files self.assertNotEqual(src_count, new_hashed.subvol_count, "The subvols for src and dest are same.") # Rename/Move the file dest_file = "{}/{}".format(self.mount_point, str(new_hashed.newname)) ret = move_file(self.mounts[0].client_system, source_file, dest_file) self.assertTrue( ret, "Failed to move files {} and {}".format(source_file, dest_file)) # Verify the Source link file is stored on hashed sub volume(s1) src_link_subvol = new_hashed.hashedbrickobject ret = self._verify_link_file_exists(src_link_subvol, str(new_hashed.newname)) self.assertTrue( ret, ("The hashed subvol {} doesn't have the " "expected linkto file: {}".format(src_link_subvol._fqpath, str(new_hashed.newname)))) # Get a file name that stores to S2 for destination new_hashed2 = find_specific_hashed(self.subvols, "/", source_hashed_subvol) self.assertIsNotNone(new_hashed2, "could not find new hashed for dstfile") # Create destination file in subvol S2 dest_hashed_subvol, dest_count, dest_file = ( self._create_file_and_get_hashed_subvol(str(new_hashed2.newname))) # Verify the subvol is S2 itself self.assertEqual( dest_count, src_count, "The destination file is not stored to desired " "subvol :{}".format(dest_count)) # Create a linkfile to dest by renaming it to hash to S1 dest_hashed = find_specific_hashed(self.subvols, "/", src_link_subvol, new_hashed.newname) # Verify the subvol is S1 self.assertEqual( dest_hashed.subvol_count, new_hashed.subvol_count, "The destination file is not stored to desired " "subvol :{}, instead to subvol : {}".format( dest_hashed.subvol_count, new_hashed)) # Rename the dest file to the new file name dest_file_2 = "{}/{}".format(self.mount_point, str(dest_hashed.newname)) ret = move_file(self.mounts[0].client_system, dest_file, dest_file_2) self.assertTrue( ret, "Failed to move files {} and {}".format(source_file, dest_file_2)) # Rename source to destination src = "{}/{}".format(self.mount_point, str(new_hashed.newname)) dest_file = "{}/{}".format(self.mount_point, str(dest_hashed.newname)) ret = move_file(self.mounts[0].client_system, src, dest_file) self.assertTrue( ret, "Failed to move files {} and {}".format(src, dest_file)) # Verify destination file is removed ret = self._verify_file_exists(dest_hashed_subvol, str(new_hashed2.newname)) self.assertFalse(ret, ("Destination file : {} is not removed in subvol" " : {}".format(str(new_hashed2.newname), dest_hashed_subvol._fqpath))) g.log.info("The destination file is removed as expected") # Verify the source link is removed ret = self._verify_link_file_exists(src_link_subvol, str(new_hashed.newname)) self.assertFalse( ret, ("The hashed subvol {} still have the " "expected linkto file: {}".format(src_link_subvol._fqpath, str(new_hashed.newname)))) g.log.info("The source link file is removed as expected") # Verify the Destination link is on hashed subvolume ret = self._verify_link_file_exists(src_link_subvol, str(dest_hashed.newname)) self.assertTrue( ret, ("The hashed subvol {} doesn't have the " "expected linkto file: {}".format(dest_hashed_subvol._fqpath, str(dest_hashed.newname)))) # Verify the dest link file points to new destination file file_path = src_link_subvol._fqpath + str(dest_hashed.newname) ret = (self._verify_file_links_to_specified_destination( src_link_subvol._host, file_path, str(dest_hashed.newname))) self.assertTrue( ret, "The dest link file not pointing towards " "the desired file") g.log.info("The Destination link file is pointing to new file" " as expected")
def test_file_rename_when_dest_hash_src_hashed_but_cache_diff(self): """ - Destination file should exist - Source file is stored on hashed subvolume it self - Destination file should be hased to some other subvolume(s2) - Destination file hased on subvolume(s2) but cached on some other subvolume(s3)(neither s1 nor s2) mv <source_file> <destination_file> - Destination file is removed. - Source file should be renamed as destination file - Destination link file should be there on hashed subvolume and should link to new destination file """ # pylint: disable=protected-access # pylint: disable=too-many-locals # Create source file and Get hashed subvol (s1) _, src_count, source_file = ( self._create_file_and_get_hashed_subvol("test_source_file")) # Find a new file name for destination to hash to some subvol S3 new_hashed = find_new_hashed(self.subvols, "/", "test_source_file") self.assertIsNotNone(new_hashed, "couldn't find new hashed for destination file") # Create Dest file in S3 dest_cached, dest_count, dest_file = ( self._create_file_and_get_hashed_subvol(str(new_hashed.newname))) # Verify S1 and S3 are not same self.assertNotEqual(src_count, dest_count, ("The destination file is cached to the source " "cached subvol")) # Find new name for dest file, that it hashes to some other subvol S2 brickobject = create_brickobjectlist(self.subvols, "/") self.assertIsNotNone(brickobject, "Failed to get brick object list") br_count = -1 subvol_new = None for brickdir in brickobject: br_count += 1 if br_count not in (src_count, dest_count): subvol_new = brickdir break dest_hashed = find_specific_hashed(self.subvols, "/", subvol_new) # Move dest to new name dest = "{}/{}".format(self.mount_point, str(dest_hashed.newname)) ret = move_file(self.mounts[0].client_system, dest_file, dest) self.assertTrue(ret, ("Failed to move file {} and {}" .format(dest_file, dest))) # Move Source file to Dest ret = move_file(self.mounts[0].client_system, source_file, dest) self.assertTrue(ret, ("Failed to move file {} and {}" .format(source_file, dest))) # Verify Destination File is removed ret = self._verify_file_exists(dest_cached, str(new_hashed.newname)) self.assertFalse(ret, "The Source file is still present in {}" .format(dest_cached._fqpath)) # Verify Destination Link is present and points to new dest file ret = self._verify_link_file_exists(dest_hashed.hashedbrickobject, str(dest_hashed.newname)) self.assertTrue(ret, "The Dest link file is not present in {}" .format(dest_hashed.hashedbrickobject._fqpath)) file_path = dest_hashed.hashedbrickobject._fqpath + str( dest_hashed.newname) ret = (self._verify_file_links_to_specified_destination( dest_hashed.hashedbrickobject._host, file_path, str(dest_hashed.newname))) self.assertTrue(ret, "The dest link file not pointing towards " "the desired file") g.log.info("The Destination link file is pointing to new file" " as expected")
def test_access_file_with_stale_linkto_xattr(self): """ Description: Checks if the files are accessible as non-root user if the files have stale linkto xattr. Steps: 1) Create a volume and start it. 2) Mount the volume on client node using FUSE. 3) Create a file. 4) Enable performance.parallel-readdir and performance.readdir-ahead on the volume. 5) Rename the file in order to create a linkto file. 6) Force the linkto xattr values to become stale by changing the dht subvols in the graph 7) Login as an non-root user and access the file. """ # pylint: disable=protected-access # Set permissions on the mount-point m_point = self.mounts[0].mountpoint ret = set_file_permissions(self.clients[0], m_point, "-R 777") self.assertTrue(ret, "Failed to set file permissions") g.log.info("Successfully set file permissions on mount-point") # Creating a file on the mount-point cmd = 'dd if=/dev/urandom of={}/FILE-1 count=1 bs=16k'.format(m_point) ret, _, _ = g.run(self.clients[0], cmd) self.assertEqual(ret, 0, "File to create file") # Enable performance.parallel-readdir and # performance.readdir-ahead on the volume options = { "performance.parallel-readdir": "enable", "performance.readdir-ahead": "enable" } ret = set_volume_options(self.mnode, self.volname, options) self.assertTrue(ret, "Failed to set volume options") g.log.info("Successfully set volume options") # Finding a file name such that renaming source file to it will form a # linkto file subvols = (get_subvols(self.mnode, self.volname))['volume_subvols'] newhash = find_new_hashed(subvols, "/", "FILE-1") new_name = str(newhash.newname) new_host = str(newhash.hashedbrickobject._host) new_name_path = str(newhash.hashedbrickobject._fqpath)[:-1] # Move file such that it hashes to some other subvol and forms linkto # file ret = move_file(self.clients[0], "{}/FILE-1".format(m_point), "{}/{}".format(m_point, new_name)) self.assertTrue(ret, "Rename failed") g.log.info('Renamed file %s to %s', "{}/FILE-1".format(m_point), "{}/{}".format(m_point, new_name)) # Check if "dst_file" is linkto file ret = is_linkto_file(new_host, '{}{}'.format(new_name_path, new_name)) self.assertTrue(ret, "File is not a linkto file") g.log.info("File is linkto file") # Force the linkto xattr values to become stale by changing the dht # subvols in the graph; for that: # disable performance.parallel-readdir and # performance.readdir-ahead on the volume options = { "performance.parallel-readdir": "disable", "performance.readdir-ahead": "disable" } ret = set_volume_options(self.mnode, self.volname, options) self.assertTrue(ret, "Failed to disable volume options") g.log.info("Successfully disabled volume options") # Access the file as non-root user cmd = "ls -lR {}".format(m_point) ret, _, _ = g.run(self.mounts[0].client_system, cmd, user="******") self.assertEqual(ret, 0, "Lookup failed ") g.log.info("Lookup successful")
def test_file_rename_when_dest_doesnt_hash_src_cached_or_hashed(self): """ - Destination file should exist - Source file is hashed on sub volume(s1) and cached on another subvolume(s2) - Destination file should be hased to subvolume(s3) other than above two subvolumes - Destination file hased on subvolume(s3) but destination file should be cached on same subvolume(s2) where source file is stored mv <source_file> <destination_file> - Destination file is removed. - Source file should be renamed as destination file - Destination file hashed on subvolume and should link to new destination file - source link file should be removed """ # pylint: disable=protected-access # pylint: disable=too-many-locals # Create source file and Get hashed subvol (s2) src_subvol, src_count, source_file = ( self._create_file_and_get_hashed_subvol("test_source_file")) # Find a new file name for destination file, which hashes # to another subvol (s1) new_hashed = find_new_hashed(self.subvols, "/", "test_source_file") self.assertIsNotNone(new_hashed, "couldn't find new hashed for destination file") # Rename the source file to the new file name dest_file = "{}/{}".format(self.mount_point, str(new_hashed.newname)) ret = move_file(self.mounts[0].client_system, source_file, dest_file) self.assertTrue(ret, ("Failed to move file {} and {}" .format(source_file, dest_file))) # Verify the Source link file is stored on hashed sub volume(s1) src_link_subvol = new_hashed.hashedbrickobject ret = self._verify_link_file_exists(src_link_subvol, str(new_hashed.newname)) self.assertTrue(ret, ("The hashed subvol {} doesn't have the " "expected linkto file: {}" .format(src_link_subvol._fqpath, str(new_hashed.newname)))) # Identify a file name for dest to get stored in S2 dest_cached_subvol = find_specific_hashed(self.subvols, "/", src_subvol) # Create the file with identified name _, _, dst_file = ( self._create_file_and_get_hashed_subvol( str(dest_cached_subvol.newname))) # Verify its in S2 itself self.assertEqual(dest_cached_subvol.subvol_count, src_count, ("The subvol found for destination is not same as " "that of the source file cached subvol")) # Find a subvol (s3) for dest file to linkto, other than S1 and S2 brickobject = create_brickobjectlist(self.subvols, "/") self.assertIsNotNone(brickobject, "Failed to get brick object list") br_count = -1 subvol_new = None for brickdir in brickobject: br_count += 1 if br_count not in (src_count, new_hashed.subvol_count): subvol_new = brickdir break new_hashed2 = find_specific_hashed(self.subvols, "/", subvol_new) self.assertIsNotNone(new_hashed2, "could not find new hashed for dstfile") # Verify the subvol is not same as S1(src_count) and S2(dest_count) self.assertNotEqual(new_hashed2.subvol_count, src_count, ("The subvol found for destination is same as that" " of the source file cached subvol")) self.assertNotEqual(new_hashed2.subvol_count, new_hashed.subvol_count, ("The subvol found for destination is same as that" " of the source file hashed subvol")) # Rename the dest file to the new file name dst_file_ln = "{}/{}".format(self.mount_point, str(new_hashed2.newname)) ret = move_file(self.mounts[0].client_system, dst_file, dst_file_ln) self.assertTrue(ret, ("Failed to move file {} and {}" .format(dst_file, dst_file_ln))) # Verify the Dest link file is stored on hashed sub volume(s3) dest_link_subvol = new_hashed2.hashedbrickobject ret = self._verify_link_file_exists(dest_link_subvol, str(new_hashed2.newname)) self.assertTrue(ret, ("The hashed subvol {} doesn't have the " "expected linkto file: {}" .format(dest_link_subvol._fqpath, str(new_hashed2.newname)))) # Move/Rename Source File to Dest src_file = "{}/{}".format(self.mount_point, str(new_hashed.newname)) ret = move_file(self.mounts[0].client_system, src_file, dst_file) self.assertTrue(ret, ("Failed to move file {} and {}" .format(src_file, dst_file))) # Verify Source file is removed ret = self._verify_file_exists(src_subvol, "test_source_file") self.assertFalse(ret, "The source file is still present in {}" .format(src_subvol._fqpath)) # Verify Source link is removed ret = self._verify_link_file_exists(src_link_subvol, str(new_hashed.newname)) self.assertFalse(ret, "The source link file is still present in {}" .format(src_link_subvol._fqpath)) # Verify the Destination link is on hashed subvolume ret = self._verify_link_file_exists(dest_link_subvol, str(new_hashed2.newname)) self.assertTrue(ret, ("The hashed subvol {} doesn't have the " "expected linkto file: {}" .format(dest_link_subvol._fqpath, str(new_hashed2.newname)))) # Verify the dest link file points to new destination file file_path = dest_link_subvol._fqpath + str(new_hashed2.newname) ret = (self._verify_file_links_to_specified_destination( dest_link_subvol._host, file_path, str(dest_cached_subvol.newname))) self.assertTrue(ret, "The dest link file not pointing towards " "the desired file") g.log.info("The Destination link file is pointing to new file" " as expected")