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