本文整理汇总了Python中storage.get_image_filename函数的典型用法代码示例。如果您正苦于以下问题:Python get_image_filename函数的具体用法?Python get_image_filename怎么用?Python get_image_filename使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_image_filename函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: preprocess_image
def preprocess_image(test, params, image_name):
"""
Preprocess a single QEMU image according to the instructions in params.
@param test: Autotest test object.
@param params: A dict containing image preprocessing parameters.
@note: Currently this function just creates an image if requested.
"""
base_dir = data_dir.get_data_dir()
if params.get("storage_type") == "iscsi":
iscsidev = qemu_storage.Iscsidev(params, base_dir, image_name)
params["image_name"] = iscsidev.setup()
else:
image_filename = storage.get_image_filename(params,
base_dir)
create_image = False
if params.get("force_create_image") == "yes":
create_image = True
elif (params.get("create_image") == "yes" and not
os.path.exists(image_filename)):
create_image = True
if create_image:
image = qemu_storage.QemuImg(params, base_dir, image_name)
if not image.create(params):
raise error.TestError("Could not create image")
示例2: print_guest_list
def print_guest_list(options):
"""
Helper function to pretty print the guest list.
This function uses a paginator, if possible (inspired on git).
:param options: OptParse object with cmdline options.
:param cartesian_parser: Cartesian parser object with test options.
"""
pipe = get_paginator()
# lvsb testing has no concept of guests
if options.vt_type == 'lvsb':
pipe.write("No guest types available for lvsb testing")
return
index = 0
pipe.write("Searched %s for guest images\n" %
os.path.join(data_dir.get_data_dir(), 'images'))
pipe.write("Available guests:")
pipe.write("\n\n")
for params in get_guest_name_parser(options).get_dicts():
index += 1
base_dir = params.get("images_base_dir", data_dir.get_data_dir())
image_name = storage.get_image_filename(params, base_dir)
name = params['name']
if os.path.isfile(image_name):
out = (bcolors.blue + str(index) + bcolors.end + " " +
name + "\n")
else:
out = (bcolors.blue + str(index) + bcolors.end + " " +
name + " " + bcolors.yellow +
"(missing %s)" % os.path.basename(image_name) +
bcolors.end + "\n")
pipe.write(out)
示例3: preprocess_image
def preprocess_image(test, params, image_name):
"""
Preprocess a single QEMU image according to the instructions in params.
:param test: Autotest test object.
:param params: A dict containing image preprocessing parameters.
:note: Currently this function just creates an image if requested.
"""
base_dir = params.get("images_base_dir", data_dir.get_data_dir())
if not storage.preprocess_image_backend(base_dir, params, image_name):
logging.error("Backend can't be prepared correctly.")
image_filename = storage.get_image_filename(params,
base_dir)
create_image = False
if params.get("force_create_image") == "yes":
create_image = True
elif (params.get("create_image") == "yes" and not
storage.file_exists(params, image_filename)):
create_image = True
if params.get("backup_image_before_testing", "no") == "yes":
image = qemu_storage.QemuImg(params, base_dir, image_name)
image.backup_image(params, base_dir, "backup", True, True)
if create_image:
image = qemu_storage.QemuImg(params, base_dir, image_name)
image.create(params)
示例4: print_guest_list
def print_guest_list(options):
"""
Helper function to pretty print the guest list.
This function uses a paginator, if possible (inspired on git).
@param options: OptParse object with cmdline options.
@param cartesian_parser: Cartesian parser object with test options.
"""
cfg = os.path.join(data_dir.get_root_dir(), options.type,
"cfg", "guest-os.cfg")
cartesian_parser = cartesian_config.Parser()
cartesian_parser.parse_file(cfg)
pipe = get_paginator()
index = 0
pipe.write("Searched %s for guest images\n" %
os.path.join(data_dir.get_data_dir(), 'images'))
pipe.write("Available guests:")
pipe.write("\n\n")
for params in cartesian_parser.get_dicts():
index += 1
image_name = storage.get_image_filename(params, data_dir.get_data_dir())
shortname = ".".join(params['name'].split(".")[1:])
if os.path.isfile(image_name):
out = (bcolors.blue + str(index) + bcolors.end + " " +
shortname + "\n")
else:
out = (bcolors.blue + str(index) + bcolors.end + " " +
shortname + " " + bcolors.yellow +
"(missing %s)" % os.path.basename(image_name) +
bcolors.end + "\n")
pipe.write(out)
示例5: convert
def convert(self, params, root_dir, cache_mode=None):
"""
Convert image
:param params: dictionary containing the test parameters
:param root_dir: dir for save the convert image
:param cache_mode: The cache mode used to write the output disk image.
Valid options are: ``none``, ``writeback``
(default), ``writethrough``, ``directsync`` and
``unsafe``.
:note: params should contain:
convert_image_tag
the image name of the convert image
convert_filename
the name of the image after convert
convert_fmt
the format after convert
compressed
indicates that target image must be compressed
encrypted
there are two value "off" and "on", default value is "off"
"""
convert_image_tag = params["image_convert"]
convert_image = params["convert_name_%s" % convert_image_tag]
convert_compressed = params.get("convert_compressed")
convert_encrypted = params.get("convert_encrypted", "off")
convert_format = params["convert_format_%s" % convert_image_tag]
params_convert = {"image_name": convert_image,
"image_format": convert_format}
convert_image_filename = storage.get_image_filename(params_convert,
root_dir)
cmd = self.image_cmd
cmd += " convert"
if convert_compressed == "yes":
cmd += " -c"
if convert_encrypted != "off":
cmd += " -o encryption=%s" % convert_encrypted
if self.image_format:
cmd += " -f %s" % self.image_format
cmd += " -O %s" % convert_format
if cache_mode:
cmd += " -t %s" % cache_mode
cmd += " %s %s" % (self.image_filename, convert_image_filename)
logging.info("Convert image %s from %s to %s", self.image_filename,
self.image_format, convert_format)
utils.system(cmd)
return convert_image_tag
示例6: check_disk_params
def check_disk_params(self, params, root_dir=''):
"""
Check gathered info from qtree/block with params
@param params: autotest params
@param root_dir: root_dir of images. If all images use absolute path
it's safe to omit this param.
@return: number of errors
"""
err = 0
disks = {}
for disk in self.disks:
if isinstance(disk, QtreeDisk):
disks[disk.get_qname()] = disk.get_params().copy()
# We don't have the params name so we need to map file_names instead
qname = None
for name in params.objects('images'):
current = None
image_params = params.object_params(name)
image_name = os.path.realpath(
storage.get_image_filename(image_params, root_dir))
for (qname, disk) in disks.iteritems():
if disk.get('image_name') == image_name:
current = disk
# autotest params might use relative path
current['image_name'] = image_params.get('image_name')
break
if not current:
logging.error("Disk %s is not in qtree but is in params.", name)
err += 1
continue
for prop in current.iterkeys():
handled = False
if prop == "drive_format":
# HOOK: params to qemu translation
if current.get(prop).startswith(image_params.get(prop)):
handled = True
elif (image_params.get(prop) and
image_params.get(prop) == current.get(prop)):
handled = True
if not handled:
logging.error("Disk %s property %s=%s doesn't match params"
" %s", qname, prop, current.get(prop),
image_params.get(prop))
err += 1
disks.pop(qname)
if disks:
logging.error('Some disks were in qtree but not in autotest params'
': %s', disks)
err += 1
return err
示例7: convert
def convert(self, params, root_dir):
"""
Convert image
@param params: dictionary containing the test parameters
@param root_dir: dir for save the convert image
@note: params should contain:
convert_image_tag -- the image name of the convert image
convert_filename -- the name of the image after convert
convert_fmt -- the format after convert
compressed -- indicates that target image must be compressed
encrypted -- there are two value "off" and "on",
default value is "off"
"""
convert_image_tag = params.get("image_convert")
convert_image = params.get("image_name_%s" % convert_image_tag)
convert_compressed = params.get("convert_compressed")
convert_encrypted = params.get("convert_encrypted", "off")
convert_format = params.get("image_format_%s" % convert_image_tag)
params_convert = {"image_name": convert_image,
"image_format": convert_format}
convert_image_filename = storage.get_image_filename(params_convert,
root_dir)
cmd = self.image_cmd
cmd += " convert"
if convert_compressed == "yes":
cmd += " -c"
if convert_encrypted != "off":
cmd += " -o encryption=%s" % convert_encrypted
if self.image_format:
cmd += " -f %s" % self.image_format
cmd += " -O %s" % convert_format
cmd += " %s %s" % (self.image_filename, convert_image_filename)
logging.info("Convert image %s from %s to %s", self.image_filename,
self.image_format,convert_format)
utils.system(cmd)
return convert_image_tag
示例8: create
def create(self, params, ignore_errors=False):
"""
Create an image using qemu_img or dd.
:param params: Dictionary containing the test parameters.
:param ignore_errors: Whether to ignore errors on the image creation
cmd.
:note: params should contain:
image_name
name of the image file, without extension
image_format
format of the image (qcow2, raw etc)
image_cluster_size (optional)
cluster size for the image
image_size
requested size of the image (a string qemu-img can
understand, such as '10G')
create_with_dd
use dd to create the image (raw format only)
base_image(optional)
the base image name when create snapshot
base_format(optional)
the format of base image
encrypted(optional)
if the image is encrypted, allowed values: on and off.
Default is "off"
preallocated(optional)
if preallocation when create image, allowed values: off,
metadata. Default is "off"
:return: tuple (path to the image created, utils.CmdResult object
containing the result of the creation command).
"""
if params.get("create_with_dd") == "yes" and self.image_format == "raw":
# maps K,M,G,T => (count, bs)
human = {'K': (1, 1),
'M': (1, 1024),
'G': (1024, 1024),
'T': (1024, 1048576),
}
if human.has_key(self.size[-1]):
block_size = human[self.size[-1]][1]
size = int(self.size[:-1]) * human[self.size[-1]][0]
qemu_img_cmd = ("dd if=/dev/zero of=%s count=%s bs=%sK"
% (self.image_filename, size, block_size))
else:
qemu_img_cmd = self.image_cmd
qemu_img_cmd += " create"
qemu_img_cmd += " -f %s" % self.image_format
image_cluster_size = params.get("image_cluster_size", None)
preallocated = params.get("preallocated", "off")
encrypted = params.get("encrypted", "off")
image_extra_params = params.get("image_extra_params", "")
has_backing_file = params.get('has_backing_file')
qemu_img_cmd += " -o "
if preallocated != "off":
qemu_img_cmd += "preallocation=%s," % preallocated
if encrypted != "off":
qemu_img_cmd += "encrypted=%s," % encrypted
if image_cluster_size is not None:
qemu_img_cmd += "cluster_size=%s," % image_cluster_size
if has_backing_file == "yes":
backing_param = params.object_params("backing_file")
backing_file = storage.get_image_filename(backing_param,
self.root_dir)
backing_fmt = backing_param.get("image_format")
qemu_img_cmd += "backing_file=%s," % backing_file
qemu_img_cmd += "backing_fmt=%s," % backing_fmt
if image_extra_params:
qemu_img_cmd += "%s," % image_extra_params
qemu_img_cmd = qemu_img_cmd.rstrip(" -o")
qemu_img_cmd = qemu_img_cmd.rstrip(",")
if self.base_tag:
qemu_img_cmd += " -b %s" % self.base_image_filename
if self.base_format:
qemu_img_cmd += " -F %s" % self.base_format
qemu_img_cmd += " %s" % self.image_filename
qemu_img_cmd += " %s" % self.size
if (params.get("image_backend", "filesystem") == "filesystem"):
image_dirname = os.path.dirname(self.image_filename)
if image_dirname and not os.path.isdir(image_dirname):
e_msg = ("Parent directory of the image file %s does "
"not exist" % self.image_filename)
logging.error(e_msg)
logging.error("This usually means a serious setup error.")
logging.error("Please verify if your data dir contains the "
#.........这里部分代码省略.........
示例9: make_create_command
def make_create_command(self, name=None, params=None, root_dir=None):
"""
Generate a libvirt command line. All parameters are optional. If a
parameter is not supplied, the corresponding value stored in the
class attributes is used.
@param name: The name of the object
@param params: A dict containing VM params
@param root_dir: Base directory for relative filenames
@note: The params dict should contain:
mem -- memory size in MBs
cdrom -- ISO filename to use with the qemu -cdrom parameter
extra_params -- a string to append to the qemu command
shell_port -- port of the remote shell daemon on the guest
(SSH, Telnet or the home-made Remote Shell Server)
shell_client -- client program to use for connecting to the
remote shell daemon on the guest (ssh, telnet or nc)
x11_display -- if specified, the DISPLAY environment variable
will be be set to this value for the qemu process (useful for
SDL rendering)
images -- a list of image object names, separated by spaces
nics -- a list of NIC object names, separated by spaces
For each image in images:
drive_format -- string to pass as 'if' parameter for this
image (e.g. ide, scsi)
image_snapshot -- if yes, pass 'snapshot=on' to qemu for
this image
image_boot -- if yes, pass 'boot=on' to qemu for this image
In addition, all parameters required by get_image_filename.
For each NIC in nics:
nic_model -- string to pass as 'model' parameter for this
NIC (e.g. e1000)
"""
# helper function for command line option wrappers
def has_option(help_text, option):
return bool(re.search(r"--%s" % option, help_text, re.MULTILINE))
# Wrappers for all supported libvirt command line parameters.
# This is meant to allow support for multiple libvirt versions.
# Each of these functions receives the output of 'libvirt --help' as a
# parameter, and should add the requested command line option
# accordingly.
def add_name(help_text, name):
return " --name '%s'" % name
def add_machine_type(help_text, machine_type):
if has_option(help_text, "machine"):
return " --machine %s" % machine_type
else:
return ""
def add_hvm_or_pv(help_text, hvm_or_pv):
if hvm_or_pv == "hvm":
return " --hvm --accelerate"
elif hvm_or_pv == "pv":
return " --paravirt"
else:
logging.warning("Unknown virt type hvm_or_pv, using default.")
return ""
def add_mem(help_text, mem):
return " --ram=%s" % mem
def add_check_cpu(help_text):
if has_option(help_text, "check-cpu"):
return " --check-cpu"
else:
return ""
def add_smp(help_text, smp):
return " --vcpu=%s" % smp
def add_location(help_text, location):
if has_option(help_text, "location"):
return " --location %s" % location
else:
return ""
def add_cdrom(help_text, filename, index=None):
if has_option(help_text, "cdrom"):
return " --cdrom %s" % filename
else:
return ""
def add_pxe(help_text):
if has_option(help_text, "pxe"):
return " --pxe"
else:
return ""
def add_import(help_text):
if has_option(help_text, "import"):
return " --import"
else:
return ""
#.........这里部分代码省略.........
示例10: preprocess
#.........这里部分代码省略.........
kvm_userspace_version = " ".join(matches[0].split()[1:]).strip(",")
else:
kvm_userspace_version = "Unknown"
logging.debug("KVM userspace version: %s" % kvm_userspace_version)
test.write_test_keyval({"kvm_userspace_version": kvm_userspace_version})
if params.get("setup_hugepages") == "yes":
h = test_setup.HugePageConfig(params)
suggest_mem = h.setup()
if suggest_mem is not None:
params['mem'] = suggest_mem
if params.get("vm_type") == "libvirt":
utils_libvirtd.libvirtd_restart()
if params.get("setup_thp") == "yes":
thp = test_setup.TransparentHugePageConfig(test, params)
thp.setup()
if params.get("setup_ksm") == "yes":
ksm = test_setup.KSMConfig(params, env)
ksm.setup(env)
# Execute any pre_commands
if params.get("pre_command"):
process_command(test, params, env, params.get("pre_command"),
int(params.get("pre_command_timeout", "600")),
params.get("pre_command_noncritical") == "yes")
# if you want set "pci=nomsi" before test, set "disable_pci_msi = yes"
# and pci_msi_sensitive = "yes"
if params.get("pci_msi_sensitive", "no") == "yes":
disable_pci_msi = params.get("disable_pci_msi", "no")
image_filename = storage.get_image_filename(params,
data_dir.get_data_dir())
grub_file = params.get("grub_file", "/boot/grub2/grub.cfg")
kernel_cfg_pos_reg = params.get("kernel_cfg_pos_reg",
r".*vmlinuz-\d+.*")
msi_keyword = params.get("msi_keyword", " pci=nomsi")
disk_obj = utils_disk.GuestFSModiDisk(image_filename)
kernel_config_ori = disk_obj.read_file(grub_file)
kernel_config = re.findall(kernel_cfg_pos_reg, kernel_config_ori)
if not kernel_config:
raise error.TestError("Cannot find the kernel config, reg is %s" %
kernel_cfg_pos_reg)
kernel_config_line = kernel_config[0]
kernel_need_modify = False
if disable_pci_msi == "yes":
if not re.findall(msi_keyword, kernel_config_line):
kernel_config_set = kernel_config_line + msi_keyword
kernel_need_modify = True
else:
if re.findall(msi_keyword, kernel_config_line):
kernel_config_set = re.sub(msi_keyword, "", kernel_config_line)
kernel_need_modify = True
if kernel_need_modify:
for vm in env.get_all_vms():
if vm:
vm.destroy()
env.unregister_vm(vm.name)
disk_obj.replace_image_file_content(grub_file, kernel_config_line,
kernel_config_set)
logging.debug("Guest cmdline 'pci=nomsi' setting is: [ %s ]" %
示例11:
kernel_extra_params_remove = params.get("kernel_extra_params_remove")
if params.get("disable_pci_msi"):
disable_pci_msi = params.get("disable-pci_msi")
if disable_pci_msi == "yes":
if "pci=" in kernel_extra_params_add:
kernel_extra_params_add = re.sub("pci=.*?\s+", "pci=nomsi ",
kernel_extra_params_add)
else:
kernel_extra_params_add += " pci=nomsi"
params["ker_remove_similar_pci"] = "yes"
else:
kernel_extra_params_remove += " pci=nomsi"
if kernel_extra_params_add or kernel_extra_params_remove:
global kernel_cmdline, kernel_modified
image_filename = storage.get_image_filename(params,
data_dir.get_data_dir())
grub_file = params.get("grub_file", "/boot/grub2/grub.cfg")
kernel_cfg_pos_reg = params.get("kernel_cfg_pos_reg",
r".*vmlinuz-\d+.*")
disk_obj = utils_disk.GuestFSModiDisk(image_filename)
kernel_config_ori = disk_obj.read_file(grub_file)
kernel_config = re.findall(kernel_cfg_pos_reg, kernel_config_ori)
if not kernel_config:
raise error.TestError("Cannot find the kernel config, reg is %s" %
kernel_cfg_pos_reg)
kernel_config = kernel_config[0]
kernel_cmdline = kernel_config
kernel_need_modify = False
kernel_config_set = kernel_config
示例12: check_disk_params
def check_disk_params(self, params):
"""
Check gathered info from qtree/block with params
:param params: autotest params
:return: number of errors
"""
def check_drive_format(node, params):
""" checks the drive format according to qtree info """
expected = params.get('drive_format')
if expected == 'scsi':
if arch.ARCH == 'ppc64':
expected = 'spapr-vscsi'
else:
expected = 'lsi53c895a'
elif expected.startswith('scsi'):
expected = params.get('scsi_hba', 'virtio-scsi-pci')
elif expected.startswith('usb'):
expected = 'usb-storage'
try:
if expected == 'virtio':
actual = node.qtree['type']
else:
actual = node.parent.parent.qtree.get('type')
except AttributeError:
logging.error("Failed to check drive format, can't get parent"
"of:\n%s", node)
if actual == 'virtio-scsi-device': # new name for virtio-scsi
actual = 'virtio-scsi-pci'
if expected not in actual:
return ("drive format in qemu is %s, in autotest %s"
% (actual, expected))
err = 0
disks = {}
for disk in self.disks:
if isinstance(disk, QtreeDisk):
disks[disk.get_qname()] = (disk.get_params().copy(), disk)
# We don't have the params name so we need to map file_names instead
qname = None
for name in params.objects('cdroms'):
image_name = utils_misc.get_path(data_dir.get_data_dir(),
params.object_params(name).get('cdrom', ''))
image_name = os.path.realpath(image_name)
for (qname, disk) in disks.iteritems():
if disk[0].get('image_name') == image_name:
break
else:
continue # Not /proc/scsi cdrom device
disks.pop(qname)
for name in params.objects('images'):
current = None
image_params = params.object_params(name)
base_dir = image_params.get("images_base_dir",
data_dir.get_data_dir())
image_name = os.path.realpath(
storage.get_image_filename(image_params,
base_dir))
for (qname, disk) in disks.iteritems():
if disk[0].get('image_name') == image_name:
current = disk[0]
current_node = disk[1]
# autotest params might use relative path
current['image_name'] = image_params.get('image_name')
break
if not current:
logging.error("Disk %s is not in qtree but is in params.",
name)
err += 1
continue
for prop in current.iterkeys():
handled = False
if prop == "drive_format":
out = check_drive_format(current_node, image_params)
if out:
logging.error("Disk %s %s", qname, out)
err += 1
handled = True
elif (image_params.get(prop) and
image_params.get(prop) == current.get(prop)):
handled = True
if not handled:
logging.error("Disk %s property %s=%s doesn't match params"
" %s", qname, prop, current.get(prop),
image_params.get(prop))
err += 1
disks.pop(qname)
if disks:
logging.error('Some disks were in qtree but not in autotest params'
': %s', disks)
err += 1
return err
示例13: check_disk_params
def check_disk_params(self, params):
"""
Check gathered info from qtree/block with params
@param params: autotest params
@return: number of errors
"""
err = 0
disks = {}
for disk in self.disks:
if isinstance(disk, QtreeDisk):
disks[disk.get_qname()] = disk.get_params().copy()
# We don't have the params name so we need to map file_names instead
qname = None
for name in params.objects('cdroms'):
image_name = utils_misc.get_path(data_dir.get_data_dir(),
params.object_params(name).get('cdrom', ''))
image_name = os.path.realpath(image_name)
for (qname, disk) in disks.iteritems():
if disk.get('image_name') == image_name:
break
else:
continue # Not /proc/scsi cdrom device
disks.pop(qname)
for name in params.objects('images'):
current = None
image_params = params.object_params(name)
base_dir = image_params.get("images_base_dir",
data_dir.get_data_dir())
image_name = os.path.realpath(
storage.get_image_filename(image_params,
base_dir))
for (qname, disk) in disks.iteritems():
if disk.get('image_name') == image_name:
current = disk
# autotest params might use relative path
current['image_name'] = image_params.get('image_name')
break
if not current:
logging.error("Disk %s is not in qtree but is in params.", name)
err += 1
continue
for prop in current.iterkeys():
handled = False
if prop == "drive_format":
# HOOK: ahci disk is ide-* disk
if (image_params.get(prop) == 'ahci' and
current.get(prop).startswith('ide-')):
handled = True
# HOOK: params to qemu translation
elif current.get(prop).startswith(image_params.get(prop)):
handled = True
elif (image_params.get(prop) and
image_params.get(prop) == current.get(prop)):
handled = True
if not handled:
logging.error("Disk %s property %s=%s doesn't match params"
" %s", qname, prop, current.get(prop),
image_params.get(prop))
err += 1
disks.pop(qname)
if disks:
logging.error('Some disks were in qtree but not in autotest params'
': %s', disks)
err += 1
return err