def _perform_glusterfind_pre_and_validate_outfile(self):
        """
        Function to perform glusterfind pre and validate outfile
        """
        # 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, self.file_limit+1):
            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])
    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])
Example #3
0
    def test_gfind_deletes(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
        * Delete the files created from mount point
        * Perform glusterfind pre
        * Perform glusterfind post
        * Check the contents of outfile
          Files deleted must be listed
        """

        # pylint: disable=too-many-statements
        # Creating a session for the volume
        g.log.info("Creating a session for the volume %s", self.volname)
        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
        g.log.info("Performing glusterfind list to check if the session is "
                   "created")
        ret, _, _ = gfind_list(self.mnode,
                               volname=self.volname,
                               sessname=self.session)
        self.assertEqual(ret, 0, "Failed to list the glusterfind session")
        g.log.info("Successfully listed the glusterfind session")

        # Starting IO on the mounts
        g.log.info("Creating Files on %s:%s", self.mounts[0].client_system,
                   self.mounts[0].mountpoint)
        cmd = ("cd %s ; for i in `seq 1 10` ; "
               "do dd if=/dev/urandom of=file$i bs=1M count=1 ; "
               "done" % 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")

        # Check if the files exist
        g.log.info("Checking the existence of files created during IO")
        for i in range(1, 11):
            ret = file_exists(self.mounts[0].client_system,
                              '%s/file%s' % (self.mounts[0].mountpoint, i))
            self.assertTrue(ret,
                            "Unexpected: File 'file%s' does not exist" % i)
            g.log.info("Successfully validated existence of 'file%s'", i)

        sleep(5)

        # Perform glusterfind pre for the session
        g.log.info("Performing glusterfind pre for the session %s",
                   self.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
        g.log.info("Checking if outfile created during glusterfind pre command"
                   " 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
        g.log.info("Performing glusterfind post for the session %s",
                   self.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")

        # Delete the files created from mount point
        g.log.info("Deleting the Files on %s:%s", self.mounts[0].client_system,
                   self.mounts[0].mountpoint)
        for i in range(1, 11):
            ret = remove_file(self.mounts[0].client_system,
                              "%s/file%s" % (self.mounts[0].mountpoint, i),
                              force=True)
            self.assertTrue(ret, "Failed to delete file%s" % i)
        g.log.info("Successfully deleted all the files")

        # Check if the files deleted exist from mount point
        g.log.info("Checking the existence of files that were deleted "
                   "(must not be present)")
        for i in range(1, 11):
            ret = file_exists(self.mounts[0].client_system,
                              '%s/file%s' % (self.mounts[0].mountpoint, i))
            self.assertFalse(
                ret, "Unexpected: File 'file%s' exists even after"
                " being deleted" % i)
            g.log.info("Successfully validated 'file%s' does not exist", i)

        sleep(5)

        # Perform glusterfind pre for the session
        g.log.info("Performing glusterfind pre for the session %s",
                   self.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
        g.log.info("Checking if outfile created during glusterfind pre command"
                   " 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 '%s'",
                   self.outfiles[1])

        # Check if all the files are listed in the outfile
        for i in range(1, 11):
            pattern = "DELETE file%s" % i
            ret = check_if_pattern_in_file(self.mnode, pattern,
                                           self.outfiles[1])
            self.assertEqual(ret, 0, ("File 'file%s' not listed in %s" %
                                      (i, self.outfiles[1])))
            g.log.info("File 'file%s' listed in %s", i, self.outfiles[1])
    def test_gfind_full_type(self):
        """
        Verifying the glusterfind --full functionality with --type f,
        --type f and --type both

        * Create a volume
        * Create a session on the volume
        * Create various files on mount point
        * Create various directories on point
        * Perform glusterfind pre with --full --type f --regenerate-outfile
        * Check the contents of outfile
        * Perform glusterfind pre with --full --type d --regenerate-outfile
        * Check the contents of outfile
        * Perform glusterfind pre with --full --type both --regenerate-outfile
        * Check the contents of outfile
        * Perform glusterfind query with --full --type f
        * Check the contents of outfile
        * Perform glusterfind query with --full --type d
        * Check the contents of outfile
        * Perform glusterfind query with --full --type both
        * Check the contents of outfile
        """

        # Create some files and directories from the mount point
        cmd = ("cd {}; mkdir dir;mkdir .hiddendir;touch file;touch .hiddenfile"
               ";mknod blockfile b 1 5;mknod charfile b 1 5; mkfifo pipefile;"
               "touch fileforhardlink;touch fileforsoftlink;"
               "ln fileforhardlink hardlinkfile;ln -s fileforsoftlink "
               "softlinkfile".format(self.mounts[0].mountpoint))
        ret, _, _ = g.run(self.mounts[0].client_system, cmd)

        # Create list of files and dir to be used for checking
        self.list_of_files = [
            'file', '.hiddenfile', 'blockfile', 'charfile', 'pipefile',
            'fileforhardlink', 'fileforsoftlink', 'hardlinkfile',
            'softlinkfile'
        ]
        self.list_of_dirs = ['dir', '.hiddendir']

        self.assertEqual(ret, 0, "Failed to create files and dirs")
        g.log.info("Files and Dirs created successfully on mountpoint")

        # Create session for 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")

        # Perform glusterfind full pre for the session with --type option
        for gftype in ('f', 'd', 'both'):
            ret, _, _ = gfind_pre(self.mnode,
                                  self.volname,
                                  self.session,
                                  self.outfile,
                                  full=True,
                                  gftype=gftype,
                                  regenoutfile=True)
            self.assertEqual(
                ret, 0, "glusterfind pre command successful "
                "with --type %s" % gftype)

            # Check the contents of the outfile
            self._check_contents_of_outfile(gftype)

        # Perform glusterfind full query with the --type option
        for gftype in ('f', 'd', 'both'):
            ret, _, _ = gfind_query(self.mnode,
                                    self.volname,
                                    self.outfile,
                                    full=True,
                                    gftype=gftype)
            self.assertEqual(
                ret, 0, "glusterfind query command successful "
                "with --type %s" % gftype)

            # Check the contents of the outfile
            self._check_contents_of_outfile(gftype)
    def test_gfind_pre_cli(self):
        """
        Verifying the glusterfind pre command functionality with valid
        and invalid values for the required and optional parameters.

        * Create a volume
        * Create a session on the volume
        * Perform some I/O from the mount point
        * Perform glusterfind pre with the following combinations:
            - Valid values for required parameters
            - Invalid values for required parameters
            - Valid values for optional parameters
            - Invalid values for optional parameters
        * Perform glusterfind post

            Where
            Required parameters: volname, sessname and outfile
            Optional parameters: full, debug, gftype, tagforfullfind,
                                 namespace, noencode, disablepartial,
                                 regenoutfile, outprefix, fieldsep
        """

        # pylint: disable=too-many-statements
        # Creating a session for the volume
        g.log.info("Creating a session for the volume %s", self.volname)
        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
        g.log.info("Performing glusterfind list to check if the session is "
                   "created")
        ret, _, _ = gfind_list(self.mnode,
                               volname=self.volname,
                               sessname=self.session)
        self.assertEqual(ret, 0, "Failed to list the glusterfind session")
        g.log.info("Successfully listed the glusterfind session")

        # Starting IO on the mounts
        mount_obj = self.mounts[0]
        mount_dir = mount_obj.mountpoint
        client = mount_obj.client_system

        g.log.info("Creating Files on %s:%s", client, mount_dir)
        cmd = ("cd %s ; for i in `seq 1 10` ; "
               "do dd if=/dev/urandom of=file$i bs=1M 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 successfully on mountpoint")

        # Check if the files exist
        g.log.info("Checking the existence of files created during IO")
        for i in range(1, 11):
            ret = file_exists(client, '%s/file%s' % (mount_dir, i))
            self.assertTrue(ret,
                            "Unexpected: File 'file%s' does not exist" % i)
            g.log.info("Successfully validated existence of 'file%s'", i)

        # Perform glusterfind pre for the session
        g.log.info("Performing glusterfind pre for the session %s",
                   self.session)
        ret, _, _ = gfind_pre(self.mnode,
                              self.volname,
                              self.session,
                              self.outfile,
                              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
        g.log.info("Checking if outfile created during glusterfind pre command"
                   " exists")
        ret = file_exists(self.mnode, self.outfile)
        self.assertTrue(ret,
                        "Unexpected: File '%s' does not exist" % self.outfile)
        g.log.info("Successfully validated existence of '%s'", self.outfile)

        # 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.outfile)
            self.assertEqual(ret, 0, ("File 'file%s' not listed in %s" %
                                      (i, self.outfile)))
            g.log.info("File 'file%s' listed in %s", i, self.outfile)

        # Perform glusterfind post for the session
        g.log.info("Performing glusterfind post for the session %s",
                   self.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")

        # Perform glusterfind pre using the invalid values for required
        # parameters
        not_volume = 'invalid-volume-name'
        not_session = 'invalid-session-name'
        not_outfile = '/tmp/not'
        g.log.info("Performing glusterfind pre with invalid values for the "
                   "required parameters")
        ret, _, _ = gfind_pre(self.mnode, not_volume, not_session, not_outfile)
        self.assertNotEqual(
            ret, 0, "Unexpected: glusterfind pre Successful "
            "even with invalid values for required parameters")
        g.log.info("Successful: glusterfind pre failed with invalid values "
                   "for required parameters")

        # Perform glusterfind pre using the invalid values for optional
        # parameters
        g.log.info("Deleting the session with invalid values for the optional "
                   "parameters")
        invalid_options = [
            ' --dbug', ' --noencod', ' --regenout', ' --type n',
            ' --tagforfullfind', ' --disablepartial', ' --fll'
            ' --outprefix none', ' --namespc'
        ]
        for opt in invalid_options:
            ret, _, _ = g.run(
                self.mnode, ("glusterfind pre %s %s %s %s" %
                             (self.volname, self.session, self.outfile, opt)))
            self.assertNotEqual(
                ret, 0, "Unexpected: glusterfind pre "
                " successful for option %s which is invalid" % opt)
        g.log.info("Successful: glusterfind pre failed with invalid value "
                   "for optional parameters")