本文整理汇总了Python中virttest.utils_misc.normalize_data_size函数的典型用法代码示例。如果您正苦于以下问题:Python normalize_data_size函数的具体用法?Python normalize_data_size怎么用?Python normalize_data_size使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了normalize_data_size函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
示例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.")
示例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
示例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
示例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))
示例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
示例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))
示例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.")
示例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))
示例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))
示例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)
示例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")
示例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)
示例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
示例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
)