def test_gfind_when_brick_down(self): """ Verifying the glusterfind functionality when a brick is down. 1. Create a volume 2. Create a session on the volume 3. Create various files from mount point 4. Bring down brick process on one of the node 5. Perform glusterfind pre 6. Perform glusterfind post 7. Check the contents of outfile """ # 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") self._perform_io_and_validate_presence_of_files() # Wait for changelog to get updated sleep(2) # Bring one of the brick down. brick_list = get_all_bricks(self.mnode, self.volname) ret = bring_bricks_offline(self.volname, choice(brick_list)) self.assertTrue(ret, "Failed to bring down the brick.") g.log.info("Succesfully brought down one brick.") self._perform_glusterfind_pre_and_validate_outfile() # 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") # Bring the brick process up. ret = volume_start(self.mnode, self.volname, force=True) self.assertTrue(ret, "Failed to start the volume.") g.log.info("Successfully started the volume.")
def test_gfind_when_node_down(self): """ Verifying the glusterfind functionality when node is down. 1. Create a volume 2. Create a session on the volume 3. Create various files from mount point 4. Bring down glusterd on one of the node 5. Perform glusterfind pre 6. Perform glusterfind post 7. Check the contents of outfile 8. Create more files from mountpoint 9. Reboot one of the nodes 10. Perform gluserfind pre 11. Perform glusterfind post 12. Check the contents of outfile """ # 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") self._perform_io_and_validate_presence_of_files() # Wait for changelog to get updated sleep(2) # Bring one of the node down. self.random_server = choice(self.servers[1:]) ret = stop_glusterd(self.random_server) self.assertTrue(ret, "Failed to stop glusterd on one node.") g.log.info("Succesfully stopped glusterd on one node.") # Wait till glusterd is completely down. while is_glusterd_running(self.random_server) != 1: sleep(2) self._perform_glusterfind_pre_and_validate_outfile() # 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") # Bring glusterd which was downed on a random node, up. ret = start_glusterd(self.random_server) self.assertTrue(ret, "Failed to start glusterd on %s" % self.random_server) g.log.info("Successfully started glusterd on node : %s", self.random_server) # Waiting for glusterd to start completely. ret = wait_for_glusterd_to_start(self.random_server) self.assertTrue(ret, "glusterd is not running on %s" % self.random_server) g.log.info("glusterd is started and running on %s", self.random_server) self._perform_io_and_validate_presence_of_files() # Perform IO self._perform_io_and_validate_presence_of_files() # Wait for changelog to get updated sleep(2) # Reboot one of the nodes. self.random_server = choice(self.servers[1:]) ret = reboot_nodes(self.random_server) self.assertTrue(ret, "Failed to reboot the said node.") g.log.info("Successfully started reboot process on one node.") self._perform_glusterfind_pre_and_validate_outfile() # 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") # Gradual sleep backoff till the node has rebooted. counter = 0 timeout = 300 ret = False while counter < timeout: ret, _ = are_nodes_online(self.random_server) if not ret: g.log.info("Node's offline, Retrying after 5 seconds ...") sleep(5) counter += 5 else: ret = True break self.assertTrue(ret, "Node is still offline.") g.log.info("Rebooted node is online") # Wait for glusterd to start completely ret = wait_for_glusterd_to_start(self.random_server) self.assertTrue(ret, "glusterd is not running on %s" % self.random_server) g.log.info("glusterd is started and running on %s", self.random_server)
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_gfind_deletes(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 * Delete the files created from mount point * Perform glusterfind pre * Perform glusterfind post * Check the contents of outfile Files deleted must be listed """ # pylint: disable=too-many-statements # Creating a session for the volume g.log.info("Creating a session for the volume %s", self.volname) 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 g.log.info("Performing glusterfind list to check if the session is " "created") ret, _, _ = gfind_list(self.mnode, volname=self.volname, sessname=self.session) self.assertEqual(ret, 0, "Failed to list the glusterfind session") g.log.info("Successfully listed the glusterfind session") # Starting IO on the mounts g.log.info("Creating Files on %s:%s", self.mounts[0].client_system, self.mounts[0].mountpoint) cmd = ("cd %s ; for i in `seq 1 10` ; " "do dd if=/dev/urandom of=file$i bs=1M count=1 ; " "done" % 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") # Check if the files exist g.log.info("Checking the existence of files created during IO") for i in range(1, 11): ret = file_exists(self.mounts[0].client_system, '%s/file%s' % (self.mounts[0].mountpoint, i)) self.assertTrue(ret, "Unexpected: File 'file%s' does not exist" % i) g.log.info("Successfully validated existence of 'file%s'", i) sleep(5) # Perform glusterfind pre for the session g.log.info("Performing glusterfind pre for the session %s", self.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 g.log.info("Checking if outfile created during glusterfind pre command" " 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 g.log.info("Performing glusterfind post for the session %s", self.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") # Delete the files created from mount point g.log.info("Deleting the Files on %s:%s", self.mounts[0].client_system, self.mounts[0].mountpoint) for i in range(1, 11): ret = remove_file(self.mounts[0].client_system, "%s/file%s" % (self.mounts[0].mountpoint, i), force=True) self.assertTrue(ret, "Failed to delete file%s" % i) g.log.info("Successfully deleted all the files") # Check if the files deleted exist from mount point g.log.info("Checking the existence of files that were deleted " "(must not be present)") for i in range(1, 11): ret = file_exists(self.mounts[0].client_system, '%s/file%s' % (self.mounts[0].mountpoint, i)) self.assertFalse( ret, "Unexpected: File 'file%s' exists even after" " being deleted" % i) g.log.info("Successfully validated 'file%s' does not exist", i) sleep(5) # Perform glusterfind pre for the session g.log.info("Performing glusterfind pre for the session %s", self.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 g.log.info("Checking if outfile created during glusterfind pre command" " 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 '%s'", self.outfiles[1]) # Check if all the files are listed in the outfile for i in range(1, 11): pattern = "DELETE file%s" % i ret = check_if_pattern_in_file(self.mnode, pattern, self.outfiles[1]) self.assertEqual(ret, 0, ("File 'file%s' not listed in %s" % (i, self.outfiles[1]))) g.log.info("File 'file%s' listed in %s", i, self.outfiles[1])
def test_gfind_pre_cli(self): """ Verifying the glusterfind pre command functionality with valid and invalid values for the required and optional parameters. * Create a volume * Create a session on the volume * Perform some I/O from the mount point * Perform glusterfind pre with the following combinations: - Valid values for required parameters - Invalid values for required parameters - Valid values for optional parameters - Invalid values for optional parameters * Perform glusterfind post Where Required parameters: volname, sessname and outfile Optional parameters: full, debug, gftype, tagforfullfind, namespace, noencode, disablepartial, regenoutfile, outprefix, fieldsep """ # pylint: disable=too-many-statements # Creating a session for the volume g.log.info("Creating a session for the volume %s", self.volname) 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 g.log.info("Performing glusterfind list to check if the session is " "created") ret, _, _ = gfind_list(self.mnode, volname=self.volname, sessname=self.session) self.assertEqual(ret, 0, "Failed to list the glusterfind session") g.log.info("Successfully listed the glusterfind session") # Starting IO on the mounts mount_obj = self.mounts[0] mount_dir = mount_obj.mountpoint client = mount_obj.client_system g.log.info("Creating Files on %s:%s", client, mount_dir) cmd = ("cd %s ; for i in `seq 1 10` ; " "do dd if=/dev/urandom of=file$i bs=1M count=1 ; " "done" % mount_dir) ret, _, _ = g.run(client, cmd) self.assertEqual(ret, 0, "Failed to create files on mountpoint") g.log.info("Files created successfully on mountpoint") # Check if the files exist g.log.info("Checking the existence of files created during IO") for i in range(1, 11): ret = file_exists(client, '%s/file%s' % (mount_dir, i)) self.assertTrue(ret, "Unexpected: File 'file%s' does not exist" % i) g.log.info("Successfully validated existence of 'file%s'", i) # Perform glusterfind pre for the session g.log.info("Performing glusterfind pre for the session %s", self.session) ret, _, _ = gfind_pre(self.mnode, self.volname, self.session, self.outfile, 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 g.log.info("Checking if outfile created during glusterfind pre command" " exists") ret = file_exists(self.mnode, self.outfile) self.assertTrue(ret, "Unexpected: File '%s' does not exist" % self.outfile) g.log.info("Successfully validated existence of '%s'", self.outfile) # 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.outfile) self.assertEqual(ret, 0, ("File 'file%s' not listed in %s" % (i, self.outfile))) g.log.info("File 'file%s' listed in %s", i, self.outfile) # Perform glusterfind post for the session g.log.info("Performing glusterfind post for the session %s", self.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") # Perform glusterfind pre using the invalid values for required # parameters not_volume = 'invalid-volume-name' not_session = 'invalid-session-name' not_outfile = '/tmp/not' g.log.info("Performing glusterfind pre with invalid values for the " "required parameters") ret, _, _ = gfind_pre(self.mnode, not_volume, not_session, not_outfile) self.assertNotEqual( ret, 0, "Unexpected: glusterfind pre Successful " "even with invalid values for required parameters") g.log.info("Successful: glusterfind pre failed with invalid values " "for required parameters") # Perform glusterfind pre using the invalid values for optional # parameters g.log.info("Deleting the session with invalid values for the optional " "parameters") invalid_options = [ ' --dbug', ' --noencod', ' --regenout', ' --type n', ' --tagforfullfind', ' --disablepartial', ' --fll' ' --outprefix none', ' --namespc' ] for opt in invalid_options: ret, _, _ = g.run( self.mnode, ("glusterfind pre %s %s %s %s" % (self.volname, self.session, self.outfile, opt))) self.assertNotEqual( ret, 0, "Unexpected: glusterfind pre " " successful for option %s which is invalid" % opt) g.log.info("Successful: glusterfind pre failed with invalid value " "for optional parameters")