Exemplo n.º 1
0
    def __init__(self,
                 test,
                 params,
                 image_name,
                 blkdebug_cfg="",
                 prompt=r"qemu-io>\s*$",
                 log_filename=None,
                 io_options="",
                 log_func=None):
        self.type = ""
        if log_filename:
            log_filename += "-" + utils_misc.generate_random_string(4)
            self.output_func = utils_misc.log_line
            self.output_params = (log_filename, )
        else:
            self.output_func = None
            self.output_params = ()
        self.output_prefix = ""
        self.prompt = prompt
        self.blkdebug_cfg = blkdebug_cfg

        self.qemu_io_cmd = utils_misc.get_qemu_io_binary(params)
        self.io_options = io_options
        self.run_command = False
        self.image_name = image_name
        self.blkdebug_cfg = blkdebug_cfg
        self.log_func = log_func
Exemplo n.º 2
0
    def run_test(qemu_src_dir):
        """
        run QEMU I/O test suite

        :qemu_src_dir: path of qemu source code
        """
        iotests_root = params.get("iotests_root", "tests/qemu-iotests")
        extra_options = params.get("qemu_io_extra_options", "")
        image_format = params.get("qemu_io_image_format")
        result_pattern = params.get("iotests_result_pattern")
        error_context.context("running qemu-iotests for image format %s"
                              % image_format, logging.info)
        os.environ["QEMU_PROG"] = utils_misc.get_qemu_binary(params)
        os.environ["QEMU_IMG_PROG"] = utils_misc.get_qemu_img_binary(params)
        os.environ["QEMU_IO_PROG"] = utils_misc.get_qemu_io_binary(params)
        os.environ["QEMU_NBD_PROG"] = utils_misc.get_binary('qemu-nbd', params)
        os.chdir(os.path.join(qemu_src_dir, iotests_root))
        cmd = './check'
        if extra_options:
            cmd += " %s" % extra_options
        cmd += " -%s" % image_format
        output = process.system_output(cmd, ignore_status=True, shell=True)
        match = re.search(result_pattern, output, re.I | re.M)
        if match:
            iotests_log_file = "qemu_iotests_%s.log" % image_format
            iotests_log_file = utils_misc.get_path(test.debugdir, iotests_log_file)
            with open(iotests_log_file, 'w+') as log:
                log.write(output)
                log.flush()
            msg = "Total test %s cases, %s failed"
            raise exceptions.TestFail(msg % (match.group(2), match.group(1)))
Exemplo n.º 3
0
def copyif(params, nbd_image, target_image, bitmap=None):
    """
    Python implementation of copyif3.sh
    :params params: utils_params.Params object
    :params nbd_image: nbd image tag
    :params target_image: target image tag
    :params bitmap: bitmap name
    """
    def _qemu_io_read(qemu_io, s, l, img):
        cmd = '{io} -C -c "r {s} {l}" -f {fmt} {f}'.format(
            io=qemu_io, s=s, l=l, fmt=img.image_format,
            f=img.image_filename
        )
        process.system(cmd, ignore_status=False, shell=True)

    qemu_io = utils_misc.get_qemu_io_binary(params)
    qemu_img = utils_misc.get_qemu_img_binary(params)
    img_obj = qemu_storage.QemuImg(params.object_params(target_image),
                                   data_dir.get_data_dir(), target_image)
    nbd_img_obj = qemu_storage.QemuImg(params.object_params(nbd_image),
                                       None, nbd_image)
    max_len = int(params.get('qemu_io_max_len', 2147483136))

    if bitmap is None:
        args = '-f %s %s' % (nbd_img_obj.image_format,
                             nbd_img_obj.image_filename)
        state = True
    else:
        opts = qemu_storage.filename_to_file_opts(
            nbd_img_obj.image_filename)
        opt = params.get('dirty_bitmap_opt', 'x-dirty-bitmap')
        opts[opt] = 'qemu:dirty-bitmap:%s' % bitmap
        args = "'json:%s'" % json.dumps(opts)
        state = False

    img_obj.base_image_filename = nbd_img_obj.image_filename
    img_obj.base_format = nbd_img_obj.image_format
    img_obj.base_tag = nbd_img_obj.tag
    img_obj.rebase(img_obj.params)

    map_cmd = '{qemu_img} map --output=json {args}'.format(
        qemu_img=qemu_img, args=args)
    result = process.run(map_cmd, ignore_status=False, shell=True)

    for item in json.loads(result.stdout.decode().strip()):
        if item['data'] is not state:
            continue

        # qemu-io can only handle length less than 2147483136,
        # so here we need to split 'large length' into several parts
        start, length = item['start'], item['length']
        while length > max_len:
            _qemu_io_read(qemu_io, start, max_len, img_obj)
            start, length = start+max_len, length-max_len
        else:
            if length > 0:
                _qemu_io_read(qemu_io, start, length, img_obj)

    img_obj.base_tag = 'null'
    img_obj.rebase(img_obj.params)
Exemplo n.º 4
0
 def qemuio_source_image(self):
     tag = self._source_images[0]
     image_params = self.params.object_params(tag)
     image = self.source_disk_define_by_params(image_params, tag)
     filename = image.image_filename
     fmt = image.image_format
     qemu_io = utils_misc.get_qemu_io_binary(self.params)
     qemuio_cmd = self.params.get("qemuio_cmd") % (qemu_io, fmt, filename)
     try:
         process.run(qemuio_cmd, shell=True)
     except process.CmdError as e:
         if self.params["error_msg"] not in e.result.stderr.decode():
             self.test.fail("Write to image that using by another process")
     else:
         self.test.fail("Can qemu-io a using image")
Exemplo n.º 5
0
def run(test, params, env):
    """
    Fetch from git and run qemu-iotests using the qemu binaries under test.

    1) Fetch qemu-io from git
    3) Run test for the file format detected
    4) Report any errors found to test

    :param test:   QEMU test object.
    :param params: Dictionary with the test parameters.
    :param env:    Dictionary with test environment.
    """
    # First, let's get qemu-io
    std = "http://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git"
    uri = params.get("qemu_io_uri", std)
    branch = params.get("qemu_io_branch", 'master')
    lbranch = params.get("qemu_io_lbranch", 'master')
    commit = params.get("qemu_io_commit", None)
    base_uri = params.get("qemu_io_base_uri", None)
    iotests_dir = params.get("qemu_iotests_dir", "tests/qemu-iotests")
    destination_dir = os.path.join(test.workdir, "qemu_io_tests")
    git.get_repo(uri=uri,
                 branch=branch,
                 lbranch=lbranch,
                 commit=commit,
                 destination_dir=destination_dir,
                 base_uri=base_uri)

    # Then, set the qemu paths for the use of the testsuite
    os.environ["QEMU_PROG"] = utils_misc.get_qemu_binary(params)
    os.environ["QEMU_IMG_PROG"] = utils_misc.get_qemu_img_binary(params)
    os.environ["QEMU_IO_PROG"] = utils_misc.get_qemu_io_binary(params)

    # qemu-iotests has merged into tests/qemu_iotests folder
    os.chdir(os.path.join(destination_dir, iotests_dir))
    image_format = params["qemu_io_image_format"]
    extra_options = params.get("qemu_io_extra_options", "")

    cmd = './check'
    if extra_options:
        cmd += extra_options

    error_context.context("running qemu-iotests for image format %s" %
                          image_format)
    process.system("%s -%s" % (cmd, image_format), shell=True)
Exemplo n.º 6
0
def run_qemu_iotests(test, params, env):
    """
    Fetch from git and run qemu-iotests using the qemu binaries under test.

    1) Fetch qemu-io from git
    3) Run test for the file format detected
    4) Report any errors found to autotest

    @param test:   QEMU test object.
    @param params: Dictionary with the test parameters.
    @param env:    Dictionary with test environment.
    """
    # First, let's get qemu-io
    std = "git://git.kernel.org/pub/scm/linux/kernel/git/hch/qemu-iotests.git"
    uri = params.get("qemu_io_uri", std)
    branch = params.get("qemu_io_branch", 'master')
    lbranch = params.get("qemu_io_lbranch", 'master')
    commit = params.get("qemu_io_commit", None)
    base_uri = params.get("qemu_io_base_uri", None)
    destination_dir = os.path.join(test.srcdir, "qemu_io_tests")
    git.get_repo(uri=uri,
                 branch=branch,
                 lbranch=lbranch,
                 commit=commit,
                 destination_dir=destination_dir,
                 base_uri=base_uri)

    # Then, set the qemu paths for the use of the testsuite
    os.environ["QEMU_PROG"] = utils_misc.get_qemu_binary(params)
    os.environ["QEMU_IMG_PROG"] = utils_misc.get_qemu_img_binary(params)
    os.environ["QEMU_IO_PROG"] = utils_misc.get_qemu_io_binary(params)

    os.chdir(destination_dir)
    image_format = params["qemu_io_image_format"]
    extra_options = params.get("qemu_io_extra_options", "")

    cmd = './check'
    if extra_options:
        cmd += extra_options

    error.context("running qemu-iotests for image format %s" % image_format)
    utils.system("%s -%s" % (cmd, image_format))
    def copyif(self, nbd_img_obj, img_obj, bitmap=None):
        qemu_img = utils_misc.get_qemu_img_binary(self.params)
        qemu_io = utils_misc.get_qemu_io_binary(self.params)

        args = ''
        if bitmap is None:
            args = '-f %s %s' % (nbd_img_obj.image_format,
                                 nbd_img_obj.image_filename)
        else:
            opts = qemu_storage.filename_to_file_opts(
                nbd_img_obj.image_filename)
            opts[self.
                 params['dirty_bitmap_opt']] = 'qemu:dirty-bitmap:%s' % bitmap
            args = "'json:%s'" % json.dumps(opts)

        img_obj.base_image_filename = nbd_img_obj.image_filename
        img_obj.base_format = nbd_img_obj.image_format
        img_obj.base_tag = nbd_img_obj.tag
        img_obj.rebase(img_obj.params)

        map_cmd = '{qemu_img} map --output=json {args}'.format(
            qemu_img=qemu_img, args=args)
        result = process.run(map_cmd, ignore_status=True, shell=True)
        if result.exit_status != 0:
            self.test.fail('Failed to run map command: %s' %
                           result.stderr.decode())

        for item in json.loads(result.stdout.decode().strip()):
            io_cmd = '{io} -C -c "read {s} {l}" -f {fmt} {fn}'.format(
                io=qemu_io,
                s=item['start'],
                l=item['length'],
                fmt=img_obj.image_format,
                fn=img_obj.image_filename)
            result = process.run(io_cmd, ignore_status=True, shell=True)
            if result.exit_status != 0:
                self.test.fail('Failed to run qemu-io command: %s' %
                               result.stderr.decode())

        img_obj.base_tag = 'null'
        img_obj.rebase(img_obj.params)
    def _make_qemu_io_cmd():
        nbd_image = params["nbd_image_tag"]
        nbd_image_params = params.object_params(nbd_image)

        nbd_image_filename = storage.get_image_filename(nbd_image_params, None)
        nbd_image_format = '-f %s' % nbd_image_params['image_format']

        tls_obj = _get_tls_creds_obj(nbd_image, nbd_image_params)
        sec_obj = _get_secret_obj(nbd_image, nbd_image_params)
        if tls_obj or sec_obj:
            nbd_image_format = ''
            nbd_image_filename = "'%s'" % qemu_storage.get_image_json(
                nbd_image, nbd_image_params, None)

        qemu_io = utils_misc.get_qemu_io_binary(params)
        return params['qemu_io_cmd'].format(qemu_io=qemu_io,
                                            tls_creds=tls_obj,
                                            secret=sec_obj,
                                            fmt=nbd_image_format,
                                            subcmd=params['qemu_io_subcmd'],
                                            filename=nbd_image_filename)
Exemplo n.º 9
0
    def __init__(self, test, params, image_name, blkdebug_cfg="",
                 prompt=r"qemu-io>\s*$", log_filename=None, io_options="",
                 log_func=None):
        self.type = ""
        if log_filename:
            log_filename += "-" + utils_misc.generate_random_string(4)
            self.output_func = utils_misc.log_line
            self.output_params = (log_filename,)
        else:
            self.output_func = None
            self.output_params = ()
        self.output_prefix = ""
        self.prompt = prompt
        self.blkdebug_cfg = blkdebug_cfg

        self.qemu_io_cmd = utils_misc.get_qemu_io_binary(params)
        self.io_options = io_options
        self.run_command = False
        self.image_name = image_name
        self.blkdebug_cfg = blkdebug_cfg
        self.log_func = log_func
Exemplo n.º 10
0
def run_qemu_iotests(test, params, env):
    """
    Fetch from git and run qemu-iotests using the qemu binaries under test.

    1) Fetch qemu-io from git
    3) Run test for the file format detected
    4) Report any errors found to autotest

    :param test:   QEMU test object.
    :param params: Dictionary with the test parameters.
    :param env:    Dictionary with test environment.
    """
    # First, let's get qemu-io
    std = "http://git.kernel.org/pub/scm/virt/kvm/qemu-kvm.git"
    uri = params.get("qemu_io_uri", std)
    branch = params.get("qemu_io_branch", 'master')
    lbranch = params.get("qemu_io_lbranch", 'master')
    commit = params.get("qemu_io_commit", None)
    base_uri = params.get("qemu_io_base_uri", None)
    iotests_dir = params.get("qemu_iotests_dir", "tests/qemu-iotests")
    destination_dir = os.path.join(test.srcdir, "qemu_io_tests")
    git.get_repo(uri=uri, branch=branch, lbranch=lbranch, commit=commit,
                 destination_dir=destination_dir, base_uri=base_uri)

    # Then, set the qemu paths for the use of the testsuite
    os.environ["QEMU_PROG"] = utils_misc.get_qemu_binary(params)
    os.environ["QEMU_IMG_PROG"] = utils_misc.get_qemu_img_binary(params)
    os.environ["QEMU_IO_PROG"] = utils_misc.get_qemu_io_binary(params)

    # qemu-iotests has merged into tests/qemu_iotests folder
    os.chdir(os.path.join(destination_dir, iotests_dir))
    image_format = params["qemu_io_image_format"]
    extra_options = params.get("qemu_io_extra_options", "")

    cmd = './check'
    if extra_options:
        cmd += extra_options

    error.context("running qemu-iotests for image format %s" % image_format)
    utils.system("%s -%s" % (cmd, image_format))