Author: gnichols
Date: 2010-01-12 16:02:53 +0000 (Tue, 12 Jan 2010)
New Revision: 282
Modified:
trunk/v7/fvtest.py
Log:
523824 - FEAT: v7 should fv_* tests should support KVM
Modified: trunk/v7/fvtest.py
===================================================================
--- trunk/v7/fvtest.py 2010-01-09 20:31:08 UTC (rev 281)
+++ trunk/v7/fvtest.py 2010-01-12 16:02:53 UTC (rev 282)
@@ -45,7 +45,7 @@
self.hardwarePlatform = Command("uname -i").getString()
self.guestName = "v7%s" % self.hardwarePlatform
self.guestImageFile = 'v7' + self.hardwarePlatform + '.img'
- self.guestConfigFile = 'v7' + self.hardwarePlatform
+ self.loopBackDevice = None
self.dataImageFile = 'v7data.img'
if self.hardwarePlatform == "ia64":
self.nvramFile = "nvram_v7ia64"
@@ -55,34 +55,72 @@
self.testToRun = ""
self.waitTime = 60 # in minutes
self.environment = Environment()
+ self.debug = Constants.off
- # read the hypervisor capabilities if that file exists
+ self.__getHypervisor()
+ if self.hypervisor == Constants.xen:
+ self.guestConfigFile = 'v7' + self.hardwarePlatform
+ self.guestConfigPath = os.path.join(self.environment.getGuestConfigDirectory(), self.guestConfigFile)
+ self.guestImageDirectory = self.environment.getGuestImageDirectory()
+ elif self.hypervisor == Constants.kvm:
+ self.guestConfigFile = 'v7' + self.hardwarePlatform + ".xml"
+ self.guestConfigPath = os.path.join(self.environment.getKVMGuestConfigDirectory(), self.guestConfigFile)
+ self.guestImageDirectory = self.environment.getKVMGuestImageDirectory()
+
+ def __getHypervisor(self):
+ cpuflags = Command("fgrep flags /proc/cpuinfo")
+ self.hypervisor = None
try:
- capabilityFile = open('/sys/hypervisor/properties/capabilities')
- self.hypervisorCapabilities = capabilityFile.readline()
- capabilityFile.close()
- except IOError:
- self.hypervisorCapabilities = 'none'
+ if cpuflags.getString(regex="(vmx|smx)", singleLine=False):
+ # read the hypervisor capabilities if that file exists
+ try:
+ capabilityFile = open('/sys/hypervisor/properties/capabilities')
+ self.hypervisorCapabilities = capabilityFile.readline()
+ capabilityFile.close()
+ if Constants.hvm in self.hypervisorCapabilities:
+ self.hypervisor = Constants.xen
+ except IOError:
+ self.hypervisorCapabilities = 'none'
+
+ # if not xen, plan in for kvm
+ if self.hypervisor != Constants.xen:
+ self.hypervisor = Constants.kvm
+ except V7CommandException, e:
+ pass # no virtualization support
def plan(self, devices):
tests = list()
- for device in devices:
- # plan this test if the current system is capable to do FV
- if 'xen' in device.getProperty("system.kernel.version") and 'hvm' in self.hypervisorCapabilities:
- test = self.makeCopy()
- test.setDevice(device)
- tests.append(test)
+ if self.hypervisor == Constants.xen:
+ for device in devices:
+ if Constants.xen in device.getProperty("system.kernel.version"):
+ self.hypervisor = Constants.xen
+ test = self.makeCopy()
+ test.setDevice(device)
+ tests.append(test)
+ return tests
+
+ # otherwise
+ if self.hypervisor == Constants.kvm:
+ test = self.makeCopy()
+ tests.append(test)
+
return tests
+ def getRequiredRPMs(self):
+ rpms = ["libvirt", "libvirt-python", "python-virtinst"]
+ if self.hypervisor == Constants.kvm:
+ rpms.append('qemu')
+ return rpms
+
def verifyGuest(self):
guestName = None
try:
- guestName = Command("xm list").getString(regex=self.guestName, singleLine=False)
+ guestName = Command("virsh list").getString(regex=self.guestName, singleLine=False)
print "Warning: Guest %s is already running" % guestName
print "Attempting shutdown:"
- Command("xm destroy %s" % self.guestName).echo()
- guestName = Command("xm list").getString(regex=self.guestName, singleLine=False)
+ Command("virsh destroy %s" % self.guestName).echo()
+ guestName = Command("virsh list").getString(regex=self.guestName, singleLine=False)
print "Error: could not shutdown guest"
return False
except:
@@ -93,24 +131,21 @@
def verifyGuestFiles(self):
-
- #if not self.verifyFile(self.environment.getGuestConfigDirectory(), self.guestConfigFile):
- filePath = os.path.join(self.environment.getGuestConfigDirectory(), self.guestConfigFile)
- if os.path.exists(filePath):
- print "Verified: " + filePath
- elif not self.generateGuestConfigFile():
+ if not self.verifyFile(self.guestImageDirectory, self.dataImageFile):
return False
- if not self.verifyFile(self.environment.getGuestImageDirectory(), self.dataImageFile):
+ if not self.verifyFile(self.guestImageDirectory, self.guestImageFile):
return False
-
- if not self.verifyFile(self.environment.getGuestImageDirectory(), self.guestImageFile):
- return False
if self.hardwarePlatform == "ia64":
if (not self.verifyFile(self.environment.getGuestBootDirectory(), self.nvramFile)
or not self.verifyFile(self.environment.getGuestBootDirectory(), self.nvramUuidFile)):
return False
+
+ if os.path.exists(self.guestConfigPath):
+ print "Verified: " + self.guestConfigPath
+ elif not self.generateGuestConfigFile():
+ return False
print "Guest files verified"
sys.stdout.flush()
@@ -157,15 +192,47 @@
print "Error: could not find or download guest file" + filename
return False
-
+ def mountDataImage(self):
+ try:
+ self.loopBackDevice = Command("losetup -f").getString(regex="^(?P<device>/dev/loop[0-9]+)", regexGroup="device", singleLine=False)
+ print "Using loopback device " + self.loopBackDevice + " for guest data image"
+ loop = os.path.basename(self.loopBackDevice)
+ Command("losetup " + self.loopBackDevice + " " + os.path.join(self.guestImageDirectory, self.dataImageFile)).echo()
+ Command("kpartx -av " + self.loopBackDevice).echo()
+ partition = Command("ls /dev/mapper").getString(regex="%sp[0-9]" % loop, singleLine=False)
+ Command("mount /dev/mapper/" + partition + " /mnt").run()
+ print "Mounted /dev/mapper/" + partition + " on /mnt"
+ if self.debug != Constants.off:
+ Command("df -h /mnt").echo()
+ Command("ls -al /mnt").echo()
+ except V7CommandException, e:
+ print "Error: could not mount data image"
+ print e
+ return False
+ return True
+
+ def unmountDataImage(self):
+ print "Unmounting /mnt"
+ sys.stdout.flush()
+ try:
+ Command("umount /mnt").echo()
+ if self.loopBackDevice:
+ print "Deleting loopback device " + self.loopBackDevice + " configuration."
+ Command("kpartx -dv " + self.loopBackDevice).echo()
+ Command("losetup -d " + self.loopBackDevice).echo()
+ except V7CommandException, e:
+ print e
+ print "Error: could not unmount data image."
+ return False
+ return True
def submitTasks(self):
# mount the data image and then write test info
try:
- dataImagePath = os.path.join(self.environment.getGuestImageDirectory(), self.dataImageFile)
- Command("umount /mnt")
- Command("lomount -diskimage %s -partition 1 /mnt" % dataImagePath).echo()
-
+ dataImagePath = os.path.join(self.guestImageDirectory, self.dataImageFile)
+ self.unmountDataImage()
+ if not self.mountDataImage():
+ return False
guestScriptFile = "/mnt/v7-guest-script"
guestScript = open(guestScriptFile, "w")
guestScript.write("#!/bin/sh\n")
@@ -187,7 +254,7 @@
guestScript.close()
os.chmod(guestScriptFile, 0744)
- Command("umount /mnt").echo()
+ self.unmountDataImage()
print "Submitted tests: " + commandToRun
sys.stdout.flush()
return True
@@ -196,7 +263,22 @@
print e
return False
+
def generateGuestConfigFile(self):
+ guestImagePath = os.path.join(self.guestImageDirectory, self.guestImageFile)
+ guestDataPath = os.path.join(self.guestImageDirectory, self.dataImageFile)
+ if self.hypervisor == Constants.kvm:
+ virtInstall = "virt-install --name " + self.guestName + " --ram 512 --disk path=" + guestImagePath + " --disk path=" + guestDataPath + " --network network:default --vnc --import --noreboot --noautoconsole"
+ print virtInstall
+ try:
+ Command(virtInstall).echo()
+ except V7CommandException, e:
+ print "Error: could not generate guest config file."
+ print e
+ return False
+ return True
+
+ # otherwise, use direct config generation for xen
try:
ifconfig = Command("ifconfig")
xenbr = ifconfig.getString(regex="eth(?P<xenbrNumber>[0-9]+)", regexGroup="xenbrNumber", singleLine=False)
@@ -215,7 +297,7 @@
# this uuid needs to match the one in the nvram files...
guestConfig.write("uuid = \"8d6e4122-a025-0a68-2efd-c4ea32a5f235\"\n")
else:
- guestConfig.write("uuid = \"60d27529-59a2-99e6-8933-ca3609c58cdf\"\n")
+ guestConfig.write("uuid = \"60d27529-59a2-99e6-8933-ca3609c58cdf\"\n")
guestConfig.write("maxmem = 512\n")
guestConfig.write("memory = 512\n")
guestConfig.write("vcpus = 1\n")
@@ -254,16 +336,19 @@
return False
+
+
def runGuest(self):
+
try:
- Command("xm create v7%s" % self.hardwarePlatform).echo()
+ Command("virsh start %s" % self.guestName).echo()
print "FV Guest started ..."
except V7CommandException, e:
print "Error: could not start the FV Guest."
print e
return False
print "%s test is running, it takes some time(less than %s minutes), please be patient ..." % (self.name, self.waitTime)
- print "You may use the virt-manager to open the virtual machine console to monitor the testing progress."
+ print "You may use \"virsh console %s\" to monitor the testing progress" % self.guestName
sys.stdout.flush()
# check the guest's status in every minute, this test should not consume more than 1 hour
@@ -271,17 +356,18 @@
while 1:
if count == self.waitTime:
try:
- Command("xm destroy v7%s" % self.hardwarePlatform).echo()
- print "time out, the FV Guest was destroyed."
+ Command("virsh destroy %s" % self.guestName).echo()
+ print "time out, the FV Guest was destroyed."
except V7CommandException, e:
pass
return False
else:
time.sleep(60)
try:
- guestIsRunning = Command("xm list").getString(regex="v7%s" % self.hardwarePlatform, singleLine=False)
+ guestIsRunning = Command("virsh list").getString(regex=self.guestName, singleLine=False)
count = count + 1
except:
+ print "Guest has shutdown"
break
return True
@@ -292,8 +378,7 @@
# mount the data image and see if the result rpm is there
result = True
try:
- dataImagePath = os.path.join(self.environment.getGuestImageDirectory(), self.dataImageFile)
- Command("lomount -diskimage %s -partition 1 /mnt" % dataImagePath).echo()
+ self.mountDataImage()
Command("cp /mnt/" + self.environment.getResultsFileName() + " .").echo()
# merge the results
result = self.getGuestTestRunResult()
@@ -303,7 +388,7 @@
result = False
try:
- Command("umount /mnt").echo()
+ self.unmountDataImage()
except:
print "Warning: could not unmount data image"
print e