• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python utils_misc.normalize_data_size函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: 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


示例2: rbd_image_create

def rbd_image_create(ceph_monitor, rbd_pool_name, rbd_image_name,
                     rbd_image_size, force_create=False):
    """
    Create a rbd image.
    :params ceph_monitor: The specified monitor to connect to
    :params rbd_pool_name: The name of rbd pool
    :params rbd_image_name: The name of rbd image
    :params rbd_image_size: The size of rbd image
    :params force_create: Force create the image or not
    """
    if rbd_image_exist(ceph_monitor, rbd_pool_name, rbd_image_name):
        create_image = False
        image_info = rbd_image_info(ceph_monitor, rbd_pool_name,
                                    rbd_image_name)
        try:
            int(rbd_image_size)
            compare_str = rbd_image_size
        except ValueError:
            compare_str = utils_misc.normalize_data_size(rbd_image_size)
        if image_info['size'] != compare_str or force_create:
            rbd_image_rm(ceph_monitor, rbd_pool_name, rbd_image_name)
            create_image = True
    if create_image:
        cmd = "rbd create %s/%s -m %s" % (rbd_pool_name, rbd_image_name,
                                          ceph_monitor)
        process.system(cmd, verbose=True)
    else:
        logging.debug("Image already exist skip the create.")
开发者ID:avocado-framework,项目名称:avocado-vt,代码行数:28,代码来源:ceph.py


示例3: rbd_image_info

def rbd_image_info(ceph_monitor, rbd_pool_name, rbd_image_name):
    """
    Get information of a rbd image
    :params ceph_monitor: The specified monitor to connect to
    :params rbd_pool_name: The name of rbd pool
    :params rbd_image_name: The name of rbd image
    """
    cmd = "rbd info %s/%s -m %s" % (rbd_pool_name, rbd_image_name,
                                    ceph_monitor)
    output = process.system(cmd)
    info_pattern = "rbd image \'%s\':.*?$" % rbd_image_name

    rbd_image_info_str = re.findall(info_pattern, output, re.S)[0]

    rbd_image_info = {}
    for rbd_image_line in rbd_image_info_str.splitlines():
        if ":" not in rbd_image_line:
            if "size" in rbd_image_line:
                size_str = re.findall("size\s+(\d+\s+\w+)\s+",
                                      rbd_image_line)[0]
                size = utils_misc.normalize_data_size(size_str)
                rbd_image_info['size'] = size
            if "order" in rbd_image_line:
                rbd_image_info['order'] = int(re.findall("order\s+(\d+)",
                                                         rbd_image_line))
        else:
            tmp_str = rbd_image_line.strip().split(":")
            rbd_image_info[tmp_str[0]] = tmp_str[1]
    return rbd_image_info
开发者ID:avocado-framework,项目名称:avocado-vt,代码行数:29,代码来源:ceph.py


示例4: get_memory_boundary

    def get_memory_boundary(self, balloon_type=''):
        """
        Get the legal memory boundary for balloon operation.

        :param balloon_type: evict or enlarge
        :type balloon_type: string
        :return: min and max size of the memory
        :rtype: tuple
        """
        max_size = self.ori_mem
        min_size = self.params.get("minmem", "512M")
        min_size = int(float(utils_misc.normalize_data_size(min_size)))
        balloon_buffer = self.params.get("balloon_buffer", 300)
        if self.params.get('os_type') == 'windows':
            logging.info("Get windows miminum balloon value:")
            self.vm.balloon(1)
            balloon_timeout = self.params.get("balloon_timeout", 900)
            self.wait_for_balloon_complete(balloon_timeout)
            used_size = min((self.get_ballooned_memory() + balloon_buffer), max_size)
            self.vm.balloon(max_size)
            self.wait_for_balloon_complete(balloon_timeout)
            self.ori_gmem = self.get_memory_status()
        else:
            vm_total = self.get_memory_status()
            vm_mem_free = self.get_free_mem()
            used_size = min((self.ori_mem - vm_mem_free + balloon_buffer), max_size)
        if balloon_type == "enlarge":
            min_size = self.current_mmem
        elif balloon_type == "evict":
            max_size = self.current_mmem
        min_size = max(used_size, min_size)
        return min_size, max_size
开发者ID:pezhang,项目名称:tp-qemu,代码行数:32,代码来源:balloon_check.py


示例5: _memory_stats_compare

    def _memory_stats_compare(self, keyname, memory_stat_qmp):
        """
        Check whether memory statistics from qmp is same with guest memory.

        :param keyname: key name of the output of the 'qom-get' property.
        :param memory_stat_qmp: memory stat values from qmp.
        """
        check_mem_ratio = float(self.params.get("check_mem_ratio", 0.1))
        check_mem_diff = float(self.params.get("check_mem_diff", 150))
        error_context.context("Get memory from guest", logging.info)
        if keyname == "stat-free-memory":
            guest_mem = self.get_guest_free_mem(self.vm)
        elif keyname == "stat-total-memory":
            guest_mem = self.get_vm_mem(self.vm)
        memory_stat_qmp = "%sB" % memory_stat_qmp
        memory_stat_qmp = int(float(utils_misc.normalize_data_size(
                                   memory_stat_qmp, order_magnitude="M")))
        mem_diff = float(abs(guest_mem - memory_stat_qmp))
        if ((mem_diff / guest_mem) > check_mem_ratio and
                mem_diff > check_mem_diff):
            self.test.fail("%s of guest %s is not equal to %s in qmp,the"
                           "acceptable ratio/diff is %s/%s" % (keyname,
                                                               guest_mem,
                                                               memory_stat_qmp,
                                                               check_mem_ratio,
                                                               check_mem_diff))
开发者ID:ldoktor,项目名称:tp-qemu,代码行数:26,代码来源:balloon_check.py


示例6: get_memory_boundary

    def get_memory_boundary(self, balloon_type=''):
        """
        Get the legal memory boundary for balloon operation.

        :param balloon_type: evict or enlarge
        :type balloon_type: string
        :return: min and max size of the memory
        :rtype: tuple
        """
        max_size = self.ori_mem
        min_size = self.params.get("minmem", "512M")
        min_size = int(float(utils_misc.normalize_data_size(min_size)))
        if self.params.get('os_type') == 'windows':
            logging.info("Get windows miminum balloon value:")
            self.vm.balloon(1)
            time.sleep(90)
            used_size = int(self.get_ballooned_memory() + self.ratio * self.ori_mem)
            self.vm.balloon(max_size)
            time.sleep(90)
            self.ori_gmem = self.get_memory_status()
        else:
            vm_total = self.get_memory_status()
            vm_mem_free = self.get_free_mem()
            used_size = vm_total - vm_mem_free + 16
        if balloon_type == "enlarge":
            min_size = self.current_mmem
        elif balloon_type == "evict":
            max_size = self.current_mmem
        min_size = max(used_size, min_size)
        return min_size, max_size
开发者ID:CongLi,项目名称:tp-qemu,代码行数:30,代码来源:balloon_check.py


示例7: memory_check

    def memory_check(vm, get_polling_output, keyname):
        """
        Check memory status.

        :param vm: VM object.
        :param get_polling_output: output of get polling in qmp.
        :param keyname: key name of the output of the 'qom-get' property.
        """
        error_context.context("Check whether memory status as expected",
                              logging.info)
        check_mem_ratio = float(params.get("check_mem_ratio", 0.1))
        mem_base = MemoryBaseTest(test, params, env)
        if keyname == "stat-free-memory":
            guest_mem = mem_base.get_guest_free_mem(vm)
        elif keyname == "stat-total-memory":
            guest_mem = mem_base.get_vm_mem(vm)

        stat_memory_qmp = get_polling_output['stats'][keyname]
        stat_memory_qmp = "%sB" % stat_memory_qmp
        stat_memory_qmp = int(float(utils_misc.normalize_data_size(
                                   (stat_memory_qmp), order_magnitude="M")))
        if (abs(guest_mem - stat_memory_qmp)) > (guest_mem * check_mem_ratio):
            raise exceptions.TestFail("%s of guest %s is not equal to %s in"
                                      " qmp, the ratio is %s" % (keyname,
                                                                 guest_mem,
                                                                 stat_memory_qmp,
                                                                 check_mem_ratio))
开发者ID:dagrh,项目名称:tp-qemu,代码行数:27,代码来源:balloon_service.py


示例8: test

        def test(self):
            self.disk_path = None
            while self.disk_path is None or os.path.exists(self.disk_path):
                self.disk_path = (
                    "%s/disk_%s" %
                    (test.tmpdir, data_factory.generate_random_string(3)))

            disk_size = int(utils_misc.normalize_data_size(
                params.get("disk_size", "10M"), "M"))

            exp_str = r".*gzip: stdout: No space left on device.*"
            vm_guest = env.get_vm("virt_test_vm1_guest")
            process.run("mkdir -p %s" % (mount_path))

            vm_guest.verify_alive()
            vm_guest.wait_for_login(timeout=login_timeout)

            create_file_disk(self.disk_path, disk_size)
            mount(self.disk_path, mount_path, "-o loop")

            vm_guest.migrate(mig_timeout, mig_protocol,
                             not_wait_for_migration=True,
                             migration_exec_cmd_src=migration_exec_cmd_src,
                             env=env)

            if not utils_misc.wait_for(lambda: process_output_check(
                                       vm_guest.process, exp_str),
                                       timeout=60, first=1):
                test.fail("The migration to destination with low "
                          "storage space didn't fail as it should.")
开发者ID:bssrikanth,项目名称:tp-qemu,代码行数:30,代码来源:migration_with_dst_problem.py


示例9: speed2byte

def speed2byte(speed):
    """
    convert speed to Bytes/s
    """
    if str(speed).isdigit():
        speed = "%sB" % speed
    speed = utils_misc.normalize_data_size(speed, "B")
    return int(float(speed))
开发者ID:Chenditang,项目名称:tp-qemu,代码行数:8,代码来源:block_copy.py


示例10: get_image_info

def get_image_info(image_file):
    """
    Get image information and put it into a dict. Image information like this:
    *******************************
    image: /path/vm1_6.3.img
    file format: raw
    virtual size: 10G (10737418240 bytes)
    disk size: 888M
    ....
    ....
    *******************************
    And the image info dict will be like this
    image_info_dict = { 'format':'raw',
                        'vsize' : '10737418240'
                        'dsize' : '931135488'
                      }
    TODO: Add more information to dict
    """
    try:
        cmd = "qemu-img info %s" % image_file
        image_info = utils.run(cmd, ignore_status=False).stdout.strip()
        image_info_dict = {}
        if image_info:
            for line in image_info.splitlines():
                if line.find("format") != -1:
                    image_info_dict['format'] = line.split(':')[-1].strip()
                elif line.find("virtual size") != -1:
                    vsize = line.split(":")[-1].strip().split(" ")[0]
                    vsize = utils_misc.normalize_data_size(vsize,
                                                           order_magnitude="B",
                                                           factor=1024)
                    image_info_dict['vsize'] = int(float(vsize))
                elif line.find("disk size") != -1:
                    dsize = line.split(':')[-1].strip()
                    dsize = utils_misc.normalize_data_size(dsize,
                                                           order_magnitude="B",
                                                           factor=1024)
                    image_info_dict['dsize'] = int(float(dsize))
        return image_info_dict
    except (KeyError, IndexError, ValueError, error.CmdError), detail:
        raise error.TestError("Fail to get information of %s:\n%s" %
                              (image_file, detail))
开发者ID:Keepod,项目名称:virt-test,代码行数:42,代码来源:__init__.py


示例11: normalize_mem_size

    def normalize_mem_size(cls, str_size):
        """
        Convert memory size unit

        :param str_size: memory size string, like: 1GB
        :return: memory size value in MB
        """
        args = (str_size, cls.UNIT, 1024)
        try:
            size = utils_misc.normalize_data_size(*args)
            return int(float(size))
        except ValueError, details:
            logging.debug("Convert memory size error('%s')" % details)
开发者ID:ngu-niny,项目名称:avocado-vt,代码行数:13,代码来源:__init__.py


示例12: get_win_mon_free_mem

    def get_win_mon_free_mem(self, session):
        """
        Get Performance Monitored Free memory.

        :param session: shell Object
        :return string: freespace M-bytes
        """
        cmd = r'typeperf "\Memory\Free & Zero Page List Bytes" -sc 1'
        status, output = session.cmd_status_output(cmd)
        if status == 0:
            free = "%s" % re.findall(r"\d+\.\d+", output)[2]
            free = float(utils_misc.normalize_data_size(free, order_magnitude="M"))
            return int(free)
        else:
            self.test.fail("Failed to get windows guest free memory")
开发者ID:ldoktor,项目名称:tp-qemu,代码行数:15,代码来源:balloon_check.py


示例13: setup

    def setup(self, force_start=False):
        """
        Setup test NFS share.

        :param force_start: Whether to make NFS service start anyway.
        """
        error_context.context("Setting up test NFS share", logging.info)

        for d in [self.nfs_dir, self.mnt_dir]:
            try:
                os.makedirs(d)
            except OSError:
                pass

        error_context.context("Checking available space to export",
                              logging.info)
        stat = os.statvfs(self.nfs_dir)
        free = str(stat.f_bsize * stat.f_bfree) + 'B'
        available_size = float(utils_misc.normalize_data_size(free,
                                                              order_magnitude="M"))
        required_size = float(utils_misc.normalize_data_size(self.required_size,
                                                             order_magnitude="M"))
        if available_size < required_size:
            raise NFSCorruptError("Space available: %fM, space needed: %fM"
                                  % (available_size, required_size))

        if force_start:
            self.start_service()
        else:
            if not self.is_service_active():
                self.start_service()

        process.run("exportfs %s:%s -o rw,no_root_squash" %
                    (self.nfs_ip, self.nfs_dir), shell=True)
        process.run("mount %s:%s %s -o rw,soft,timeo=30,retrans=1,vers=3" %
                    (self.nfs_ip, self.nfs_dir, self.mnt_dir), shell=True)
开发者ID:bssrikanth,项目名称:tp-qemu,代码行数:36,代码来源:nfs_corrupt.py


示例14: get_image_size

 def get_image_size(self, image):
     """
     Get image size for given image.
     :param image: image file.
     :return: image size.
     """
     params = self.params.object_params(image)
     qemu_image = qemu_storage.QemuImg(params, self.data_dir, image)
     image_info = qemu_image.info()
     if not image_info:
         self.test.error("Get image info failed.")
     image_size = re.findall("disk size: (\d\.?\d*?.*)", image_info)[0]
     image_size = int(float(utils_misc.normalize_data_size(image_size, "B")))
     logging.info("Image size of %s is %s" % (image, image_size))
     return image_size
开发者ID:EIChaoYang,项目名称:tp-qemu,代码行数:15,代码来源:live_backup_base.py


示例15: get_block_size

 def get_block_size(session, block_cmd, block_pattern):
     """
     Get block size inside guest.
     """
     output = session.cmd_output(block_cmd)
     block_size = re.findall(block_pattern, output)
     if block_size:
         if not re.search("[a-zA-Z]", block_size[0]):
             return int(block_size[0])
         else:
             return float(utils_misc.normalize_data_size(block_size[0], order_magnitude="B"))
     else:
         raise error.TestError(
             "Can not find the block size for the" " deivce. The output of command" " is: %s" % output
         )
开发者ID:MiriamDeng,项目名称:tp-qemu,代码行数:15,代码来源:block_resize.py


示例16: get_tmpfs_write_speed

def get_tmpfs_write_speed():
    """
    Get the tmpfs write speed of the host
    return: The write speed of tmpfs, the unit is kb/s.
    """
    utils.run("mkdir -p /tmp/test_speed && mount -t tmpfs none /tmp/test_speed")
    output = utils.run("dd if=/dev/urandom of=/tmp/test_speed/test bs=1k count=1024")
    try:
        speed = re.search("\s([\w\s\.]+)/s", output.stderr, re.I).group(1)
        return float(utils_misc.normalize_data_size(speed, 'K', 1024))
    except Exception:
        return 3072
    finally:
        utils.run("umount /tmp/test_speed")
        os.removedirs("/tmp/test_speed")
开发者ID:EIChaoYang,项目名称:tp-qemu,代码行数:15,代码来源:numa_stress.py


示例17: test_normalize_data_size

 def test_normalize_data_size(self):
     n1 = utils_misc.normalize_data_size("12M")
     n2 = utils_misc.normalize_data_size("1024M", "G")
     n3 = utils_misc.normalize_data_size("1024M", "T")
     n4 = utils_misc.normalize_data_size("1000M", "G", 1000)
     n5 = utils_misc.normalize_data_size("1T", "G", 1000)
     n6 = utils_misc.normalize_data_size("1T", "M")
     self.assertEqual(n1, "12.0")
     self.assertEqual(n2, "1.0")
     self.assertEqual(n3, "0.0009765625")
     self.assertEqual(n4, "1.0")
     self.assertEqual(n5, "1000.0")
     self.assertEqual(n6, "1048576.0")
开发者ID:EIChaoYang,项目名称:avocado-vt,代码行数:13,代码来源:test_utils_misc.py


示例18: check_memory_in_procfs

def check_memory_in_procfs(test, params, vm):
    """
    Check memory info in procfs

    :param test: QEMU test object
    :param params: Dictionary with the test parameters
    :param vm: VM object
    """
    qemu_pid = vm.get_pid()
    policy = params['policy_mem']
    if policy == 'preferred':
        policy = 'prefer'
    for mem_dev in params['mem_devs'].split():
        memdev_params = params.object_params(mem_dev)
        mem_size = memdev_params['size']
        mem_size = int(float(utils_misc.normalize_data_size(mem_size, "K")))
        smaps = process.system_output("grep -1 %d /proc/%d/smaps"
                                      % (mem_size, qemu_pid))
        smaps = decode_to_text(smaps).strip()
        mem_path = memdev_params.get("mem-path")
        if mem_path and (mem_path not in smaps):
            test.fail("memdev = %s: mem-path '%s' is not in smaps '%s'!"
                      % (mem_dev, mem_path, smaps))
        mem_start = smaps.split('-')[0]
        numa_maps = process.system_output("grep %s /proc/%d/numa_maps"
                                          % (mem_start, qemu_pid))
        numa_maps = decode_to_text(numa_maps).strip()
        if mem_path and (mem_path not in numa_maps):
            test.fail("memdev = %s: mem-path '%s' is not in numa_maps '%s'!"
                      % (mem_dev, mem_path, numa_maps))
        policy_numa = numa_maps.split()[1].split(':')
        if policy != policy_numa[0]:
            test.fail("memdev = %s:"
                      " 'policy' in numa_maps is '%s', but not '%s'!"
                      % (mem_dev, policy_numa[0], policy))
        elif (policy != 'default'):
            host_node = memdev_params['host-nodes']
            if (policy_numa[1] != host_node):
                test.fail("memdev = %s:"
                          " 'host-nodes' in numa_maps is '%s', but not '%s'!"
                          % (mem_dev, policy_numa[1], host_node))
开发者ID:ldoktor,项目名称:tp-qemu,代码行数:41,代码来源:numa_memdev_options.py


示例19: get_memory_boundary

    def get_memory_boundary(self, balloon_type="evict"):
        """
        Get the legal memory boundary for balloon operation.

        :param balloon_type: evict or enlarge
        :type balloon_type: string
        :return: min and max size of the memory
        :rtype: tuple
        """
        max_size = self.ori_mem
        min_size = self.params.get("minmem", "512M")
        min_size = int(float(utils_misc.normalize_data_size(min_size)))
        if balloon_type == "enlarge":
            min_size = self.current_mmem
        else:
            vm_total = self.get_memory_status()
            vm_mem_free = self.get_free_mem()
            # leave 16M buffer to ensure os keep working when do
            # evict balloon device.
            used_size = vm_total - vm_mem_free + 16
            min_size = max(used_size, min_size)
        return min_size, max_size
开发者ID:sathnaga,项目名称:tp-qemu,代码行数:22,代码来源:balloon_check.py


示例20: edit_memory

    def edit_memory(source):
        """
        Modify vm's maximum and current memory(unit and value).

        :param source: virsh edit's option.
        :return: True if edit successed,False if edit failed.
        """
        mem_unit = params.get("mem_unit", "K")
        mem_value = params.get("mem_value", "1048576")
        mem_delta = params.get("mem_delta", 1000)
        edit_cmd = []
        del_cmd = r":g/currentMemory/d"
        edit_cmd.append(del_cmd)
        update_cmd = r":%s/<memory unit='KiB'>[0-9]*<\/memory>/<memory unit='"
        update_cmd += mem_unit + "'>" + mem_value + r"<\/memory>"
        edit_cmd.append(update_cmd)
        try:
            expected_mem = int(utils_misc.normalize_data_size(
                mem_value + mem_unit, 'K').split('.')[0])
        except ValueError:
            logging.error("Fail to translate %s to KiB", mem_value + mem_unit)
            return False
        logging.debug("Expected max memory is %s", expected_mem)
        status = libvirt.exec_virsh_edit(source, edit_cmd)
        try:
            if status:
                # Restart vm to check memory value
                virsh.destroy(vm_name)
                virsh.start(vm_name)
                new_mem = vm.get_max_mem()
                if new_mem - expected_mem > int(mem_delta):
                    logging.error("New max memory %s is not excepted", new_mem)
                    return False
        except Exception as e:
            logging.error("Error occured when check domain memory: %s", e)
            return False
        return status
开发者ID:nasastry,项目名称:tp-libvirt,代码行数:37,代码来源:virsh_edit.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils_misc.umount函数代码示例发布时间:2022-05-26
下一篇:
Python utils_misc.mount函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap