本文整理汇总了Python中virttest.virsh.domain_exists函数的典型用法代码示例。如果您正苦于以下问题:Python domain_exists函数的具体用法?Python domain_exists怎么用?Python domain_exists使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了domain_exists函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: result_confirm
def result_confirm(self, params):
"""
Confirm if VM installation is succeed
"""
if self.twice_execute and self.kill_first:
get_pid_cmd = "ps -ef | grep '%s' | grep qemu-kvm | grep -v grep"\
% self.vm_name
result = utils.run(get_pid_cmd, ignore_status=True)
if result.exit_status:
raise error.TestFail("First install failed!")
install_pid = result.stdout.strip().split()[1]
utils_misc.safe_kill(int(install_pid), signal.SIGKILL)
self.td.join()
if self.read_only:
if virsh.domain_exists(self.vm_name):
raise error.TestFail("Domain '%s' should not exist"
% self.vm_name)
os.chmod(self.image_path,
stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
else:
if not virsh.domain_exists(self.vm_name):
raise error.TestFail("Domain '%s' should exists, no matter its"
" installation is succeed or failed!"
% self.vm_name)
else:
if not self.kill_first:
if self.vm.is_dead():
self.vm.start()
try:
self.vm.wait_for_login()
except remote.LoginTimeoutError, detail:
raise error.TestFail(str(detail))
else:
virsh.remove_domain(self.vm_name)
开发者ID:noxdafox,项目名称:tp-libvirt,代码行数:34,代码来源:resource_abnormal.py
示例2: recover
def recover(self, params):
"""
Recover test environment
"""
abnormal_type = params.get("abnormal_type")
cpu_enable = True if self.cpu_status else False
utils_misc.set_cpu_status(self.cpu_num, cpu_enable)
if virsh.domain_exists(self.vm_new_name):
virsh.remove_domain(self.vm_new_name)
if os.path.exists(self.new_image_file):
os.remove(self.new_image_file)
if self.twice_execute:
if virsh.domain_exists(self.vm_new_name1):
virsh.remove_domain(self.vm_new_name1)
if os.path.exists(self.new_image_file1):
os.remove(self.new_image_file1)
if abnormal_type == "memory_lack":
if 'memory_pid' in params:
pid = params.get('memory_pid')
utils_misc.safe_kill(pid, signal.SIGKILL)
process.run("swapon -a", shell=True)
tmp_c_file = params.get("tmp_c_file", "/tmp/test.c")
tmp_exe_file = params.get("tmp_exe_file", "/tmp/test")
if os.path.exists(tmp_c_file):
os.remove(tmp_c_file)
if os.path.exists(tmp_exe_file):
os.remove(tmp_exe_file)
elif abnormal_type in ["disk_lack", ""]:
if self.selinux_enforcing:
utils_selinux.set_status("enforcing")
tmp_file = os.path.join(self.mount_dir, "tmp")
if os.path.exists(tmp_file):
os.remove(tmp_file)
# Sometimes one umount action is not enough
utils_misc.wait_for(lambda: utils_misc.umount(self.partition,
self.mount_dir,
self.fs_type), 120)
if self.iscsi_dev:
self.iscsi_dev.cleanup()
os.rmdir(self.mount_dir)
remove_machine_cgroup()
开发者ID:balamuruhans,项目名称:tp-libvirt,代码行数:41,代码来源:resource_abnormal.py
示例3: clean_clone_vm
def clean_clone_vm():
"""
Clean up cloned domain.
"""
try:
if virsh.domain_exists(vm_clone_name):
if virsh.is_alive(vm_clone_name):
virsh.destroy(vm_clone_name, ignore_status=False)
virsh.undefine(vm_clone_name, ignore_status=False)
if os.path.exists(clone_image):
os.remove(clone_image)
except error.CmdError, detail:
raise error.TestFail("Clean clone guest failed!:%s" % detail)
开发者ID:Guannan-Ren,项目名称:tp-libvirt,代码行数:13,代码来源:virt_sysprep.py
示例4: __init__
def __init__(self, test, params):
self.vm_name = params.get("vm_name", "test-vm1")
self.test = test
while virsh.domain_exists(self.vm_name):
self.vm_name += ".test"
params["main_vm"] = self.vm_name
ios_file = os.path.join(data_dir.get_data_dir(),
params.get('cdrom_cd1'))
if not os.path.exists(ios_file):
self.test.cancel("Please prepare ios file:%s" % ios_file)
self.env = params.get('env')
self.vm = self.env.create_vm("libvirt", None, self.vm_name, params,
test.bindir)
self.env.register_vm(self.vm_name, self.vm)
self.twice_execute = "yes" == params.get("twice_execute", "no")
self.kill_first = "yes" == params.get("kill_first", "no")
self.read_only = "yes" == params.get("read_only", "no")
self.selinux_enforcing = utils_selinux.is_enforcing()
if self.selinux_enforcing:
utils_selinux.set_status("permissive")
self.image_path = os.path.join(test.virtdir, "test_image")
if not os.path.exists(self.image_path):
os.mkdir(self.image_path)
if self.read_only:
os.chmod(self.image_path,
stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH)
params["image_name"] = os.path.join(self.image_path, self.vm_name)
params["image_format"] = "raw"
params['force_create_image'] = "yes"
params['remove_image'] = "yes"
params['shutdown_cleanly'] = "yes"
params['shutdown_cleanly_timeout'] = 120
params['guest_port_unattended_install'] = 12323
params['inactivity_watcher'] = "error"
params['inactivity_treshold'] = 1800
params['image_verify_bootable'] = "no"
params['unattended_delivery_method'] = "cdrom"
params['drive_index_unattended'] = 1
params['drive_index_cd1'] = 2
params['boot_once'] = "d"
params['medium'] = "cdrom"
params['wait_no_ack'] = "yes"
params['image_raw_device'] = "yes"
params['backup_image_before_testing'] = "no"
params['kernel_params'] = ("ks=cdrom nicdelay=60 "
"console=ttyS0,115200 console=tty0")
params['cdroms'] += " unattended"
params['redirs'] += " unattended_install"
self.params = params
开发者ID:balamuruhans,项目名称:tp-libvirt,代码行数:50,代码来源:resource_abnormal.py
示例5: result_confirm
def result_confirm(self, params):
"""
Confirm if virt-clone executed succeed
"""
if self.kill_first:
# Stop this threading
first_pid = self.cgroup.get_pids(self.cgroup_index)[-1]
utils_misc.safe_kill(int(first_pid), signal.SIGKILL)
else:
self.td0.join(self.time_out)
if self.td1:
self.td1.join(self.time_out)
abnormal_type = params.get("abnormal_type")
if abnormal_type == "cpu_lack":
if not virsh.domain_exists(self.vm_new_name):
self.test.fail("Clone '%s' failed" % self.vm_new_name)
else:
result = virsh.start(self.vm_new_name, ignore_status=True)
if result.exit_status:
self.test.fail("Cloned domain cannot be started!")
elif abnormal_type == "disk_lack":
if virsh.domain_exists(self.vm_new_name):
self.test.fail("Clone '%s' succeed but expect failed!"
% self.vm_new_name)
else:
if self.twice_execute and not self.kill_first:
if virsh.domain_exists(self.vm_new_name):
self.test.fail("Clone '%s' succeed but expect"
" failed!" % self.vm_new_name)
if virsh.domain_exists(self.vm_new_name1):
self.test.fail("Clone '%s' succeed but expect"
" failed!" % self.vm_new_name1)
elif self.twice_execute and self.kill_first:
if not virsh.domain_exists(self.vm_new_name):
self.test.fail("Clone '%s' failed!"
% self.vm_new_name)
开发者ID:balamuruhans,项目名称:tp-libvirt,代码行数:37,代码来源:resource_abnormal.py
示例6: check_new_name
def check_new_name(output, expected_name):
"""
Verify guest name changed to the new name.
"""
found = False
if output_mode == "libvirt":
found = virsh.domain_exists(expected_name)
if output_mode == "local":
found = os.path.isfile(os.path.join(output_storage,
expected_name + "-sda"))
if output_mode in ["rhev", "vdsm"]:
ovf = get_ovf_content(output)
found = "<Name>%s</Name>" % expected_name in ovf
else:
return
if found:
logging.info("Guest name renamed when converting it")
else:
raise exceptions.TestFail("Rename guest failed")
开发者ID:chloerh,项目名称:tp-libvirt,代码行数:19,代码来源:v2v_options.py
示例7: run
def run(test, params, env):
"""
Test svirt in virt-install.
(1). Init variables.
(2). Set selinux on host.
(3). Set label of image.
(4). run unattended install.
(5). clean up.
"""
# Get general variables.
status_error = ('yes' == params.get("status_error", 'no'))
host_sestatus = params.get("host_selinux", "enforcing")
# Set selinux status on host.
backup_sestatus = utils_selinux.get_status()
utils_selinux.set_status(host_sestatus)
# Set the image label.
disk_label = params.get("disk_label", None)
vm_name = params.get("main_vm", None)
vm_params = params.object_params(vm_name)
base_dir = params.get("images_base_dir", data_dir.get_data_dir())
image_filename = storage.get_image_filename(vm_params, base_dir)
utils_selinux.set_context_of_file(image_filename, disk_label)
try:
try:
unattended_install.run(test, params, env)
# Install completed.
if status_error:
raise error.TestFail('Test successed in negative case.')
except error.CmdError, e:
# Install failed.
if not status_error:
raise error.TestFail("Test failed in positive case."
"error: %s" % e)
finally:
# cleanup
utils_selinux.set_status(backup_sestatus)
if virsh.domain_exists(vm_name):
virsh.remove_domain(vm_name)
开发者ID:Guannan-Ren,项目名称:tp-libvirt,代码行数:42,代码来源:svirt_install.py
示例8: cleanup_dest
def cleanup_dest(vm, src_uri=""):
"""
Clean up the destination host environment
when doing the uni-direction migration.
"""
logging.info("Cleaning up VMs on %s" % vm.connect_uri)
try:
if virsh.domain_exists(vm.name, uri=vm.connect_uri):
vm_state = vm.state()
if vm_state == "paused":
vm.resume()
elif vm_state == "shut off":
vm.start()
vm.destroy()
if vm.is_persistent():
vm.undefine()
except Exception, detail:
logging.error("Cleaning up destination failed.\n%s" % detail)
开发者ID:FengYang,项目名称:virt-test,代码行数:20,代码来源:virsh_migrate.py
示例9: run_test
def run_test(self):
"""
Start test, clone a guest in a cgroup
"""
if virsh.domain_exists(self.vm_new_name):
self.test.cancel("'%s' already exists! Please"
" select another domain name!"
% self.vm_new_name)
if os.path.exists(self.new_image_file):
os.remove(self.new_image_file)
modules = utils_cgroup.CgroupModules(self.cgroup_dir)
modules.init(['cpuset'])
self.cgroup = utils_cgroup.Cgroup('cpuset', None)
self.cgroup.initialize(modules)
self.cgroup_index = self.cgroup.mk_cgroup(cgroup=self.cgroup_name)
# Before use the cpu, set it to be enable
if self.cpu_status < 1:
utils_misc.set_cpu_status(self.cpu_num, True)
self.cgroup.set_property("cpuset.cpus", self.cpu_num,
self.cgroup_index, check=False)
self.cgroup.set_property("cpuset.mems", 0, self.cgroup_index,
check=False)
self.td0 = threading.Thread(target=self.cgroup.cgexec,
args=(self.cgroup_name, "virt-clone",
"-o %s -n %s --force --file %s"
% (self.vm_name, self.vm_new_name,
self.new_image_file)))
self.td1 = None
if self.twice_execute:
self.vm_new_name1 = self.vm_new_name + "1"
self.new_image_file1 = self.new_image_file + "1"
self.td1 = threading.Thread(target=self.cgroup.cgexec,
args=(self.cgroup_name, "virt-clone",
"-o %s -n %s --force --file %s"
% (self.vm_name,
self.vm_new_name1,
self.new_image_file1)))
self.td1.start()
self.td0.start()
# Wait for virt-clone has been started
time.sleep(30)
开发者ID:balamuruhans,项目名称:tp-libvirt,代码行数:41,代码来源:resource_abnormal.py
示例10: cleanup_dest
def cleanup_dest(vm):
"""
Clean up the destination host environment
when doing the uni-direction migration.
:param vm: the guest to be cleaned up
"""
logging.info("Cleaning up VMs on %s", vm.connect_uri)
try:
if virsh.domain_exists(vm.name, uri=vm.connect_uri):
vm_state = vm.state()
if vm_state == "paused":
vm.resume()
elif vm_state == "shut off":
vm.start()
vm.destroy(gracefully=False)
if vm.is_persistent():
vm.undefine()
except Exception as detail:
logging.error("Cleaning up destination failed.\n%s", detail)
开发者ID:balamuruhans,项目名称:tp-libvirt,代码行数:22,代码来源:migrate_options_shared.py
示例11: run_virsh_undefine
def run_virsh_undefine(test, params, env):
"""
Test virsh undefine command.
Undefine an inactive domain, or convert persistent to transient.
1.Prepare test environment.
2.Backup the VM's information to a xml file.
3.When the libvirtd == "off", stop the libvirtd service.
4.Perform virsh undefine operation.
5.Recover test environment.(libvirts service,VM)
6.Confirm the test result.
"""
vm_ref = params.get("undefine_vm_ref", "vm_name")
extra = params.get("undefine_extra", "")
libvirtd_state = params.get("libvirtd", "on")
status_error = params.get("status_error")
undefine_twice = params.get("undefine_twice", 'no')
local_ip = params.get("local_ip", "LOCAL.EXAMPLE.COM")
remote_ip = params.get("remote_ip", "REMOTE.EXAMPLE.COM")
xml_file = os.path.join(test.tmpdir, 'tmp.xml')
remote_user = params.get("remote_user", "user")
remote_password = params.get("remote_password", "password")
remote_prompt = params.get("remote_prompt", "#")
vm_name = params.get("main_vm")
vm = env.get_vm(vm_name)
vm_id = vm.get_id()
vm_uuid = vm.get_uuid()
# Back up xml file.Xen host has no guest xml file to define a guset.
virsh.dumpxml(vm_name, extra="", to_file=xml_file)
# Confirm how to reference a VM.
if vm_ref == "vm_name":
vm_ref = vm_name
elif vm_ref == "id":
vm_ref = vm_id
elif vm_ref == "hex_vm_id":
vm_ref = hex(int(vm_id))
elif vm_ref == "uuid":
vm_ref = vm_uuid
elif vm_ref.find("invalid") != -1:
vm_ref = params.get(vm_ref)
# Turn libvirtd into certain state.
if libvirtd_state == "off":
utils_libvirtd.libvirtd_stop()
# Test virsh undefine command.
status = 0
try:
uri = libvirt_vm.complete_uri(local_ip)
except error.CmdError:
status = 1
uri = None
if vm_ref != "remote":
vm_ref = "%s %s" % (vm_ref, extra)
cmdresult = virsh.undefine(vm_ref, uri=uri,
ignore_status=True, debug=True)
status = cmdresult.exit_status
if status:
logging.debug("Error status, command output: %s", cmdresult.stdout)
if undefine_twice == "yes":
status2 = virsh.undefine(vm_ref, uri=uri,
ignore_status=True).exit_status
else:
if remote_ip.count("EXAMPLE.COM") or local_ip.count("EXAMPLE.COM"):
raise error.TestNAError("remote_ip and/or local_ip parameters not"
" changed from default values")
session = remote.remote_login("ssh", remote_ip, "22", remote_user,
remote_password, remote_prompt)
cmd_undefine = "virsh -c %s undefine %s" % (uri, vm_name)
status, output = session.cmd_status_output(cmd_undefine)
logging.info("Undefine output: %s", output)
# Recover libvirtd state.
if libvirtd_state == "off":
utils_libvirtd.libvirtd_start()
# Shutdown VM.
if virsh.domain_exists(vm.name, uri=uri):
try:
if vm.is_alive():
vm.destroy()
except error.CmdError, detail:
logging.error("Detail: %s", detail)
开发者ID:FT4VT,项目名称:FT4VM-L1_test,代码行数:87,代码来源:virsh_undefine.py
示例12:
logging.info("Undefine output: %s", output)
# Recover libvirtd state.
if libvirtd_state == "off":
utils_libvirtd.libvirtd_start()
# Shutdown VM.
if virsh.domain_exists(vm.name, uri=uri):
try:
if vm.is_alive():
vm.destroy()
except error.CmdError, detail:
logging.error("Detail: %s", detail)
# Check if VM exists.
vm_exist = virsh.domain_exists(vm.name, uri=uri)
# Check if xml file exists.
xml_exist = False
if (os.path.exists("/etc/libvirt/qemu/%s.xml" % vm_name) or
os.path.exists("/etc/xen/%s" % vm_name)):
xml_exist = True
# Recover main VM.
if not virsh.domain_exists(vm.name, uri=uri):
s_define = virsh.define(xml_file)
if s_define is not True or not virsh.domain_exists(vm.name, uri=uri):
logging.error("Failed to define %s.", vm.name)
# Check results.
if status_error == 'yes':
开发者ID:FT4VT,项目名称:FT4VM-L1_test,代码行数:31,代码来源:virsh_undefine.py
示例13: except
uri = libvirt_vm.complete_uri(local_ip)
session = remote.remote_login("ssh", remote_ip, "22", remote_user,
remote_password, remote_prompt)
cmd_undefine = "virsh -c %s undefine %s" % (uri, vm_name)
status, output = session.cmd_status_output(cmd_undefine)
logging.info("Undefine output: %s", output)
except (error.CmdError, remote.LoginError, aexpect.ShellError), detail:
logging.error("Detail: %s", detail)
status = 1
# Recover libvirtd state.
if libvirtd_state == "off":
utils_libvirtd.libvirtd_start()
# Shutdown VM.
if virsh.domain_exists(vm.name):
try:
if vm.is_alive():
vm.destroy()
except error.CmdError, detail:
logging.error("Detail: %s", detail)
# Check if VM exists.
vm_exist = virsh.domain_exists(vm.name)
# Check if xml file exists.
xml_exist = False
if (os.path.exists("/etc/libvirt/qemu/%s.xml" % vm_name) or
os.path.exists("/etc/xen/%s" % vm_name)):
xml_exist = True
开发者ID:Antique,项目名称:virt-test,代码行数:30,代码来源:virsh_undefine.py
示例14:
status = 1
# Recover libvirtd state.
if libvirtd_state == "off":
utils_libvirtd.libvirtd_start()
# Shutdown VM.
if virsh.domain_exists(vm.name):
try:
if vm.is_alive():
vm.destroy(gracefully=False)
except error.CmdError, detail:
logging.error("Detail: %s", detail)
# Check if VM exists.
vm_exist = virsh.domain_exists(vm_name)
# Check if xml file exists.
xml_exist = False
if os.path.exists("/etc/libvirt/qemu/%s.xml" % vm_name) or\
os.path.exists("/etc/xen/%s" % vm_name):
xml_exist = True
# Check if save file exists if use --managed-save
save_exist = False
if os.path.exists(save_file):
save_exist = True
# Check if save file exists if use --managed-save
volume_exist = False
if volume and os.path.exists(volume):
开发者ID:libvirt-qe,项目名称:tp-libvirt,代码行数:31,代码来源:virsh_undefine.py
示例15:
user_pwd = "[['%s', '%s']]" % (params.get("sasl_user"),
params.get("sasl_pwd"))
v2v_sasl = utils_sasl.SASL(sasl_user_pwd=user_pwd)
v2v_sasl.server_ip = params.get("remote_ip")
v2v_sasl.server_user = params.get('remote_user')
v2v_sasl.server_pwd = params.get('remote_pwd')
v2v_sasl.setup(remote=True)
# Create libvirt dir pool
if output_mode == 'libvirt':
pvt.pre_pool(pool_name, pool_type, pool_target, '')
uri = utils_v2v.Uri('xen').get_uri(xen_host)
# Check if xen guest exists
if not virsh.domain_exists(vm_name, uri=uri):
logging.error('VM %s not exists', vm_name)
virsh_instance = virsh.VirshPersistent()
virsh_instance.set_uri(uri)
if checkpoint in bk_list:
bk_xml = vm_xml.VMXML.new_from_inactive_dumpxml(
vm_name, virsh_instance=virsh_instance)
if checkpoint == 'guest_uuid':
uuid = virsh.domuuid(vm_name, uri=uri).stdout.strip()
v2v_params['main_vm'] = uuid
if checkpoint in ['format_convert', 'xvda_disk']:
# Get remote disk image path
blklist = virsh.domblklist(vm_name, uri=uri).stdout.split('\n')
logging.debug('domblklist %s:\n%s', vm_name, blklist)
开发者ID:lento-sun,项目名称:tp-libvirt,代码行数:31,代码来源:function_test_xen.py
示例16: run
#.........这里部分代码省略.........
test.fail("VmType check failed")
def check_image(img_path, check_point, expected_value):
"""
Verify image file allocation mode and format
"""
if not img_path or not os.path.isfile(img_path):
test.error("Image path: '%s' is invalid" % img_path)
img_info = utils_misc.get_image_info(img_path)
logging.debug("Image info: %s", img_info)
if check_point == "allocation":
if expected_value == "sparse":
if img_info['vsize'] > img_info['dsize']:
logging.info("%s is a sparse image", img_path)
else:
test.fail("%s is not a sparse image" % img_path)
elif expected_value == "preallocated":
if img_info['vsize'] <= img_info['dsize']:
logging.info("%s is a preallocated image", img_path)
else:
test.fail("%s is not a preallocated image" % img_path)
if check_point == "format":
if expected_value == img_info['format']:
logging.info("%s format is %s", img_path, expected_value)
else:
test.fail("%s format is not %s" % (img_path, expected_value))
def check_new_name(output, expected_name):
"""
Verify guest name changed to the new name.
"""
found = False
if output_mode == "libvirt":
found = virsh.domain_exists(expected_name)
if output_mode == "local":
found = os.path.isfile(os.path.join(output_storage,
expected_name + "-sda"))
if output_mode in ["rhev", "vdsm"]:
ovf = get_ovf_content(output)
found = "<Name>%s</Name>" % expected_name in ovf
else:
return
if found:
logging.info("Guest name renamed when converting it")
else:
test.fail("Rename guest failed")
def check_nocopy(output):
"""
Verify no image created if convert command use --no-copy option
"""
img_path = get_img_path(output)
if not os.path.isfile(img_path):
logging.info("No image created with --no-copy option")
else:
test.fail("Find %s" % img_path)
def check_connection(output, expected_uri):
"""
Check output connection uri used when converting guest
"""
init_msg = "Initializing the target -o libvirt -oc %s" % expected_uri
if init_msg in output:
logging.info("Find message: %s", init_msg)
else:
test.fail("Not find message: %s" % init_msg)
开发者ID:lento-sun,项目名称:tp-libvirt,代码行数:67,代码来源:v2v_options.py
示例17: run
def run(test, params, env):
"""
Test storage pool and volumes with applications such as:
install vms, attached to vms...
"""
pool_type = params.get("pool_type")
pool_name = "test_%s_app" % pool_type
pool_target = params.get("pool_target")
emulated_img = params.get("emulated_image", "emulated-image")
volume_count = int(params.get("volume_count", 1))
volume_size = params.get("volume_size", "1G")
emulated_size = "%sG" % (volume_count * int(volume_size[:-1]) + 1)
application = params.get("application", "install")
disk_target = params.get("disk_target", "vdb")
test_message = params.get("test_message", "")
vm_name = params.get("main_vm", "avocado-vt-vm1")
block_device = params.get("block_device", "/DEV/EXAMPLE")
if application == "install":
cdrom_path = os.path.join(data_dir.get_data_dir(),
params.get("cdrom_cd1"))
if not os.path.exists(cdrom_path):
raise error.TestNAError("Can't find installation cdrom:%s"
% cdrom_path)
# Get a nonexist domain name
vm_name = "vol_install_test"
try:
pvtest = utlv.PoolVolumeTest(test, params)
pvtest.pre_pool(pool_name, pool_type, pool_target, emulated_img,
image_size=emulated_size, pre_disk_vol=[volume_size],
device_name=block_device)
logging.debug("Current pools:\n%s",
libvirt_storage.StoragePool().list_pools())
new_pool = libvirt_storage.PoolVolume(pool_name)
if pool_type == "disk":
volumes = new_pool.list_volumes()
logging.debug("Current volumes:%s", volumes)
else:
volumes = create_volumes(new_pool, volume_count, volume_size)
if application == "attach":
vm = env.get_vm(vm_name)
session = vm.wait_for_login()
virsh.attach_disk(vm_name, volumes.values()[volume_count - 1],
disk_target)
vm_attach_device = "/dev/%s" % disk_target
if session.cmd_status("which parted"):
# No parted command, check device only
if session.cmd_status("ls %s" % vm_attach_device):
raise error.TestFail("Didn't find attached device:%s"
% vm_attach_device)
return
# Test if attached disk can be used normally
utlv.mk_part(vm_attach_device, session=session)
session.cmd("mkfs.ext4 %s1" % vm_attach_device)
session.cmd("mount %s1 /mnt" % vm_attach_device)
session.cmd("echo %s > /mnt/test" % test_message)
output = session.cmd_output("cat /mnt/test").strip()
if output != test_message:
raise error.TestFail("%s cannot be used normally!"
% vm_attach_device)
elif application == "install":
# Get a nonexist domain name anyway
while virsh.domain_exists(vm_name):
vm_name += "_test"
# Prepare installation parameters
params["main_vm"] = vm_name
vm = env.create_vm("libvirt", None, vm_name, params,
test.bindir)
env.register_vm(vm_name, vm)
params["image_name"] = volumes.values()[volume_count - 1]
params["image_format"] = "raw"
params['force_create_image'] = "yes"
params['remove_image'] = "yes"
params['shutdown_cleanly'] = "yes"
params['shutdown_cleanly_timeout'] = 120
params['guest_port_unattended_install'] = 12323
params['inactivity_watcher'] = "error"
params['inactivity_treshold'] = 1800
params['image_verify_bootable'] = "no"
params['unattended_delivery_method'] = "cdrom"
params['drive_index_unattended'] = 1
params['drive_index_cd1'] = 2
params['boot_once'] = "d"
params['medium'] = "cdrom"
params['wait_no_ack'] = "yes"
params['image_raw_device'] = "yes"
params['backup_image_before_testing'] = "no"
params['kernel_params'] = ("ks=cdrom nicdelay=60 "
"console=ttyS0,115200 console=tty0")
params['cdroms'] = "unattended cd1"
params['redirs'] += " unattended_install"
selinux_mode = None
try:
selinux_mode = utils_selinux.get_status()
utils_selinux.set_status("permissive")
try:
unattended_install.run(test, params, env)
except process.CmdError, detail:
#.........这里部分代码省略.........
开发者ID:CongLi,项目名称:tp-libvirt,代码行数:101,代码来源:virsh_volume_application.py
示例18: run
#.........这里部分代码省略.........
process.run("echo 'pts/0' >> %s/etc/securetty" % install_root,
shell=True)
for i in ["session required pam_selinux.so close",
"session required pam_selinux.so open",
"session required pam_loginuid.so"]:
process.run('sed -i s/"%s\"/"#%s"/g %s/etc/pam.d/login' %
(i, i, install_root), shell=True)
# Fix root login for sshd
process.run('sed -i s/"%s\"/"#%s"/g %s/etc/pam.d/sshd' %
(i, i, install_root), shell=True)
# Config basic network
net_file = install_root + '/etc/sysconfig/network'
with open(net_file, 'w') as f:
f.write('NETWORKING=yes\nHOSTNAME=%s\n' % vm_name)
net_script = install_root + '/etc/sysconfig/network-scripts/ifcfg-eth0'
with open(net_script, 'w') as f:
f.write('DEVICE=eth0\nBOOTPROTO=dhcp\nONBOOT=yes\n')
# Set root password and enable sshd
session = aexpect.ShellSession("chroot %s" % install_root)
session.sendline('echo %s|passwd root --stdin' % passwd)
session.sendline('chkconfig sshd on')
session.close()
# Create
result = virsh.create(vmxml.xml, **virsh_args)
utlv.check_exit_status(result)
check_state('running')
# Destroy
result = virsh.destroy(vm_name, **virsh_args)
utlv.check_exit_status(result)
if not virsh.domain_exists(vm_name, **virsh_args):
logging.info("Destroy transient LXC domain successfully")
else:
raise TestFail("Transient LXC domain still exist after destroy")
# Define
result = virsh.define(vmxml.xml, **virsh_args)
utlv.check_exit_status(result)
check_state('shut off')
# List
result = virsh.dom_list('--inactive', **virsh_args)
utlv.check_exit_status(result)
if re.findall("(%s)\s+shut off" % vm_name, result.stdout):
logging.info("Find %s in virsh list output", vm_name)
else:
raise TestFail("Not find %s in virsh list output")
# Dumpxml
result = virsh.dumpxml(vm_name, uri=uri, debug=False)
utlv.check_exit_status(result)
# Edit
edit_vcpu = '2'
logging.info("Change vcpu of LXC container to %s", edit_vcpu)
edit_cmd = [r":%s /[0-9]*<\/vcpu>/" + edit_vcpu + r"<\/vcpu>"]
if not utlv.exec_virsh_edit(vm_name, edit_cmd, connect_uri=uri):
raise TestFail("Run edit command fail")
else:
result = virsh.dumpxml(vm_name, **virsh_args)
new_vcpu = re.search(r'(\d*)</vcpu>', result.stdout).group(1)
if new_vcpu == edit_vcpu:
logging.info("vcpu number is expected after do edit")
开发者ID:CongLi,项目名称:tp-libvirt,代码行数:67,代码来源:lxc_life_cycle.py
示例19: run
#.........这里部分代码省略.........
# Back up xml file.Xen host has no guest xml file to define a guset.
backup_xml = vm_xml.VMXML.new_from_inactive_dumpxml(vm_name)
# Confirm how to reference a VM.
if vm_ref == "vm_name":
vm_ref = vm_name
elif vm_ref == "id":
vm_ref = vm_id
elif vm_ref == "hex_vm_id":
vm_ref = hex(int(vm_id))
elif vm_ref == "uuid":
vm_ref = vm_uuid
elif vm_ref.find("invalid") != -1:
vm_ref = params.get(vm_ref)
volume = None
pvtest = None
status3 = None
try:
save_file = "/var/lib/libvirt/qemu/save/%s.save" % vm_name
if option.count("managedsave") and vm.is_alive():
virsh.managedsave(vm_name)
if not vm.is_lxc():
snp_list = virsh.snapshot_list(vm_name)
if option.count("snapshot"):
snp_file_list = []
if not len(snp_list):
virsh.snapshot_create(vm_name)
logging.debug("Create a snapshot for test!")
else:
# Backup snapshots for domain
for snp_item in snp_list:
tmp_file = os.path.join(test.tmpdir, snp_item + ".xml")
virsh.snapshot_dumpxml(vm_name, snp_item, to_file=tmp_file)
snp_file_list.append(tmp_file)
else:
if len(snp_list):
raise error.TestNAError("This domain has snapshot(s), "
"cannot be undefined!")
if option.count("remove-all-storage"):
pvtest = utlv.PoolVolumeTest(test, params)
pvtest.pre_pool(pool_name, pool_type, pool_target, emulated_img,
emulated_size=emulated_size)
new_pool = libvirt_storage.PoolVolume(pool_name)
if not new_pool.create_volume(vol_name, volume_size):
raise error.TestFail("Creation of volume %s failed." % vol_name)
volumes = new_pool.list_volumes()
volume = volumes[vol_name]
virsh.attach_disk(vm_name, volume, disk_target, "--config")
# Turn libvirtd into certain state.
if libvirtd_state == "off":
utils_libvirtd.libvirtd_stop()
# Test virsh undefine command.
output = ""
if vm_ref != "remote":
vm_ref = "%s %s" % (vm_ref, extra)
cmdresult = virsh.undefine(vm_ref, option,
unprivileged_user=unprivileged_user,
uri=uri,
ignore_status=True, debug=True)
status = cmdresult.exit_status
output = cmdresult.stdout.strip()
if status:
logging.debug("Error status, command output: %s",
cmdresult.stderr.strip()
|
请发表评论