2006-02-16 22:50:52 +00:00
|
|
|
#!/usr/bin/python -u
|
|
|
|
import libvirt
|
|
|
|
import sys
|
2006-02-17 13:18:57 +00:00
|
|
|
import os
|
|
|
|
import time
|
|
|
|
|
2006-02-20 20:50:48 +00:00
|
|
|
if not os.access("/proc/xen", os.R_OK):
|
|
|
|
print 'System is not running a Xen kernel'
|
|
|
|
sys.exit(1)
|
|
|
|
|
2006-02-17 13:18:57 +00:00
|
|
|
#
|
|
|
|
# Try to provide default OS images paths here, of course non standard
|
|
|
|
#
|
|
|
|
osroots = [
|
2006-03-29 13:33:37 +00:00
|
|
|
"/u/fc4-2.img",
|
2006-02-17 13:18:57 +00:00
|
|
|
"/u/fc4.img",
|
2006-03-22 13:44:01 +00:00
|
|
|
"/xen/fc4.img",
|
2006-02-17 13:18:57 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
okay = 1
|
|
|
|
|
|
|
|
osroot = None
|
|
|
|
for root in osroots:
|
|
|
|
if os.access(root, os.R_OK):
|
|
|
|
osroot = root
|
2011-02-16 15:57:50 +00:00
|
|
|
break
|
2006-02-17 13:18:57 +00:00
|
|
|
|
|
|
|
if osroot == None:
|
|
|
|
print "Could not find a guest OS root, edit to add the path in osroots"
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
kernel=open("/proc/version").read().split()
|
|
|
|
kernelOv = kernel[2]
|
2006-03-22 13:33:20 +00:00
|
|
|
|
|
|
|
if kernelOv.find('hypervisor'):
|
|
|
|
kernelU = "/boot/vmlinuz-" + kernelOv.replace('hypervisor', 'guest')
|
|
|
|
initrdU = "/boot/initrd-" + kernelOv.replace('hypervisor', 'guest') + ".img"
|
|
|
|
elif kernelOv.find('xen0'):
|
|
|
|
kernelU = "/boot/vmlinuz-" + kernelOv.replace('xen0', 'xenU')
|
|
|
|
initrdU = "/boot/initrd-" + kernelOv.replace('xen0', 'xenU') + ".img"
|
2006-02-17 13:18:57 +00:00
|
|
|
|
|
|
|
if not os.access(kernelU, os.R_OK):
|
2011-02-21 17:35:25 +00:00
|
|
|
print "Did not find the guest kernel %s" % (kernelU)
|
2006-02-17 13:18:57 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
kernelU = "<kernel>" + kernelU + "</kernel>"
|
|
|
|
|
|
|
|
if not os.access(initrdU, os.R_OK):
|
2011-02-21 17:35:25 +00:00
|
|
|
print "Did not find the guest initrd %s" % (initrdU)
|
2006-02-17 13:18:57 +00:00
|
|
|
initrdU = ""
|
|
|
|
else:
|
|
|
|
initrdU = "<initrd>" + initrdU + "</initrd>"
|
|
|
|
|
2006-02-16 22:50:52 +00:00
|
|
|
|
2009-07-06 15:05:41 +00:00
|
|
|
conn = libvirt.open(None)
|
2006-02-16 22:50:52 +00:00
|
|
|
if conn == None:
|
|
|
|
print 'Failed to open connection to the hypervisor'
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
xmldesc="""<domain type='xen'>
|
|
|
|
<name>test</name>
|
|
|
|
<os>
|
|
|
|
<type>linux</type>
|
2006-02-17 13:18:57 +00:00
|
|
|
""" + kernelU + initrdU + """
|
2006-02-16 22:50:52 +00:00
|
|
|
<cmdline> root=/dev/sda1 ro selinux=0 3</cmdline>
|
|
|
|
</os>
|
|
|
|
<memory>131072</memory>
|
|
|
|
<vcpu>1</vcpu>
|
|
|
|
<devices>
|
|
|
|
<disk type='file'>
|
2006-02-17 13:18:57 +00:00
|
|
|
<source file='%s'/>
|
2006-02-16 22:50:52 +00:00
|
|
|
<target dev='sda1'/>
|
|
|
|
</disk>
|
|
|
|
<interface type='bridge'>
|
|
|
|
<source bridge='xenbr0'/>
|
|
|
|
<mac address='aa:00:00:00:00:12'/>
|
|
|
|
<script path='/etc/xen/scripts/vif-bridge'/>
|
|
|
|
</interface>
|
|
|
|
</devices>
|
|
|
|
</domain>
|
2006-02-17 13:18:57 +00:00
|
|
|
""" % (osroot)
|
|
|
|
|
2006-02-16 22:50:52 +00:00
|
|
|
dom = conn.createLinux(xmldesc, 0)
|
|
|
|
if dom == None:
|
2006-02-17 13:18:57 +00:00
|
|
|
print 'Failed to create a test domain'
|
2006-02-16 22:50:52 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
2006-03-29 13:33:37 +00:00
|
|
|
# print dom
|
2006-02-16 22:50:52 +00:00
|
|
|
|
|
|
|
print "Domain: id %d running %s" % (dom.ID(), dom.OSType())
|
2006-02-17 13:18:57 +00:00
|
|
|
|
|
|
|
print "Suspending test domain for 5 seconds"
|
|
|
|
if dom.suspend() != 0:
|
|
|
|
print 'Failed to suspend domain test'
|
|
|
|
dom.destroy()
|
|
|
|
del dom
|
|
|
|
del conn
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
infos = dom.info()
|
|
|
|
time.sleep(5)
|
|
|
|
infos2 = dom.info()
|
|
|
|
if infos[4] != infos2[4]:
|
|
|
|
print 'Suspended domain test got CPU cycles'
|
|
|
|
okay = 0
|
|
|
|
|
|
|
|
print "resuming test domain for 10 seconds"
|
|
|
|
if dom.resume() != 0:
|
|
|
|
print 'Failed to resume domain test'
|
|
|
|
dom.destroy()
|
|
|
|
del dom
|
|
|
|
del conn
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
time.sleep(10)
|
|
|
|
print "shutdown of test domain"
|
|
|
|
|
|
|
|
if dom.shutdown() != 0:
|
2006-03-28 14:41:04 +00:00
|
|
|
okay = 0
|
2006-02-17 13:18:57 +00:00
|
|
|
print 'Failed to shutdown domain test'
|
|
|
|
|
|
|
|
i = 0
|
|
|
|
while i < 30:
|
|
|
|
time.sleep(1)
|
|
|
|
i = i + 1
|
2006-03-28 14:41:04 +00:00
|
|
|
try:
|
2011-02-16 15:57:50 +00:00
|
|
|
t = dom.info()[4]
|
2006-03-28 14:41:04 +00:00
|
|
|
except:
|
|
|
|
okay = 0
|
2011-02-16 15:57:50 +00:00
|
|
|
t = -1
|
|
|
|
break;
|
2008-02-05 19:27:37 +00:00
|
|
|
|
2006-02-17 13:18:57 +00:00
|
|
|
if t == 0:
|
|
|
|
break
|
|
|
|
|
|
|
|
if t != 0:
|
|
|
|
print 'Shutdown failed destroying domain test'
|
|
|
|
okay = 0
|
|
|
|
dom.destroy()
|
|
|
|
|
2006-02-16 22:50:52 +00:00
|
|
|
del dom
|
|
|
|
del conn
|
2006-02-17 13:18:57 +00:00
|
|
|
if okay == 1:
|
|
|
|
print "OK"
|
2006-02-16 22:50:52 +00:00
|
|
|
|
|
|
|
sys.exit(0)
|