def _delete_xattr_trusted_foo(self): """Removes xattr trusted.foo from all the files.""" for fname in self.list_of_device_files: ret = delete_fattr(self.clients[0], fname, 'trusted.foo') self.assertTrue( ret, "Unable to remove custom xattr for " "file {}".format(fname))
def delete_xattr_user_foo(self, list_of_files): """ Removes xattr user.foo from all the files. """ for fname in list_of_files: ret = delete_fattr(self.client_node, fname, 'user.foo') self.assertTrue( ret, "Unable to remove custom xattr for " "file {}".format(fname)) g.log.info("Successfully removed custom xattr for each file.")
def test_dir_gfid_heal_on_all_subvols(self): """ - Create a volume and mount it. - Create a directory on mount and check whether all the bricks have the same gfid. - Now delete gfid attr from all but one backend bricks, - Do lookup from the mount. - Check whether all the bricks have the same gfid assigned. """ # Create a directory on the mount cmd = ("/usr/bin/env python %s create_deep_dir -d 0 -l 0 " "%s/dir1" % (self.script_upload_path, self.mounts[0].mountpoint)) ret, _, _ = g.run(self.clients[0], cmd) self.assertEqual(ret, 0, "Failed to create directory on mountpoint") g.log.info("Directory created successfully on mountpoint") # Verify gfids are same on all the bricks and get dir1 gfid bricks_list = get_all_bricks(self.mnode, self.volname)[1:] dir_gfid = self.verify_gfid_and_retun_gfid("dir1") # Delete gfid attr from all but one backend bricks for brick in bricks_list: brick_node, brick_path = brick.split(":") ret = delete_fattr(brick_node, '%s/dir1' % (brick_path), 'trusted.gfid') self.assertTrue( ret, 'Failed to delete gfid for brick ' 'path %s:%s/dir1' % (brick_node, brick_path)) g.log.info("Successfully deleted gfid xattr for %s:%s/dir1", brick_node, brick_path) g.log.info( "Successfully deleted gfid xattr for dir1 on the " "following bricks %s", str(bricks_list[1:])) # Trigger heal from mount point sleep(10) for mount_obj in self.mounts: g.log.info("Triggering heal for %s:%s", mount_obj.client_system, mount_obj.mountpoint) command = ('cd %s; ls -l' % mount_obj.mountpoint) ret, _, _ = g.run(mount_obj.client_system, command) self.assertFalse( ret, 'Failed to run lookup ' 'on %s ' % mount_obj.client_system) sleep(10) ret = get_mounts_stat(self.mounts) self.assertTrue(ret, "Failed to stat lookup on clients") g.log.info('stat lookup on clients succeeded') # Verify that all gfids for dir1 are same and get the gfid dir_gfid_new = self.verify_gfid_and_retun_gfid("dir1") self.assertTrue( all(gfid in dir_gfid for gfid in dir_gfid_new), 'Previous gfid and new gfid are not equal, ' 'which is not expected, previous gfid %s ' 'and new gfid %s' % (dir_gfid, dir_gfid_new)) g.log.info('gfid heal was successful from client lookup and all ' 'backend bricks have same gfid xattr, no gfid mismatch')
def _create_xattr_check_self_heal(self): """Create custom xattr and check if its healed""" # Set the xattr on the dir1 self._set_xattr_value(fattr_value="bar2") # Get online brick list online_bricks = get_online_bricks_list(self.mnode, self.volname) self.assertIsNotNone(online_bricks, "Failed to get online bricks") # Check if the custom xattr is being displayed on the # mount-point for dir1 self._check_xattr_value_on_mnt(expected_value="bar2") # Check if the xattr is being displayed on the online-bricks # for dir1 self._check_xattr_value_on_bricks(online_bricks, expected_value="bar2") # Modify custom xattr value on dir1 self._set_xattr_value(fattr_value="ABC") # Lookup on moint-point to refresh the value of xattr self._perform_lookup() # Check if the modified custom xattr is being displayed # on the mount-point for dir1 self._check_xattr_value_on_mnt(expected_value="ABC") # Check if the modified custom xattr is being # displayed on the bricks for dir1 self._check_xattr_value_on_bricks(online_bricks, expected_value="ABC") # Remove the custom xattr from the mount point for dir1 ret = delete_fattr(self.client, '{}/dir1'.format(self.m_point), 'user.foo') self.assertTrue(ret, "Failed to delete the xattr for " "dir1 on mountpoint") g.log.info( "Successfully deleted the xattr for dir1 from mountpoint") # Lookup on moint-point to refresh the value of xattr self._perform_lookup() # Check that the custom xattr is not displayed on the # for dir1 on mountpoint ret = get_fattr(self.client, '{}/dir1'.format(self.m_point), 'user.foo', encode="text") self.assertEqual(ret, None, "Xattr for dir1 is not removed" " on:{}".format(self.client)) g.log.info("Success: xattr is removed for dir1 on mointpoint") # Check that the custom xattr is not displayed on the # for dir1 on the backend bricks for brick in online_bricks: host, brick_path = brick.split(':') ret = get_fattr(host, '{}/dir1'.format(brick_path), 'user.foo', encode="text") self.assertEqual(ret, None, "Xattr for dir1 is not removed" " on:{}".format(brick_path)) g.log.info("Xattr for dir1 is removed from " "brick:%s", brick_path) # Check if the trusted.glusterfs.pathinfo is displayed # for dir1 on mointpoint ret = get_fattr(self.client, '{}/dir1'.format(self.m_point), '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 dir1") # Set the xattr on the dir1 self._set_xattr_value(fattr_value="star1") # Bring back the bricks online ret, _, _ = volume_start(self.mnode, self.volname, force=True) self.assertFalse(ret, 'Failed to start volume %s with "force" option' % self.volname) g.log.info('Successfully started volume %s with "force" option', self.volname) # Execute lookup on the mointpoint self._perform_lookup() # Get online brick list online_bricks = get_online_bricks_list(self.mnode, self.volname) self.assertIsNotNone(online_bricks, "Failed to get online bricks") # Check if the custom xattr is being displayed # on the mount-point for dir1 self._check_xattr_value_on_mnt(expected_value="star1") # Check if the custom xattr is displayed on all the bricks self._check_xattr_value_on_bricks(online_bricks, expected_value="star1")
def test_directory_custom_extended_attr(self): """Test - set custom xattr to directory and link to directory """ # pylint: disable = too-many-statements dir_prefix = '{root}/folder_{client_index}' for mount_index, mount_point in enumerate(self.mounts): folder_name = dir_prefix.format(root=mount_point.mountpoint, client_index=mount_index) # Create a directory from mount point g.log.info('Creating directory : %s:%s', mount_point.mountpoint, folder_name) ret = mkdir(mount_point.client_system, folder_name) self.assertTrue( ret, 'Failed to create directory %s on mount point %s' % (folder_name, mount_point.mountpoint)) ret = file_exists(mount_point.client_system, folder_name) self.assertTrue( ret, 'Created Directory %s does not exists on mount ' 'point %s' % (folder_name, mount_point.mountpoint)) g.log.info('Created directory %s:%s', mount_point.mountpoint, folder_name) # Verify that hash layout values are set on each # bricks for the dir g.log.debug("Verifying hash layout values") ret = validate_files_in_dir(mount_point.client_system, mount_point.mountpoint, test_type=FILE_ON_HASHED_BRICKS, file_type=FILETYPE_DIR) self.assertTrue( ret, "Expected - Directory is stored " "on hashed bricks") g.log.info("Hash layout values are set on each bricks") # Verify that mount point should not display # xattr : trusted.gfid and dht g.log.debug("Loading extra attributes") ret = get_fattr_list(mount_point.client_system, folder_name) self.assertTrue( 'trusted.gfid' not in ret, "Extended attribute trusted.gfid is presented on " "mount point %s and folder %s" % (mount_point.mountpoint, folder_name)) self.assertTrue( 'trusted.glusterfs.dht' not in ret, "Extended attribute trusted.glusterfs.dht is " "presented on mount point %s and folder %s" % (mount_point.mountpoint, folder_name)) g.log.info( 'Extended attributes trusted.gfid and ' 'trusted.glusterfs.dht does not exists on ' 'mount point %s:%s ', mount_point.mountpoint, folder_name) # Verify that mount point shows pathinfo xattr g.log.debug("Check for xattr trusted.glusterfs.pathinfo on %s:%s", mount_point, folder_name) ret = get_fattr(mount_point.client_system, mount_point.mountpoint, 'trusted.glusterfs.pathinfo', encode="text") self.assertIsNotNone( ret, "trusted.glusterfs.pathinfo is not " "presented on %s:%s" % (mount_point.mountpoint, folder_name)) g.log.info( 'pathinfo xattr is displayed on mount point %s and ' 'dir %s', mount_point.mountpoint, folder_name) # Create a custom xattr for dir g.log.info("Set attribute user.foo to %s", folder_name) ret = set_fattr(mount_point.client_system, folder_name, 'user.foo', 'bar2') self.assertTrue( ret, "Setup custom attribute on %s:%s failed" % (mount_point.client_system, folder_name)) g.log.info('Set custom attribute is set on %s:%s', mount_point.client_system, folder_name) # Verify that custom xattr for directory is displayed # on mount point and bricks g.log.debug('Check xarttr user.foo on %s:%s', mount_point.client_system, folder_name) ret = get_fattr(mount_point.client_system, folder_name, 'user.foo', encode="text") self.assertEqual( ret, 'bar2', "Xattr attribute user.foo is not presented on " "mount point %s and directory %s" % (mount_point.client_system, folder_name)) g.log.info( 'Custom xattr user.foo is presented on mount point' ' %s:%s ', mount_point.client_system, folder_name) for brick in get_all_bricks(self.mnode, self.volname): brick_server, brick_dir = brick.split(':') brick_path = dir_prefix.format(root=brick_dir, client_index=mount_index) ret = get_fattr(brick_server, brick_path, 'user.foo', encode="text") g.log.debug('Check custom xattr for directory on brick %s:%s', brick_server, brick_path) self.assertEqual( 'bar2', ret, "Expected: user.foo should be on brick %s\n" "Actual: Value of attribute foo.bar %s" % (brick_path, ret)) g.log.info('Custom xattr is presented on brick %s', brick_path) # Delete custom attribute ret = delete_fattr(mount_point.client_system, folder_name, 'user.foo') self.assertTrue(ret, "Failed to delete custom attribute") g.log.info('Removed custom attribute from directory %s:%s', mount_point.client_system, folder_name) # Verify that custom xattr is not displayed after delete # on mount point and on the bricks g.log.debug('Looking if custom extra attribute user.foo is ' 'presented on mount or on bricks after deletion') self.assertIsNone( get_fattr(mount_point.client_system, folder_name, 'user.foo', encode="text"), "Xattr user.foo is presented on mount point" " %s:%s after deletion" % (mount_point.mountpoint, folder_name)) g.log.info( "Xattr user.foo is not presented after deletion" " on mount point %s:%s", mount_point.mountpoint, folder_name) for brick in get_all_bricks(self.mnode, self.volname): brick_server, brick_dir = brick.split(':') brick_path = dir_prefix.format(root=brick_dir, client_index=mount_index) self.assertIsNone( get_fattr(brick_server, brick_path, 'user.foo'), "Deleted xattr user.foo is presented on " "brick %s:%s" % (brick, brick_path)) g.log.info( 'Custom attribute is not presented after delete ' 'from directory on brick %s:%s', brick, brick_path) # Repeat all of the steps for link of created directory for mount_index, mount_point in enumerate(self.mounts): linked_folder_name = dir_prefix.format(root=mount_point.mountpoint, client_index="%s_linked" % mount_index) folder_name = dir_prefix.format(root=mount_point.mountpoint, client_index=mount_index) # Create link to created dir command = 'ln -s {src} {dst}'.format(dst=linked_folder_name, src=folder_name) ret, _, _ = g.run(mount_point.client_system, command) self.assertEqual( 0, ret, 'Failed to create link %s to directory %s' % (linked_folder_name, folder_name)) self.assertTrue( file_exists(mount_point.client_system, linked_folder_name), 'Link does not exists on %s:%s' % (mount_point.client_system, linked_folder_name)) g.log.info('Create link %s to directory %s', linked_folder_name, folder_name) # Verify that hash layout values are set on each # bricks for the link to dir g.log.debug("Verifying hash layout values") ret = validate_files_in_dir(mount_point.client_system, mount_point.mountpoint, test_type=FILE_ON_HASHED_BRICKS, file_type=FILETYPE_LINK) self.assertTrue( ret, "Expected - Link to directory is stored " "on hashed bricks") g.log.info("Hash layout values are set on each bricks") # Verify that mount point should not display xattr : # trusted.gfid and dht g.log.debug("Loading extra attributes") ret = get_fattr_list(mount_point.client_system, linked_folder_name) self.assertTrue( 'trusted.gfid' not in ret, "Extended attribute trudted.gfid is presented on " "mount point %s and folder %s" % (mount_point.mountpoint, linked_folder_name)) self.assertTrue( 'trusted.glusterfs.dht' not in ret, "Extended attribute trusted.glusterfs.dht is " "presented on mount point %s and folder %s" % (mount_point.mountpoint, linked_folder_name)) g.log.info( 'Extended attributes trusted.gfid and ' 'trusted.glusterfs.dht does not exists on ' 'mount point %s:%s ', mount_point.mountpoint, linked_folder_name) # Verify that mount point shows pathinfo xattr g.log.debug("Check if pathinfo is presented on %s:%s", mount_point.client_system, linked_folder_name) self.assertIsNotNone( get_fattr(mount_point.client_system, mount_point.mountpoint, 'trusted.glusterfs.pathinfo'), "pathinfo is not displayed on mountpoint " "%s:%s" % (mount_point.client_system, linked_folder_name)) g.log.info('pathinfo value is displayed on mount point %s:%s', mount_point.client_system, linked_folder_name) # Set custom Attribute to link g.log.debug("Set custom xattribute user.foo to %s:%s", mount_point.client_system, linked_folder_name) self.assertTrue( set_fattr(mount_point.client_system, linked_folder_name, 'user.foo', 'bar2')) g.log.info('Successful in set custom attribute to %s:%s', mount_point.client_system, linked_folder_name) # Verify that custom xattr for directory is displayed # on mount point and bricks g.log.debug('Check mountpoint and bricks for custom xattribute') self.assertEqual( 'bar2', get_fattr(mount_point.client_system, linked_folder_name, 'user.foo', encode="text"), 'Custom xattribute is not presented on ' 'mount point %s:%s' % (mount_point.client_system, linked_folder_name)) g.log.info("Custom xattribute is presented on mount point %s:%s", mount_point.client_system, linked_folder_name) for brick in get_all_bricks(self.mnode, self.volname): brick_server, brick_dir = brick.split(':') brick_path = dir_prefix. \ format(root=brick_dir, client_index="%s_linked" % mount_index) cmd = '[ -f %s ] && echo "yes" || echo "no"' % brick_path # Check if link exists _, ret, _ = g.run(brick_server, cmd) if 'no' in ret: g.log.info("Link %s:%s does not exists", brick_server, brick_path) continue self.assertEqual( get_fattr(brick_server, brick_path, 'user.foo', encode="text"), 'bar2', "Actual: custom attribute not " "found on brick %s:%s" % (brick_server, brick_path)) g.log.info('Custom xattr for link found on brick %s:%s', brick, brick_path) # Delete custom attribute g.log.debug('Removing customer attribute on mount point %s:%s', mount_point.client_system, linked_folder_name) self.assertTrue( delete_fattr(mount_point.client_system, linked_folder_name, 'user.foo'), 'Fail on delete xattr user.foo') g.log.info('Deleted custom xattr from link %s:%s', mount_point.client_system, linked_folder_name) # Verify that custom xattr is not displayed after delete # on mount point and on the bricks g.log.debug( "Check if custom xattr is presented on %s:%s " "after deletion", mount_point.client_system, linked_folder_name) self.assertIsNone( get_fattr(mount_point.client_system, linked_folder_name, 'user.foo', encode="text"), "Expected: xattr user.foo to be not presented on" " %s:%s" % (mount_point.client_system, linked_folder_name)) g.log.info("Custom xattr user.foo is not presented on %s:%s", mount_point.client_system, linked_folder_name) for brick in get_all_bricks(self.mnode, self.volname): brick_server, brick_dir = brick.split(':') brick_path = dir_prefix. \ format(root=brick_dir, client_index="%s_linked" % mount_index) cmd = '[ -f %s ] && echo "yes" || echo "no"' % brick_path # Check if link exists _, ret, _ = g.run(brick_server, cmd) if 'no' in ret: g.log.info("Link %s:%s does not exists", brick_server, brick_path) continue self.assertIsNone( get_fattr(brick_server, brick_path, 'user.foo', encode="text"), "Extended custom attribute is presented on " "%s:%s after deletion" % (brick_server, brick_path)) g.log.info( 'Custom attribute is not presented after delete ' 'from link on brick %s:%s', brick_server, brick_path) g.log.info('Directory - custom extended attribute validation getfattr,' ' setfattr is successful')