def test_nfs_ganesha_export_after_vol_restart(self): """ Tests script to check nfs-ganesha volume gets exported after multiple volume restarts. """ for i in range(1, 6): g.log.info( "Testing nfs ganesha export after volume stop/start." "Count : %s", str(i)) # Stopping volume ret = volume_stop(self.mnode, self.volname) self.assertTrue(ret, ("Failed to stop volume %s" % self.volname)) # Waiting for few seconds for volume unexport. Max wait time is # 120 seconds. ret = wait_for_nfs_ganesha_volume_to_get_unexported( self.mnode, self.volname) self.assertTrue(ret, ("Failed to unexport volume %s after " "stopping volume" % self.volname)) # Starting volume ret = volume_start(self.mnode, self.volname) self.assertTrue(ret, ("Failed to start volume %s" % self.volname)) # Waiting for few seconds for volume export. Max wait time is # 120 seconds. ret = wait_for_nfs_ganesha_volume_to_get_exported( self.mnode, self.volname) self.assertTrue(ret, ("Failed to export volume %s after " "starting volume" % self.volname))
def tearDown(self): """ Disbale ACL if enabled Unexport volume Unmount and cleanup volume """ if self.acl_check_flag: ret = set_acl(self.mnode, self.volname, False) if not ret: raise ExecutionError("Failed to disable acl on %s" % self.volname) self.acl_check_flag = False # Unexport volume unexport_nfs_ganesha_volume(self.mnode, self.volname) ret = wait_for_nfs_ganesha_volume_to_get_unexported( self.mnode, self.volname) if not ret: raise ExecutionError("Volume %s is not unexported." % self.volname) # Unmount volume ret = self.unmount_volume(self.mounts) if ret: g.log.info("Successfully unmounted the volume") else: g.log.error("Failed to unmount volume") # Cleanup volume ret = self.cleanup_volume() if not ret: raise ExecutionError("Failed to cleanup volume") g.log.info("Cleanup volume %s completed successfully", self.volname)
def tearDown(self): # Disable root-squash ret = set_root_squash(self.mnode, self.volname, squash=False, do_refresh_config=True) if not ret: raise ExecutionError("Failed to disable root-squash on nfs " "ganesha cluster") g.log.info("root-squash is disabled on volume") # Unexport volume unexport_nfs_ganesha_volume(self.mnode, self.volname) ret = wait_for_nfs_ganesha_volume_to_get_unexported( self.mnode, self.volname) if not ret: raise ExecutionError("Volume %s is not unexported." % self.volname) g.log.info("Unexporting of volume is successful") # Unmount and cleanup Volume ret = self.unmount_volume_and_cleanup_volume(self.mounts) if ret: g.log.info("Successfull unmount and cleanup of volume") else: raise ExecutionError("Failed to unmount and cleanup volume")
def test_nfs_ganesha_exportID_after_vol_restart(self): """ Tests script to check nfs-ganesha volume gets exported with same Export ID after multiple volume restarts. Steps: 1. Create and Export the Volume 2. Stop and Start the volume multiple times 3. Check for export ID Export ID should not change """ for i in range(1, 4): g.log.info( "Testing nfs ganesha exportID after volume stop and " "start.\n Count : %s", str(i)) # Stopping volume ret = volume_stop(self.mnode, self.volname) self.assertTrue(ret, ("Failed to stop volume %s" % self.volname)) g.log.info("Volume is stopped") # Waiting for few seconds for volume unexport. Max wait time is # 120 seconds. ret = wait_for_nfs_ganesha_volume_to_get_unexported( self.mnode, self.volname) self.assertTrue(ret, ("Failed to unexport volume %s after " "stopping volume" % self.volname)) g.log.info("Volume is unexported via ganesha") # Starting volume ret = volume_start(self.mnode, self.volname) self.assertTrue(ret, ("Failed to start volume %s" % self.volname)) g.log.info("Volume is started") # Waiting for few seconds for volume export. Max wait time is # 120 seconds. ret = wait_for_nfs_ganesha_volume_to_get_exported( self.mnode, self.volname) self.assertTrue(ret, ("Failed to export volume %s after " "starting volume" % self.volname)) g.log.info("Volume is exported via ganesha") # Check for Export ID cmd = ("cat /run/gluster/shared_storage/nfs-ganesha/exports/" "export.*.conf | grep Export_Id | grep -Eo '[0-9]'") ret, out, _ = g.run(self.mnode, cmd) self.assertEqual( ret, 0, "Unable to get export ID of the volume %s" % self.volname) g.log.info("Successful in getting volume export ID: %s " % out) self.assertEqual( out.strip("\n"), "2", "Export ID changed after export and unexport " "of volume: %s" % out) g.log.info("Export ID of volume is same after export " "and export: %s" % out)
def tearDown(self): """ Unexport volumes Unmount and cleanup volumes """ # Cleanup volumes created in test case for i in range(5): vol = "nfsvol" + str(i) # Unexport and cleanup volume if exists if volume_exists(self.mnode, vol): unexport_nfs_ganesha_volume(self.mnode, vol) ret = wait_for_nfs_ganesha_volume_to_get_unexported( self.mnode, vol) if not ret: raise ExecutionError("Volume %s is not unexported." % vol) ret = cleanup_volume(mnode=self.mnode, volname=vol) if not ret: raise ExecutionError("Cleanup volume %s failed" % vol) # Unexport pre existing volume unexport_nfs_ganesha_volume(self.mnode, self.volname) ret = wait_for_nfs_ganesha_volume_to_get_unexported( self.mnode, self.volname) if not ret: raise ExecutionError("Volume %s is not unexported." % self.volname) # Unmount pre existing volume ret = self.unmount_volume(self.mounts) if ret: g.log.info("Successfully unmounted the volume") else: g.log.error("Failed to unmount volume") # Cleanup pre existing volume ret = self.cleanup_volume() if not ret: raise ExecutionError("Failed to cleanup volume") g.log.info("Cleanup volume %s completed successfully", self.volname)
def tearDown(self): # Unexport volume unexport_nfs_ganesha_volume(self.mnode, self.volname) ret = wait_for_nfs_ganesha_volume_to_get_unexported( self.mnode, self.volname) if not ret: raise ExecutionError("Failed:Volume %s is not unexported." % self.volname) g.log.info("Unexporting of volume is successful") # Unmount and cleanup Volume ret = self.unmount_volume_and_cleanup_volume(self.mounts) if ret: g.log.info("Successful unmount and cleanup of volume") else: raise ExecutionError("Failed to unmount and cleanup volume")
def tearDown(self): """ Unexport volume Unmount and cleanup volume """ # Unexport volume unexport_nfs_ganesha_volume(self.mnode, self.volname) ret = wait_for_nfs_ganesha_volume_to_get_unexported( self.mnode, self.volname) if not ret: raise ExecutionError("Volume %s is not unexported" % self.volname) # Unmount volume ret = self.unmount_volume(self.mounts) if ret: g.log.info("Successfully unmounted the volume") else: g.log.error("Failed to unmount volume") # Cleanup volume ret = self.cleanup_volume() if not ret: raise ExecutionError("Failed to cleanup volume") g.log.info("Cleanup volume %s completed successfully", self.volname)
def test_nfs_ganesha_subdirectory_mount_from_server_side(self): """ Tests script to verify nfs ganesha subdirectory mount from server side succeeds and able to write IOs. """ subdir_to_mount = self.subdir_path.replace(self.mounts[0].mountpoint, '') if not subdir_to_mount.startswith(os.path.sep): subdir_to_mount = os.path.sep + subdir_to_mount subdir = self.volname + subdir_to_mount for mount_obj in self.sub_dir_mounts: mount_obj.volname = subdir export_file = ("/var/run/gluster/shared_storage/nfs-ganesha/exports/" "export.%s.conf" % self.volname) cmd = (r"sed -i s/'Path = .*'/'Path = \"\/%s\";'/g %s" % (re.escape(subdir), export_file)) ret, _, _ = g.run(self.mnode, cmd) self.assertEqual(ret, 0, ("Unable to change Path info to %s in %s" % ("/" + subdir, export_file))) cmd = ("sed -i 's/volume=.*/& \\n volpath=\"%s\";/g' %s" % (re.escape(subdir_to_mount), export_file)) ret, _, _ = g.run(self.mnode, cmd) self.assertEqual(ret, 0, ("Unable to add volpath info to %s in %s" % ("/" + subdir, export_file))) cmd = (r"sed -i s/'Pseudo=.*'/'Pseudo=\"\/%s\";'/g %s" % (re.escape(subdir), export_file)) ret, _, _ = g.run(self.mnode, cmd) self.assertEqual(ret, 0, ("Unable to change pseudo Path info to " "%s in %s" % ("/" + subdir, export_file))) # Stop and start volume to take the modified export file to effect. # Stopping volume ret = volume_stop(self.mnode, self.volname) self.assertTrue(ret, ("Failed to stop volume %s" % self.volname)) # Waiting for few seconds for volume unexport. Max wait time is # 120 seconds. ret = wait_for_nfs_ganesha_volume_to_get_unexported( self.mnode, self.volname) self.assertTrue(ret, ("Failed to unexport volume %s after " "stopping volume" % self.volname)) # Starting volume ret = volume_start(self.mnode, self.volname) self.assertTrue(ret, ("Failed to start volume %s" % self.volname)) # Waiting for few seconds for volume export. Max wait time is # 120 seconds. ret = wait_for_nfs_ganesha_volume_to_get_exported(self.mnode, subdir) self.assertTrue(ret, ("Failed to export sub directory %s after " "starting volume" % subdir)) for mount_obj in self.sub_dir_mounts: if not mount_obj.is_mounted(): ret = mount_obj.mount() self.assertTrue( ret, ("Unable to mount volume '%s:%s' " "on '%s:%s'" % (mount_obj.server_system, mount_obj.volname, mount_obj.client_system, mount_obj.mountpoint))) ret = self.start_and_wait_for_io_to_complete(self.sub_dir_mounts) self.assertTrue(ret, ("Failed to write IOs when sub directory is" " mounted from server side")) g.log.info("IO successful on clients")
def test_root_squash_enable(self): """ Tests to verify Nfs Ganesha rootsquash functionality when volume is restarted Steps: 1. Create some files and dirs inside mount point 2. Set permission as 777 for mount point 3. Enable root-squash on volume 4. Create some more files and dirs 5. Restart volume 6. Try to edit file created in step 1 It should not allow to edit the file 7. Try to edit the file created in step 5 It should allow to edit the file """ # Start IO on mount point. cmd = ("for i in {1..10}; do touch %s/file$i; done" % self.mounts[0].mountpoint) ret, _, err = g.run(self.mounts[0].client_system, cmd, user=self.mounts[0].user) self.assertEqual(ret, 0, err) # Get stat of all the files/dirs created. ret = get_mounts_stat(self.mounts) self.assertTrue(ret, "Stat failed on some of the clients") g.log.info("Successful in getting stats of files/dirs " "from mount point") # Set mount point permission to 777 ret = set_file_permissions(self.mounts[0].client_system, self.mounts[0].mountpoint, 777) self.assertTrue(ret, "Failed to set permission for directory") g.log.info("Successfully set permissions for directory") # Enable root-squash on volume ret = set_root_squash(self.servers[0], self.volname) self.assertTrue(ret, "Failed to enable root-squash on volume") g.log.info("root-squash is enable on the volume") # Start IO on mount point. cmd = ("for i in {1..10}; do touch %s/Squashfile$i; done" % self.mounts[0].mountpoint) ret, _, err = g.run(self.mounts[0].client_system, cmd, user=self.mounts[0].user) self.assertEqual(ret, 0, err) # Get stat of all the files/dirs created. ret = get_mounts_stat(self.mounts) self.assertTrue(ret, "Stat failed on some of the clients") g.log.info("Successful in getting stats of files/dirs " "from mount point") # Stopping volume ret = volume_stop(self.mnode, self.volname) self.assertTrue(ret, ("Failed to stop volume %s" % self.volname)) g.log.info("Successful in stopping volume %s" % self.volname) # Waiting for few seconds for volume unexport. Max wait time is # 120 seconds. ret = wait_for_nfs_ganesha_volume_to_get_unexported( self.mnode, self.volname) self.assertTrue(ret, ("Failed to unexport volume %s after " "stopping volume" % self.volname)) g.log.info("Volume is unexported successfully") # Starting volume ret = volume_start(self.mnode, self.volname) self.assertTrue(ret, ("Failed to start volume %s" % self.volname)) g.log.info("Successful in starting volume %s" % self.volname) # Waiting for few seconds for volume export. Max wait time is # 120 seconds. ret = wait_for_nfs_ganesha_volume_to_get_exported( self.mnode, self.volname) self.assertTrue(ret, ("Failed to export volume %s after " "starting volume" % self.volname)) g.log.info("Volume is exported successfully") # Edit file created by root user for mount_obj in self.mounts: ret = append_string_to_file(mount_obj.client_system, "%s/file10" % mount_obj.mountpoint, 'hello') self.assertFalse( ret, "Unexpected:nfsnobody user editing file " "created by root user should FAIL") g.log.info("Successful:nfsnobody user failed to edit file " "created by root user") # Edit the file created by nfsnobody user for mount_obj in self.mounts: ret = append_string_to_file( mount_obj.client_system, "%s/Squashfile5" % mount_obj.mountpoint, 'hello') self.assertTrue( ret, "Unexpected:nfsnobody user failed to edit " "the file created by nfsnobody user") g.log.info("Successful:nfsnobody user successfully edited the " "file created by nfsnobody user")