def _insert_bp(self, host, logpath):
     """
     Generates and inserts a breakpoint in the given logpath on the host
     """
     append_string = self.bp_text + str(self.bp_count)
     ret = append_string_to_file(host, logpath, append_string)
     self.assertTrue(
         ret, 'Not able to append string to the file {} '
         'on {}'.format(logpath, host))
     self.bp_count += 1
Exemple #2
0
 def _filecreate_and_hashcheck(self, timeoutval):
     """Create a file and check on which subvol it is hashed to"""
     # Create and write to a file to test the eagerlock timeout behavior
     objectname = 'EagerLockTimeoutCheck-file-' + timeoutval
     objectpath = ("{}/{}".format(self.mounts[0].mountpoint, objectname))
     ret = append_string_to_file(self.mounts[0].client_system, objectpath,
                                 'EagerLockTest')
     self.assertTrue(ret, 'create and append of %s failed' % objectname)
     ret = get_subvols(self.mnode, self.volname)
     # Find the hashed subvol of the file created
     if len(ret['volume_subvols']) > 1:
         _, hashed_subvol = find_hashed_subvol(ret['volume_subvols'], '',
                                               objectname)
         if hashed_subvol is None:
             g.log.error("Error in finding hash value of %s", objectname)
             return None
         return (objectname, ret['volume_subvols'], hashed_subvol)
     # Set subvol to 0 for plain(non-distributed) disperse volume
     hashed_subvol = 0
     return (objectname, ret['volume_subvols'], hashed_subvol)
    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])
Exemple #4
0
    def test_dht_custom_xattr(self):
        """
        Test case:
        1.Create a gluster volume and start it.
        2.Create file and link files.
        3.Create a custom xattr for file.
        4.Verify that xattr for file is displayed on
          mount point and bricks
        5.Modify custom xattr value and verify that xattr
          for file is displayed on mount point and bricks
        6.Verify that custom xattr is not displayed
          once you remove it
        7.Create a custom xattr for symbolic link.
        8.Verify that xattr for symbolic link
          is displayed on mount point and sub-volume
        9.Modify custom xattr value and verify that
          xattr for symbolic link is displayed on
          mount point and bricks
        10.Verify that custom xattr is not
           displayed once you remove it.
        """
        # Initializing variables
        mount_point = self.mounts[0].mountpoint
        self.client_node = self.mounts[0].client_system
        self.list_of_files, list_of_softlinks = [], []
        list_of_hardlinks = []

        for number in range(1, 3):

            # Create regular files
            fname = '{0}/regular_file_{1}'.format(mount_point, str(number))
            ret = append_string_to_file(self.client_node, fname,
                                        'Sample content for file.')
            self.assertTrue(
                ret, "Unable to create regular file "
                "{}".format(fname))
            self.list_of_files.append(fname)

            # Create hard link for file
            hardlink = '{0}/link_file_{1}'.format(mount_point, str(number))
            ret = create_link_file(self.client_node, fname, hardlink)
            self.assertTrue(
                ret, "Unable to create hard link file "
                "{}".format(hardlink))
            list_of_hardlinks.append(hardlink)

            # Create soft link for file
            softlink = '{0}/symlink_file_{1}'.format(mount_point, str(number))
            ret = create_link_file(self.client_node,
                                   fname,
                                   softlink,
                                   soft=True)
            self.assertTrue(
                ret, "Unable to create symlink file "
                "{}".format(softlink))
            list_of_softlinks.append(softlink)

        self.files_and_soft_links = self.list_of_files + list_of_softlinks

        # Check if files are created on the right subvol
        ret = validate_files_in_dir(
            self.client_node,
            mount_point,
            file_type=k.FILETYPE_FILES,
            test_type=k.TEST_FILE_EXISTS_ON_HASHED_BRICKS)
        self.assertTrue(ret, "Files not created on correct sub-vols")
        g.log.info("Files are on correct sub-vols according to "
                   "the hash value")

        # Set custom xattr on all the regular files
        self.set_xattr_user_foo(self.list_of_files, 'bar2')

        # Check if custom xattr is set to all the regular files
        self.check_custom_xattr_visible('bar2')

        # Change the custom xattr on all the regular files
        self.set_xattr_user_foo(self.list_of_files, 'ABC')

        # Check if xattr is set to all the regular files
        self.check_custom_xattr_visible('ABC')

        # Delete Custom xattr from all regular files
        self.delete_xattr_user_foo(self.list_of_files)

        # Check mount point and brick for the xattr
        list_of_all_files = list_of_hardlinks + self.files_and_soft_links
        self.check_mount_point_and_bricks_for_xattr(list_of_all_files)

        # Check if pathinfo xattr is visible
        self.check_for_trusted_glusterfs_pathinfo(self.list_of_files)

        # Set custom xattr on all the regular files
        self.set_xattr_user_foo(list_of_softlinks, 'bar2')

        # Check if custom xattr is set to all the regular files
        self.check_custom_xattr_visible('bar2')

        # Change the custom xattr on all the regular files
        self.set_xattr_user_foo(list_of_softlinks, 'ABC')

        # Check if xattr is set to all the regular files
        self.check_custom_xattr_visible('ABC')

        # Delete Custom xattr from all regular files
        self.delete_xattr_user_foo(list_of_softlinks)

        # Check mount point and brick for the xattr
        self.check_mount_point_and_bricks_for_xattr(list_of_all_files)

        # Check if pathinfo xattr is visible
        self.check_for_trusted_glusterfs_pathinfo(list_of_softlinks)
    def test_alert_time_out(self):
        """
        Verifying directory quota functionality with respect to
        alert-time, soft-timeout and hard-timeout.

        * Enable quota
        * Set limit on '/'
        * Set default-soft-limit to 50%
        * Set alert time to 1 sec
        * Set soft-timeout to 0 sec
        * Set hard timeout to 0 sec
        * Check quota list
        * Perform some IO such that soft limit is not exceeded
        * Check for alert message in brick logfile (NO alert present)
        * Perform IO and exceed the soft limit
        * Check for alert message in brick logfile (Alert present)
        * Remove some files so that usage falls below soft limit
        * Create some files such that hard limit is exceeded
        * Check for alert message in brick logfile
        * Remove some files so that usage falls below soft limit
        * Check for alert message in brick logfile (NO alert present)

        """

        # pylint: disable=too-many-statements
        # Enable Quota
        g.log.info("Enabling quota on the volume %s", self.volname)
        ret, _, _ = quota_enable(self.mnode, self.volname)
        self.assertFalse(
            ret, "Failed to enable quota on the volume %s" % self.volname)
        g.log.info("Successfully enabled quota on the volume %s", self.volname)

        # Path to set quota limit
        path = "/"

        # Create a directory from mount point
        mount_obj = self.mounts[0]
        mount_dir = mount_obj.mountpoint
        client = mount_obj.client_system

        g.log.info("Creating dir named 'foo' from client %s", client)
        ret = mkdir(client, "%s/foo" % mount_dir)
        self.assertTrue(
            ret, "Failed to create dir under %s-%s" % (client, mount_dir))
        g.log.info("Directory 'foo' created successfully")

        # Set Quota limit on the root of the volume
        g.log.info("Set Quota Limit on the path %s of the volume %s", path,
                   self.volname)
        ret, _, _ = quota_limit_usage(self.mnode,
                                      self.volname,
                                      path=path,
                                      limit="100MB")
        self.assertEqual(ret, 0, ("Failed to set quota limit on path %s of "
                                  " the volume %s", path, self.volname))
        g.log.info("Successfully set the Quota limit on %s of the volume %s",
                   path, self.volname)

        # Set default soft limit to 50%
        g.log.info("Set default soft limit:")
        ret, _, _ = quota_set_default_soft_limit(self.mnode, self.volname,
                                                 '50%')
        self.assertEqual(ret, 0, ("Failed to set quota default soft limit"))
        g.log.info("Quota default soft limit set successfully")

        # Check quota list to validate limits
        g.log.info("List all files and directories:")
        ret = quota_validate(self.mnode,
                             self.volname,
                             path=path,
                             soft_limit_percent=50,
                             hard_limit=104857600)
        self.assertTrue(ret, "Failed to validate Quota list")
        g.log.info("Quota List successful")

        # Set alert time to 1 second
        g.log.info("Set quota alert timeout:")
        ret, _, _ = quota_set_alert_time(self.mnode, self.volname, '1sec')
        self.assertEqual(ret, 0, ("Failed to set alert timeout"))
        g.log.info("Quota alert time set successful")

        # Set soft timeout to 0 second
        g.log.info("Set quota soft timeout:")
        ret, _, _ = quota_set_soft_timeout(self.mnode, self.volname, '0sec')
        self.assertEqual(ret, 0, ("Failed to set soft timeout"))
        g.log.info("Quota soft timeout set successful")

        # Set hard timeout to 0 second
        g.log.info("Set quota hard timeout:")
        ret, _, _ = quota_set_hard_timeout(self.mnode, self.volname, '0sec')
        self.assertEqual(ret, 0, ("Failed to set hard timeout"))
        g.log.info("Quota hard timeout set successful")

        # Get the brick log file path for a random node
        bricks = get_all_bricks(self.mnode, self.volname)
        selected_node, brick_path = random.choice(bricks[0:6]).split(':')
        brickpath = str.replace(brick_path, '/', '-')
        brickpathfinal = brickpath[1:]
        brick_log = "/var/log/glusterfs/bricks/%s.log" % brickpathfinal

        # Append unique string to the brick log
        g.log.info("Appending string 'appended_string_1' to the log:")
        append_string_to_file(selected_node, brick_log, "appended_string_1")

        # Starting IO on the mounts without crossing the soft limit
        # file creation should be normal
        g.log.info("Creating Files on %s:%s", client, mount_dir)
        cmd = ("cd %s/foo ; "
               "for i in `seq 1 9` ; "
               "do dd if=/dev/urandom of=file$i "
               "bs=5M "
               "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 succesfully on mountpoint")

        # Append unique string to the brick log
        g.log.info("Appending string 'appended_string_2' to the log:")
        append_string_to_file(selected_node, brick_log, "appended_string_2")

        # Soft limit not crossed
        # Check if alert message is logged in the brick (shouldn't be logged)
        g.log.info("Check for alert message in logfile:")
        ret = search_pattern_in_file(selected_node, "120004", brick_log,
                                     "appended_string_1", "appended_string_2")
        self.assertFalse(ret, "Found unnecessary alert in logfile")
        g.log.info("Alert message not seen before crossing soft limit")

        # Continue IO on the mounts to exceed soft limit
        g.log.info("Creating Files on %s:%s", client, mount_dir)
        cmd = ("cd %s/foo ; "
               "for i in `seq 1 200` ; "
               "do dd if=/dev/urandom of=foo$i "
               "bs=100K "
               "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 succesfully on mountpoint and "
                   "exceed soft limit")

        # Check if quota soft limit exceeded
        g.log.info("Check soft limit:")
        ret = quota_validate(self.mnode,
                             self.volname,
                             path=path,
                             sl_exceeded=True)
        self.assertTrue(ret, "Failed: soft limit not exceeded")
        g.log.info('Quota soft limit exceeded')

        # Inserting sleep of 2 seconds so the alert message gets enough time
        # to be logged
        time.sleep(2)

        # Append unique string to the brick log
        g.log.info("Appending string 'appended_string_3' to the log:")
        append_string_to_file(selected_node, brick_log, "appended_string_3")

        # Check if alert message logged in the brick
        g.log.info("Check for message:")
        ret = search_pattern_in_file(selected_node, "120004", brick_log,
                                     "appended_string_2", "appended_string_3")
        self.assertTrue(ret, "Alert message not found")
        g.log.info("Pattern Found: got alert message")

        # Append unique string to the brick log
        g.log.info("Appending string 'appended_string_4' to the log:")
        append_string_to_file(selected_node, brick_log, "appended_string_4")

        # Continue IO on the mounts by removing data
        g.log.info("Removing Files on %s:%s", client, mount_dir)
        cmd = ("rm -rfv %s/foo/foo* " % mount_dir)
        ret, _, _ = g.run(client, cmd)
        self.assertEqual(ret, 0, ("Failed to delete files on mountpoint"))
        g.log.info("Files removed succesfully from mountpoint and reached "
                   "below soft limit")

        # Check if quota soft limit exceeded
        g.log.info("Check soft limit:")
        ret = quota_validate(self.mnode,
                             self.volname,
                             path=path,
                             sl_exceeded=False)
        self.assertTrue(ret, "Failed: soft limit exceeded")
        g.log.info('Quota soft limit not exceeded')

        # Inserting sleep of 2 seconds so the alert message gets enough time
        # to be logged
        time.sleep(2)

        # Append unique string to the brick log
        g.log.info("Appending string 'appended_string_5' to the log:")
        append_string_to_file(selected_node, brick_log, "appended_string_5")

        # Check if alert message is logged in the brick
        g.log.info("Check for message:")
        ret = search_pattern_in_file(selected_node, "120004", brick_log,
                                     "appended_string_4", "appended_string_5")
        self.assertFalse(ret, "Found unnecessary alert message in logfile")
        g.log.info("Alert message not seen before crossing soft limit")

        # Continue IO on the mounts to exceed hard limit
        g.log.info("Creating Files on %s:%s", client, mount_dir)
        cmd = ("cd %s/foo ; "
               "for i in `seq 11 20` ; "
               "do dd if=/dev/urandom of=file$i "
               "bs=10M "
               "count=1 ; "
               "done" % mount_dir)
        ret, _, _ = g.run(client, cmd)
        self.assertEqual(ret, 1, ("Failed: Files created successfully inspite "
                                  "of crossing hard-limit"))
        g.log.info("Files creation stopped on mountpoint once exceeded "
                   "hard limit")

        # Inserting sleep of 6 seconds so the alert message gets enough time
        # to be logged
        time.sleep(6)

        # Append unique string to the brick log
        g.log.info("Appending string 'appended_string_6' to the log:")
        append_string_to_file(selected_node, brick_log, "appended_string_6")

        # Check if alert message is logged in the brick
        g.log.info("Check for message:")
        ret = search_pattern_in_file(selected_node, "120004", brick_log,
                                     "appended_string_5", "appended_string_6")
        self.assertTrue(ret, "Alert message not seen in logfile")
        g.log.info("Pattern Found: got alert message")

        # Append unique string to the brick log
        g.log.info("Appending string 'Done_with_alert_check_7' to the log:")
        append_string_to_file(selected_node, brick_log,
                              "Done_with_alert_check_7")

        # Continue IO on the mounts by removing data to come below hard limit
        g.log.info("Removing Files on %s:%s", client, mount_dir)
        cmd = ("rm -rfv %s/foo/file{11..20}" % mount_dir)
        ret, _, _ = g.run(client, cmd)
        self.assertEqual(ret, 0, ("Failed to delete files on mountpoint"))
        g.log.info("Files removed succesfully on mountpoint and "
                   "reached below soft limit")

        # Inserting sleep of 2 seconds so the alert message gets enough time
        # to be logged
        time.sleep(2)

        # Append unique string to the brick log
        g.log.info("Appending string 'Done_with_alert_check_8' to the log:")
        append_string_to_file(selected_node, brick_log,
                              "Done_with_alert_check_8")

        # Check if alert message is logged in the brick
        g.log.info("Check for message:")
        ret = search_pattern_in_file(selected_node, "120004", brick_log,
                                     "Done_with_alert_check_7",
                                     "Done_with_alert_check_8")
        self.assertFalse(ret, "Found unnecessary alert in logfile")
        g.log.info("EXPECTED: Alert message not seen before crossing "
                   "soft limit")

        # have got below the soft and hard limit
        # check quota list
        g.log.info("List all files and directories:")
        ret = quota_validate(self.mnode,
                             self.volname,
                             path=path,
                             sl_exceeded=False,
                             hl_exceeded=False)
        self.assertTrue(
            ret, "Failed to validate Quota list with "
            "soft and hard limits")
        g.log.info("Quota List validated successfully")
Exemple #6
0
    def test_special_file_creation(self):
        """
        Description : check creation of different types of files.

        Steps:
        1) From mount point, Create a regular file
        eg:
        touch f1
        - From mount point, create character, block device and pipe files
        mknod c
        mknod b
        mkfifo
        2) Stat on the files created in Step-2 from mount point
        3) Verify that file is stored on only one bricks which is mentioned in
           trusted.glusterfs.pathinfo xattr
           On mount point -
           " getfattr -n trusted.glusterfs.pathinfo
           On all bricks
           " ls / "
        4) Verify that file permissions are same on mount point and sub-volumes
           " stat "
        5) Append some data to the file.
        6) List content of file to verify that data has been appended.
           " cat "
        7) Verify that file change time and size has been updated
           accordingly(from mount point and sub-volume)
           " stat / "
        """
        # pylint: disable=too-many-statements
        # pylint: disable=too-many-locals
        # Create a regular file
        self._create_file_using_touch("regfile")

        # Create a character and block file
        for (file_name, parameter) in [("blockfile", "b"), ("charfile", "c")]:
            cmd = "mknod {}/{} {} 1 5".format(self.m_point, file_name,
                                              parameter)
            ret, _, _ = g.run(self.client, cmd)
            self.assertEqual(ret, 0,
                             "Failed to create {} file".format(file_name))
            g.log.info("%s file created successfully", file_name)

        # Create a pipe file
        cmd = "mkfifo {}/pipefile".format(self.m_point)
        ret, _, _ = g.run(self.client, cmd)
        self.assertEqual(ret, 0, "Failed to create pipe file")
        g.log.info("Pipe file is created successfully")

        # Stat all the files created on mount-point
        for (file_name, check_string) in [("regfile", "regular empty file"),
                                          ("charfile",
                                           "character special file"),
                                          ("blockfile", "block special file"),
                                          ("pipefile", "fifo")]:
            self._check_file_stat_on_mountpoint(file_name, check_string)

        # Verify files are stored on backend bricks as per
        # the trusted.glusterfs.pathinfo
        file_types = ["regfile", "charfile", "blockfile", "pipefile"]

        for file_name in file_types:
            self._is_file_present_on_brick(file_name)

        # Verify that the file permissions are same on
        # mount-point and bricks
        for file_name in file_types:
            self._compare_file_permissions(file_name)

        # Note the modification time on mount and bricks
        # for all files. Also it should be same on mnt and bricks
        reg_mnt_ctime_1 = self._check_change_time_mnt("regfile")
        char_mnt_ctime_1 = self._check_change_time_mnt("charfile")
        block_mnt_ctime_1 = self._check_change_time_mnt("blockfile")
        fifo_mnt_ctime_1 = self._check_change_time_mnt("pipefile")

        reg_brick_ctime_1 = self._check_change_time_brick("regfile")
        char_brick_ctime_1 = self._check_change_time_brick("charfile")
        block_brick_ctime_1 = self._check_change_time_brick("blockfile")
        fifo_brick_ctime_1 = self._check_change_time_brick("pipefile")

        for (file_name, mnt_ctime, brick_ctime) in [
            ("regfile", reg_mnt_ctime_1, reg_brick_ctime_1),
            ("charfile", char_mnt_ctime_1, char_brick_ctime_1),
            ("blockfile", block_mnt_ctime_1, block_brick_ctime_1),
            ("pipefile", fifo_mnt_ctime_1, fifo_brick_ctime_1)
        ]:
            self._compare_file_permissions(file_name, mnt_ctime, brick_ctime)

        # Append some data to the files
        for (file_name, data_str) in [("regfile", "regular"),
                                      ("charfile", "character special"),
                                      ("blockfile", "block special")]:
            ret = append_string_to_file(
                self.client, "{}/{}".format(self.m_point, file_name),
                "Welcome! This is a {} file".format(data_str))
            self.assertTrue(ret,
                            "Failed to append data to {}".format(file_name))
            g.log.info("Successfully appended data to %s", file_name)

        # Check if the data has been appended
        check = "Welcome! This is a regular file"
        cmd = "cat {}/{}".format(self.m_point, "regfile")
        ret, out, _ = g.run(self.client, cmd)
        self.assertEqual(out.strip(), check, "No data present at regfile")

        # Append data to pipefile and check if it has been appended
        g.run_async(self.client,
                    "echo 'Hello' > {}/{} ".format(self.m_point, "pipefile"))
        ret, out, _ = g.run(self.client,
                            "cat < {}/{}".format(self.m_point, "pipefile"))
        self.assertEqual(ret, 0, "Unable to fetch datat on other terimnal")
        self.assertEqual("Hello",
                         out.split('\n')[0],
                         "Hello not recieved on the second terimnal")

        # Lookup on mount-point
        cmd = "ls -lR {}".format(self.m_point)
        ret, _, _ = g.run(self.client, cmd)
        self.assertEqual(ret, 0, "Lookup on mountpoint failed")

        # Collect ctime on mount point after appending data
        reg_mnt_ctime_2 = self._check_change_time_mnt("regfile")

        # After appending data the ctime for file should change
        self.assertNotEqual(reg_mnt_ctime_1, reg_mnt_ctime_2, "Unexpected:"
                            "The ctime has not been changed")
        g.log.info("The modification time for regfile has been"
                   " changed as expected")

        # Collect the ctime on bricks
        reg_brick_ctime_2 = self._check_change_time_brick("regfile")

        # Check if the ctime has changed on bricks as per mount
        self._compare_file_permissions("regfile", reg_mnt_ctime_2,
                                       reg_brick_ctime_2)
    def test_root_squash_enable(self):
        """
        Tests to verify Nfs Ganesha rootsquash functionality when glusterd
        service 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 glusterd on all the nodes
        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("Successfull in getting stats of files/dirs "
                   "from mount point")

        # Restart glusterd on all servers
        ret = restart_glusterd(self.servers)
        self.assertTrue(ret, ("Failed to restart glusterd on all servers %s",
                              self.servers))
        g.log.info("Successfully restarted glusterd on all servers %s",
                   self.servers)

        # Check if glusterd is running on all servers
        ret = is_glusterd_running(self.servers)
        self.assertEqual(ret, 0, ("Failed:Glusterd is not running on all "
                                  "servers %s",
                                  self.servers))
        g.log.info("Glusterd is running on all the servers %s", self.servers)

        # Checking if peer is connected.
        ret = wait_for_peers_to_connect(self.mnode, self.servers)
        self.assertTrue(ret, "Failed:Peer is not in connected state.")
        g.log.info("Peers are in connected state.")

        # 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")
Exemple #8
0
    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")
Exemple #9
0
    def test_root_squash_enable(self):
        """
        Tests to verify Nfs Ganesha rootsquash functionality with multi
        client
        Steps:
        1. Create some directories on mount point.
        2. Create some files inside those directories
        3. Set permission as 777 for mount point
        4. Enable root-squash on volume
        5. Edit file created by root user from client 2
           It should not allow to edit the file
        6. Create some directories on mount point.
        7. Create some files inside the directories
           Files and directories will be created by
           nfsnobody user
        8. Edit the file created in step 7
           It should allow to edit the file
        9. Disable root squash
        10. Edit the file created at step 7
            It should allow to edit the file
        """
        # Create Directories on Mount point
        cmd = ("for i in {1..10}; do mkdir %s/dir$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)

        # Create files inside directories on mount point.
        cmd = ("for i in {1..10}; do touch %s/dir$i/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")

        # Edit file created by root user from client 2
        ret = append_string_to_file(
            self.mounts[1].client_system,
            "%s/dir5/file5" % self.mounts[1].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")

        # Create Directories on Mount point
        cmd = ("for i in {1..10}; do mkdir %s/SquashDir$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)

        # Create files inside directories on mount point
        cmd = ("for i in {1..10}; do touch %s/SquashDir$i/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")

        # Edit the file created by nfsnobody user from client 2
        ret = append_string_to_file(
            self.mounts[1].client_system,
            "%s/SquashDir5/Squashfile5" % self.mounts[1].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")

        # Disable root-squash
        ret = set_root_squash(self.servers[0],
                              self.volname,
                              squash=False,
                              do_refresh_config=True)
        self.assertTrue(ret, "Failed to disable root-squash on volume")
        g.log.info("root-squash is disabled on the volume")

        # Edit the file created by nfsnobody user from root user
        ret = append_string_to_file(
            self.mounts[1].client_system,
            "%s/SquashDir10/Squashfile10" % self.mounts[1].mountpoint, 'hello')
        self.assertTrue(
            ret, "Unexpected:root user failed to edit "
            "the file created by nfsnobody user")
        g.log.info("Successful:root user successfully edited the "
                   "file created by nfsnobody user")
Exemple #10
0
    def test_root_squash_mount_unmount(self):
        """
        Tests to verify Nfs Ganesha rootsquash functionality when volume
        is remounted
        Steps:
        1. Set permission as 777 for mount point
        2. Create some files and dirs inside mount point
        3. Enable root-squash on volume
        4. Create some more files and dirs inside mount point
        5. Unmount the volume
        6. Remount the volume
        7. Try to edit file created in step 2
           It should not allow to edit the file
        8. Try to edit the file created in step 4
           It should allow to edit the file
        9. Create some more files and directory inside mount point
            It should be created as nobody user
        10. Disable root-squash on volume
        11. Edit any of the file created in step 2.
            It should allow to edit the file
        """
        # 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")

        # Create Directories on Mount point
        cmd = ("for i in {1..20}; do mkdir %s/dir$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)

        # Create multiple files inside directories on mount point.
        for i in range(1, 21):
            cmd = ("for j in {1..20}; do touch %s/dir%s/file$j; done" %
                   (self.mounts[0].mountpoint, i))
            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")

        # 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")

        # Create some more Directories after enabling root-squash
        cmd = ("for i in {1..20}; do mkdir %s/squashed_dir$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)

        # Create some more files inside directories
        for i in range(1, 21):
            cmd = ("for j in {1..20}; do touch "
                   "%s/squashed_dir%s/squashed_file$j; done" %
                   (self.mounts[0].mountpoint, i))
            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")

        # Unmount volume
        ret = unmount_mounts(self.mounts)
        self.assertTrue(ret, "Volume unmount failed for %s" % self.volname)

        # Remount volume
        ret = self.mount_volume(self.mounts)
        self.assertTrue(ret, "Volume mount failed for %s" % self.volname)

        # Edit file created by root user
        for mount_obj in self.mounts:
            ret = append_string_to_file(
                mount_obj.client_system,
                "%s/dir10/file10" % mount_obj.mountpoint, 'hello')
            self.assertFalse(
                ret, "Unexpected:nobody user editing file "
                "created by root user should FAIL")
            g.log.info("Successful:nobody user failed to edit file "
                       "created by root user")

        # Edit the file created by nobody user
        for mount_obj in self.mounts:
            ret = append_string_to_file(
                mount_obj.client_system,
                "%s/squashed_dir10/squashed_file10" % mount_obj.mountpoint,
                'hello')
            self.assertTrue(
                ret, "Unexpected:nobody user failed to edit "
                "the file created by nobody user")
            g.log.info("Successful:nobody user successfully edited the "
                       "file created by nobody user")

        # Create some more files on mount point post remount.
        cmd = ("for i in {1..20}; do touch %s/remount_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")

        # Check for owner and group of all the files
        for mount_obj in self.mounts:
            for i in range(1, 21):
                cmd = (
                    "ls -l %s/remount_file%i | awk '{ print $3, $4 }' |sort" %
                    (mount_obj.mountpoint, i))
                ret, out, err = g.run(mount_obj.client_system, cmd)
                self.assertFalse(ret, err)
                if is_rhel7:
                    self.assertIn("nobody nobody", out,
                                  "Owner and group is not nobody")
                else:
                    self.assertIn("nfsnobody nfsnobody", out,
                                  "Owner and group is not nobody")
                g.log.info("Owner and group of file is nobody")

        # Disable root-squash
        ret = set_root_squash(self.mnode,
                              self.volname,
                              squash=False,
                              do_refresh_config=True)
        self.assertTrue(ret, "Failed to disable root-squash on volume")
        g.log.info("root-squash is disable on the volume")

        # Edit file created by root user
        for mount_obj in self.mounts:
            ret = append_string_to_file(
                mount_obj.client_system,
                "%s/dir15/file15" % mount_obj.mountpoint, 'hello')
            self.assertTrue(
                ret, "Unexpected:root user should be allowed to "
                "edit the file created by root user")
            g.log.info("Successful:root user successful in editing file "
                       "created by root user")