Ejemplo n.º 1
0
    def setup(self):

        testcase = self.__class__.__name__

        self.need_dpc_server_start = True

        # Parse configuration file
        config_file = fun_test.get_script_name_without_ext() + ".json"
        fun_test.log("Benchmark file being used: {}".format(config_file))
        benchmark_dict = utils.parse_file_to_json(config_file)

        for k, v in benchmark_dict[testcase].iteritems():
            setattr(self, k, v)
        # End of Config json file parsing

        self.topology = fun_test.shared_variables["topology"]
        self.dut = self.topology.get_dut_instance(index=0)
        fun_test.test_assert(self.dut, "Retrieved dut instance 0")
        self.host = self.topology.get_host_instance(dut_index=0,
                                                    interface_index=0,
                                                    host_index=0)
        self.qemu = QemuStorageTemplate(host=self.host, dut=self.dut)
        self.funos_running = True

        # Preserving the funos-posix and qemu commandline
        self.funos_cmdline = self.qemu.get_process_cmdline(
            F1.FUN_OS_SIMULATION_PROCESS_NAME)
        fun_test.log("\nfunos-posix commandline: {}".format(
            self.funos_cmdline))
        self.qemu_cmdline = self.qemu.get_process_cmdline(
            DockerContainerOrchestrator.QEMU_PROCESS)
        fun_test.log("\nQemu commandline: {}".format(self.qemu_cmdline))
        self.qemu_cmdline = re.sub(r'(.*append)\s+(root.*mem=\d+M)(.*)',
                                   r'\1 "\2"\3', self.qemu_cmdline)
        fun_test.log("\nProcessed Qemu commandline: {}".format(
            self.qemu_cmdline))

        # Starting the dpc server in the qemu host
        if self.need_dpc_server_start:
            self.qemu.start_dpc_server()
            fun_test.sleep(
                "Waiting for the DPC server and DPCSH TCP proxy to settle down",
                self.iter_interval)
            self.need_dpc_server_start = False

        self.volume_name = self.nvme_device.replace("/dev/", "") + "n" + str(
            self.ns_id)
        self.nvme_block_device = self.nvme_device + "n" + str(self.ns_id)
        self.volume_attached = False
class BLTSpecificBlockIOTestcase(FunTestCase):

    def describe(self):
        pass

    def setup_blt_volume(self):
        """
        Create BLT volume using nvme commands
        :return:
        """
        # create namespace / BLT volume of 1GB (2 extents)
        cmd2 = self.qemu.host.command("/usr/local/sbin/nvme create-ns --nsze=262144 --ncap=262144 /dev/nvme0")
        fun_test.log("Namespace is created {}".format(cmd2))
        fun_test.simple_assert(expression="Success" in cmd2, message="Namespace is created")

        # attach namespace
        cmd3 = self.qemu.host.command("nvme attach-ns --namespace-id=1 --controllers=1 /dev/nvme0")
        fun_test.log("Namespace is attached {}".format(cmd3))

        # fun_test.add_checkpoint("BLT volume is created", "PASSED", True, command_result["status"])

        # Rebooting the qemu host before checking the disk as a workaround to the bug swos-1331
        if self.reboot_after_config:
            fun_test.simple_assert(self.qemu.reboot(timeout=self.command_timeout, retries=12), "Qemu Host Rebooted")
            self.need_dpc_server_start = True

        # Checking that the volume is accessible to the host
        lsblk_output = self.host.lsblk()
        fun_test.test_assert(self.volume_name in lsblk_output, "{} device available".format(self.volume_name))
        fun_test.test_assert_expected(expected="disk", actual=lsblk_output[self.volume_name]["type"],
                                      message="{} device type check".format(self.volume_name))

    def cleanup_ec_volume(self, data, parity):
        pass

    def cleanup_blt_volume(self):
        pass

    def setup(self):

        testcase = self.__class__.__name__

        self.need_dpc_server_start = True

        # Parse configuration file
        config_file = fun_test.get_script_name_without_ext() + ".json"
        fun_test.log("Benchmark file being used: {}".format(config_file))
        benchmark_dict = utils.parse_file_to_json(config_file)

        for k, v in benchmark_dict[testcase].iteritems():
            setattr(self, k, v)
        # End of Config json file parsing

        self.topology = fun_test.shared_variables["topology"]
        self.dut = self.topology.get_dut_instance(index=0)
        fun_test.test_assert(self.dut, "Retrieved dut instance 0")
        self.host = self.topology.get_host_instance(dut_index=0, interface_index=0, host_index=0)
        self.qemu = QemuStorageTemplate(host=self.host, dut=self.dut)
        self.funos_running = True

        # Preserving the funos-posix and qemu commandline
        self.funos_cmdline = self.qemu.get_process_cmdline(F1.FUN_OS_SIMULATION_PROCESS_NAME)
        fun_test.log("\nfunos-posix commandline: {}".format(self.funos_cmdline))
        self.qemu_cmdline = self.qemu.get_process_cmdline(DockerContainerOrchestrator.QEMU_PROCESS)
        fun_test.log("\nQemu commandline: {}".format(self.qemu_cmdline))
        self.qemu_cmdline = re.sub(r'(.*append)\s+(root.*mem=\d+M)(.*)', r'\1 "\2"\3', self.qemu_cmdline)
        fun_test.log("\nProcessed Qemu commandline: {}".format(self.qemu_cmdline))

        # Starting the dpc server in the qemu host
        if self.need_dpc_server_start:
            self.qemu.start_dpc_server()
            fun_test.sleep("Waiting for the DPC server and DPCSH TCP proxy to settle down", self.iter_interval)
            self.need_dpc_server_start = False

        self.volume_name = self.nvme_device.replace("/dev/", "") + "n" + str(self.ns_id)
        self.nvme_block_device = self.nvme_device + "n" + str(self.ns_id)
        self.volume_attached = False

    def write_test(self):
        """
        Writting 4KB data in a specific block of subextent
        """
        self.input_size = self.dd_block_size * self.dd_count
        return_size = self.qemu.dd(input_file=self.data_pattern, output_file=self.input_data,
                                   block_size=self.dd_block_size, count=self.dd_count)
        fun_test.test_assert_expected(self.input_size, return_size, "Input data creation")
        self.input_md5sum = self.qemu.md5sum(file_name=self.input_data)
        fun_test.simple_assert(self.input_md5sum, "Finding md5sum for input data")

        self.nvme_count = (self.dd_count - 1)
        write_result = self.qemu.nvme_write(device=self.nvme_block_device, start=self.nvme_start_block,
                                            count=self.nvme_count, size=self.input_size, data=self.input_data)
        if write_result != "Success":
            self.write_result = False
            fun_test.critical("Write failed")
        else:
            fun_test.log("Write succeeded")

        # TODO: Code to validate two sub-extents are consumed for this write

    def read_test(self):
        num_reads = self.dataset_size / self.input_size
        read_result = self.qemu.nvme_read(device=self.nvme_block_device, start=self.nvme_start_block,
                                          count=self.nvme_count, size=self.input_size, data=self.output_data)

        if read_result != "Success":
            self.read_result = False
            fun_test.critical("Read failed")
        else:
            fun_test.log("Read succeeded ")

        output_md5sum = self.qemu.md5sum(file_name=self.output_data)
        if output_md5sum == self.input_md5sum:
            fun_test.log("md5sum for read {} matches with write md5sum {}".format(output_md5sum, self.input_md5sum))
        else:
            self.read_result = False
            fun_test.critical("md5sum for {} is not matching with input md5sum {}".
                              format(output_md5sum, self.input_md5sum))

    def run(self):
        pass

    def cleanup(self):
        self.qemu.stop_dpc_server()