def test_file_rename_when_source_and_dest_hash_same_subvol(self):
        """
        Case 2:
        - Destination file does not exist
        - Source file is stored on hashed subvolume(s1) it self
        - Destination file should be hashed to same subvolume(s1)
            mv <source_file> <destination_file>
        - Source file should be renamed to destination file
        """
        # pylint: disable=protected-access
        # pylint: disable=unsubscriptable-object

        # Create soruce file and Get hashed subvol (s1)
        source_hashed_subvol, count, source_file = (
            self._create_file_and_get_hashed_subvol("test_source_file"))

        # Rename the file such that the new name hashes to a new subvol
        new_hashed = find_specific_hashed(self.subvols, "/",
                                          source_hashed_subvol)
        self.assertIsNotNone(new_hashed,
                             "could not find new hashed for destination file")

        # Rename the source file to the destination file
        dest_file = "{}/{}".format(self.mount_point, str(new_hashed.newname))
        ret = move_file(self.clients[0], source_file, dest_file)
        self.assertTrue(
            ret,
            "Failed to move files {} and {}".format(source_file, dest_file))

        _, rename_count = find_hashed_subvol(self.subvols, "/",
                                             str(new_hashed.newname))
        self.assertEqual(count, rename_count,
                         "The hashed subvols for src and dest are not same.")
    def test_dht_file_rename_dest_exists_src_and_dest_hash_same(self):
        """
        Case 7:
        - Destination file should exist
        - Source file is stored on hashed subvolume(s1) it self
        - Destination file should be hashed to same subvolume(s1)
        - Destination file is stored on hashed subvolume
            mv <source_file> <destination_file>
        - Destination file is removed.
        - Source file should be renamed to destination file
        """
        # pylint: disable=protected-access
        # pylint: disable=unsubscriptable-object

        # Create soruce file and Get hashed subvol (s1)
        source_hashed_subvol, src_count, source_file = (
            self._create_file_and_get_hashed_subvol("test_source_file"))

        # Find a new file name for destination file that hashes
        # to same subvol (s1)
        new_hashed = find_specific_hashed(self.subvols, "/",
                                          source_hashed_subvol)
        self.assertIsNotNone(
            new_hashed, "Couldn't find a new hashed subvol "
            "for destination file")

        # Create destination_file and get its hashed subvol (should be s1)
        dest_hashed_subvol, dest_count, dest_file = (
            self._create_file_and_get_hashed_subvol(str(new_hashed.newname)))

        # Verify the subvols are not same for source and destination files
        self.assertEqual(src_count, dest_count,
                         "The subvols for src and dest are not same.")

        # Rename the source file to the destination file
        ret = move_file(self.mounts[0].client_system, source_file, dest_file)
        self.assertTrue(
            ret,
            ("Failed to move files {} and {}".format(source_file, dest_file)))

        # Verify the file move and the destination file is hashed to
        # same subvol or not
        _, rename_count = find_hashed_subvol(self.subvols, "/",
                                             str(new_hashed.newname))
        self.assertEqual(dest_count, rename_count,
                         ("The subvols for source : {} and dest : {} are "
                          "not same.".format(source_hashed_subvol._fqpath,
                                             dest_hashed_subvol._fqpath)))

        # Verify destination file is removed
        ret = self._verify_file_exists(dest_hashed_subvol,
                                       str(new_hashed.newname))
        self.assertTrue(ret, ("Destination file : {} is not removed in subvol"
                              " : {}".format(str(new_hashed.newname),
                                             dest_hashed_subvol._fqpath)))
        g.log.info("The destination file is removed as expected")
Exemplo n.º 3
0
 def _create_number_of_files_on_the_subvol(self, subvol_object, directory,
                                           number_of_files, mountpath):
     """Creates number of files specified on the given subvol"""
     name = None
     for _ in range(number_of_files):
         hashed = find_specific_hashed(self.subvols,
                                       directory,
                                       subvol_object,
                                       existing_names=name)
         self.assertIsNotNone(hashed, "Couldn't find a subvol to "
                              "create a file.")
         self._create_file(mountpath, hashed.newname)
         name = hashed.newname
    def _create_dest_file_find_hash(
            self, src_cache_subvol_count, src_hash_subvol_count):
        """Find a name for dest file such that it hashed to a subvol different
        from the src file's hash and cache subvol"""
        # Get subvol list
        subvol_list = (get_subvols(self.mnode, self.volname))['volume_subvols']
        self.assertIsNotNone(subvol_list, "Failed to get subvols")
        for item in (subvol_list[src_hash_subvol_count],
                     subvol_list[src_cache_subvol_count]):
            subvol_list.remove(item)

        # Find name for dest file
        dest_subvol = BrickDir(subvol_list[0][0] + "/" + "/")
        dest_file = find_specific_hashed(self.subvols, "/", dest_subvol)
        self.assertIsNotNone(dest_file, "Could not find hashed for destfile")

        # Create dest file
        cmd = "touch {}/{}".format(self.m_point, dest_file.newname)
        ret, _, _ = g.run(self.client, cmd)
        self.assertEqual(ret, 0, "Failed to create destfile")
        g.log.info("Successfully created destfile")
        return dest_file.newname, dest_file.subvol_count
    def test_file_rename_dest_exist_and_hash_to_srclink_subvol(self):
        """
        Case 10:
        - Destination file should exist
        - Source file is hashed sub volume(s1) and
          cached on another subvolume(s2)
        - Destination file should be hashed to same subvolume(s1) where source
          file is hashed.
            mv <source_file> <destination_file>
        - Destination file is removed.
        - Source file(cached) should be renamed to destination file
        - Source file(hashed) should be removed.
        - Destination hahshed file should be created on its
          hashed subvolume(s1)
        """
        # pylint: disable=protected-access
        # pylint: disable=unsubscriptable-object

        # Get hashed subvol s2)
        _, src_count, source_file = (
            self._create_file_and_get_hashed_subvol("test_source_file"))

        # Rename the file to create link in another subvol - (s1)
        new_hashed = find_new_hashed(self.subvols, "/", "test_source_file")
        self.assertIsNotNone(new_hashed, ("could not find new hashed subvol "
                                          "for {}".format(source_file)))

        self.assertNotEqual(src_count, new_hashed.subvol_count,
                            "New file should hash to different sub-volume")

        # Rename the source file to the new file name
        dest_file = "{}/{}".format(self.mount_point, str(new_hashed.newname))
        ret = move_file(self.mounts[0].client_system, source_file, dest_file)
        self.assertTrue(
            ret,
            ("Failed to move file {} and {}".format(source_file, dest_file)))

        # Verify the Source link file is stored on hashed sub volume(s1)
        src_link_subvol = new_hashed.hashedbrickobject
        ret = self._verify_link_file_exists(src_link_subvol,
                                            str(new_hashed.newname))
        self.assertTrue(
            ret, ("The New hashed volume {} doesn't have the "
                  "expected linkto file {}".format(src_link_subvol._fqpath,
                                                   str(new_hashed.newname))))

        # Get a file name for dest to hash to the subvol s1
        new_hashed2 = find_specific_hashed(self.subvols, "/", src_link_subvol,
                                           new_hashed.newname)
        self.assertIsNotNone(new_hashed2,
                             ("Couldn't find a name hashed to the"
                              " given subvol {}".format(src_link_subvol)))
        # Create destination file in the subvol (s2)
        dest_hashed_subvol, dest_count, dest_file = (
            self._create_file_and_get_hashed_subvol(str(new_hashed2.newname)))

        # Verify the subvol is same as S1
        self.assertEqual(new_hashed.subvol_count, dest_count,
                         "The subvols for src and dest are not same.")

        # Move the source file to the new file name
        source_file = "{}/{}".format(self.mount_point, str(new_hashed.newname))
        dest_file = "{}/{}".format(self.mount_point, str(new_hashed2.newname))
        ret = move_file(self.mounts[0].client_system, source_file, dest_file)
        self.assertTrue(ret, "Failed to move file")

        # Verify destination file is removed
        ret = self._verify_file_exists(dest_hashed_subvol,
                                       str(new_hashed2.newname))
        self.assertTrue(ret, ("Destination file : {} is not removed in subvol"
                              " : {}".format(str(new_hashed.newname),
                                             dest_hashed_subvol._fqpath)))
        g.log.info("The destination file is removed as expected")

        # Check that the source link file is removed.
        ret = self._verify_link_file_exists(src_link_subvol,
                                            str(new_hashed.newname))
        self.assertFalse(
            ret, ("The hashed volume {} still have the "
                  "expected linkto file {}".format(src_link_subvol._fqpath,
                                                   str(new_hashed.newname))))
        g.log.info("The source link file is removed")

        # Check Destination link file is created on its hashed sub-volume(s1)
        ret = self._verify_link_file_exists(src_link_subvol,
                                            str(new_hashed2.newname))
        self.assertTrue(
            ret, ("The New hashed volume {} doesn't have the "
                  "expected linkto file {}".format(src_link_subvol._fqpath,
                                                   str(new_hashed2.newname))))
        g.log.info("Destinaion link is created in desired subvol")
    def test_file_rename_dest_exist_and_not_hash_src_srclink_subvol(self):
        """
        Case 8:
        - Destination file should exist
        - Source file is hashed sub volume(s1) and
          cached on another subvolume(s2)
        - Destination file should be hashed to some other subvolume(s3)
          (should not be same subvolumes mentioned in above condition)
             mv <source_file> <destination_file>
        - Destination file is removed.
        - Source file should be renamed as destination file
        - Souce hashed file should be removed
        - Destination hashed file should be created on its hashed subvolume(s3)
        """
        # pylint: disable=protected-access
        # pylint: disable=too-many-locals
        # pylint: disable=unsubscriptable-object

        # Find a non hashed subvolume(or brick)
        # Create soruce file and Get hashed subvol (s2)
        _, count, source_file = (
            self._create_file_and_get_hashed_subvol("test_source_file"))

        # Rename the file to create link in hashed subvol -(s1)
        new_hashed = find_new_hashed(self.subvols, "/", "test_source_file")
        self.assertIsNotNone(new_hashed,
                             "could not find new hashed for dstfile")
        count2 = new_hashed.subvol_count
        # Rename the source file to the new file name
        dest_file = "{}/{}".format(self.mount_point, str(new_hashed.newname))
        ret = move_file(self.mounts[0].client_system, source_file, dest_file)
        self.assertTrue(
            ret,
            ("Failed to move file {} and {}".format(source_file, dest_file)))

        # Verify the Source link file is stored on hashed sub volume(s1)
        src_link_subvol = new_hashed.hashedbrickobject
        ret = self._verify_link_file_exists(src_link_subvol,
                                            str(new_hashed.newname))
        self.assertTrue(
            ret, ("The hashed subvol {} doesn't have the "
                  "expected linkto file: {}".format(src_link_subvol._fqpath,
                                                    str(new_hashed.newname))))

        # Find a subvol (s3) other than S1 and S2
        brickobject = create_brickobjectlist(self.subvols, "/")
        self.assertIsNotNone(brickobject, "Failed to get brick object list")
        br_count = -1
        subvol_new = None
        for brickdir in brickobject:
            br_count += 1
            if br_count not in (count, count2):
                subvol_new = brickdir
                break

        new_hashed2 = find_specific_hashed(self.subvols, "/", subvol_new)
        self.assertIsNotNone(new_hashed2,
                             "could not find new hashed for dstfile")

        # Create destination file in a new subvol (s3)
        dest_hashed_subvol, dest_count, dest_file = (
            self._create_file_and_get_hashed_subvol(str(new_hashed2.newname)))

        # Verify the subvol is not same as S1 or S2
        self.assertNotEqual(
            count2, dest_count,
            ("The subvols for src :{} and dest : {} are same.".format(
                count2, dest_count)))
        # Verify the subvol is not same as S1 or S2
        self.assertNotEqual(
            count, dest_count,
            ("The subvols for src :{} and dest : {} are same.".format(
                count, dest_count)))

        # Rename the source file to the destination file
        source_file = "{}/{}".format(self.mount_point, str(new_hashed.newname))
        ret = move_file(self.mounts[0].client_system, source_file, dest_file)
        self.assertTrue(
            ret,
            ("Failed to move file {} and {}".format(source_file, dest_file)))

        # Verify destination file is removed
        ret = self._verify_file_exists(dest_hashed_subvol,
                                       str(new_hashed2.newname))
        self.assertTrue(ret, ("Destination file : {} is not removed in subvol"
                              " : {}".format(str(new_hashed.newname),
                                             dest_hashed_subvol._fqpath)))
        g.log.info("The destination file is removed as expected")

        # Check that the source link file is removed.
        ret = self._verify_link_file_exists(src_link_subvol,
                                            str(new_hashed.newname))
        self.assertFalse(
            ret, ("The New hashed volume {} still have the "
                  "expected linkto file {}".format(src_link_subvol._fqpath,
                                                   str(new_hashed.newname))))
        g.log.info("The source link file is removed")

        # Check Destination link file is created on its hashed sub-volume(s3)
        ret = self._verify_link_file_exists(dest_hashed_subvol,
                                            str(new_hashed2.newname))
        self.assertTrue(
            ret, ("The New hashed volume {} doesn't have the "
                  "expected linkto file {}".format(dest_hashed_subvol._fqpath,
                                                   str(new_hashed2.newname))))
        g.log.info("Destinaion link is created in desired subvol")
    def test_file_rename_when_src_file_and_dest_file_hash_same_subvol(self):
        """
       Case 4:
       - Destination file does not exist
       - Source link file is stored on hashed sub volume(s1) and Source
         file is stored on another subvolume(s2)
       - Destination file should be hashed to same subvolume(s2)
            mv <source_file> <destination_file>
       - Source file should be ranamed to destination file
       - source link file should be removed.
        """
        # pylint: disable=protected-access
        # pylint: disable=unsubscriptable-object

        # Get hashed subvol (S2)
        source_hashed_subvol, count, source_file = (
            self._create_file_and_get_hashed_subvol("test_source_file"))

        # Rename the file to create link in hashed subvol -(s1)
        new_hashed = find_new_hashed(self.subvols, "/", "test_source_file")
        self.assertIsNotNone(
            new_hashed,
            ("could not find new hashed for {}".format(source_file)))

        # Rename the source file to the new file name
        dest_file = "{}/{}".format(self.mount_point, str(new_hashed.newname))
        ret = move_file(self.clients[0], source_file, dest_file)
        self.assertTrue(
            ret,
            ("Failed to move file {} and {}".format(source_file, dest_file)))

        # Verify the Source link file is stored on hashed sub volume(s1)
        src_link_subvol = new_hashed.hashedbrickobject
        ret = self._verify_link_file_exists(src_link_subvol,
                                            str(new_hashed.newname))
        self.assertTrue(
            ret, ("The New hashed volume {} doesn't have the "
                  "expected linkto file {}".format(src_link_subvol._fqpath,
                                                   str(new_hashed.newname))))

        # Get a file name to hash to the subvol s2
        new_hashed2 = find_specific_hashed(self.subvols, "/",
                                           source_hashed_subvol)
        self.assertIsNotNone(
            new_hashed2, "Could not find a name hashed"
            "to the given subvol")

        _, rename_count = (find_hashed_subvol(self.subvols, "/",
                                              str(new_hashed2.newname)))
        self.assertEqual(count, rename_count,
                         "The subvols for src and dest are not same.")

        # Move the source file to the new file name
        source_file = "{}/{}".format(self.mount_point, str(new_hashed.newname))
        dest_file = "{}/{}".format(self.mount_point, str(new_hashed2.newname))
        ret = move_file(self.clients[0], source_file, dest_file)
        self.assertTrue(
            ret,
            ("Failed to move file {} and {}".format(source_file, dest_file)))

        # check that the source link file is removed.
        ret = self._verify_link_file_exists(src_link_subvol,
                                            str(new_hashed.newname))
        self.assertFalse(
            ret, ("The New hashed volume {} still have the "
                  "expected linkto file {}".format(src_link_subvol._fqpath,
                                                   str(new_hashed.newname))))
        g.log.info("The source link file is removed")
    def test_file_rename_when_dest_hash_to_src_subvol(self):
        """
        - Destination file should exist
        - Source file is stored on hashed subvolume it self
        - Destination file should be hased to same subvolume(s1)
          where source file is
        - Destination file hased subvolume(s1) but cached onsubvolume(s2)
            mv <source_file> <destination_file>
        - Destination file is removed.
        - Source file should be renamed as destination file
        - Destination link file should be removed
        """
        # pylint: disable=protected-access

        # Create soruce file and Get hashed subvol (s1)
        source_hashed_subvol, src_count, source_file = (
            self._create_file_and_get_hashed_subvol("test_source_file"))

        # Find a file name that hashes to another subvol (s2)
        new_hashed = find_new_hashed(self.subvols, "/", "test_source_file")
        self.assertIsNotNone(
            new_hashed,
            ("could'nt find new hashed for {}".format(source_file)))

        # Create destination file in subvol S2
        _, dest_count, dest_file = (self._create_file_and_get_hashed_subvol(
            str(new_hashed.newname)))

        # Rename dest file such that it hashes to S1
        new_hashed2 = find_specific_hashed(self.subvols, "/",
                                           source_hashed_subvol)
        self.assertIsNotNone(new_hashed2,
                             "could not find new hashed for dstfile")

        # Verify the subvol is S1 itself
        self.assertEqual(
            new_hashed2.subvol_count, src_count,
            "The destination file is not stored to desired "
            "subvol :{}".format(dest_count))

        # Rename/Move the file
        dest_file2 = "{}/{}".format(self.mount_point, str(new_hashed2.newname))
        ret = move_file(self.mounts[0].client_system, dest_file, dest_file2)
        self.assertTrue(
            ret,
            "Failed to move files {} and {}".format(source_file, dest_file))

        # Verify the Dest link file is stored on hashed sub volume(s1)
        dest_link_subvol = new_hashed2.hashedbrickobject
        ret = self._verify_link_file_exists(dest_link_subvol,
                                            str(new_hashed2.newname))
        self.assertTrue(
            ret, ("The hashed subvol {} doesn't have the "
                  "expected linkto file: {}".format(dest_link_subvol._fqpath,
                                                    str(new_hashed2.newname))))

        # Rename Source to Dest
        src = "{}/{}".format(self.mount_point, "test_source_file")
        dest_file = "{}/{}".format(self.mount_point, str(new_hashed2.newname))
        ret = move_file(self.mounts[0].client_system, src, dest_file)
        self.assertTrue(
            ret, "Failed to move files {} and {}".format(src, dest_file))

        # Verify destination file is removed
        ret = self._verify_file_exists(new_hashed.hashedbrickobject,
                                       str(new_hashed.newname))
        self.assertFalse(
            ret, ("Destination file : {} is not removed in subvol"
                  " : {}".format(str(new_hashed.newname),
                                 new_hashed.hashedbrickobject._fqpath)))
        g.log.info("The destination file is removed as expected")

        # Verify the Destination link is removed
        ret = self._verify_link_file_exists(new_hashed2.hashedbrickobject,
                                            str(new_hashed2.newname))
        self.assertFalse(ret, ("The hashed subvol {} still have the "
                               "expected linkto file: {}".format(
                                   new_hashed2.hashedbrickobject._fqpath,
                                   str(new_hashed2.newname))))

        g.log.info("The Destination link file is removed as expected")
    def test_file_rename_when_dest_cache_to_src_subvol(self):
        """
        - Destination file should exist
        - Source file is stored on hashed subvolume it self
        - Destination file should be hased to some other subvolume(s2)
        - Destination file hashed on subvolume(s2) but cached on the
          subvolume(s1) where souce file is present
            mv <source_file> <destination_file>
        - Destination file is removed.
        - Source file should be renamed as destination file
        - Destination link file should be there on hashed subvolume and
          should link to new destination file
        """
        # pylint: disable=protected-access

        # Create soruce file and Get hashed subvol (s1)
        source_hashed_subvol, src_count, _ = (
            self._create_file_and_get_hashed_subvol("test_source_file"))

        # Find name for dest file to cache to S1
        dest_subvol = find_specific_hashed(self.subvols, "/",
                                           source_hashed_subvol)
        dest_name = str(dest_subvol.newname)

        # Create destination file in subvol S1
        _, dest_count, _ = self._create_file_and_get_hashed_subvol(dest_name)

        # Verify its subvol (s1)
        self.assertEqual(src_count, dest_count,
                         ("The newly created file falls under subvol {} "
                          "rather than {}".format(dest_count, src_count)))

        # Rename dest file such that it hashes to some other subvol S2
        dest_hashed_subvol = find_new_hashed(self.subvols, "/", dest_name)
        self.assertIsNotNone(dest_hashed_subvol,
                             "could not find new hashed for dstfile")

        # Rename/Move the file
        dest_file = "{}/{}".format(self.mount_point,
                                   dest_hashed_subvol.newname)
        src_file = "{}/{}".format(self.mount_point, dest_name)
        ret = move_file(self.mounts[0].client_system, src_file, dest_file)
        self.assertTrue(
            ret, "Failed to move files {} and {}".format(src_file, dest_file))

        # Verify the Dest link file is stored on hashed sub volume(s2)
        dest_link_subvol = dest_hashed_subvol.hashedbrickobject
        ret = self._verify_link_file_exists(dest_link_subvol,
                                            str(dest_hashed_subvol.newname))
        self.assertTrue(
            ret,
            ("The hashed subvol {} doesn't have the "
             "expected linkto file: {}".format(
                 dest_link_subvol._fqpath, str(dest_hashed_subvol.newname))))

        # Rename Source to Dest
        src = "{}/{}".format(self.mount_point, "test_source_file")
        dest_file = "{}/{}".format(self.mount_point,
                                   dest_hashed_subvol.newname)
        ret = move_file(self.mounts[0].client_system, src, dest_file)
        self.assertTrue(
            ret, "Failed to move files {} and {}".format(src, dest_file))

        # Verify destination file is removed
        ret = self._verify_file_exists(dest_subvol.hashedbrickobject,
                                       dest_name)
        self.assertFalse(ret, ("Destination file : {} is not removed in subvol"
                               " : {}".format(str(dest_hashed_subvol.newname),
                                              dest_link_subvol._fqpath)))
        g.log.info("The destination file is removed as expected")

        # Verify the Destination link is present
        ret = self._verify_link_file_exists(dest_link_subvol,
                                            str(dest_hashed_subvol.newname))
        self.assertTrue(
            ret,
            ("The hashed subvol {} still have the "
             "expected linkto file: {}".format(
                 dest_link_subvol._fqpath, str(dest_hashed_subvol.newname))))

        g.log.info("The Destination link file is present as expected")

        # Verify the dest link file points to new destination file
        file_path = dest_link_subvol._fqpath + str(dest_hashed_subvol.newname)
        ret = (self._verify_file_links_to_specified_destination(
            dest_link_subvol._host, file_path,
            str(dest_hashed_subvol.newname)))
        self.assertTrue(
            ret, "The dest link file not pointing towards "
            "the desired file")
        g.log.info("The Destination link file is pointing to new file"
                   " as expected")
    def test_file_rename_when_source_and_dest_hash_same_subvol(self):
        """
        - Destination file should exist
        - Source file is hashed sub volume(s1) and cached on another
          subvolume(s2)
        - Destination file should be hased to same subvolume(s1) where
          source file is hased
        - Destination hashed on subvolume(s1) but should be cached on
          subvolume(s2) where source file is stored
            mv <source_file> <destination_file>
        - Destination file is removed.
        - Source file should be renamed as destination file
        - Destination link file should be there on hashed subvolume and
          should link to new destination file
        - source link file should be removed
        """
        # pylint: disable=protected-access
        # pylint: disable=too-many-locals

        # Create soruce file and Get hashed subvol (s2)
        source_hashed_subvol, src_count, source_file = (
            self._create_file_and_get_hashed_subvol("test_source_file"))

        # Rename the file such that the new name hashes to a new subvol (S1)
        new_hashed = find_new_hashed(self.subvols, "/", "test_source_file")
        self.assertIsNotNone(
            new_hashed,
            ("could'nt find new hashed for {}".format(source_file)))

        # Verify the subvols are not same for source and destination files
        self.assertNotEqual(src_count, new_hashed.subvol_count,
                            "The subvols for src and dest are same.")

        # Rename/Move the file
        dest_file = "{}/{}".format(self.mount_point, str(new_hashed.newname))
        ret = move_file(self.mounts[0].client_system, source_file, dest_file)
        self.assertTrue(
            ret,
            "Failed to move files {} and {}".format(source_file, dest_file))

        # Verify the Source link file is stored on hashed sub volume(s1)
        src_link_subvol = new_hashed.hashedbrickobject
        ret = self._verify_link_file_exists(src_link_subvol,
                                            str(new_hashed.newname))
        self.assertTrue(
            ret, ("The hashed subvol {} doesn't have the "
                  "expected linkto file: {}".format(src_link_subvol._fqpath,
                                                    str(new_hashed.newname))))

        # Get a file name that stores to S2 for destination
        new_hashed2 = find_specific_hashed(self.subvols, "/",
                                           source_hashed_subvol)
        self.assertIsNotNone(new_hashed2,
                             "could not find new hashed for dstfile")

        # Create destination file in subvol S2
        dest_hashed_subvol, dest_count, dest_file = (
            self._create_file_and_get_hashed_subvol(str(new_hashed2.newname)))

        # Verify the subvol is S2 itself
        self.assertEqual(
            dest_count, src_count,
            "The destination file is not stored to desired "
            "subvol :{}".format(dest_count))

        # Create a linkfile to dest by renaming it to hash to S1
        dest_hashed = find_specific_hashed(self.subvols, "/", src_link_subvol,
                                           new_hashed.newname)
        # Verify the subvol is S1
        self.assertEqual(
            dest_hashed.subvol_count, new_hashed.subvol_count,
            "The destination file is not stored to desired "
            "subvol :{}, instead to subvol : {}".format(
                dest_hashed.subvol_count, new_hashed))

        # Rename the dest file to the new file name
        dest_file_2 = "{}/{}".format(self.mount_point,
                                     str(dest_hashed.newname))
        ret = move_file(self.mounts[0].client_system, dest_file, dest_file_2)
        self.assertTrue(
            ret,
            "Failed to move files {} and {}".format(source_file, dest_file_2))

        # Rename source to destination
        src = "{}/{}".format(self.mount_point, str(new_hashed.newname))
        dest_file = "{}/{}".format(self.mount_point, str(dest_hashed.newname))
        ret = move_file(self.mounts[0].client_system, src, dest_file)
        self.assertTrue(
            ret, "Failed to move files {} and {}".format(src, dest_file))

        # Verify destination file is removed
        ret = self._verify_file_exists(dest_hashed_subvol,
                                       str(new_hashed2.newname))
        self.assertFalse(ret, ("Destination file : {} is not removed in subvol"
                               " : {}".format(str(new_hashed2.newname),
                                              dest_hashed_subvol._fqpath)))
        g.log.info("The destination file is removed as expected")

        # Verify the source link is removed
        ret = self._verify_link_file_exists(src_link_subvol,
                                            str(new_hashed.newname))
        self.assertFalse(
            ret, ("The hashed subvol {} still have the "
                  "expected linkto file: {}".format(src_link_subvol._fqpath,
                                                    str(new_hashed.newname))))

        g.log.info("The source link file is removed as expected")

        # Verify the Destination link is on hashed subvolume
        ret = self._verify_link_file_exists(src_link_subvol,
                                            str(dest_hashed.newname))
        self.assertTrue(
            ret, ("The hashed subvol {} doesn't have the "
                  "expected linkto file: {}".format(dest_hashed_subvol._fqpath,
                                                    str(dest_hashed.newname))))

        # Verify the dest link file points to new destination file
        file_path = src_link_subvol._fqpath + str(dest_hashed.newname)
        ret = (self._verify_file_links_to_specified_destination(
            src_link_subvol._host, file_path, str(dest_hashed.newname)))
        self.assertTrue(
            ret, "The dest link file not pointing towards "
            "the desired file")
        g.log.info("The Destination link file is pointing to new file"
                   " as expected")
Exemplo n.º 11
0
    def test_file_rename_when_dest_hash_src_hashed_but_cache_diff(self):
        """
        - Destination file should exist
        - Source file is stored on hashed subvolume it self
        - Destination file should be hased to some other subvolume(s2)
        - Destination file hased on subvolume(s2) but cached on some other
          subvolume(s3)(neither s1 nor s2)
            mv <source_file> <destination_file>
        - Destination file is removed.
        - Source file should be renamed as destination file
        - Destination link file should be there on hashed subvolume and
          should link to new destination file
        """
        # pylint: disable=protected-access
        # pylint: disable=too-many-locals

        # Create source file and Get hashed subvol (s1)
        _, src_count, source_file = (
            self._create_file_and_get_hashed_subvol("test_source_file"))

        # Find a new file name for destination to hash to some subvol S3
        new_hashed = find_new_hashed(self.subvols, "/", "test_source_file")
        self.assertIsNotNone(new_hashed,
                             "couldn't find new hashed for destination file")

        # Create Dest file in S3
        dest_cached, dest_count, dest_file = (
            self._create_file_and_get_hashed_subvol(str(new_hashed.newname)))

        # Verify S1 and S3 are not same
        self.assertNotEqual(src_count, dest_count,
                            ("The destination file is cached to the source "
                             "cached subvol"))

        # Find new name for dest file, that it hashes to some other subvol S2
        brickobject = create_brickobjectlist(self.subvols, "/")
        self.assertIsNotNone(brickobject, "Failed to get brick object list")
        br_count = -1
        subvol_new = None
        for brickdir in brickobject:
            br_count += 1
            if br_count not in (src_count, dest_count):
                subvol_new = brickdir
                break

        dest_hashed = find_specific_hashed(self.subvols,
                                           "/",
                                           subvol_new)
        # Move dest to new name
        dest = "{}/{}".format(self.mount_point, str(dest_hashed.newname))
        ret = move_file(self.mounts[0].client_system, dest_file, dest)
        self.assertTrue(ret, ("Failed to move file {} and {}"
                              .format(dest_file, dest)))

        # Move Source file to Dest
        ret = move_file(self.mounts[0].client_system, source_file, dest)
        self.assertTrue(ret, ("Failed to move file {} and {}"
                              .format(source_file, dest)))

        # Verify Destination File is removed
        ret = self._verify_file_exists(dest_cached,
                                       str(new_hashed.newname))
        self.assertFalse(ret, "The Source file is still present in {}"
                         .format(dest_cached._fqpath))

        # Verify Destination Link is present and points to new dest file
        ret = self._verify_link_file_exists(dest_hashed.hashedbrickobject,
                                            str(dest_hashed.newname))
        self.assertTrue(ret, "The Dest link file is not present in {}"
                        .format(dest_hashed.hashedbrickobject._fqpath))

        file_path = dest_hashed.hashedbrickobject._fqpath + str(
            dest_hashed.newname)
        ret = (self._verify_file_links_to_specified_destination(
            dest_hashed.hashedbrickobject._host, file_path,
            str(dest_hashed.newname)))
        self.assertTrue(ret, "The dest link file not pointing towards "
                             "the desired file")
        g.log.info("The Destination link file is pointing to new file"
                   " as expected")
Exemplo n.º 12
0
    def test_file_rename_when_dest_neither_hash_cache_to_src_subvols(self):
        """
        - Destination file should exist
        - Source file hashed on sub volume(s1) and cached on
          another subvolume(s2)
        - Destination file should be hased to some other subvolume(s3)
          (neither s1 nor s2)
        - Destination file hased on subvolume(s3) but cached on
          remaining subvolume(s4)
            mv <source_file> <destination_file>
        - Destination file is removed.
        - Source file should be renamed as destination file
        - Destination link file should be there on hashed subvolume
          and should link to new destination file
        - source link file should be removed
        """
        # pylint: disable=protected-access
        # pylint: disable=too-many-locals

        # Create source file and Get hashed subvol (s2)
        _, src_count, source_file = (
            self._create_file_and_get_hashed_subvol("test_source_file"))

        # Find a new file name for destination file, which hashes
        # to another subvol (s2)
        new_hashed = find_new_hashed(self.subvols, "/", "test_source_file")
        self.assertIsNotNone(new_hashed,
                             "couldn't find new hashed for destination file")

        # Rename the source file to the new file name
        src_hashed = "{}/{}".format(self.mount_point, str(new_hashed.newname))
        ret = move_file(self.mounts[0].client_system, source_file, src_hashed)
        self.assertTrue(ret, ("Failed to move file {} and {}"
                              .format(source_file, src_hashed)))

        # Verify the Source link file is stored on hashed sub volume(s1)
        src_link_subvol = new_hashed.hashedbrickobject
        ret = self._verify_link_file_exists(src_link_subvol,
                                            str(new_hashed.newname))
        self.assertTrue(ret, ("The hashed subvol {} doesn't have the "
                              "expected linkto file: {}"
                              .format(src_link_subvol._fqpath,
                                      str(new_hashed.newname))))

        # Destination file cached on S4.
        # Find a subvol (s4) for dest file to linkto, other than S1 and S2
        brickobject = create_brickobjectlist(self.subvols, "/")
        self.assertIsNotNone(brickobject, "Failed to get brick object list")
        br_count = -1
        subvol_new = None
        for brickdir in brickobject:
            br_count += 1
            if br_count not in (src_count, new_hashed.subvol_count):
                subvol_new = brickdir
                break

        dest_cached = find_specific_hashed(self.subvols,
                                           "/",
                                           subvol_new)
        self.assertIsNotNone(dest_cached,
                             "could not find new hashed for dstfile")
        # Create a file in S3
        _, _, dest_src = self._create_file_and_get_hashed_subvol(
            str(dest_cached.newname))

        # Verify the subvol is not S2 and S1
        self.assertNotEqual(dest_cached.subvol_count, new_hashed.subvol_count,
                            ("The subvol found for destination is same as "
                             "that of the source file hashed subvol"))
        self.assertNotEqual(dest_cached.subvol_count, src_count,
                            ("The subvol found for destination is same as "
                             "that of the source file cached subvol"))

        # Identify a name for dest that hashes to another subvol S3
        # Find a subvol (s3) for dest file to linkto, other than S1 and S2 and
        # S4
        brickobject = create_brickobjectlist(self.subvols, "/")
        self.assertIsNotNone(brickobject, "Failed to get brick object list")
        br_count = -1
        subvol_new = None
        for brickdir in brickobject:
            br_count += 1
            if br_count not in (src_count, new_hashed.subvol_count,
                                dest_cached.subvol_count):
                subvol_new = brickdir
                break

        dest_hashed = find_specific_hashed(self.subvols,
                                           "/",
                                           subvol_new)

        # Move dest to new name
        dest = "{}/{}".format(self.mount_point, str(dest_hashed.newname))
        ret = move_file(self.mounts[0].client_system, dest_src, dest)
        self.assertTrue(ret, ("Failed to move file {} and {}"
                              .format(dest_src, dest)))

        # Move Source file to Dest
        src = "{}/{}".format(self.mount_point, str(new_hashed.newname))
        ret = move_file(self.mounts[0].client_system, src, dest)
        self.assertTrue(ret, ("Failed to move file {} and {}"
                              .format(src, dest)))

        # Verify Destination File is removed
        ret = self._verify_file_exists(dest_cached.hashedbrickobject,
                                       str(dest_cached.newname))
        self.assertFalse(ret, "The Source file is still present in {}"
                         .format(dest_cached.hashedbrickobject._fqpath))

        # Verify Source link is removed
        ret = self._verify_link_file_exists(src_link_subvol,
                                            str(new_hashed.newname))
        self.assertFalse(ret, "The source link file is still present in {}"
                         .format(src_link_subvol._fqpath))

        # Verify Destination Link is present and points to new dest file
        ret = self._verify_link_file_exists(dest_hashed.hashedbrickobject,
                                            str(dest_hashed.newname))
        self.assertTrue(ret, "The Dest link file is not present in {}"
                        .format(dest_hashed.hashedbrickobject._fqpath))

        file_path = dest_hashed.hashedbrickobject._fqpath + str(
            dest_hashed.newname)
        ret = (self._verify_file_links_to_specified_destination(
            dest_hashed.hashedbrickobject._host, file_path,
            str(dest_hashed.newname)))
        self.assertTrue(ret, "The dest link file not pointing towards "
                             "the desired file")
        g.log.info("The Destination link file is pointing to new file"
                   " as expected")
Exemplo n.º 13
0
    def test_file_rename_when_dest_hash_src_cached(self):
        """
        - Destination file should exist
        - Source file hashed sub volume(s1) and cached on another subvolume(s2)
        - Destination file should be hased to subvolume where source file is
          stored(s2)
        - Destination file hased on subvolume(s2) but should be cached on
          some other subvolume(s3) than this two subvolume
            mv <source_file> <destination_file>
        - Destination file is removed.
        - Source file should be renamed as destination file
        - Destination link file should be removed
        - source link file should be removed
        """
        # pylint: disable=protected-access
        # pylint: disable=too-many-locals

        # Create source file and Get hashed subvol (s2)
        src_subvol, src_count, source_file = (
            self._create_file_and_get_hashed_subvol("test_source_file"))

        # Find a new file name for destination file, which hashes
        # to another subvol (s2)
        new_hashed = find_new_hashed(self.subvols, "/", "test_source_file")
        self.assertIsNotNone(new_hashed,
                             "couldn't find new hashed for destination file")

        # Rename the source file to the new file name
        src_hashed = "{}/{}".format(self.mount_point, str(new_hashed.newname))
        ret = move_file(self.mounts[0].client_system, source_file, src_hashed)
        self.assertTrue(ret, ("Failed to move file {} and {}"
                              .format(source_file, src_hashed)))

        # Verify the Source link file is stored on hashed sub volume(s1)
        src_link_subvol = new_hashed.hashedbrickobject
        ret = self._verify_link_file_exists(src_link_subvol,
                                            str(new_hashed.newname))
        self.assertTrue(ret, ("The hashed subvol {} doesn't have the "
                              "expected linkto file: {}"
                              .format(src_link_subvol._fqpath,
                                      str(new_hashed.newname))))

        # Find a subvol (s3) for dest file to linkto, other than S1 and S2
        brickobject = create_brickobjectlist(self.subvols, "/")
        self.assertIsNotNone(brickobject, "Failed to get brick object list")
        br_count = -1
        subvol_new = None
        for brickdir in brickobject:
            br_count += 1
            if br_count not in (src_count, new_hashed.subvol_count):
                subvol_new = brickdir
                break

        new_hashed2 = find_specific_hashed(self.subvols,
                                           "/",
                                           subvol_new)
        self.assertIsNotNone(new_hashed2,
                             "could not find new hashed for dstfile")

        # Create a file in the subvol S3
        dest_subvol, count, dest_file = (
            self._create_file_and_get_hashed_subvol(str(new_hashed2.newname)))

        # Verify the subvol is not same as S1 and S2
        self.assertNotEqual(count, src_count,
                            ("The subvol found for destination is same as that"
                             " of the source file cached subvol"))
        self.assertNotEqual(count, new_hashed.subvol_count,
                            ("The subvol found for destination is same as that"
                             " of the source file hashed subvol"))

        # Find a file name that hashes to S2
        dest_hashed = find_specific_hashed(self.subvols,
                                           "/",
                                           src_subvol)
        self.assertIsNotNone(dest_hashed,
                             "could not find new hashed for dstfile")

        # Rename destination to hash to S2 and verify
        dest = "{}/{}".format(self.mount_point, str(dest_hashed.newname))
        ret = move_file(self.mounts[0].client_system, dest_file, dest)
        self.assertTrue(ret, ("Failed to move file {} and {}"
                              .format(dest_file, dest)))

        # Rename Source File to Dest
        ret = move_file(self.mounts[0].client_system, src_hashed, dest)
        self.assertTrue(ret, ("Failed to move file {} and {}"
                              .format(src_hashed, dest)))

        # Verify Destination File is removed
        ret = self._verify_file_exists(new_hashed2.hashedbrickobject,
                                       str(new_hashed2.newname))
        self.assertFalse(ret, "The Destination file is still present in {}"
                         .format(dest_subvol._fqpath))

        # Verify Source link is removed
        ret = self._verify_link_file_exists(src_link_subvol,
                                            str(new_hashed.newname))
        self.assertFalse(ret, "The source link file is still present in {}"
                         .format(src_link_subvol._fqpath))

        # Verify Destination Link is removed
        ret = self._verify_link_file_exists(dest_hashed.hashedbrickobject,
                                            str(dest_hashed.newname))
        self.assertFalse(ret, "The Dest link file is still present in {}"
                         .format(dest_hashed.hashedbrickobject._fqpath))
Exemplo n.º 14
0
    def test_file_rename_when_dest_doesnt_hash_src_cached_or_hashed(self):
        """
        - Destination file should exist
        - Source file is hashed on sub volume(s1) and cached on
          another subvolume(s2)
        - Destination file should be hased to subvolume(s3) other
          than above two subvolumes
        - Destination file hased on subvolume(s3) but destination file
          should be cached on same subvolume(s2) where source file is stored
            mv <source_file> <destination_file>
        - Destination file is removed.
        - Source file should be renamed as destination file
        - Destination file hashed on subvolume and should link
          to new destination file
        - source link file should be removed
        """
        # pylint: disable=protected-access
        # pylint: disable=too-many-locals

        # Create source file and Get hashed subvol (s2)
        src_subvol, src_count, source_file = (
            self._create_file_and_get_hashed_subvol("test_source_file"))

        # Find a new file name for destination file, which hashes
        # to another subvol (s1)
        new_hashed = find_new_hashed(self.subvols, "/", "test_source_file")
        self.assertIsNotNone(new_hashed,
                             "couldn't find new hashed for destination file")

        # Rename the source file to the new file name
        dest_file = "{}/{}".format(self.mount_point, str(new_hashed.newname))
        ret = move_file(self.mounts[0].client_system, source_file, dest_file)
        self.assertTrue(ret, ("Failed to move file {} and {}"
                              .format(source_file, dest_file)))

        # Verify the Source link file is stored on hashed sub volume(s1)
        src_link_subvol = new_hashed.hashedbrickobject
        ret = self._verify_link_file_exists(src_link_subvol,
                                            str(new_hashed.newname))
        self.assertTrue(ret, ("The hashed subvol {} doesn't have the "
                              "expected linkto file: {}"
                              .format(src_link_subvol._fqpath,
                                      str(new_hashed.newname))))

        # Identify a file name for dest to get stored in S2
        dest_cached_subvol = find_specific_hashed(self.subvols,
                                                  "/",
                                                  src_subvol)
        # Create the file with identified name
        _, _, dst_file = (
            self._create_file_and_get_hashed_subvol(
                str(dest_cached_subvol.newname)))
        # Verify its in S2 itself
        self.assertEqual(dest_cached_subvol.subvol_count, src_count,
                         ("The subvol found for destination is not same as "
                          "that of the source file cached subvol"))

        # Find a subvol (s3) for dest file to linkto, other than S1 and S2
        brickobject = create_brickobjectlist(self.subvols, "/")
        self.assertIsNotNone(brickobject, "Failed to get brick object list")
        br_count = -1
        subvol_new = None
        for brickdir in brickobject:
            br_count += 1
            if br_count not in (src_count, new_hashed.subvol_count):
                subvol_new = brickdir
                break

        new_hashed2 = find_specific_hashed(self.subvols,
                                           "/",
                                           subvol_new)
        self.assertIsNotNone(new_hashed2,
                             "could not find new hashed for dstfile")

        # Verify the subvol is not same as S1(src_count) and S2(dest_count)
        self.assertNotEqual(new_hashed2.subvol_count, src_count,
                            ("The subvol found for destination is same as that"
                             " of the source file cached subvol"))
        self.assertNotEqual(new_hashed2.subvol_count, new_hashed.subvol_count,
                            ("The subvol found for destination is same as that"
                             " of the source file hashed subvol"))

        # Rename the dest file to the new file name
        dst_file_ln = "{}/{}".format(self.mount_point,
                                     str(new_hashed2.newname))
        ret = move_file(self.mounts[0].client_system, dst_file, dst_file_ln)
        self.assertTrue(ret, ("Failed to move file {} and {}"
                              .format(dst_file, dst_file_ln)))

        # Verify the Dest link file is stored on hashed sub volume(s3)
        dest_link_subvol = new_hashed2.hashedbrickobject
        ret = self._verify_link_file_exists(dest_link_subvol,
                                            str(new_hashed2.newname))
        self.assertTrue(ret, ("The hashed subvol {} doesn't have the "
                              "expected linkto file: {}"
                              .format(dest_link_subvol._fqpath,
                                      str(new_hashed2.newname))))

        # Move/Rename Source File to Dest
        src_file = "{}/{}".format(self.mount_point, str(new_hashed.newname))
        ret = move_file(self.mounts[0].client_system, src_file, dst_file)
        self.assertTrue(ret, ("Failed to move file {} and {}"
                              .format(src_file, dst_file)))

        # Verify Source file is removed
        ret = self._verify_file_exists(src_subvol, "test_source_file")
        self.assertFalse(ret, "The source file is still present in {}"
                         .format(src_subvol._fqpath))

        # Verify Source link is removed
        ret = self._verify_link_file_exists(src_link_subvol,
                                            str(new_hashed.newname))
        self.assertFalse(ret, "The source link file is still present in {}"
                         .format(src_link_subvol._fqpath))

        # Verify the Destination link is on hashed subvolume
        ret = self._verify_link_file_exists(dest_link_subvol,
                                            str(new_hashed2.newname))
        self.assertTrue(ret, ("The hashed subvol {} doesn't have the "
                              "expected linkto file: {}"
                              .format(dest_link_subvol._fqpath,
                                      str(new_hashed2.newname))))

        # Verify the dest link file points to new destination file
        file_path = dest_link_subvol._fqpath + str(new_hashed2.newname)
        ret = (self._verify_file_links_to_specified_destination(
            dest_link_subvol._host, file_path,
            str(dest_cached_subvol.newname)))
        self.assertTrue(ret, "The dest link file not pointing towards "
                             "the desired file")
        g.log.info("The Destination link file is pointing to new file"
                   " as expected")