当前位置: 首页>>代码示例>>Python>>正文


Python storage.get_image_filename函数代码示例

本文整理汇总了Python中virttest.storage.get_image_filename函数的典型用法代码示例。如果您正苦于以下问题:Python get_image_filename函数的具体用法?Python get_image_filename怎么用?Python get_image_filename使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_image_filename函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _action_after_fsfreeze

    def _action_after_fsfreeze(self, *args):
        error.context("Run live snapshot for guest.", logging.info)

        image1 = self.params.get("image", "image1")
        image_params = self.params.object_params(image1)
        sn_params = image_params.copy()
        sn_params["image_name"] += "-snapshot"
        sn_file = storage.get_image_filename(sn_params, data_dir.get_data_dir())
        base_file = storage.get_image_filename(image_params, data_dir.get_data_dir())
        snapshot_format = image_params["image_format"]

        self.vm.live_snapshot(base_file, sn_file, snapshot_format)
开发者ID:wl59454024,项目名称:virt-test,代码行数:12,代码来源:qemu_guest_agent_snapshot.py

示例2: run_qemu_img

def run_qemu_img(test, params, env):
    """
    'qemu-img' functions test:
    1) Judge what subcommand is going to be tested
    2) Run subcommand test

    @param test: kvm test object
    @param params: Dictionary with the test parameters
    @param env: Dictionary with test environment.
    """
    cmd = utils_misc.get_path(test.bindir, params.get("qemu_img_binary"))
    if not os.path.exists(cmd):
        raise error.TestError("Binary of 'qemu-img' not found")
    image_format = params.get("image_format")
    image_size = params.get("image_size", "10G")
    image_name = storage.get_image_filename(params, test.bindir)


    def _check(cmd, img):
        """
        Simple 'qemu-img check' function implementation.

        @param cmd: qemu-img base command.
        @param img: image to be checked
        """
        cmd += " check %s" % img
        logging.info("Checking image '%s'...", img)
        try:
            output = utils.system_output(cmd)
        except error.CmdError, e:
            if "does not support checks" in str(e):
                return (True, "")
            else:
                return (False, str(e))
        return (True, output)
开发者ID:kongove,项目名称:virt-test,代码行数:35,代码来源:qemu_img.py

示例3: get_base_image

 def get_base_image(self):
     """
     Get base image.
     """
     base_file = storage.get_image_filename(self.params,
                                            data_dir.get_data_dir())
     return self.vm.get_block({"file": base_file})
开发者ID:gogoxiaoxiao,项目名称:tp-qemu,代码行数:7,代码来源:live_snapshot_basic.py

示例4: verify_info

 def verify_info(self, params=None):
     """
     verify option is applied to image file correctly
     """
     error_context.context("verify option of converted image", logging.info)
     image_filename = storage.get_image_filename(params, self.data_dir)
     info = utils_test.get_image_info(image_filename)
     avalue = evalue = ""
     for option in params.objects("option_verified"):
         avalue = info.get(option)
         if option == "format":
             evalue = params.get("image_format")
         elif option == "lcounts":
             if params.get("lazy_refcounts") == "on":
                 evalue = "true"
             elif params.get("lazy_refcounts") == "off":
                 evalue = "false"
         elif option == "csize":
             csize = params.get("cluster_size")
             evalue = int(float(utils_misc.normalize_data_size(csize, "B")))
         elif option == "sparse_size":
             if info.get("dsize") < info.get("vsize"):
                 avalue = info.get("dsize")
                 evalue = info.get("vsize")
         else:
             evalue = params.get(option)
         if avalue is not None and avalue != evalue:
             msg = "Get wrong %s from image %s!" % (option, image_filename)
             msg += "Expect: %s, actual: %s" % (evalue, avalue)
             self.test.fail(msg)
开发者ID:bssrikanth,项目名称:tp-qemu,代码行数:30,代码来源:qemu_disk_img.py

示例5: find_image

 def find_image(image_name):
     """
     Find the path of the iamge.
     """
     image_params = params.object_params(image_name)
     o = storage.get_image_filename(image_params, data_dir.get_data_dir())
     return o
开发者ID:Zhengtong,项目名称:tp-qemu,代码行数:7,代码来源:block_hotplug.py

示例6: get_target_image

 def get_target_image(self):
     params = self.parser_test_args()
     t_params = {}
     t_params["image_name"] = params["target_image"]
     t_params["image_format"] = params["target_format"]
     target_image = storage.get_image_filename(t_params, self.data_dir)
     return target_image
开发者ID:LeiCui,项目名称:virt-test,代码行数:7,代码来源:drive_mirror.py

示例7: run_block_stream_with_stress

def run_block_stream_with_stress(test, params, env):
    """
    block_stream_with_stress test:
    1). boot guest
    2). make guest under heavyload status
    3). create live snpshot file and start block stream job
    4). wait for it done correctly

    @param test: Kvm test object
    @param params: Dictionary with the test parameters
    @param env: Dictionary with test environment.
    """
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    timeout = int(params.get("login_timeout", 360))
    session = vm.wait_for_login(timeout=timeout)
    image_filename = storage.get_image_filename(params, data_dir.get_data_dir())
    device_id = vm.get_block({"file": image_filename})
    snapshot_file = os.path.splitext(image_filename)[0] + "-snp"
    sub_test = params.get("pre_test")
    start_cmd = params.get("start_cmd")

    def is_job_done():
        """
        Query block job status to check is job finished
        """
        job = vm.monitor.query_block_job(device_id)
        if job:
            processed = float(job["offset"]) / job["len"] * 100
            logging.debug("%s, rocessed: %.2f" % (job["type"], processed))
            return False
        logging.info("block stream job done")
        return True

    try:
        utils_test.run_virt_sub_test(test, params, env, sub_type=sub_test)
        error.context("Heavy load in guest ...", logging.info)
        if start_cmd.startswith("stress"):
            cpu = int(params.get("smp", 1))
            mem = int(params.get("mem", 1024))
            start_cmd = start_cmd.format(cpu=cpu,
                                         vm=cpu * 2,
                                         mem=(mem - 512) / cpu)
        session.sendline(start_cmd)
        error.context("Creating live snapshot", logging.info)
        if vm.monitor.live_snapshot(device_id, snapshot_file):
            raise error.TestFail("Fail to create live snapshot")
        error.context("Start block device stream job", logging.info)
        if vm.monitor.block_stream(device_id):
            raise error.TestFail("Fail to start block stream job")
        if not utils_misc.wait_for(is_job_done,
                               timeout=int(params.get("job_timeout", 2400)),
                               text="wait job done, it will take long time"):
            raise error.TestFail("Wait job finish timeout")
    finally:
        if session:
            session.close()
        if os.path.isfile(snapshot_file):
            os.remove(snapshot_file)
开发者ID:FengYang,项目名称:virt-test,代码行数:59,代码来源:block_stream_with_stress.py

示例8: get_device

 def get_device(self):
     """
     according configuration get target device ID;
     """
     image_file = storage.get_image_filename(self.parser_test_args(),
                                             self.data_dir)
     logging.info("image filename: %s" % image_file)
     return self.vm.get_block({"file": image_file})
开发者ID:Chenditang,项目名称:tp-qemu,代码行数:8,代码来源:block_copy.py

示例9: run

def run(test, params, env):
    """
    live_snapshot_base test:
    1). Boot up guest
    2). Create a file on host and record md5
    3). Copy the file to guest
    3). Create live snapshot
    4). Copy the file from guest,then check md5

    :param test: Kvm test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment.
    """
    vm = env.get_vm(params["main_vm"])
    vm.verify_alive()
    timeout = int(params.get("login_timeout", 3600))
    session = vm.wait_for_login(timeout=timeout)

    dd_timeout = params.get("dd_timeoout", 600)
    copy_timeout = params.get("copy_timeoout", 600)
    base_file = storage.get_image_filename(params, data_dir.get_data_dir())
    device = vm.get_block({"file": base_file})
    snapshot_file = "images/%s" % params.get("snapshot_name")
    snapshot_file = utils_misc.get_path(data_dir.get_data_dir(), snapshot_file)
    snapshot_format = params.get("snapshot_format", "qcow2")
    tmp_name = utils_misc.generate_random_string(5)
    src = dst = "/tmp/%s" % tmp_name
    if params.get("os_type") != "linux":
        dst = "c:\\users\\public\\%s" % tmp_name

    try:
        error_context.context("create file on host, copy it to guest",
                              logging.info)
        cmd = params.get("dd_cmd") % src
        process.system(cmd, timeout=dd_timeout, shell=True)
        md5 = crypto.hash_file(src, algorithm="md5")
        vm.copy_files_to(src, dst, timeout=copy_timeout)
        process.system("rm -f %s" % src)
        error_context.context("create live snapshot", logging.info)
        if vm.live_snapshot(base_file, snapshot_file,
                            snapshot_format) != device:
            test.fail("Fail to create snapshot")
        backing_file = vm.monitor.get_backingfile(device)
        if backing_file != base_file:
            logging.error(
                "backing file: %s, base file: %s", backing_file, base_file)
            test.fail("Got incorrect backing file")
        error_context.context("copy file to host, check content not changed",
                              logging.info)
        vm.copy_files_from(dst, src, timeout=copy_timeout)
        if md5 and (md5 != crypto.hash_file(src, algorithm="md5")):
            test.fail("diff md5 before/after create snapshot")
        session.cmd(params.get("alive_check_cmd", "dir"))
    finally:
        if session:
            session.close()
        process.system("rm -f %s %s" % (snapshot_file, src))
开发者ID:bssrikanth,项目名称:tp-qemu,代码行数:57,代码来源:live_snapshot_base.py

示例10: get_device

 def get_device(self):
     """
     according configuration get target device ID;
     """
     root_dir = self.data_dir
     params = self.parser_test_args()
     image_file = storage.get_image_filename(params, root_dir)
     device = self.vm.get_block({"file": image_file})
     return device
开发者ID:sibiaoluo,项目名称:tp-qemu,代码行数:9,代码来源:block_copy.py

示例11: qemu_img_check

 def qemu_img_check():
     """
     Check guest disk image, and backup image when error occured
     """
     params["backup_image_on_check_error"] = 'yes'
     base_dir = data_dir.get_data_dir()
     image_name = storage.get_image_filename(params, base_dir)
     image = qemu_storage.QemuImg(params, base_dir, image_name)
     image.check_image(params, base_dir)
开发者ID:kongove,项目名称:tp-qemu,代码行数:9,代码来源:iofuzz.py

示例12: find_image

    def find_image(image_name):
        """
        Find the path of the iamge.

        :param image_name: name of image.
        :return mage_filename: filename of image.
        """
        image_params = params.object_params(image_name)
        image_filename = storage.get_image_filename(image_params, data_dir.get_data_dir())
        return image_filename
开发者ID:Zhengtong,项目名称:tp-qemu,代码行数:10,代码来源:block_hotplug_negative.py

示例13: rebase_test

    def rebase_test(cmd):
        """
        Subcommand 'qemu-img rebase' test

        Change the backing file of a snapshot image in "unsafe mode":
        Assume the previous backing file had missed and we just have to change
        reference of snapshot to new one. After change the backing file of a
        snapshot image in unsafe mode, the snapshot should work still.

        :param cmd: qemu-img base command.
        """
        if not 'rebase' in utils.system_output(cmd + ' --help',
                                               ignore_status=True):
            raise error.TestNAError("Current kvm user space version does not"
                                    " support 'rebase' subcommand")
        sn_fmt = params.get("snapshot_format", "qcow2")
        sn1 = params["image_name_snapshot1"]
        sn1 = utils_misc.get_path(
            data_dir.get_data_dir(), sn1) + ".%s" % sn_fmt
        base_img = storage.get_image_filename(params, data_dir.get_data_dir())
        _create(cmd, sn1, sn_fmt, base_img=base_img, base_img_fmt=image_format)

        # Create snapshot2 based on snapshot1
        sn2 = params["image_name_snapshot2"]
        sn2 = utils_misc.get_path(
            data_dir.get_data_dir(), sn2) + ".%s" % sn_fmt
        _create(cmd, sn2, sn_fmt, base_img=sn1, base_img_fmt=sn_fmt)

        rebase_mode = params.get("rebase_mode")
        if rebase_mode == "unsafe":
            os.remove(sn1)

        _rebase(cmd, sn2, base_img, image_format, mode=rebase_mode)
        # Boot snapshot image after rebase
        img_name, img_format = sn2.split('.')
        _boot(img_name, img_format)

        # Check sn2's format and backing_file
        actual_base_img = _info(cmd, sn2, "backing file")
        base_img_name = os.path.basename(base_img)
        if not base_img_name in actual_base_img:
            raise error.TestFail("After rebase the backing_file of 'sn2' is "
                                 "'%s' which is not expected as '%s'"
                                 % (actual_base_img, base_img_name))
        status, output = _check(cmd, sn2)
        if not status:
            raise error.TestFail("Check image '%s' failed after rebase;"
                                 "got error: %s" % (sn2, output))
        try:
            os.remove(sn2)
            os.remove(sn1)
        except Exception:
            pass
开发者ID:QiuMike,项目名称:tp-qemu,代码行数:53,代码来源:qemu_img.py

示例14: run_image_copy

def run_image_copy(test, params, env):
    """
    Copy guest images from nfs server.
    1) Mount the NFS share directory
    2) Check the existence of source image
    3) If it exists, copy the image from NFS

    :param test: kvm test object
    :param params: Dictionary with the test parameters
    :param env: Dictionary with test environment.
    """
    vm = env.get_vm(params["main_vm"])
    if vm is not None:
        vm.destroy()

    src = params.get('images_good')
    asset_name = '%s' % (os.path.split(params['image_name'])[1])
    image = '%s.%s' % (params['image_name'], params['image_format'])
    dst_path = storage.get_image_filename(params, data_dir.get_data_dir())
    image_dir = os.path.dirname(dst_path)
    if params.get("rename_error_image", "no") == "yes":
        error_image = os.path.basename(params['image_name']) + "-error"
        error_image += '.' + params['image_format']
        error_dst_path = os.path.join(image_dir, error_image)
        mv_cmd = "/bin/mv %s %s" % (dst_path, error_dst_path)
        utils.system(mv_cmd, timeout=360, ignore_status=True)

    if src:
        mount_dest_dir = params.get('dst_dir', '/mnt/images')
        if not os.path.exists(mount_dest_dir):
            try:
                os.makedirs(mount_dest_dir)
            except OSError, err:
                logging.warning('mkdir %s error:\n%s', mount_dest_dir, err)

        if not os.path.exists(mount_dest_dir):
            raise error.TestError('Failed to create NFS share dir %s' %
                                  mount_dest_dir)

        error.context("Mount the NFS share directory")
        if not utils_misc.mount(src, mount_dest_dir, 'nfs', 'ro'):
            raise error.TestError('Could not mount NFS share %s to %s' %
                                  (src, mount_dest_dir))

        error.context("Check the existence of source image")
        src_path = '%s/%s.%s' % (mount_dest_dir, asset_name,
                                 params['image_format'])
        asset_info = virttest.asset.get_file_asset(asset_name, src_path,
                                                   dst_path)
        if asset_info is None:
            raise error.TestError('Could not find %s' % image)
开发者ID:Keepod,项目名称:virt-test,代码行数:51,代码来源:__init__.py

示例15: convert

 def convert(self, t_params={}):
     """
     create image file from one format to another format
     """
     error.context("convert image file", logging.info)
     params = self.params.object_params(self.tag)
     params.update(t_params)
     cache_mode = params.get("cache_mode")
     super(ConvertTest, self).convert(params, self.data_dir, cache_mode)
     params["image_name"] = params["convert_name"]
     params["image_format"] = params["convert_format"]
     converted = storage.get_image_filename(params, self.data_dir)
     utils.run("sync")
     self.trash.append(converted)
     return params
开发者ID:uni-peter-zheng,项目名称:tp-qemu,代码行数:15,代码来源:qemu_disk_img_convert.py


注:本文中的virttest.storage.get_image_filename函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。