本文整理汇总了Python中virttest.virsh.start函数的典型用法代码示例。如果您正苦于以下问题:Python start函数的具体用法?Python start怎么用?Python start使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了start函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: vm_recover_check
def vm_recover_check(guest_name, option):
"""
Check if the vm can be recovered correctly.
:param guest_name : Checked vm's name.
:param option : managedsave command option.
"""
# This time vm not be shut down
if vm.is_alive():
raise error.TestFail("Guest should be inactive")
virsh.start(guest_name)
# This time vm should be in the list
if vm.is_dead():
raise error.TestFail("Guest should be active")
if option:
if option.count("running"):
if vm.is_dead() or vm.is_paused():
raise error.TestFail("Guest state should be"
" running after started"
" because of '--running' option")
elif option.count("paused"):
if not vm.is_paused():
raise error.TestFail("Guest state should be"
" paused after started"
" because of '--paused' option")
else:
if params.get("paused_after_start_vm") == "yes":
if not vm.is_paused():
raise error.TestFail("Guest state should be"
" paused after started"
" because of initia guest state")
示例2: vm_recover_check
def vm_recover_check(guest_name, option, libvirtd, check_shutdown=False):
"""
Check if the vm can be recovered correctly.
:param guest_name : Checked vm's name.
:param option : managedsave command option.
"""
# This time vm not be shut down
if vm.is_alive():
raise error.TestFail("Guest should be inactive")
# Check vm managed save state.
ret = virsh.dom_list("--managed-save --inactive")
vm_state1 = re.findall(r".*%s.*" % guest_name,
ret.stdout.strip())[0].split()[2]
ret = virsh.dom_list("--managed-save --all")
vm_state2 = re.findall(r".*%s.*" % guest_name,
ret.stdout.strip())[0].split()[2]
if vm_state1 != "saved" or vm_state2 != "saved":
raise error.TestFail("Guest state should be saved")
virsh.start(guest_name)
# This time vm should be in the list
if vm.is_dead():
raise error.TestFail("Guest should be active")
# Restart libvirtd and check vm status again.
libvirtd.restart()
if vm.is_dead():
raise error.TestFail("Guest should be active after"
" restarting libvirtd")
# Check managed save file:
if os.path.exists(managed_save_file):
raise error.TestFail("Managed save image exist "
"after starting the domain")
if option:
if option.count("running"):
if vm.is_dead() or vm.is_paused():
raise error.TestFail("Guest state should be"
" running after started"
" because of '--running' option")
elif option.count("paused"):
if not vm.is_paused():
raise error.TestFail("Guest state should be"
" paused after started"
" because of '--paused' option")
else:
if params.get("paused_after_start_vm") == "yes":
if not vm.is_paused():
raise error.TestFail("Guest state should be"
" paused after started"
" because of initia guest state")
if check_shutdown:
# Resume the domain.
if vm.is_paused():
vm.resume()
vm.wait_for_login()
# Shutdown and start the domain, it should be in runing state and can be login.
vm.shutdown()
vm.wait_for_shutdown()
vm.start()
vm.wait_for_login()
示例3: check_result
def check_result(result, status_error):
"""
Check virt-v2v command result
"""
libvirt.check_exit_status(result, status_error)
output = result.stdout + result.stderr
if skip_check:
logging.info('Skip checking vm after conversion')
elif not status_error:
if output_mode == 'rhev':
if not utils_v2v.import_vm_to_ovirt(params, address_cache,
timeout=v2v_timeout):
test.fail('Import VM failed')
if output_mode == 'libvirt':
try:
virsh.start(vm_name, debug=True, ignore_status=False)
except Exception, e:
test.fail('Start vm failed: %s' % str(e))
# Check guest following the checkpoint document after convertion
vmchecker = VMChecker(test, params, env)
params['vmchecker'] = vmchecker
if params.get('skip_vm_check') != 'yes':
if checkpoint != 'win2008r2_ostk':
ret = vmchecker.run()
if len(ret) == 0:
logging.info("All common checkpoints passed")
if checkpoint == 'win2008r2_ostk':
check_BSOD()
# Merge 2 error lists
error_list.extend(vmchecker.errors)
示例4: check_numatune_xml
def check_numatune_xml(params):
"""
Compare mode and nodeset value with guest XML configuration
:params: the parameter dictionary
"""
# vm_name = params.get("vms")
vm_name = params.get("main_vm")
mode = params.get("numa_mode", "")
nodeset = params.get("numa_nodeset", "")
options = params.get("options", "")
# --config option will act after vm shutdown.
if options == "config":
virsh.shutdown(vm_name)
# The verification of the numa params should
# be done when vm is running.
if not virsh.is_alive(vm_name):
virsh.start(vm_name)
try:
numa_params = libvirt_xml.VMXML.get_numa_memory_params(vm_name)
# VM XML omit numa entry when the placement is auto and mode is strict
# So we need to set numa_params manually when exception happens.
except LibvirtXMLAccessorError:
numa_params = {"placement": "auto", "mode": "strict"}
if not numa_params:
logging.error("Could not get numa parameters for %s", vm_name)
return False
mode_from_xml = numa_params["mode"]
# if the placement is auto, there is no nodeset in numa param.
try:
nodeset_from_xml = numa_params["nodeset"]
except KeyError:
nodeset_from_xml = ""
if mode and mode != mode_from_xml:
logging.error("To expect %s: %s", mode, mode_from_xml)
return False
# The actual nodeset value is different with guest XML configuration,
# so need to compare them via a middle result, for example, if you
# set nodeset is '0,1,2' then it will be a list '0-2' in guest XML
nodeset = cpus_parser(nodeset)
nodeset_from_xml = cpus_parser(nodeset_from_xml)
if nodeset and nodeset != nodeset_from_xml:
logging.error("To expect %s: %s", nodeset, nodeset_from_xml)
return False
return True
示例5: attach_interface
def attach_interface():
"""
Attach interface:
1.Attach interface from xml;
2.Check the vf driver after attach interface;
3.Check the live xml after attach interface;
"""
if managed == "no":
result = virsh.nodedev_detach(nodedev_pci_addr)
utils_test.libvirt.check_exit_status(result, expect_error=False)
logging.debug("attach interface xml:\n %s", new_iface)
result = virsh.attach_device(vm_name, file_opt=new_iface.xml, flagstr=option, debug=True)
utils_test.libvirt.check_exit_status(result, expect_error=False)
if option == "--config":
result = virsh.start(vm_name)
utils_test.libvirt.check_exit_status(result, expect_error=False)
# For option == "--persistent", after VM destroyed and then start, the device should still be there.
if option == "--persistent":
virsh.destroy(vm_name)
result = virsh.start(vm_name, debug=True)
utils_test.libvirt.check_exit_status(result, expect_error=False)
live_xml = vm_xml.VMXML.new_from_dumpxml(vm_name)
logging.debug(live_xml)
get_ip_by_mac(mac_addr, timeout=60)
device = live_xml.devices
if vf_type == "vf" or vf_type == "vf_pool":
for interface in device.by_device_tag("interface"):
if interface.type_name == "hostdev":
if interface.driver.driver_attr['name'] != 'vfio':
test.fail("The driver of the hostdev interface is not vfio\n")
break
vf_addr_attrs = interface.hostdev_address.attrs
pci_addr = addr_to_pci(vf_addr_attrs)
nic_driver = os.readlink(os.path.join(pci_device_dir, vf_addr, "driver")).split('/')[-1]
if nic_driver != "vfio-pci":
test.fail("The driver of the hostdev interface is not vfio\n")
elif vf_type == "macvtap" or vf_type == "macvtap_network":
for interface in device.by_device_tag("interface"):
if interface.type_name == "direct":
if vf_type == "macvtap":
if interface.source["dev"] == new_iface.source["dev"]:
match = "yes"
vf_name = interface.source["dev"]
elif interface.source['dev'] in vf_name_list:
match = "yes"
vf_name = interface.source["dev"]
if match != "yes":
test.fail("The dev name or mode of macvtap interface is wrong after attach\n")
return interface
示例6: vm_msave_remove_check
def vm_msave_remove_check(vm_name):
"""
Check managed save remove command.
"""
if not os.path.exists(managed_save_file):
raise error.TestFail("Can't find managed save image")
virsh.managedsave_remove(vm_name)
if os.path.exists(managed_save_file):
raise error.TestFail("Managed save image still exists")
virsh.start(vm_name)
# The domain state should be running
if vm.state() != "running":
raise error.TestFail("Guest state should be"
" running after started")
示例7: check_multi_guests
def check_multi_guests(guests, start_delay, libvirt_guests):
"""
Check start_delay option for multiple guests.
"""
# Destroy vm first
if vm.is_alive():
vm.destroy(gracefully=False)
# Clone given number of guests
timeout = params.get("clone_timeout", 360)
for i in range(int(guests)):
dst_vm = "%s_%s" % (vm_name, i)
utils_libguestfs.virt_clone_cmd(vm_name, dst_vm,
True, timeout=timeout)
virsh.start(dst_vm, debug=True)
# Wait 10 seconds for vm to start
time.sleep(10)
is_systemd = process.run("cat /proc/1/comm", shell=True).stdout.count("systemd")
if is_systemd:
libvirt_guests.restart()
pattern = r'(.+ \d\d:\d\d:\d\d).+: Resuming guest.+done'
else:
ret = process.run("service libvirt-guests restart | \
awk '{ print strftime(\"%b %y %H:%M:%S\"), \
$0; fflush(); }'", shell=True)
pattern = r'(.+ \d\d:\d\d:\d\d)+ Resuming guest.+done'
# libvirt-guests status command read messages from systemd
# journal, in cases of messages are not ready in time,
# add a time wait here.
def wait_func():
return libvirt_guests.raw_status().stdout.count("Resuming guest")
utils_misc.wait_for(wait_func, 5)
if is_systemd:
ret = libvirt_guests.raw_status()
logging.info("status output: %s", ret.stdout)
resume_time = re.findall(pattern, ret.stdout, re.M)
if not resume_time:
test.fail("Can't see messages of resuming guest")
# Convert time string to int
resume_seconds = [time.mktime(time.strptime(
tm, "%b %y %H:%M:%S")) for tm in resume_time]
logging.info("Resume time in seconds: %s", resume_seconds)
# Check if start_delay take effect
for i in range(len(resume_seconds)-1):
if resume_seconds[i+1] - resume_seconds[i] < int(start_delay):
test.fail("Checking start_delay failed")
示例8: restore
def restore(self, name):
dom = name
name = dom['name']
doms = self.current_state
if name in doms:
self.remove(doms[name])
domfile = tempfile.NamedTemporaryFile(delete=False)
fname = domfile.name
domfile.writelines(dom['inactive xml'])
domfile.close()
try:
if dom['persistent'] == 'yes':
res = virsh.define(fname)
if res.exit_status:
raise Exception(str(res))
if dom['state'] != 'shut off':
res = virsh.start(name)
if res.exit_status:
raise Exception(str(res))
else:
res = virsh.create(fname)
if res.exit_status:
raise Exception(str(res))
finally:
os.remove(fname)
if dom['autostart'] == 'enable':
res = virsh.autostart(name, '')
if res.exit_status:
raise Exception(str(res))
示例9: vm_managedsave_loop
def vm_managedsave_loop(vm_name, loop_range, libvirtd):
"""
Run a loop of managedsave command and check its result.
"""
if vm.is_dead():
virsh.start(vm_name)
for i in range(int(loop_range)):
logging.debug("Test loop: %s" % i)
virsh.managedsave(vm_name)
virsh.start(vm_name)
# Check libvirtd status.
if not libvirtd.is_running():
raise error.TestFail("libvirtd is stopped after cmd")
# Check vm status.
if vm.state() != "running":
raise error.TestFail("Guest isn't in running state")
示例10: edit_iface
def edit_iface(vm_name):
"""
Modify vm's interface information by virsh edit command.
"""
iface_type = params.get("iface_type")
iface_model = params.get("iface_model")
edit_error = "yes" == params.get("edit_error", "no")
if iface_type:
edit_cmd = (r":%s /<interface type=.*>/<interface type='{0}'>/"
"".format(iface_type))
status = libvirt.exec_virsh_edit(vm_name, [edit_cmd])
elif iface_model:
edit_cmd = (r":/<interface/,/<\/interface>/s/<model type=.*\/>/"
"<model type='%s'\/>/" % iface_model)
status = libvirt.exec_virsh_edit(vm_name, [edit_cmd])
if not status and not edit_error:
logging.error("Expect success, but failure")
return False
if edit_error and status:
logging.error("Expect error, but success")
return False
# Destroy domain and start it to check if vm can be started
start_error = "yes" == params.get("start_error", "no")
vm.destroy()
ret = virsh.start(vm_name, ignore_status=True)
if start_error and not ret.exit_status:
logging.error("Vm started unexpectedly")
return False
if not start_error and ret.exit_status:
logging.error("Vm failed to start")
return False
return True
示例11: state_test
def state_test():
states = [ServiceState(), FileState(), DirState(), DomainState(),
NetworkState(), PoolState(), SecretState(), MountState()]
for state in states:
state.backup()
utils.run('echo hello > /etc/exports')
virsh.start('virt-tests-vm1')
virsh.net_autostart('default', '--disable')
virsh.pool_destroy('mount')
utils.run('rm /var/lib/virt_test/images/hello')
utils.run('mkdir /var/lib/virt_test/images/hi')
utils_libvirtd.Libvirtd().stop()
utils_selinux.set_status('permissive')
for state in states:
lines = state.check(recover=True)
for line in lines:
print line
示例12: make_unclean_fs
def make_unclean_fs():
"""
Use force off to make unclean file system of win8
"""
if virsh.start(vm_name, ignore_status=True).exit_status:
raise exceptions.TestError('Start vm failed')
time.sleep(10)
virsh.destroy(vm_name, debug=True)
示例13: vm_recover_check
def vm_recover_check(guest_name):
"""
Check if the vm can be recovered correctly.
@param: guest_name : Checked vm's name.
"""
ret = virsh.dom_list()
#This time vm should not be in the list
if re.search(guest_name, ret.stdout):
raise error.TestFail("virsh list output invalid")
virsh.start(guest_name)
if params.get("paused_after_start_vm") == "yes":
virsh.resume(guest_name)
#This time vm should be in the list
ret = virsh.dom_list()
if not re.search(guest_name, ret.stdout):
raise error.TestFail("virsh list output invalid")
示例14: check_multi_guests
def check_multi_guests(guests, start_delay, libvirt_guests):
"""
Check start_delay option for multiple guests.
"""
# Destroy vm first
if vm.is_alive():
vm.destroy(gracefully=False)
# Clone given number of guests
timeout = params.get("clone_timeout", 360)
for i in range(int(guests)):
dst_vm = "%s_%s" % (vm_name, i)
utils_libguestfs.virt_clone_cmd(vm_name, dst_vm,
True, timeout=timeout)
virsh.start(dst_vm)
# Wait 10 seconds for vm to start
time.sleep(10)
libvirt_guests.restart()
# libvirt-guests status command read messages from systemd
# journal, in cases of messages are not ready in time,
# add a time wait here.
def wait_func():
return not utils.run("service libvirt-guests status"
" | grep 'Resuming guest'",
ignore_status=True).exit_status
utils_misc.wait_for(wait_func, 5)
ret = utils.run("service libvirt-guests status",
ignore_status=True)
logging.info("status output: %s", ret.stdout)
pattern = r'(.+ \d\d:\d\d:\d\d).+: Resuming guest.+done'
resume_time = re.findall(pattern, ret.stdout, re.M)
if not resume_time:
raise error.TestFail("Can't see messages of resuming guest")
# Convert time string to int
resume_seconds = [time.mktime(time.strptime(
tm, "%b %y %H:%M:%S")) for tm in resume_time]
logging.info("Resume time in seconds: %s", resume_seconds)
# Check if start_delay take effect
for i in range(len(resume_seconds)-1):
if resume_seconds[i+1] - resume_seconds[i] < int(start_delay):
raise error.TestFail("Checking start_delay failed")
示例15: check_result
def check_result(result, status_error):
"""
Check virt-v2v command result
"""
libvirt.check_exit_status(result, status_error)
output = result.stdout + result.stderr
if checkpoint == 'empty_cdrom':
if status_error:
log_fail('Virsh dumpxml failed for empty cdrom image')
elif not status_error:
if output_mode == 'rhev':
if not utils_v2v.import_vm_to_ovirt(params, address_cache,
timeout=v2v_timeout):
test.fail('Import VM failed')
elif output_mode == 'libvirt':
virsh.start(vm_name, debug=True)
# Check guest following the checkpoint document after convertion
logging.info('Checking common checkpoints for v2v')
vmchecker = VMChecker(test, params, env)
params['vmchecker'] = vmchecker
if checkpoint not in ['GPO_AV', 'ovmf']:
ret = vmchecker.run()
if len(ret) == 0:
logging.info("All common checkpoints passed")
# Check specific checkpoints
if checkpoint == 'cdrom':
virsh_session = utils_sasl.VirshSessionSASL(params)
virsh_session_id = virsh_session.get_id()
check_device_exist('cdrom', virsh_session_id)
if checkpoint.startswith('vmtools'):
check_vmtools(vmchecker.checker, checkpoint)
if checkpoint == 'modprobe':
check_modprobe(vmchecker.checker)
if checkpoint == 'device_map':
check_device_map(vmchecker.checker)
if checkpoint == 'resume_swap':
check_resume_swap(vmchecker.checker)
# Merge 2 error lists
error_list.extend(vmchecker.errors)
log_check = utils_v2v.check_log(params, output)
if log_check:
log_fail(log_check)
if len(error_list):
test.fail('%d checkpoints failed: %s' %
(len(error_list), error_list))