Esempio n. 1
0
    def test_ec_truncate(self):
        """Jira ID: DAOS-7328.

        Test Description:
            Verify the truncate on EC object class works fine over fuse.

        Use Cases:
            Create the container with EC class
            Create the data file with verify pattern over Fuse
            Truncate the file and increase the size
            Verify the data content and file size
            Truncate the file and reduce the size to original
            Verify the data content and file size

        :avocado: tags=all,full_regression
        :avocado: tags=hw,large,ib2
        :avocado: tags=ec,ec_fio,ec_posix
        :avocado: tags=ec_truncate
        """
        truncate_size = int(self.params.get("truncate_size", '/run/fio/*'))
        fname = self.params.get("names", '/run/fio/*')

        # Write the file using Fio
        self.execute_fio(stop_dfuse=False)

        # Get the fuse file name.
        testfile = "{}.0.0".format(
            os.path.join(self.dfuse.mount_dir.value, fname[0]))
        original_fs = int(self.fio_cmd._jobs['test'].size.value)

        # Read and verify the original data.
        self.fio_cmd._jobs['test'].rw = 'read'
        self.fio_cmd.run()

        # Get the file stats and confirm size
        file_size = get_remote_file_size(self.hostlist_clients[0], testfile)
        self.assertEqual(original_fs, file_size)

        # Truncate the original file which will extend the size of file.
        result = run_pcmd(self.hostlist_clients,
                          "truncate -s {} {}".format(truncate_size, testfile))
        if result[0]["exit_status"] == 1:
            self.fail("Failed to truncate file {}".format(testfile))

        # Verify the file size is extended.
        file_size = get_remote_file_size(self.hostlist_clients[0], testfile)
        self.assertEqual(truncate_size, file_size)

        # Read and verify the data after truncate.
        self.fio_cmd.run()

        # Truncate the original file and shrink to original size.
        result = run_pcmd(self.hostlist_clients,
                          "truncate -s {} {}".format(original_fs, testfile))
        if result[0]["exit_status"] == 1:
            self.fail("Failed to truncate file {}".format(testfile))

        # Verify the file size is shrink to original.
        file_size = get_remote_file_size(self.hostlist_clients[0], testfile)
        self.assertEqual(original_fs, file_size)

        # Read and verify the data after truncate.
        self.fio_cmd.run()
Esempio n. 2
0
    def test_stat_parameters(self):
        """JIRA ID: DAOS-3769

        Create files of 1M, 10M, 100M, 500M, and verify the size and creation
        time.

        :avocado: tags=all,full_regression
        :avocado: tags=small
        :avocado: tags=dfuse
        :avocado: tags=stat_parameters
        """
        block_sizes = self.params.get("block_sizes", "/run/*")
        error_list = []

        self.add_pool(connect=False)
        self.add_container(pool=self.pool)

        i = 1
        for block_size in block_sizes:
            self.log.info("Block Size = %s", block_size)
            self.ior_cmd.block_size.update(block_size)

            # 1. Verify creation time.
            test_file_suffix = "_{}".format(i)
            i += 1

            # Run ior command.
            try:
                self.run_ior_with_pool(timeout=200,
                                       stop_dfuse=False,
                                       create_pool=False,
                                       create_cont=False,
                                       test_file_suffix=test_file_suffix)
            except TestFail:
                self.log.info("ior command failed!")

            # Get current epoch.
            current_epoch = -1
            output = run_pcmd(hosts=self.hostlist_clients, command="date +%s")
            stdout = output[0]["stdout"]
            self.log.info("date stdout = %s", stdout)
            current_epoch = stdout[-1]

            # Get epoch of the created file. (technically %Z is for last status
            # change. %W is file birth, but it returns 0.)
            creation_epoch = -1
            # As in date command, run stat command in the client node.
            stat_command = "stat -c%Z {}".format(self.ior_cmd.test_file.value)
            output = run_pcmd(hosts=self.hostlist_clients,
                              command=stat_command)
            stdout = output[0]["stdout"]
            self.log.info("stat stdout = %s", stdout)
            creation_epoch = stdout[-1]

            # Calculate the epoch difference between the creation time and the
            # value in the file metadata. They're usually 2 sec apart.
            creation_epoch_int = int(creation_epoch)
            current_epoch_int = int(current_epoch)
            diff_epoch = creation_epoch_int - current_epoch_int
            if diff_epoch > 10:
                msg = "Unexpected creation time! Expected = {}; Actual = {}"
                error_list.append(
                    msg.format(current_epoch_int, creation_epoch_int))

            # 2. Verify file size.
            # Get file size.
            file_size = get_remote_file_size(self.hostlist_clients[0],
                                             self.ior_cmd.test_file.value)

            # Adjust the file size and verify that it matches the expected size.
            expected_size = block_size[:-1]
            # Obtained size is in byte, so convert it to MB.
            file_size_adjusted = file_size / 1024 / 1024
            if int(expected_size) != file_size_adjusted:
                msg = "Unexpected file size! Expected = {}; Actual = {}"
                error_list.append(
                    msg.format(int(expected_size), file_size_adjusted))

        if error_list:
            self.fail("\n----- Errors detected! -----\n{}".format(
                "\n".join(error_list)))
Esempio n. 3
0
    def test_dfusesparsefile(self):
        """Jira ID: DAOS-3768.

        Test Description:
            Purpose of this test is to mount dfuse and verify behavior
            when reading sparse file.
        Use cases:
            Create Pool
            Create Posix container
            Mount dfuse
            Create sparsefile.txt and set it's max size to max available
            space in nvme.
            Write to it's first byte.
            Then, write to it's 1024th Byte
            Verify both the bytes got written with desired data.
            Verify, the bytes between 1st byte and 1024th byte are empty.
            Now try to read the file from it's last 512 bytes till EOF.
            This should return EOF, otherwise fail the test.
        :avocado: tags=all,hw,daosio,small,full_regression,dfusesparsefile
        """
        # Create a pool, container and start dfuse.
        self.create_pool()
        self.create_cont()
        self.start_dfuse(self.hostlist_clients, self.pool, self.container)

        # get scm space before write
        self.space_before = self.pool.get_pool_free_space("nvme")

        # create large file and perform write to it so that if goes out of
        # space.
        sparse_file = str(self.dfuse.mount_dir.value + "/" + "sparsefile.txt")
        self.execute_cmd("touch {}".format(sparse_file))
        self.log.info(
            "File size (in bytes) before truncate: %s",
            get_remote_file_size(self.hostlist_clients[0], sparse_file))

        # create and open a connection on remote node to open file on that
        # remote node
        ssh = paramiko.SSHClient()
        ssh.load_system_host_keys()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh.connect(self.hostlist_clients[0], username=getuser())
        sftp = ssh.open_sftp()

        # open remote file
        file_obj = sftp.open(sparse_file, 'r+')
        # set file size to max available nvme size
        sftp.truncate(sparse_file, self.space_before)
        fsize_after_truncate = get_remote_file_size(self.hostlist_clients[0],
                                                    sparse_file)
        self.log.info("File size (in bytes) after truncate: %s",
                      fsize_after_truncate)
        # verifying the file size got set to desired value
        self.assertTrue(fsize_after_truncate == self.space_before)

        # write to the first byte of the file with char 'A'
        dd_first_byte = "echo 'A' | dd conv=notrunc of={} bs=1 count=1".\
                        format(sparse_file)
        self.execute_cmd(dd_first_byte)
        fsize_write_1stbyte = get_remote_file_size(self.hostlist_clients[0],
                                                   sparse_file)
        self.log.info("File size (in bytes) after writing first byte: %s",
                      fsize_write_1stbyte)
        # verify file did not got overriten after dd write.
        self.assertTrue(fsize_write_1stbyte == self.space_before)

        # write to the 1024th byte position of the file
        dd_1024_byte = "echo 'A' | dd conv=notrunc of={} obs=1 seek=1023 \
                       bs=1 count=1".format(sparse_file)
        self.execute_cmd(dd_1024_byte)
        fsize_write_1024thwrite = get_remote_file_size(
            self.hostlist_clients[0], sparse_file)
        self.log.info("File size (in bytes) after writing 1024th byte: %s",
                      fsize_write_1024thwrite)
        # verify file did not got overriten after dd write.
        self.assertTrue(fsize_write_1024thwrite == self.space_before)

        # Obtain the value of 1st byte and 1024th byte in the file and
        # compare their values, they should be same.
        check_first_byte = file_obj.read(1)
        file_obj.seek(1022, 1)
        check_1024th_byte = file_obj.read(1)
        self.assertTrue(check_first_byte == check_1024th_byte)

        # check the middle 1022 bytes if they are filled with zeros
        middle_1022_bytes = \
            "cmp --ignore-initial=1 --bytes=1022 {} {}".format(
                sparse_file, "/dev/zero")
        self.execute_cmd(middle_1022_bytes)

        # read last 512 bytes which should be zeros till end of file.
        ignore_bytes = self.space_before - 512
        read_till_eof = "cmp --ignore-initial={} {} {}".format(
            ignore_bytes, sparse_file, "/dev/zero")
        #        self.execute_cmd(read_till_eof, False)
        # fail the test if the above command is successful.
        if 0 in self.execute_cmd(read_till_eof, False):
            self.fail("read_till_eof command was supposed to fail. "
                      "But it completed successfully.")