1AUTHOR = 'ryanh@us.ibm.com (Ryan Harper)' 2TIME = 'SHORT' 3NAME = 'KVM Test with KVM module build' 4TEST_TYPE = 'client' 5TEST_CLASS = 'Kernel' 6TEST_CATEGORY = 'Functional' 7DOC = ''' 8Run kvm-test after first downloading, building and installing the KVM module. 9''' 10 11# CHANGEME - point to kvm release tarball 12# 13# 14# nightly kvm snapshot base URL 15SNAPBASE = 'http://people.qumranet.com/avi/snapshots/' 16 17#CHAGEME - point to your kvmtest test dir 18TESTDIR = '/opt/kvmtest_tests' 19 20# change this value to point to older snapshots , defaults to 21# look for yesterday's snapshot 22DAYSOLD=1 23 24import test 25import os, sys 26from datetime import * 27from utils import * 28 29 30 31def install_kvm_external_modules(tarball=None, base=SNAPBASE, daysold=DAYSOLD): 32 dldir = os.environ['AUTODIR']+'/tmp' 33 srcdir = os.environ['AUTODIR']+'/tmp/kvm' 34 print "kvm dldir->%s"%(dldir) 35 print "kvm srcdir->%s"%(srcdir) 36 37 # ex: http://people.qumranet.com/avi/snapshots/kvm-snapshot-20071021.tar.gz 38 if tarball is None: 39 d = (date.today() - timedelta(days=daysold)).strftime('%Y%m%d') 40 tarball = base+'kvm-snapshot-%s.tar.gz' %(d) 41 sys.stderr.write("tarball url: %s\n" %(tarball)) 42 43 tarball = unmap_url("/", tarball, dldir) 44 extract_tarball_to_dir(tarball, srcdir) 45 os.chdir(srcdir) 46 47 print "detecting cpu vendor..." 48 vendor = "intel" 49 if os.system("grep vmx /proc/cpuinfo 1>/dev/null") != 0: 50 vendor = "amd" 51 print "detected cpu vendor as '%s'" %(vendor) 52 53 print "building kvm..." 54 system('./configure') 55 system('make') 56 system('make install') 57 print "done building and installing kvm" 58 59 # remove existing in kernel kvm modules 60 print "unloading loaded kvm modules (if present) ..." 61 if system("grep kvm_%s /proc/modules 1>/dev/null" %(vendor), 1) == 0: 62 system("rmmod -f kvm_%s" %(vendor)) 63 if system("grep kvm /proc/modules 1>/dev/null", 1) == 0: 64 system("rmmod -f kvm") 65 66 # load new modules 67 print "loading new kvm modules..." 68 os.chdir(srcdir+'/kernel') 69 system("insmod ./kvm.ko && sleep 1 && insmod ./kvm-%s.ko" %(vendor)) 70 71 72# build and install kvm external modules 73install_kvm_external_modules() 74 75# run kvmtest on all tests in testdir 76job.run_test('kvmtest', testdir=TESTDIR) 77