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")
Exemplo n.º 2
0
    def test_activate_deactivate(self):
        # pylint: disable=too-many-branches, too-many-statements
        """
        Verifying Snapshot activation/deactivation functionality.

        * Create Snapshot
        * Validate snapshot info before activation
        * Validate snapshot status before activation
        * Activate snapshot
        * Validate snapshot info after activation
        * Validate snapshot status after activation
        * Deactivate snapshot
        * Validate snapshot info after deactivation
        * Validate snapshot status after deactivation
        """

        # Create Snapshot
        snap_name = 'snap_%s' % self.volname
        g.log.info("Starting to Create Snapshot %s", snap_name)
        ret, _, _ = snap_create(self.mnode, self.volname, snap_name)
        self.assertEqual(ret, 0,
                         ("Snapshot Creation failed for %s", snap_name))
        g.log.info("Successfully created Snapshot %s for volume %s", snap_name,
                   self.volname)

        # Validate Snapshot Info Before Activation
        g.log.info("Validating 'snapshot info' in 'stopped' state before "
                   "activating the snapshot")
        ret = get_snap_info_by_snapname(self.mnode, snap_name)
        self.assertIsNotNone(
            ret, ("Failed to Fetch Snapshot info for %s", snap_name))
        g.log.info("Snapshot info Success for %s", ret['snapVolume']['status'])
        self.assertEqual(
            ret['snapVolume']['status'], 'Stopped',
            ("Unexpected: Snapshot %s Status is in Started state", snap_name))
        g.log.info("Expected: Snapshot is in Stopped state as it is "
                   "not Activated")

        # Validate Snapshot Status Before Activation
        g.log.info("Validating 'snapshot status' in 'stopped' state before "
                   "activating the snapshot")
        ret = get_snap_status_by_snapname(self.mnode, snap_name)
        self.assertIsNotNone(
            ret, ("Failed to Fetch Snapshot status for %s", snap_name))
        g.log.info("Snapshot Status Success for %s", snap_name)
        for brick in ret['volume']['brick']:
            self.assertEqual(brick['pid'], 'N/A',
                             ("Unexpected: Brick Pid '%s' is available for %s",
                              brick['pid'], brick['path']))
        g.log.info("Expected: Deactivated Snapshot Brick PID is 'N/A'")

        # Activate Snapshot
        g.log.info("Starting to Activate %s", snap_name)
        ret, _, _ = snap_activate(self.mnode, snap_name)
        self.assertEqual(ret, 0,
                         ("Snapshot Activation Failed for %s", snap_name))
        g.log.info("Snapshot %s Activated Successfully", snap_name)

        # Validate Snapshot Info After Activation
        g.log.info("Validating 'snapshot info' in 'started' state after"
                   " activating the snapshot")
        snap_info = get_snap_info_by_snapname(self.mnode, snap_name)
        self.assertEqual(snap_info['snapVolume']['status'], "Started",
                         ("Failed to Fetch Snapshot info after activate "
                          "for %s", snap_name))
        g.log.info("Success: Snapshot info in 'started' state")

        # Validate Snaphot Status After Activation
        g.log.info("Validating 'snapshot status' in started state after "
                   "activating the snapshot")
        ret = get_snap_status_by_snapname(self.mnode, snap_name)
        for brick in ret['volume']['brick']:
            self.assertNotEqual(brick['pid'], 'N/A',
                                ("Brick Path %s  Not Available for Activated "
                                 "Snapshot %s", (brick['path'], snap_name)))
        g.log.info("Sucessfully validated Activated Snapshot Brick Path "
                   "Available")

        # Deactivate Snapshot
        g.log.info("Starting to Deactivate %s", snap_name)
        ret, _, _ = snap_deactivate(self.mnode, snap_name)
        self.assertEqual(ret, 0,
                         ("Snapshot Deactivation Failed for %s", snap_name))
        g.log.info("Successfully Deactivated Snapshot %s", snap_name)

        # Validate Snapshot Info After Deactivation
        g.log.info("Validating 'snapshot info' in stopped state after "
                   "deactivating the snapshot")
        ret = get_snap_info_by_snapname(self.mnode, snap_name)
        self.assertEqual(ret['snapVolume']['status'], 'Stopped',
                         ("Snapshot Status is not in 'Stopped' State"))
        g.log.info("Expected: Snapshot is in Stopped state after Deactivation")

        # Validate Snaphot Status After Deactivation
        g.log.info("Validating 'snapshot status' in started state after "
                   "deactivating the snapshot")
        ret = get_snap_status_by_snapname(self.mnode, snap_name)
        for brick in ret['volume']['brick']:
            self.assertEqual(brick['pid'], 'N/A',
                             ("Deactivated Snapshot Brick Pid %s available "
                              "for %s", brick['pid'], brick['path']))
        g.log.info("Expected: Deactivated Snapshot Brick PID is 'N/A'")
    def test_snap_glusterd_down(self):
        # pylint: disable=too-many-statements
        """
        Steps:

        1. create a volume
        2. mount volume
        3. create snapshot of that volume
        4. validate using snapshot info
        5. Activate snapshot
        6. List all snapshots present
        7. validate using snapshot info
        8. Stop glusterd on one node
        9. Check glusterd status
       10. deactivate created snapshot
       11. Start glusterd on that node
       12. Check glusterd status
       13. validate using snapshot info
       13. Check all peers are connected

        """
        # Creating snapshot:
        g.log.info("Starting to Create snapshot")
        ret, _, _ = snap_create(self.mnode, self.volname, self.snap)
        self.assertEqual(ret, 0, ("Failed to create snapshot %s for volume %s"
                                  % (self.snap, self.volname)))
        g.log.info("Snapshot %s created successfully "
                   "for volume %s", self.snap, self.volname)

        # Check snapshot info
        g.log.info("Checking snapshot info")
        snap_info = get_snap_info_by_snapname(self.mnode, self.snap)
        self.assertIsNotNone(snap_info, "Failed to get snap information"
                             "for snapshot %s" % self.snap)
        status = snap_info['snapVolume']['status']
        self.assertNotEqual(status, 'Started', "snapshot %s "
                            "not started" % self.snap)
        g.log.info("Successfully checked snapshot info")

        # Activating snapshot
        g.log.info("Starting to Activate Snapshot")
        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)

        # snapshot list
        g.log.info("Starting to validate list of snapshots")
        snap_list1 = get_snap_list(self.mnode)
        self.assertIsNotNone(snap_list1, "Failed to list all the snapshot")
        self.assertEqual(len(snap_list1), 1, "Failed to validate snap list")
        g.log.info("Snapshot list successfully validated")

        # Check snapshot info
        g.log.info("Checking snapshot info")
        snap_info = get_snap_info_by_snapname(self.mnode, self.snap)
        status = snap_info['snapVolume']['status']
        self.assertEqual(status, 'Started', "Failed to"
                         "start snapshot info")
        g.log.info("Successfully checked snapshot info")

        # Stop Glusterd on one node
        g.log.info("Stopping Glusterd on one node")
        ret = stop_glusterd(self.servers[1])

        # Check Glusterd status
        g.log.info("Check glusterd running or not")
        count = 0
        while count < 80:
            ret = is_glusterd_running(self.servers[1])
            if ret == 1:
                break
            time.sleep(2)
            count += 2
        self.assertEqual(ret, 1, "Unexpected: glusterd running on node %s" %
                         self.servers[1])
        g.log.info("Expected: Glusterd not running on node %s",
                   self.servers[1])

        # de-activating snapshot
        g.log.info("Starting to de-activate Snapshot")
        ret, _, _ = snap_deactivate(self.mnode, self.snap)
        self.assertEqual(ret, 0, ("Failed to deactivate snapshot %s"
                                  % self.snap))
        g.log.info("Snapshot %s deactivated successfully", self.snap)

        # validate snapshot info
        g.log.info("Checking snapshot info")
        snap_info = get_snap_info_by_snapname(self.mnode, self.snap)
        status = snap_info['snapVolume']['status']
        self.assertNotEqual(status, 'Started', "snapshot %s "
                            "not started" % self.snap)
        g.log.info("Successfully validated snapshot info")

        # Start Glusterd on node
        g.log.info("Starting Glusterd on node %s", self.servers[1])
        ret = start_glusterd(self.servers[1])
        self.assertTrue(ret, "Failed to start glusterd on %s node"
                        % self.servers[1])
        g.log.info("Successfully started glusterd on "
                   "%s node", self.servers[1])

        # Check Glusterd status
        g.log.info("Check glusterd running or not")
        count = 0
        while count < 80:
            ret = is_glusterd_running(self.servers[1])
            if ret:
                break
            time.sleep(2)
            count += 2
        self.assertEqual(ret, 0, "glusterd not running on node %s "
                         % self.servers[1])
        g.log.info("glusterd is running on %s node",
                   self.servers[1])

        # validate snapshot info
        g.log.info("Checking snapshot info")
        snap_info = get_snap_info_by_snapname(self.mnode, self.snap)
        self.assertIsNotNone(snap_info, "Failed to get snap info for"
                             " snapshot %s" % self.snap)
        status = snap_info['snapVolume']['status']
        self.assertNotEqual(status, 'Started', "snapshot"
                            " %s failed to validate with snap info"
                            % self.snap)
        g.log.info("Successfully validated snapshot info")

        # Check all the peers are in connected state
        g.log.info("Validating all the peers are in connected state")
        for servers in self.servers:
            count = 0
            while count < 80:
                ret = is_peer_connected(self.mnode, servers)
                if ret:
                    break
                time.sleep(2)
                count += 2
            self.assertTrue(ret, "All the nodes are not in cluster")
        g.log.info("Successfully validated all the peers")
    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")
Exemplo n.º 5
0
    def test_activate_deactivate(self):
        # pylint: disable=too-many-branches, too-many-statements
        """
        Verifying Snapshot activation/deactivation functionality.
        """
        snap_name = 'snap_%s' % self.volname
        # Create Snapshot
        g.log.info("Starting to Create Snapshot %s", snap_name)
        ret, _, _ = snap_create(self.mnode, self.volname, snap_name)
        self.assertEqual(ret, 0, "Snapshot Creation failed"
                         " for %s" % snap_name)
        g.log.info("Snapshot %s of volume %s created"
                   " successfully", snap_name, self.volname)

        # Validate Snapshot Info Before Activation
        ret = get_snap_info_by_snapname(self.mnode, snap_name)
        if ret is None:
            raise ExecutionError("Failed to Fetch Snapshot"
                                 "info for %s" % snap_name)
        g.log.info("Snapshot info Success"
                   "for %s", ret['snapVolume']['status'])
        if ret['snapVolume']['status'] != 'Stopped':
            raise ExecutionError("Unexpected: "
                                 "Snapshot %s Status is in "
                                 "Started State" % snap_name)
        g.log.info("Expected: Snapshot is in Stopped state "
                   "as it is not Activated")

        # Validate Snapshot Status Before Activation
        ret = get_snap_status_by_snapname(self.mnode, snap_name)
        if ret is None:
            raise ExecutionError("Failed to Fetch Snapshot"
                                 "status for %s" % snap_name)
        g.log.info("Snapshot Status Success for %s", snap_name)
        for brick in ret['volume']['brick']:
            if brick['pid'] != 'N/A':
                raise ExecutionError(
                    "Brick Pid %s available for %s" % brick['pid'],
                    brick['path'])
        g.log.info("Deactivated Snapshot Brick PID N/A as Expected")

        # Activate Snapshot
        g.log.info("Starting to Activate %s", snap_name)
        ret, _, _ = snap_activate(self.mnode, snap_name)
        self.assertEqual(ret, 0, "Snapshot Activation Failed"
                         " for %s" % snap_name)
        g.log.info("Snapshot %s Activated Successfully", snap_name)

        # Validate Snapshot Info After Activation
        g.log.info("Validate snapshot info")
        snap_info = get_snap_info_by_snapname(self.mnode, snap_name)
        self.assertEqual(
            snap_info['snapVolume']['status'], "Started",
            "Failed to Fetch Snapshot"
            "info after activate "
            "for %s" % snap_name)
        g.log.info("Snapshot info Success ")

        # Validate Snaphot Status After Activation
        g.log.info("Validate snapshot status")
        ret = get_snap_status_by_snapname(self.mnode, snap_name)
        for brick in ret['volume']['brick']:
            self.assertNotEqual(
                brick['pid'], 'N/A', "Brick Path "
                "%s  Not Available "
                "for Activated Snapshot %s" % (brick['path'], snap_name))
        g.log.info("Activated Snapshot Brick Path " "Available as Expected")

        # Validation After Snapshot Deactivate
        g.log.info("Starting to Deactivate %s", snap_name)
        ret, _, _ = snap_deactivate(self.mnode, snap_name)
        self.assertEqual(ret, 0, "Snapshot Deactivation Failed"
                         " for %s" % snap_name)
        g.log.info("Snapshot %s Deactivation Successfully", snap_name)

        # Validate Snapshot Info After Deactivation
        ret = get_snap_info_by_snapname(self.mnode, snap_name)
        self.assertEqual(ret['snapVolume']['status'], 'Stopped',
                         "Snapshot Status is not "
                         "in Stopped State")
        g.log.info("Snapshot is in Stopped state after Deactivation")

        # Validate Snaphot Status After Activation
        g.log.info("Validate snapshot status")
        ret = get_snap_status_by_snapname(self.mnode, snap_name)
        for brick in ret['volume']['brick']:
            self.assertEqual(
                brick['pid'], 'N/A', "Deactivated "
                "Snapshot Brick "
                "Pid %s available "
                "for %s" % (brick['pid'], brick['path']))
        g.log.info("Deactivated Snapshot Brick PID N/A as Expected")