def tearDown(self):
        """
        tearDown for every test
        """
        ret, _, _ = snap_delete_all(self.mnode)
        if ret != 0:
            raise ExecutionError("Snapshot Delete Failed")
        ret, _, _ = set_snap_config(self.mnode, self.option_disable)
        if ret != 0:
            raise ExecutionError("Failed to execute set_snap_config")
        ret = get_snap_config(self.mnode, self.volname)
        if ret is None:
            raise ExecutionError("Failed to execute get_snap_config")
        if 'disable' not in ret['systemConfig']['activateOnCreate']:
            raise ExecutionError("Failed to disable activate-on-create")
        g.log.info("set_snap_config Success to disable "
                   "activate-on-create")

        # Cleanup-volume
        ret = self.cleanup_volume()
        if not ret:
            raise ExecutionError("Failed to Cleanup Volume")
        g.log.info("Successful in Cleanup Volume")

        # Calling GlusterBaseClass tearDown
        self.get_super_method(self, 'tearDown')()
    def tearDown(self):
        """
        tearDown for every test
        """
        ret, _, _ = snap_delete_all(self.mnode)
        self.assertEqual(ret, 0, "Snapshot Delete Failed")
        ret, _, _ = set_snap_config(self.mnode, self.option_disable)
        self.assertEqual(ret, 0, "Failed to execute set_snap_config")
        ret = get_snap_config(self.mnode, self.volname)
        if ret is None:
            raise ExecutionError("Failed to execute get_snap_config")
        if 'disable' not in ret['systemConfig']['activateOnCreate']:
            raise ExecutionError("Failed to disable activate-on-create")
        g.log.info("set_snap_config Success to disable " "activate-on-create")

        # Calling GlusterBaseClass tearDown
        GlusterBaseClass.tearDown.im_func(self)
Пример #3
0
    def setUp(self):
        """
        Initialize necessary variables.
        """
        # Calling GlusterBaseClass setUp
        self.get_super_method(self, 'setUp')()

        # Gather the default snapshot config option values
        self.snap_conf = get_snap_config(self.mnode)
        self.assertIsNotNone(self.snap_conf,
                             "Failed to get the snapshot config options")
        softlim = self.snap_conf['systemConfig']['softLimit']
        self.def_conf_softlim = {'snap-max-soft-limit': softlim[:-1]}
        autodel = self.snap_conf['systemConfig']['autoDelete']
        self.def_conf_autodel = {'auto-delete': autodel}
        g.log.info("Successfully gathered the default snapshot config options")

        self.snapshots = [
            ('snap-test-snap-auto-delete-%s-%s' % (self.volname, i))
            for i in range(0, 20)
        ]
Пример #4
0
    def test_validate_snaps_restore(self):
        # pylint: disable=too-many-statements
        # Start IO on all mounts.
        all_mounts_procs = []
        count = 1
        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 10 "
                   "--max-num-of-dirs 5 "
                   "--num-of-files 5 %s" %
                   (self.script_upload_path, count, mount_obj.mountpoint))
            proc = g.run_async(mount_obj.client_system,
                               cmd,
                               user=mount_obj.user)
            all_mounts_procs.append(proc)
            count = count + 10

        # Validate IO
        g.log.info("Validating IO's")
        ret = validate_io_procs(all_mounts_procs, self.mounts)
        self.assertTrue(ret, "IO failed on some of the clients")
        g.log.info("Successfully validated all io's")

        # Get stat of all the files/dirs created.
        g.log.info("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("Successfully got stat of all files/dirs created")

        # Setting some volume option related to snapshot
        option_before_restore = {
            'volumeConfig': [{
                'softLimit': '100',
                'effectiveHardLimit': '200',
                'hardLimit': '256'
            }],
            'systemConfig': {
                'softLimit': '90%',
                'activateOnCreate': 'disable',
                'hardLimit': '256',
                'autoDelete': 'disable'
            }
        }
        ret = set_snap_config(self.mnode, option_before_restore)
        self.assertTrue(ret,
                        ("Failed to set vol option on  %s" % self.volname))
        g.log.info("Volume options for%s is set successfully", self.volname)

        # Get brick list before taking snap_restore
        bricks_before_snap_restore = get_all_bricks(self.mnode, self.volname)
        g.log.info("Brick List before snap restore "
                   "volume: %s", bricks_before_snap_restore)

        # Creating snapshot
        ret = snap_create(self.mnode, self.volname, "snap1")
        self.assertTrue(ret,
                        ("Failed to create snapshot for %s" % self.volname))
        g.log.info("Snapshot snap1 created successfully for volume  %s",
                   self.volname)

        # Again start IO on all mounts.
        all_mounts_procs = []
        count = 1000
        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 10 "
                   "--max-num-of-dirs 5 "
                   "--num-of-files 5 %s" %
                   (self.script_upload_path, count, mount_obj.mountpoint))
            proc = g.run_async(mount_obj.client_system,
                               cmd,
                               user=mount_obj.user)
            all_mounts_procs.append(proc)
            count = count + 10

        # Validate IO
        g.log.info("Validating IO's")
        ret = validate_io_procs(all_mounts_procs, self.mounts)
        self.assertTrue(ret, "IO failed on some of the clients")
        g.log.info("Successfully validated all io's")

        # Get stat of all the files/dirs created.
        g.log.info("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("Successfully got stat of all files/dirs created")

        # Reset volume to make sure volume options will reset
        ret = volume_reset(self.mnode, self.volname, force=False)
        self.assertTrue(ret, ("Failed to reset %s" % self.volname))
        g.log.info("Reset Volume %s is Successful", self.volname)

        # Removing one brick
        g.log.info("Starting volume shrink")
        ret = shrink_volume(self.mnode, self.volname, force=True)
        self.assertTrue(ret, ("Failed to shrink the volume on "
                              "volume %s", self.volname))
        g.log.info("Shrinking volume is successful on "
                   "volume %s", self.volname)

        # Restore snapshot
        ret = snap_restore_complete(self.mnode, self.volname, "snap1")
        self.assertTrue(ret, ("Failed to restore snap snap1 on the "
                              "volume %s", self.volname))
        g.log.info(
            "Restore of volume is successful from snap1 on "
            "volume  %s", self.volname)

        # Validate volume is up and running
        g.log.info("Verifying volume is up and process are online")
        ret = verify_all_process_of_volume_are_online(self.mnode, self.volname)
        self.assertTrue(
            ret, ("Volume %s : All process are not online", self.volname))
        g.log.info("Volume %s : All process are online", self.volname)

        # Get volume options post restore
        option_after_restore = get_snap_config(self.mnode)
        # Compare volume options
        self.assertNotEqual(option_before_restore, option_after_restore,
                            "Volume Options are not same after snap restore")

        # Get brick list post restore
        bricks_after_snap_restore = get_all_bricks(self.mnode, self.volname)
        g.log.info("Brick List after snap restore "
                   "volume: %s", bricks_after_snap_restore)
        # Compare brick_list
        self.assertNotEqual(bricks_before_snap_restore,
                            bricks_after_snap_restore,
                            "Bricks are not same after snap restore")

        # Creating snapshot
        ret = snap_create(self.mnode, self.volname, "snap2")
        self.assertTrue(ret,
                        ("Failed to create snapshot for %s" % self.volname))
        g.log.info("Snapshot snap2 created successfully for volume  %s",
                   self.volname)

        # Again start IO on all mounts after restore
        all_mounts_procs = []
        count = 1000
        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 10 "
                   "--max-num-of-dirs 5 "
                   "--num-of-files 5 %s" %
                   (self.script_upload_path, count, mount_obj.mountpoint))
            proc = g.run_async(mount_obj.client_system,
                               cmd,
                               user=mount_obj.user)
            all_mounts_procs.append(proc)
            count = count + 10

        # Validate IO
        g.log.info("Validating IO's")
        ret = validate_io_procs(all_mounts_procs, self.mounts)
        self.assertTrue(ret, "IO failed on some of the clients")
        g.log.info("Successfully validated all io's")

        # Get stat of all the files/dirs created.
        g.log.info("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("Successfully got stat of all files/dirs created")
Пример #5
0
    def test_snap_auto_delete(self):
        """
        Verifying snapshot auto-delete config option

        * Enable auto-delete snapshot
        * Set snap-max-hard limit and snap-max-soft-limit
        * Validate snap-max-hard-limit and snap-max-soft-limit
        * Verify the limits by creating another 20 snapshots
        * Oldest of newly created snapshots will be deleted
        * Retaining the latest 8 (softlimit) snapshots
        * Cleanup snapshots and volumes
        """

        # pylint: disable=too-many-statements
        # Enable auto-delete snapshot config option
        ret, _, _ = set_snap_config(self.mnode, self.autodel_enable)
        self.assertEqual(ret, 0, ("Failed to enable auto-delete snapshot "
                                  "config option on volume %s", self.volname))
        g.log.info("Successfully enabled snapshot auto-delete")

        # Set snap-max-hard-limit snapshot config option for volume
        max_hard_limit = {'snap-max-hard-limit': '10'}
        ret, _, _ = set_snap_config(self.mnode, max_hard_limit, self.volname)
        self.assertEqual(ret, 0, ("Failed to set snap-max-hard-limit"
                                  "config option for volume %s", self.volname))
        g.log.info(
            "Successfully set snap-max-hard-limit config option for"
            "volume %s", self.volname)

        # Validate snap-max-hard-limit snapshot config option
        hard_limit_val = get_snap_config(self.mnode)
        self.assertEqual(hard_limit_val['volumeConfig'][0]['hardLimit'], '10',
                         ("Failed to Validate snap-max-hard-limit"))
        g.log.info("Successfully validated snap-max-hard-limit")

        # Set snap-max-soft-limit snapshot config option
        max_soft_limit = {'snap-max-soft-limit': '80'}
        ret, _, _ = set_snap_config(self.mnode, max_soft_limit)
        self.assertEqual(ret, 0, ("Failed to set snap-max-soft-limit"
                                  "config option"))
        g.log.info("Successfully set snap-max-soft-limit config option")

        # Validate snap-max-soft-limit snapshot config option
        soft_limit_val = get_snap_config(self.mnode)
        self.assertEqual(soft_limit_val['volumeConfig'][0]['softLimit'], '8',
                         ("Failed to Validate max-soft-limit"))
        g.log.info("Successfully validated snap-max-soft-limit")

        # Create 20 snapshots. As the count of snapshots crosses the
        # soft-limit the oldest of newly created snapshot should
        # be deleted and only the latest 8 snapshots must remain.
        for snapname in self.snapshots:
            ret, _, _ = snap_create(self.mnode,
                                    self.volname,
                                    snapname,
                                    description="This is the Description wit#"
                                    " ($p3c1al) ch@r@cters!")
            self.assertEqual(ret, 0, ("Failed to create snapshot %s for "
                                      "volume %s", snapname, self.volname))
            g.log.info("Snapshot snap%s of volume %s created successfully",
                       snapname, self.volname)

        # Perform snapshot list to get total number of snaps after auto-delete
        # Validate the existence of the snapshots using the snapname
        snaplist = get_snap_list(self.mnode)
        self.assertEqual(len(snaplist), 8,
                         ("Failed: The snapshot count is not as expected"))
        for snapname in self.snapshots[-8:]:
            self.assertIn(
                snapname, snaplist, "Failed to validate snapshot "
                "existence for the snapshot %s" % snapname)
        g.log.info("Successful in validating the Snapshot count and existence "
                   "by snapname")
Пример #6
0
    def test_auto_delete_snap(self):
        """
        * enabling auto-delete snapshot
        * Setting max-hard limit and max-soft-limit
        * Validating max-hard-limit and max-soft-limit
        * Verify the limits by creating another 20 snapshots
        * Oldest of newly created snapshots will be deleted
        * Retaining the latest 8(softlimit) snapshots
        * cleanup snapshots and volumes
        """
        # Setup volume
        ret = self.setup_volume()
        if not ret:
            raise ExecutionError("Failed to setup volume %s" % self.volname)
        g.log.info("Volume %s has been setup successfully" % self.volname)

        # enabling auto-delete
        cmd = "gluster snapshot config auto-delete enable"
        ret = g.run(self.mnode, cmd)
        self.assertTrue(ret, ("Failed to enable auto-delete snapshot config"
                              "option on volume % s" % self.volname))
        g.log.info("Snapshot auto-delete Successfully enabled")

        # setting max-hard-limit
        option = {'snap-max-hard-limit': '10'}
        ret = set_snap_config(self.mnode, option, self.volname)
        self.assertTrue(ret, ("Failed to set snap-max-hardlimit"
                              "config option for volume %s" % self.volname))
        g.log.info("snap-max-hardlimit config option Successfully set for"
                   "volume %s" % self.volname)

        # Validating max-hard-limit
        hardlimit = get_snap_config(self.mnode)
        get_hardlimit = hardlimit['volumeConfig'][0]['hardLimit']
        if get_hardlimit != '10':
            self.assertTrue(ret, ("Failed to Validate max-hard-limit"))
        g.log.info("Successfully validated max-hard-limit")

        # setting max-soft-limit
        option = {'snap-max-soft-limit': '80'}
        ret = set_snap_config(self.mnode, option)
        self.assertTrue(ret, ("Failed to set snap-max-soft-limit"
                              "config option"))
        g.log.info("snap-max-soft-limit config option Successfully set")

        # Validating max-soft-limit
        softlimit = get_snap_config(self.mnode)
        get_softlimit = softlimit['volumeConfig'][0]['softLimit']
        if get_softlimit != '8':
            self.assertTrue(ret, ("Failed to Validate max-soft-limit"))
        g.log.info("Successfully validated max-soft-limit")

        # creating 20 snapshots. As the count
        # of snapshots crosses the
        # soft-limit the oldest of newly created snapshot should
        # be deleted only latest 8 snapshots
        # should remain.

        # creating 20 more snapshots
        for snap_count in range(10, 30):
            ret = snap_create(
                self.mnode, self.volname, "snap%s" % snap_count, False,
                "This is the Description with $p3c1al"
                "characters!")
            self.assertTrue(ret, ("Failed to create snapshot snap%s for volume"
                                  "%s" % (snap_count, self.volname)))
            g.log.info("Snapshot snap%s of volume %s created successfully")

        # snapshot list to list total number of snaps after auto-delete
        cmd = "gluster snapshot list | wc -l"
        ret, out, _ = g.run(self.mnode, cmd)
        self.assertEqual(
            ret, 0, ("Failed to list snapshot of volume %s" % self.volname))
        g.log.info("Total number of snapshots created after auto-delete"
                   "enabled is %s" % out)
        if out != 8:
            g.log.info("Failed to validate snapshots with expected"
                       "number of snapshots")
        g.log.info("Snapshot Validation Successful")
        g.log.info("Snapshot list command for volume %s was successful" %
                   self.volname)
Пример #7
0
    def test_snap_delete(self):
        # pylint: disable=too-many-statements
        """
        Delete a snapshot of a volume

        * Creating and deleting 10 snapshots
        * deleting previously created 10 snapshots
        * enabling auto-delete snapshot
        * Setting max-hard limit and max-soft-limit
        * Verify the limits by creating another 20 snapshots
        * Oldest of newly created snapshots will be deleted
        * Retaining the latest 8(softlimit) snapshots
        * cleanup snapshots and volumes
        """

        # creating 10 snapshots
        g.log.info("Creating 10 snapshots")
        for snap_count in range(0, 10):
            ret, _, _ = snap_create(self.mnode, self.volname,
                                    "snap%s" % snap_count, False,
                                    "Description with $p3c1al characters!")
            self.assertEqual(ret, 0, ("Failed to create snapshot"
                                      "snap%s" % snap_count))
            g.log.info("Snapshot snap%s of volume %s created"
                       "successfully.", snap_count, self.volname)

        # snapshot list
        g.log.info("Starting to list all snapshots")
        ret, _, _ = snap_list(self.mnode)
        self.assertEqual(ret, 0, ("Failed to list snapshot"
                                  "of volume %s" % self.volname))
        g.log.info("Snapshot list command for volume %s"
                   "was successful", self.volname)

        # deleting all 10 snapshots from the volume
        g.log.info("Starting to Delete 10 created snapshots")
        ret, _, _ = snap_delete_by_volumename(self.mnode, self.volname)
        self.assertEqual(ret, 0, ("Failed to delete"
                                  "snapshot of volume %s" % self.volname))
        g.log.info("Snapshots of volume %s deleted Successfully", self.volname)

        # enabling auto-delete
        g.log.info("Enabling auto-delete")
        cmd = "gluster snapshot config auto-delete enable"
        ret, _, _ = g.run(self.mnode, cmd)
        self.assertEqual(ret, 0, ("Failed to enable auto-delete"
                                  "snapshot config"
                                  "option on volume % s" % self.volname))
        g.log.info("Snapshot auto-delete Successfully enabled")

        # setting max-hard-limit
        g.log.info("Setting max-hard-limit")
        option = {'snap-max-hard-limit': '10'}
        ret, _, _ = set_snap_config(self.mnode, option, self.volname)
        self.assertEqual(ret, 0, ("Failed to set snap-max-hardlimit"
                                  "config option for"
                                  "volume %s" % self.volname))
        g.log.info(
            "snap-max-hardlimit config option Successfully set for"
            "volume %s", self.volname)

        # Validating max-hard-limit
        g.log.info("Validating max-hard-limit")
        hardlimit = get_snap_config(self.mnode)
        self.assertIsNotNone(hardlimit, "Failed to get snap config")
        get_hardlimit = hardlimit['volumeConfig'][0]['hardLimit']
        self.assertEqual(get_hardlimit, '10', ("Failed to Validate"
                                               "max-hard-limit"))
        g.log.info("Successfully validated max-hard-limit")

        # setting max-soft-limit
        g.log.info("Setting max-soft-limit")
        option = {'snap-max-soft-limit': '80'}
        ret, _, _ = set_snap_config(self.mnode, option)
        self.assertEqual(ret, 0, ("Failed to set snap-max-soft-limit"
                                  "config option"))
        g.log.info("snap-max-soft-limit config option Successfully set")

        # Validating max-soft-limit
        g.log.info("Validating max-soft-limit")
        softlimit = get_snap_config(self.mnode)
        self.assertIsNotNone(softlimit, "Failed to get snap config")
        get_softlimit = softlimit['volumeConfig'][0]['softLimit']
        self.assertEqual(get_softlimit, '8', ("Failed to Validate"
                                              "max-soft-limit"))
        g.log.info("Successfully validated max-soft-limit")

        # creating 20 more snapshots. As the count
        # of snapshots crosses the
        # soft-limit the oldest of newly created snapshot should
        # be deleted only latest 8(softlimit) snapshots
        # should remain
        g.log.info("Starting to create 20 more snapshots")
        for snap_count in range(10, 30):
            ret, _, _ = snap_create(
                self.mnode, self.volname, "snap%s" % snap_count, False,
                "This is the Description with $p3c1al"
                "characters!")
            self.assertEqual(ret, 0, ("Failed to create snapshot snap%s"
                                      "for volume"
                                      "%s" % (snap_count, self.volname)))
            g.log.info("Snapshot snap%s of volume"
                       "%s created successfully.", snap_count, self.volname)

        # snapshot list to list total number of snaps after auto-delete
        g.log.info("validate total no.of snapshots after auto-delete enable")
        cmd = "gluster snapshot list | wc -l"
        ret, out, _ = g.run(self.mnode, cmd)
        tot = out.strip().split('\n')
        self.assertEqual(
            ret, 0, ("Failed to list snapshot of volume %s" % self.volname))
        g.log.info(
            "Total number of snapshots created after auto-delete"
            "enabled is %s", tot[0])
        self.assertEqual(tot[0], '8', ("Failed to validate snapshots with"
                                       "expected number of snapshots "))
        g.log.info("Successfully validated snapshots with expected"
                   "number of snapshots")
    def test_activate_on_create(self):
        # pylint: disable=too-many-branches, too-many-statements
        """
        Verifying Snapshot activate on create

        * Create a default snapshot
        * Enable activate-on-create snapshot config option
        * Create more snapshots
            * Validate snapshot info after snapshot create. It should be in
              started state.
            * Validate snapshot status after snapshot create. It should be in
              started state.
        * Validate the default snapshot info and status. It should be in
          stopped state
        """

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

        # Enable activate_on_create snapshot
        g.log.info("Enabling snapshot activate-on-create config option")
        ret, _, _ = set_snap_config(self.mnode, self.option_enable)
        self.assertEqual(ret, 0, "Failed to execute set_snap_config")
        g.log.info("Validating the value of activate-on-create")
        ret = get_snap_config(self.mnode, self.volname)
        self.assertIsNotNone(ret, ("Failed to execute get_snap_config"))
        self.assertIn('enable', (ret['systemConfig']['activateOnCreate']),
                      ("Failed to validate activate-on-create value as "
                       "'enabled'"))
        g.log.info("Successfully enabled activate-on-create")

        # Create Snapshots after enabling activate-on-create
        g.log.info("Starting to Create Snapshots")
        for snap_count in range(1, 5):
            snap_name = "snap_%s" % snap_count
            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 of volume %s",
                       snap_name, self.volname)

            # Validate Snapshot Info After Snapshot Create
            g.log.info("Validating 'snapshot info' after enabling "
                       "activate-on-create")
            ret = get_snap_info_by_snapname(self.mnode, snap_name)
            self.assertIsNotNone(ret, ("Failed to Fetch Snapshot info after "
                                       "activation for %s", snap_name))
            g.log.info("Snapshot info Success for %s",
                       ret['snapVolume']['status'])
            self.assertEqual(ret['snapVolume']['status'], 'Started',
                             ("Activated Snapshot is in Stopped State %s",
                              (ret['snapVolume']['status'])))
            g.log.info("Snapshot %s is Activated By Default - %s state",
                       snap_name, (ret['snapVolume']['status']))

            # Validate Snaphot Status After Snapshot Create
            g.log.info("Validating 'snapshot status' after enabling "
                       "activate-on-create")
            ret = get_snap_status_by_snapname(self.mnode, snap_name)
            self.assertIsNotNone("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.assertNotEqual(brick['pid'], 'N/A',
                                    ("Brick Path %s  Not Available for "
                                     "Activated Snapshot %s",
                                     (brick['path'], snap_name)))
            g.log.info("Success: Snapshot Brick Path Available")

        # Validate Snapshot Info for the 'default' snapshot
        # Expected to be Stopped
        g.log.info("Validating 'snapshot info' of the 'default' snapshot")
        ret = get_snap_info_by_snapname(self.mnode, snap_default)
        self.assertIsNotNone(ret, ("Failed to Fetch Snapshot info for %s",
                                   snap_default))
        g.log.info("Snapshot info Success for %s", ret['snapVolume']['status'])
        self.assertEqual(ret['snapVolume']['status'], 'Stopped',
                         ("Snapshot Status is not in Stopped State"))
        g.log.info("Snapshot %s is in Stopped state as it "
                   "is not Activated", snap_default)

        # Validate Snapshot Status for the 'default' snapshot
        # Expected to be N/A
        g.log.info("Validating 'snapshot status' of the 'default' snapshot")
        ret = get_snap_status_by_snapname(self.mnode, snap_default)
        self.assertIsNotNone(ret, ("Failed to Fetch Snapshot status for %s",
                                   snap_default))
        g.log.info("Snapshot Status Success for %s", snap_default)
        for brick in ret['volume']['brick']:
            self.assertEqual(brick['pid'], 'N/A',
                             ("Brick Pid available for %s", brick['path']))
        g.log.info("Success: Snapshot %s Brick PID is 'N/A'", snap_default)
    def test_activate_on_create(self):
        # pylint: disable=too-many-branches
        """
        Verifying Snapshot activate on create
        """
        # Create Default Snapshot
        g.log.info("Starting to Create Snapshot one")
        snap_default = "snap_%s" % self.volname
        ret, _, _ = snap_create(self.mnode, self.volname, snap_default)
        self.assertEqual(ret, 0, "Snapshot Creation failed"
                         " for %s" % snap_default)
        g.log.info("Snapshot %s of volume %s created"
                   " successfully", snap_default, self.volname)

        # Enable activate_on_create snapshot
        ret, _, _ = set_snap_config(self.mnode, self.option_enable)
        self.assertEqual(ret, 0, "Failed to execute set_snap_config")
        ret = get_snap_config(self.mnode, self.volname)
        if ret is None:
            raise ExecutionError("Failed to execute get_snap_config")
        if 'enable' not in ret['systemConfig']['activateOnCreate']:
            raise ExecutionError("Failed to enable activate-on-create")
        g.log.info("set_snap_config Success to enable " "activate-on-create")
        # Create Snapshot Snapshots
        g.log.info("Starting to Create Snapshot two")
        for snap_count in range(1, 5):
            snap_name = "snap_%s" % snap_count
            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 After Snapshot Create
            ret = get_snap_info_by_snapname(self.mnode, snap_name)
            if ret is None:
                raise ExecutionError("Failed to Fetch Snapshot"
                                     "info after activate "
                                     "for %s" % snap_name)
            g.log.info("Snapshot info Success "
                       "for %s", ret['snapVolume']['status'])
            if ret['snapVolume']['status'] != 'Started':
                raise ExecutionError("Activated Snapshot is in Stopped "
                                     "State %s" %
                                     (ret['snapVolume']['status']))
            g.log.info("%s Activated By "
                       "Default- %s state", snap_name,
                       (ret['snapVolume']['status']))

            # Validate Snaphot Status After Snapshot Create
            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.error("Snapshot Status Success for %s", snap_name)
            for brick in ret['volume']['brick']:
                if brick['pid'] == 'N/A':
                    raise ExecutionError("Brick Path %s  Not Available "
                                         "for Activated Snapshot %s" %
                                         (brick['path'], snap_name))
            g.log.info("snap_2 Snapshot Brick Path Available as Expected")

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

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