本文整理汇总了Python中src.bvtlib.run.run函数的典型用法代码示例。如果您正苦于以下问题:Python run函数的具体用法?Python run怎么用?Python run使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了run函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_boot_order
def set_boot_order(host,name,order):
#would check exclusive, but makes an easy check
valid_boot = ['c','d','n']
for letter in order:
if letter not in valid_boot:
raise InvalidBootOption()
run(['xec-vm', '-n', name, 'set', 'boot', order], host=host)
示例2: editfs
def editfs(machine,vms,steps,build,test_path,caller):
r = run(['mount','-o','rw,remount','/'], host=machine)
tslib.cmdResponse(r, 'cryptsetup luksDump /dev/xenclient/config')
r = run(['touch','/testfolder1'], host=machine)
tslib.cmdResponse(r, 'cryptsetup luksDump /dev/xenclient/config')
power_control.platform_transition(machine, 'reboot')
wait_to_go_down(machine)
tslib.interact(machine, "At the TPM protection screen, choose shutdown. Ensure that machine shutsdown")
power_control.set_s0(machine)
tslib.interact(machine, "At the TPM protection screen, choose continue. Enter the wrong password 3 times. Ensure that machine shutsdown")
power_control.set_s0(machine)
tslib.interact(machine, "At the TPM protection screen, choose continue. Enter the correct password. Choose not to reseal the device")
wait_to_come_up(machine)
power_control.platform_transition(machine, 'reboot')
wait_to_go_down(machine)
tslib.interact(machine, "Ensure that TPM protection screen is shown, enter password and choose to reseal the device")
wait_to_come_up(machine)
print "Rebooting the device to check if reseal has taken effect. TPM screen should not be seen anymore"
power_control.platform_transition(machine, 'reboot')
wait_to_go_down(machine)
wait_to_come_up(machine)
示例3: ensure_stable
def ensure_stable(vm_address, interval, timeout=600, description=None, method="exec_daemon"):
"""Ensure that vm_address is continuaully up for interval"""
assert method in ['exec_daemon', "ssh"]
last_down = time()
start = time()
last_out = time()
reached = False
while 1:
delta = time() - last_down
run_time = time() - start
if delta > interval:
print 'HEADLINE: VM at', vm_address, description, 'has been stable for', delta
return
if run_time > timeout:
args = (time() - last_out, timeout, vm_address, description)
if reached:
raise SystemUnstable(*args)
else:
raise SystemUnreachable(*args)
try:
if method == "exec_daemon":
call_exec_daemon('windowsVersion', [], host=vm_address, timeout=60)
elif method == "ssh":
run(['true'], host=vm_address, timeout=60, check_host_key=False)
else:
raise Exception("Unkonwn method %s" % method)
except Exception, exc:
last_down = time()
else:
delta = time() - last_down
print 'WAIT_FOR_SYSTEM: stable for', delta, 'of', interval, 'seconds'
last_out = time()
reached = True
sleep(1)
示例4: wait_for_guest
def wait_for_guest(host, guest, method=None, timeout=600):
"""Return address for guest on host, checking that it is responding
and retrying as necessary"""
if method is None:
method = get_default_exec_method(host, guest)
assert method in ['exec_daemon', "ssh"]
print 'WAIT_FOR_SYSTEM: contacting', guest, 'using', method
_, name = name_split(guest)
start = time()
run(['xec-vm', '-n', name, 'switch'], host=host)
def check_running():
"""check VM is running"""
count = 0
while(1):
out = run(['xec-vm', '-n', name, 'get', 'state'], word_split=True, host=host)
print 'WAIT_FOR_SYSTEM: VM', name, 'state', out[0]
if out[0] == 'stopped':
if count > 4: raise SystemStoppedWhileWaitingForSystem(out, guest, host)
else: count+=1
sleep(2)
else: break
def get_address():
"""get address for VM """
check_running()
return domain_address(host, guest, timeout=5)
address = retry(get_address, 'get %s address on %s' % (guest, host),
timeout=timeout, propagate=[SystemStoppedWhileWaitingForSystem])
delta = time() - start
rtimeout = max(30, int(timeout - delta))
print 'WAIT_FOR_SYSTEM: remainining timeout', rtimeout, 'of', timeout
def check_windows_version():
"""Check that VM is still running"""
check_running()
out = call_exec_daemon('windowsVersion', [], host=address, timeout=60)
print 'WAIT_FOR_SYSTEM: windows version returned', out
def check_ssh_access():
"""Check that VM is available over ssh"""
check_running()
run(['echo', 'test succeeded'], host=address, timeout=60, check_host_key=False)
print 'WAIT_FOR_SYSTEM: ssh command execution succeeded'
if method == "exec_daemon":
try:
ver = retry(check_windows_version,
description='run windowsVersion on '+host+' '+guest,
timeout=rtimeout,
propagate=[SystemStoppedWhileWaitingForSystem])
except error:
raise UnableToContactGuestService(host, guest, timeout, error)
print 'WAIT_FOR_SYSTEM:', guest, 'on', host, \
'replied with windows version', ver, 'from address', address
elif method == "ssh":
retry(check_ssh_access,
description='run ssh check on '+host+' '+guest,
timeout=rtimeout,
propagate=[SystemStoppedWhileWaitingForSystem])
print 'WAIT_FOR_SYSTEM:', guest, 'on', host, \
'ssh test succeed on', address
return address
示例5: test_enforce_encrypted_disks
def test_enforce_encrypted_disks(dut):
vm = create_guest(dut, "enforce_enc_disks", "windows")
try:
SIZE = 1 # size of virtual disk for test, in MB
# 1. Ensure vm is shut-down
guest_shutdown(dut, vm)
# 2. Add an encrypted disk. Start and stop VM
vhd = run(['xec', 'create-vhd', str(SIZE)], host=dut, timeout=600).strip()
vm_disk = run(['xec-vm', '-u', guest_uuid(dut, vm), 'add-disk'], host=dut).strip()
run(['xec', '-o', vm_disk, 'attach-vhd', vhd], host=dut)
run(['xec', '-o', vm_disk, 'generate-crypto-key', '256'], host=dut, timeout=600)
guest_start(dut, vm)
guest_shutdown(dut, vm)
# 3. Replace encrypted disk with an unencrypted one. Verify VM does not start.
run(['rm', '-f', vhd], host = dut)
run(['vhd-util', 'create', '-n', vhd, '-s', str(SIZE)], host = dut)
try:
guest_start(dut, vm)
except:
pass
else:
raise VMStartedAfterTampering
finally:
guest_destroy(dut, vm)
guest_delete(dut, vm)
示例6: clean_old_vhds
def clean_old_vhds():
"""Clean up old VHDs"""
references = set()
builddir = VHD_WITH_TOOLS_PATTERN[:VHD_WITH_TOOLS_PATTERN.find('%')-1]
builddocs = get_autotest().builds.find(
{}, sort=[('build_time', DESCENDING)], limit=5)
recentbuilds = [bd['_id'] for bd in builddocs]
builds = listdir(builddir)
for name in builds:
if name not in recentbuilds:
fname = builddir + '/'+ name
print 'delete', fname
run(['rm', '-rf', fname], ignore_failure=True)
for (dirpath, dirnames, filenames) in walk('/home/xc_vhds/dev_vhds'):
for name in filenames:
full = dirpath+'/'+name
if not islink(full):
continue
references.add(readlink(full))
print 'INFO: have references to', len(references), 'VHDs'
for (dirpath, dirnames, filenames) in \
walk('/home/xc_bvt_output/archive-vhds'):
for name in filenames:
full = dirpath+'/'+name
if full not in references:
print 'INFO: deleting unreferenced', full
try:
unlink(full)
except OSError:
pass
示例7: read_boot_time
def read_boot_time(dut, build):
boot_times = None
print 'INFO: sending reboot'
# The first boot time after a fresh install is much slower than the following
wait_to_come_up(dut)
run(['reboot'], host=dut)
with time_limit(600, 'wait for sync up event'):
while 1:
try:
print 'INFO: checking if', dut, 'is still up'
check_up(dut)
except Exception, exc:
print 'INFO:', dut, 'is down', exc
break
else:
print 'INFO:', dut, 'still up'
sleep(1)
print
while 1:
wait_to_come_up(dut, timeout=1200)
log = grep_dut_log(dut, '/var/log/messages', UI_READY)
boot_times = parse_sys_log(log)
print 'INFO: boot times:', ' '.join(['%.2f' % t for t in boot_times])
if len(boot_times) >= 2:
break
sleep(5)
示例8: reboot_windows_vm
def reboot_windows_vm(dut, domain):
"""Triger a reboot of guest"""
_, name = name_split(domain)
domain = find_domain(dut, name)
print 'INFO: rebooting guest', domain
run(['xec-vm', '-n', name, 'reboot'], host=dut)
wait_for_domid_change(dut, name, domain['dom_id'])
print 'INFO: reboot of', domain, 'completed'
示例9: install_python
def install_python(dut):
_, ec= run(['python', '--version'], host=dut, ignore_failure=True)
if ec == 0:
print 'INFO: python already installed'
return
print 'INFO: copying python files on target'
run(['scp', '-r', abspath(split(split(__file__)[0])[0])+'/pyxc', '[email protected]'+dut+':/root'])
print 'INFO: launching python installer'
run(['/root/pyxc/pysetup'], host=dut, timeout=3600)
示例10: get_disk_key
def get_disk_key(dut, disk_uuid):
key_dir = run(['xec', 'get', 'platform-crypto-key-dirs'],
host=dut, word_split=True)[0]
disk_keys = [join(key_dir, key) for key in
run(['ls', key_dir], word_split=True, host=dut)
if key.startswith(disk_uuid)]
if len(disk_keys) > 1:
raise MultipleDiskKeys(disk_keys, dut, guest, disk_uuid)
return disk_keys[0] if disk_keys else None
示例11: shutdown_domain
def shutdown_domain(dut, vm_uuid):
"""Attempt to cleanly shut down a VM. Requires tools to be installed."""
run(['xec-vm', '-u', vm_uuid, 'shutdown'], host=dut, timeout=600)
for _ in range(30):
sleep(5)
state = run(['xec-vm', '-u', vm_uuid, 'get', 'state'], host=dut, timeout=600)
if state.strip() == 'stopped':
return
raise VMFailedToShutDown
示例12: vm_poweroff
def vm_poweroff(dut, who='all'):
"""force poweroff a VM from domo"""
domlist = find_guest_vms(dut)
for domain in domlist:
if who == 'all' or domain['name'] == who:
run(['xec-vm', '-n', domain['name'], 'destroy'], host=dut, timeout=20)
for domain in domlist:
if who == 'all' or domain['name'] == who:
wait_for_guest_to_go_down(dut, domain['name'])
示例13: vm_shutdown_dom0
def vm_shutdown_dom0(dut, who='all'):
"""shutdown vm/vms from dom0"""
domlist = find_guest_vms(dut)
for domain in domlist:
if who == 'all' or domain['name'] == who:
run(['xec-vm', '-n', domain['name'], 'shutdown'], host=dut)
for domain in domlist:
if who == 'all' or domain['name'] == who:
wait_for_guest_to_go_down(dut, domain['name'])
示例14: disableusbPassthrough
def disableusbPassthrough(machine,vms,steps,build,test_path,caller):
(vendor_id1,device_id1,vendor_id2,device_id2) = getDeviceID(machine,vms,steps,build,test_path,caller)
tslib.forcepowerstate(machine, 'off', vms)
r = run(['xec-vm','-n',vms,'delete-pt-rule','0x0c03',vendor_id1,device_id1], host=machine)
tslib.cmdResponse(r, 'xec-vm -n vms delete-pt-rule 0x0c03'+vendor_id1+' '+device_id1)
r = run(['xec-vm','-n',vms,'delete-pt-rule','0x0c03',vendor_id2,device_id2], host=machine)
tslib.cmdResponse(r, 'xec-vm -n vms delete-pt-rule 0x0c03'+vendor_id2+' '+device_id2)
windows_transitions.vm_poweron(machine, vms)
tslib.interact(machine, "Plugin a usb device and verify that it is not passed through to the VM")
示例15: audioPassthrough
def audioPassthrough(machine,vms,steps,build,test_path,caller):
tslib.forcepowerstate(machine, 'off', vms)
r = run(['xec-vm','-n',vms,'add-pt-rule','0x0403','any','any'], host=machine)
tslib.cmdResponse(r,'xec-vm -n <vmname> add-pt-rule 0x0403 any any')
windows_transitions.vm_poweron(machine, vms)
r = run(['xec-vm','-n',vms,'list-pt-pci-devices'], host=machine)
tslib.cmdResponse(r,'xec-vm -n '+vms+' list-pt-pci-devices')
tslib.interact(machine, "Verify if the o/p of list-pt-pci-devices is as expected")
tslib.interact(machine, "Verify from the VM that a new audio device is detected. Install driver and proceed")