def get_files_from_cold_tier(mnode, volname): """Lists files from cold tier for the given volume Args: mnode (str): Node on which command has to be executed. volname (str): volume name Returns: Emptylist: if there are no files in cold tier. list: list of files in cold tier on success. Examples: >>>get_files_from_hot_tier("testvol") """ files = [] from glustolibs.gluster.volume_libs import get_subvols subvols = get_subvols(mnode, volname) for subvol in subvols['cold_tier_subvols']: info = subvol[0].split(':') file_list = list_files(info[0], info[1]) for file in file_list: if ".glusterfs" not in file: files.append(file) return files
def _perform_io_and_validate_presence_of_files(self): """ Function to perform the IO and validate the presence of files. """ self.file_limit += 10 # Starting IO on the mounts cmd = ("cd %s ; touch file{%d..%d}" % (self.mounts[0].mountpoint, self.file_limit-10, self.file_limit)) ret, _, _ = g.run(self.mounts[0].client_system, cmd) self.assertEqual(ret, 0, "Failed to create files on mountpoint") g.log.info("Files created successfully on mountpoint") # Gather the list of files from the mount point files = list_files(self.mounts[0].client_system, self.mounts[0].mountpoint) self.assertIsNotNone(files, "Failed to get the list of files") g.log.info("Successfully gathered the list of files from mount point") # Check if the files exist for filename in files: ret = file_exists(self.mounts[0].client_system, filename) self.assertTrue(ret, ("Unexpected: File '%s' does not exist" % filename)) g.log.info("Successfully validated existence of '%s'", filename)
def _get_files_in_brick(self, brick_path, dir_path): """ Returns files in format of `dir_path/file_name` from the given brick path """ node, path = brick_path.split(':') files = list_files(node, path, dir_path) self.assertIsNotNone( files, 'Unable to get list of files from {}'.format(brick_path)) files = [file_name.rsplit('/', 1)[-1] for file_name in files] return [ each_file for each_file in files if each_file in ('file1', 'file2', 'file3') ]
def check_file_availability(mnode, file_path, filename): """ Check for ctdb files and delete Args: mnode(str): Node on which command is executed filepath(str): Absolute path of the file to be validated filename(str): File to be deleted if available in /etc/ctdb/ Returns: bool: True if concerned files are available else false """ if file_path in list_files(mnode, "/etc/ctdb/", filename): ret, _, _ = g.run(mnode, "rm -rf %s" % file_path) if ret: return False return True
def test_gfind_modify(self): """ Verifying the glusterfind functionality with deletion of files. * Create a volume * Create a session on the volume * Create various files from mount point * Perform glusterfind pre * Perform glusterfind post * Check the contents of outfile * Modify the contents of the files from mount point * Perform glusterfind pre * Perform glusterfind post * Check the contents of outfile Files modified must be listed """ # pylint: disable=too-many-statements # Create a session for the volume ret, _, _ = gfind_create(self.mnode, self.volname, self.session) self.assertEqual(ret, 0, ("Unexpected: Creation of a session for the " "volume %s failed" % self.volname)) g.log.info("Successfully created a session for the volume %s", self.volname) # Perform glusterfind list to check if session exists _, out, _ = gfind_list(self.mnode, volname=self.volname, sessname=self.session) self.assertNotEqual(out, "No sessions found.", "Failed to list the glusterfind session") g.log.info("Successfully listed the glusterfind session") # Starting IO on the mounts cmd = "cd %s ; touch file{1..10}" % self.mounts[0].mountpoint ret, _, _ = g.run(self.mounts[0].client_system, cmd) self.assertEqual(ret, 0, "Failed to create files on mountpoint") g.log.info("Files created successfully on mountpoint") # Gather the list of files from the mount point files = list_files(self.mounts[0].client_system, self.mounts[0].mountpoint) self.assertIsNotNone(files, "Failed to get the list of files") g.log.info("Successfully gathered the list of files from mount point") # Check if the files exist for filename in files: ret = file_exists(self.mounts[0].client_system, filename) self.assertTrue(ret, ("Unexpected: File '%s' does not exist" % filename)) g.log.info("Successfully validated existence of '%s'", filename) # Wait for changelog to get updated sleep(2) # Perform glusterfind pre for the session ret, _, _ = gfind_pre(self.mnode, self.volname, self.session, self.outfiles[0], full=True, noencode=True, debug=True) self.assertEqual(ret, 0, ("Failed to perform glusterfind pre")) g.log.info("Successfully performed glusterfind pre") # Check if the outfile exists ret = file_exists(self.mnode, self.outfiles[0]) self.assertTrue(ret, ("Unexpected: File '%s' does not exist" % self.outfiles[0])) g.log.info("Successfully validated existence of '%s'", self.outfiles[0]) # Check if all the files are listed in the outfile for i in range(1, 11): ret = check_if_pattern_in_file(self.mnode, "file%s" % i, self.outfiles[0]) self.assertEqual(ret, 0, ("File 'file%s' not listed in %s" % (i, self.outfiles[0]))) g.log.info("File 'file%s' listed in %s", i, self.outfiles[0]) # Perform glusterfind post for the session ret, _, _ = gfind_post(self.mnode, self.volname, self.session) self.assertEqual(ret, 0, ("Failed to perform glusterfind post")) g.log.info("Successfully performed glusterfind post") # Modify the files created from mount point mod_string = "this is a test string\n" for filenum in files: ret = append_string_to_file(self.mounts[0].client_system, filenum, mod_string) self.assertTrue(ret, "Failed to append to file '%s'" % filenum) g.log.info("Successfully modified all the files") # Check if the files modified exist from mount point for filenum in files: ret = check_if_pattern_in_file(self.mounts[0].client_system, mod_string, filenum) self.assertEqual(ret, 0, ("Unexpected: File '%s' does not contain" " the string '%s' after being modified" % (filenum, mod_string))) g.log.info("Successfully validated '%s' is modified", filenum) # Wait for changelog to get updated sleep(2) # Perform glusterfind pre for the session ret, _, _ = gfind_pre(self.mnode, self.volname, self.session, self.outfiles[1], debug=True) self.assertEqual(ret, 0, ("Failed to perform glusterfind pre")) g.log.info("Successfully performed glusterfind pre") # Check if the outfile exists ret = file_exists(self.mnode, self.outfiles[1]) self.assertTrue(ret, ("Unexpected: File '%s' does not exist" % self.outfiles[1])) g.log.info("Successfully validated existence of outfile '%s'", self.outfiles[1]) # Check if all the files are listed in the outfile for num in range(1, 11): pattern = "MODIFY file%s" % num ret = check_if_pattern_in_file(self.mnode, pattern, self.outfiles[1]) self.assertEqual(ret, 0, ("File 'file%s' not listed in '%s'" % (num, self.outfiles[1]))) g.log.info("File 'file%s' listed in '%s'", num, self.outfiles[1])
def test_oom_on_client_heal_in_progress(self): """ - Create a 1x(2+1) arbiter replicate volume - Create IO - Bring down the 1-st data brick while creating IO - Bring up the 1-st data brick after creating and checking IO - Bring down the 3-d arbiter brick - Bring up the 3-d arbiter brick - Check there no any oom by listing the files from mountpoint """ # Creating IO on client side for mount_obj in self.mounts: g.log.info("Generating data for %s:%s", mount_obj.client_system, mount_obj.mountpoint) # Create files g.log.info('Creating files...') command = ("/usr/bin/env python %s create_files " "-f 1000 " "--fixed-file-size 10k " "%s" % (self.script_upload_path, mount_obj.mountpoint)) proc = g.run_async(mount_obj.client_system, command, user=mount_obj.user) self.all_mounts_procs.append(proc) self.io_validation_complete = False # get the bricks for the volume g.log.info("Fetching bricks for the volume: %s", self.volname) bricks_list = get_all_bricks(self.mnode, self.volname) g.log.info("Brick list: %s", bricks_list) # Bring brick 1 offline bricks_to_bring_offline = [bricks_list[0]] g.log.info('Bringing bricks %s offline...', bricks_to_bring_offline) ret = bring_bricks_offline(self.volname, bricks_to_bring_offline) self.assertTrue( ret, 'Failed to bring bricks %s offline' % bricks_to_bring_offline) ret = are_bricks_offline(self.mnode, self.volname, bricks_to_bring_offline) self.assertTrue(ret, 'Bricks %s are not offline' % bricks_to_bring_offline) g.log.info('Bringing bricks %s offline is successful', bricks_to_bring_offline) # Validate IO self.assertTrue(validate_io_procs(self.all_mounts_procs, self.mounts), "IO failed on some of the clients") self.io_validation_complete = True # Bring 1-st brick online g.log.info('Bringing bricks %s online...', bricks_to_bring_offline) ret = bring_bricks_online(self.mnode, self.volname, bricks_to_bring_offline) self.assertTrue( ret, 'Failed to bring bricks %s online' % bricks_to_bring_offline) g.log.info('Bringing bricks %s online is successful', bricks_to_bring_offline) # Bring brick 3 offline bricks_to_bring_offline = [bricks_list[-1]] g.log.info('Bringing bricks %s offline...', bricks_to_bring_offline) ret = bring_bricks_offline(self.volname, bricks_to_bring_offline) self.assertTrue( ret, 'Failed to bring bricks %s offline' % bricks_to_bring_offline) ret = are_bricks_offline(self.mnode, self.volname, bricks_to_bring_offline) self.assertTrue(ret, 'Bricks %s are not offline' % bricks_to_bring_offline) g.log.info('Bringing bricks %s offline is successful', bricks_to_bring_offline) # Bring brick 3 online g.log.info('Bringing bricks %s online...', bricks_to_bring_offline) ret = bring_bricks_online(self.mnode, self.volname, bricks_to_bring_offline) self.assertTrue( ret, 'Failed to bring bricks %s online' % bricks_to_bring_offline) g.log.info('Bringing bricks %s online is successful', bricks_to_bring_offline) # Get file list from mountpoint g.log.info('Getting file list from mountpoints...') for mount_obj in self.mounts: g.log.info("Getting file list for %s:%s", mount_obj.client_system, mount_obj.mountpoint) g.log.info('Getting file list...') file_list = list_files(mount_obj.client_system, mount_obj.mountpoint) self.assertIsNotNone(file_list) g.log.info('Getting file list from mountpoints finished successfully')