def validate_snaps(self): """ Validate snapshots under .snaps folder """ for count in range(0, 40): ret = view_snaps_from_mount(self.mount1, self.snaps_list) if ret: break sleep(2) count += 1 self.assertTrue(ret, "Failed to lists .snaps folder") g.log.info("Successfully validated snapshots from .snaps folder")
def test_uss_snap_active_deactive(self): # pylint: disable=too-many-statements """ Steps: * Create volume * Mount volume * Perform I/O on mounts * Create 2 snapshots snapy1 & snapy2 * Validate snap created * Enable USS * Validate USS is enabled * Validate snapd is running * Activate snapy1 & snapy2 * List snaps under .snap directory -- snap1 and snap2 should be listed under .snaps * Deactivate snapy2 * List snaps under .snap directory -- snapy2 is not listed as it is deactivated * Activate snapy2 * List snaps under .snap directory -- snap1 and snap2 should be listed under .snaps """ # Perform I/O g.log.info("Starting IO on all mounts...") self.counter = 1 self.all_mounts_procs = [] for mount_obj in self.mounts: g.log.info("Starting IO on %s:%s", mount_obj.client_system, mount_obj.mountpoint) cmd = ( "python %s create_deep_dirs_with_files " "--dirname-start-num %d " "--dir-depth 2 " "--dir-length 2 " "--max-num-of-dirs 2 " "--num-of-files 2 %s" % (self.script_upload_path, self.counter, mount_obj.mountpoint)) proc = g.run_async(mount_obj.client_system, cmd, user=mount_obj.user) self.all_mounts_procs.append(proc) self.io_validation_complete = False # Validate IO g.log.info("Wait for IO to complete and validate IO ...") ret = validate_io_procs(self.all_mounts_procs, self.mounts) self.assertTrue(ret, "IO failed on some of the clients") self.io_validation_complete = True g.log.info("I/O successful on clients") # Enable USS g.log.info("Enable USS on volume") ret, _, _ = enable_uss(self.mnode, self.volname) self.assertEqual(ret, 0, "Failed to enable USS on volume") g.log.info("Successfully enabled USS on volume") # Validate USS is enabled g.log.info("Validating USS is enabled") ret = is_uss_enabled(self.mnode, self.volname) self.assertTrue(ret, "USS is disabled on volume " "%s" % self.volname) g.log.info("USS enabled on volume %s", self.volname) # Validate snapd running for server in self.servers: g.log.info("Validating snapd daemon on:%s", server) ret = is_snapd_running(server, self.volname) self.assertTrue(ret, "Snapd is Not running on " "%s" % server) g.log.info("Snapd Running on node: %s", server) # Create 2 snapshot g.log.info("Creating 2 snapshots for volume %s", self.volname) for i in range(1, 3): ret, _, _ = snap_create(self.mnode, self.volname, "snapy%s" % i) self.assertEqual( ret, 0, ("Failed to create snapshot for %s" % self.volname)) g.log.info("Snapshot %s created successfully for volume %s", "snapy%s" % i, self.volname) # Check for no of snaps using snap_list it should be 2 now snap_list = get_snap_list(self.mnode) self.assertEqual( 2, len(snap_list), "No of snaps not consistent " "for volume %s" % self.volname) g.log.info("Successfully validated number of snaps.") # Activate snapshot snapy1 & snapy2 g.log.info("Activating snapshot snapy1 & snapy2") for i in range(1, 3): ret, _, _ = snap_activate(self.mnode, "snapy%s" % i) self.assertEqual(ret, 0, "Failed to activate snapshot snapy%s" % i) g.log.info("Both snapshots activated successfully") # list activated snapshots directory under .snaps g.log.info("Listing activated snapshots under .snaps") for mount_obj in self.mounts: ret, out, _ = uss_list_snaps(mount_obj.client_system, mount_obj.mountpoint) self.assertEqual( ret, 0, "Directory Listing Failed for" " Activated Snapshot") validate_dir = out.split('\n') self.assertIn( "snapy1", validate_dir, "Failed to " "validate snapy1 under .snaps directory") g.log.info("Activated Snapshot snapy1 listed Successfully") self.assertIn( "snapy2", validate_dir, "Successfully listed" " snapy2 under.snaps directory") g.log.info("Expected: De-activated Snapshot not listed") # Deactivate snapshot snapy2 g.log.info("Deactivating snapshot snapy2") ret, _, _ = snap_deactivate(self.mnode, "snapy2") self.assertEqual(ret, 0, "Failed to deactivate snapshot snapy2") g.log.info("Successfully deactivated snapshot snapy2") # validate snapy2 should not present in mountpoint ret = view_snaps_from_mount(self.mounts, "snapy2") self.assertFalse( ret, " UnExpected : Still able to View snapy2" " from mount ") g.log.info("Successfully verified deactivated snapshot " "snapy2 is not listed") # Activate snapshot snapy2 ret, _, _ = snap_activate(self.mnode, "snapy2") self.assertEqual(ret, 0, "Failed to activate Snapshot snapy2") g.log.info("Snapshot snapy2 activated successfully") # list activated snapshots directory under .snaps g.log.info("Listing activated snapshots under .snaps") for mount_obj in self.mounts: ret, out, _ = uss_list_snaps(mount_obj.client_system, mount_obj.mountpoint) self.assertEqual( ret, 0, "Directory Listing Failed for" " Activated Snapshot") validate_dir = out.split('\n') self.assertIn( "snapy1", validate_dir, "Failed to " "validate snapy%s under .snaps directory") g.log.info("Activated Snapshot listed Successfully") self.assertIn( "snapy2", validate_dir, "Successfully listed" "snapy2 under .snaps directory") g.log.info("Expected: De-activated Snapshot not listed")
def test_snapshot_basic_commands_when_io_in_progress(self): """Create, List, Activate, Enable USS (User Serviceable Snapshot), Viewing Snap of the volume from mount, De-Activate when IO is in progress. """ snap_name = "snap_cvt" # Create Snapshot g.log.info("Creating snapshot %s of the volume %s", snap_name, self.volname) ret, _, _ = snap_create(self.mnode, self.volname, snap_name) self.assertEqual(ret, 0, ("Failed to create snapshot with name %s " " of the volume %s", snap_name, self.volname)) g.log.info("Successfully created snapshot %s of the volume %s", snap_name, self.volname) # List Snapshot g.log.info("Listing the snapshot created for the volume %s", self.volname) snap_list = get_snap_list(self.mnode) self.assertIsNotNone(snap_list, "Unable to get the Snapshot list") self.assertIn(snap_name, snap_list, ("snapshot %s not listed in Snapshot list", snap_name)) g.log.info("Successfully listed snapshot %s in gluster snapshot list", snap_name) # Activate the snapshot g.log.info("Activating snapshot %s of the volume %s", snap_name, self.volname) ret, _, _ = snap_activate(self.mnode, snap_name) self.assertEqual(ret, 0, ("Failed to activate snapshot with name %s " " of the volume %s", snap_name, self.volname)) g.log.info("Successfully activated snapshot %s of the volume %s", snap_name, self.volname) # Enable USS on the volume. uss_options = ["features.uss"] if self.mount_type == "cifs": uss_options.append("features.show-snapshot-directory") g.log.info("Enable uss options %s on the volume %s", uss_options, self.volname) ret = enable_and_validate_volume_options(self.mnode, self.volname, uss_options, time_delay=30) self.assertTrue(ret, ("Unable to enable uss options %s on volume %s", uss_options, self.volname)) g.log.info("Successfully enabled uss options %s on the volume: %s", uss_options, self.volname) # Viewing snapshot from mount g.log.info("Viewing Snapshot %s from mounts:", snap_name) ret = view_snaps_from_mount(self.mounts, snap_name) self.assertTrue(ret, ("Failed to View snap %s from mounts", snap_name)) g.log.info("Successfully viewed snap %s from mounts", snap_name) # De-Activate the snapshot g.log.info("Deactivating snapshot %s of the volume %s", snap_name, self.volname) ret, _, _ = snap_deactivate(self.mnode, snap_name) self.assertEqual(ret, 0, ("Failed to deactivate snapshot with name %s " " of the volume %s", snap_name, self.volname)) g.log.info("Successfully deactivated snapshot %s of the volume %s", snap_name, self.volname) # Viewing snapshot from mount (.snaps shouldn't be listed from mount) for mount_obj in self.mounts: g.log.info("Viewing Snapshot %s from mount %s:%s", snap_name, mount_obj.client_system, mount_obj.mountpoint) ret = view_snaps_from_mount(mount_obj, snap_name) self.assertFalse(ret, ("Still able to View snap %s from mount " "%s:%s", snap_name, mount_obj.client_system, mount_obj.mountpoint)) g.log.info("%s not listed under .snaps from mount %s:%s", snap_name, mount_obj.client_system, mount_obj.mountpoint) g.log.info( "%s not listed under .snaps from mounts after " "deactivating ", snap_name) # Validate IO g.log.info("Wait for IO to complete and validate IO ...") ret = validate_io_procs(self.all_mounts_procs, self.mounts) self.io_validation_complete = True self.assertTrue(ret, "IO failed on some of the clients") g.log.info("IO is successful on all mounts") # List all files and dirs created g.log.info("List all files and directories:") ret = list_all_files_and_dirs_mounts(self.mounts) self.assertTrue(ret, "Failed to list all files and dirs") g.log.info("Listing all files and directories is successful")
def test_validate_snaps_dir_over_uss(self): # pylint: disable=too-many-statements """ Run IOs on mount and take 2 snapshot. Activate 1 snapshot and check directory listing. Try to write to .snaps should not allow. Try listing the other snapshot should fail. """ # run IOs self.counter = 1 g.log.info("Starting IO on all mounts...") self.all_mounts_procs = [] for mount_obj in self.mounts: g.log.info("Starting IO on %s:%s", mount_obj.client_system, mount_obj.mountpoint) cmd = ( "/usr/bin/env python %s create_deep_dirs_with_files " "--dirname-start-num %d " "--dir-depth 2 " "--dir-length 2 " "--max-num-of-dirs 2 " "--num-of-files 2 %s" % (self.script_upload_path, self.counter, mount_obj.mountpoint)) proc = g.run_async(mount_obj.client_system, cmd, user=mount_obj.user) self.all_mounts_procs.append(proc) self.io_validation_complete = False # 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 # get the snapshot list. snap_list = get_snap_list(self.mnode) self.assertEqual(len(snap_list), 0, "Unexpected: %s snapshots" "present" % len(snap_list)) g.log.info("Expected: No snapshots present") # Create 2 snapshot g.log.info("Starting to Create Snapshots") for snap_num in range(0, 2): ret, _, _ = snap_create(self.mnode, self.volname, "snap-%s" % snap_num) self.assertEqual( ret, 0, "Snapshot Creation failed" " for snap-%s" % snap_num) g.log.info("Snapshot snap-%s of volume %s created" " successfully", snap_num, self.volname) # Activate snap-0 g.log.info("Activating snapshot snap-0") ret, _, _ = snap_activate(self.mnode, "snap-0") self.assertEqual(ret, 0, "Failed to activate " "Snapshot snap-0") g.log.info("Snapshot snap-0 Activated Successfully") # Enable USS for volume g.log.info("Enable uss for volume") ret, _, _ = enable_uss(self.mnode, self.volname) self.assertEqual( ret, 0, "Failed to enable USS for " " volume %s" % self.volname) g.log.info("Successfully enabled USS " "for volume %s", self.volname) # Validate uss enabled g.log.info("Validating uss enabled") ret = is_uss_enabled(self.mnode, self.volname) self.assertTrue(ret, "Failed to validate uss enable") g.log.info("Successfully validated uss enable for volume" "%s", self.volname) # list activated snapshots directory under .snaps g.log.info("Listing activated snapshots under .snaps") for mount_obj in self.mounts: ret, out, _ = uss_list_snaps(mount_obj.client_system, mount_obj.mountpoint) self.assertEqual( ret, 0, "Directory Listing Failed for" " Activated Snapshot") validate_dir = out.split('\n') self.assertIn( 'snap-0', validate_dir, "Failed to " "validate snap-0 under .snaps directory") g.log.info("Activated Snapshot Successfully listed") self.assertNotIn( 'snap-1', validate_dir, "Unexpected: " "Successfully listed snap-1 under " ".snaps directory") g.log.info("Expected: De-activated Snapshot not listed") # start I/0 ( write and read ) g.log.info("Starting IO on all mounts...") all_mounts_procs = [] for mount_obj in self.mounts: cmd = ("/usr/bin/env python %s create_files " "-f 10 --base-file-name file %s/.snaps/abc/" % (self.script_upload_path, mount_obj.mountpoint)) proc = g.run_async(mount_obj.client_system, cmd, user=mount_obj.user) all_mounts_procs.append(proc) # IO should fail g.log.info("IO should Fail with ROFS error.....") self.assertFalse(validate_io_procs(all_mounts_procs, self.mounts), "Unexpected: IO successfully completed") g.log.info("Expected: IO failed to complete") # validate snap-0 present in mountpoint ret = view_snaps_from_mount(self.mounts, "snap-0") self.assertTrue( ret, "UnExpected: Unable to list content " "in activated snapshot" " activated snapshot") g.log.info("Expected: Successfully listed contents in" " activated snapshot")
def test_snap_uss_while_io(self): # pylint: disable=too-many-statements """ Steps: 1. Create volume 2. enable uss on created volume 3. validate uss running 4. validate snapd running on all nodes 5. perform io on mounts 6. create 10 snapshots with description 7. validate with snapshot list 8. validate io is completed 9. Activate snapshots to list all snaps under .snaps 10. validate snapshots under .snaps directory """ # Enable USS g.log.info("Enable USS for volume") ret, _, _ = enable_uss(self.mnode, self.volname) self.assertEqual(ret, 0, "Failed to enable USS on volume" "%s" % self.volname) g.log.info("Successfully enabled USS on volume %s", self.volname) # Validate USS running g.log.info("Validating USS enabled or disabled") ret = is_uss_enabled(self.mnode, self.volname) self.assertTrue( ret, "Failed to validate USS for volume " "%s" % self.volname) g.log.info("Successfully validated USS for Volume" "%s", self.volname) # Validate snapd running for server in self.servers: g.log.info("Validating snapd daemon on:%s", server) ret = is_snapd_running(server, self.volname) self.assertTrue(ret, "Snapd is Not running on " "%s" % server) g.log.info("Snapd Running on node: %s", server) # Perform I/O g.log.info("Starting to Perform I/O") all_mounts_procs = [] 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 = ( "python %s create_files -f 100 --fixed-file-size 1M %s" % (self.script_upload_path, mount_obj.mountpoint)) proc = g.run_async(mount_obj.client_system, command, user=mount_obj.user) all_mounts_procs.append(proc) self.io_validation_complete = False # Creating snapshot with description g.log.info("Starting to Create snapshot") for count in range(0, self.snap_count): self.snap = "snap%s" % count ret, _, _ = snap_create(self.mnode, self.volname, self.snap, description='$p3C!@l C#@R@cT#R$') self.assertEqual( ret, 0, ("Failed to create snapshot for volume %s" % self.volname)) g.log.info("Snapshot %s created successfully" " for volume %s", self.snap, self.volname) # Validate snapshot list g.log.info("Starting to list all snapshots") ret, out, _ = snap_list(self.mnode) self.assertEqual( ret, 0, ("Failed to list snapshot of volume %s" % self.volname)) s_list = out.strip().split('\n') self.assertEqual(len(s_list), self.snap_count, "Failed to validate " "all snapshots") g.log.info( "Snapshot listed and Validated for volume %s" " successfully", self.volname) # Activating snapshot g.log.info("Activating snapshot") for count in range(0, self.snap_count): self.snap = "snap%s" % count ret, _, _ = snap_activate(self.mnode, self.snap) self.assertEqual(ret, 0, "Failed to Activate snapshot " "%s" % self.snap) g.log.info("snapshot %s activated successfully", self.snap) # Validate IO is completed self.assertTrue(validate_io_procs(all_mounts_procs, self.mounts), "IO failed on some of the clients") self.io_validation_complete = True # validate snapshots are listed under .snaps directory g.log.info("Validating snaps under .snaps") ret = view_snaps_from_mount(self.mounts, s_list) self.assertTrue(ret, "Failed to list snaps under .snaps" "directory") g.log.info("Snapshots Validated successfully")
def validate_snaps(self): # Validate snapshots under .snaps folder g.log.info("Validating snapshots under .snaps") ret = view_snaps_from_mount(self.mounts, self.snaps_list) self.assertTrue(ret, "Failed to lists .snaps folder") g.log.info("Successfully validated snapshots under .snaps")