<s> """<STR_LIT>""" <EOL> import os <EOL> from os import stat , path <EOL> from stat import ST_MODE , ST_SIZE <EOL> from os . path import abspath <EOL> from sys import exit , stdout , argv , modules <EOL> import re <EOL> from glob import glob <EOL> from subprocess import check_output , call , Popen <EOL> from tempfile import mkdtemp , NamedTemporaryFile <EOL> from time import time , strftime , localtime <EOL> import argparse <EOL> from distutils . spawn import find_executable <EOL> import inspect <EOL> pexpect = None <EOL> TIMEOUT = <NUM_LIT> <EOL> LogToConsole = False <EOL> SaveQCOW2 = False <EOL> NoKVM = False <EOL> Branch = None <EOL> Zip = False <EOL> Forward = [ ] <EOL> Chown = '<STR_LIT>' <EOL> VMImageDir = os . environ [ '<STR_LIT>' ] + '<STR_LIT>' <EOL> Prompt = '<STR_LIT>' <EOL> isoURLs = { <EOL> '<STR_LIT>' : <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' : <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' : <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' : <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' : <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' : <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> } <EOL> def OSVersion ( flavor ) : <EOL> "<STR_LIT>" <EOL> urlbase = path . basename ( isoURLs . get ( flavor , '<STR_LIT>' ) ) <EOL> return path . splitext ( urlbase ) [ <NUM_LIT:0> ] <EOL> def OVFOSNameID ( flavor ) : <EOL> "<STR_LIT>" <EOL> version = OSVersion ( flavor ) <EOL> arch = archFor ( flavor ) <EOL> if '<STR_LIT>' in version : <EOL> map = { '<STR_LIT>' : ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , <NUM_LIT> ) } <EOL> else : <EOL> map = { '<STR_LIT>' : ( '<STR_LIT>' , <NUM_LIT> ) , <EOL> '<STR_LIT>' : ( '<STR_LIT>' , <NUM_LIT> ) } <EOL> osname , osid = map [ arch ] <EOL> return osname , osid <EOL> LogStartTime = time ( ) <EOL> LogFile = None <EOL> def log ( * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> cr = kwargs . get ( '<STR_LIT>' , True ) <EOL> elapsed = time ( ) - LogStartTime <EOL> clocktime = strftime ( '<STR_LIT>' , localtime ( ) ) <EOL> msg = '<STR_LIT:U+0020>' . join ( str ( arg ) for arg in args ) <EOL> output = '<STR_LIT>' % ( clocktime , elapsed , msg ) <EOL> if cr : <EOL> print output <EOL> else : <EOL> print output , <EOL> if type ( LogFile ) is file : <EOL> if cr : <EOL> output += '<STR_LIT:\n>' <EOL> LogFile . write ( output ) <EOL> LogFile . flush ( ) <EOL> def run ( cmd , ** kwargs ) : <EOL> "<STR_LIT>" <EOL> log ( '<STR_LIT:->' , cmd ) <EOL> cmd = cmd . split ( ) <EOL> arg0 = cmd [ <NUM_LIT:0> ] <EOL> if not find_executable ( arg0 ) : <EOL> raise Exception ( '<STR_LIT>' % arg0 + <EOL> '<STR_LIT>' % argv [ <NUM_LIT:0> ] ) <EOL> return check_output ( cmd , ** kwargs ) <EOL> def srun ( cmd , ** kwargs ) : <EOL> "<STR_LIT>" <EOL> return run ( '<STR_LIT>' + cmd , ** kwargs ) <EOL> def depend ( ) : <EOL> "<STR_LIT>" <EOL> log ( '<STR_LIT>' ) <EOL> run ( '<STR_LIT>' ) <EOL> run ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> run ( '<STR_LIT>' ) <EOL> def popen ( cmd ) : <EOL> "<STR_LIT>" <EOL> log ( cmd ) <EOL> cmd = cmd . split ( ) <EOL> return Popen ( cmd ) <EOL> def remove ( fname ) : <EOL> "<STR_LIT>" <EOL> try : <EOL> os . remove ( fname ) <EOL> except OSError : <EOL> pass <EOL> def findiso ( flavor ) : <EOL> "<STR_LIT>" <EOL> url = isoURLs [ flavor ] <EOL> name = path . basename ( url ) <EOL> iso = path . join ( VMImageDir , name ) <EOL> if not path . exists ( iso ) or ( stat ( iso ) [ ST_MODE ] & <NUM_LIT:0> <NUM_LIT> != <NUM_LIT:0> <NUM_LIT> ) : <EOL> log ( '<STR_LIT>' , url ) <EOL> run ( '<STR_LIT>' % ( iso , url ) ) <EOL> result = run ( '<STR_LIT>' + iso ) <EOL> if '<STR_LIT>' not in result and '<STR_LIT>' not in result : <EOL> os . remove ( iso ) <EOL> raise Exception ( '<STR_LIT>' + url ) <EOL> log ( '<STR_LIT>' , iso ) <EOL> os . chmod ( iso , <NUM_LIT:0> <NUM_LIT> ) <EOL> log ( '<STR_LIT>' , iso ) <EOL> return iso <EOL> def attachNBD ( cow , flags = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> cow = abspath ( cow ) <EOL> log ( '<STR_LIT>' ) <EOL> for i in range ( <NUM_LIT:0> , <NUM_LIT> ) : <EOL> nbd = '<STR_LIT>' % i <EOL> if call ( [ '<STR_LIT>' , '<STR_LIT>' , nbd ] ) == <NUM_LIT:0> : <EOL> continue <EOL> srun ( '<STR_LIT>' ) <EOL> srun ( '<STR_LIT>' % ( flags , nbd , cow ) ) <EOL> print <EOL> return nbd <EOL> raise Exception ( "<STR_LIT>" ) <EOL> def detachNBD ( nbd ) : <EOL> "<STR_LIT>" <EOL> srun ( '<STR_LIT>' + nbd ) <EOL> def extractKernel ( image , flavor , imageDir = VMImageDir ) : <EOL> "<STR_LIT>" <EOL> kernel = path . join ( imageDir , flavor + '<STR_LIT>' ) <EOL> initrd = path . join ( imageDir , flavor + '<STR_LIT>' ) <EOL> if path . exists ( kernel ) and ( stat ( image ) [ ST_MODE ] & <NUM_LIT:0> <NUM_LIT> ) == <NUM_LIT:0> <NUM_LIT> : <EOL> return kernel , initrd <EOL> log ( '<STR_LIT>' , kernel ) <EOL> nbd = attachNBD ( image , flags = '<STR_LIT>' ) <EOL> print srun ( '<STR_LIT>' + nbd ) <EOL> part = nbd + '<STR_LIT>' <EOL> mnt = mkdtemp ( ) <EOL> srun ( '<STR_LIT>' % ( part , mnt ) ) <EOL> kernsrc = glob ( '<STR_LIT>' % mnt ) [ <NUM_LIT:0> ] <EOL> initrdsrc = glob ( '<STR_LIT>' % mnt ) [ <NUM_LIT:0> ] <EOL> srun ( '<STR_LIT>' % ( initrdsrc , initrd ) ) <EOL> srun ( '<STR_LIT>' + initrd ) <EOL> srun ( '<STR_LIT>' % ( kernsrc , kernel ) ) <EOL> srun ( '<STR_LIT>' + kernel ) <EOL> srun ( '<STR_LIT>' + mnt ) <EOL> run ( '<STR_LIT>' + mnt ) <EOL> detachNBD ( nbd ) <EOL> return kernel , initrd <EOL> def findBaseImage ( flavor , size = '<STR_LIT>' ) : <EOL> "<STR_LIT>" <EOL> image = path . join ( VMImageDir , flavor + '<STR_LIT>' ) <EOL> if path . exists ( image ) : <EOL> perms = stat ( image ) [ ST_MODE ] & <NUM_LIT:0> <NUM_LIT> <EOL> if perms != <NUM_LIT:0> <NUM_LIT> : <EOL> raise Exception ( '<STR_LIT>' % image + <EOL> '<STR_LIT>' ) <EOL> else : <EOL> run ( '<STR_LIT>' % VMImageDir ) <EOL> iso = findiso ( flavor ) <EOL> log ( '<STR_LIT>' , image ) <EOL> run ( '<STR_LIT>' % ( image , size ) ) <EOL> installUbuntu ( iso , image ) <EOL> log ( '<STR_LIT>' , image ) <EOL> os . chmod ( image , <NUM_LIT:0> <NUM_LIT> ) <EOL> kernel , initrd = extractKernel ( image , flavor ) <EOL> log ( '<STR_LIT>' , image , '<STR_LIT>' , kernel ) <EOL> return image , kernel , initrd <EOL> KickstartText = """<STR_LIT>""" <EOL> PreseedText = ( """<STR_LIT:U+0020>""" <EOL> """<STR_LIT>""" ) <EOL> def makeKickstartFloppy ( ) : <EOL> "<STR_LIT>" <EOL> kickstart = '<STR_LIT>' <EOL> with open ( kickstart , '<STR_LIT:w>' ) as f : <EOL> f . write ( KickstartText ) <EOL> preseed = '<STR_LIT>' <EOL> with open ( preseed , '<STR_LIT:w>' ) as f : <EOL> f . write ( PreseedText ) <EOL> floppy = '<STR_LIT>' <EOL> run ( '<STR_LIT>' % floppy ) <EOL> run ( '<STR_LIT>' + floppy ) <EOL> run ( '<STR_LIT>' % ( floppy , kickstart ) ) <EOL> run ( '<STR_LIT>' % ( floppy , preseed ) ) <EOL> return floppy , kickstart , preseed <EOL> def archFor ( filepath ) : <EOL> "<STR_LIT>" <EOL> name = path . basename ( filepath ) <EOL> if '<STR_LIT>' in name or '<STR_LIT>' in name : <EOL> arch = '<STR_LIT>' <EOL> elif '<STR_LIT>' in name or '<STR_LIT>' in name or '<STR_LIT>' in name : <EOL> arch = '<STR_LIT>' <EOL> elif '<STR_LIT>' in name : <EOL> arch = '<STR_LIT>' <EOL> else : <EOL> log ( "<STR_LIT>" , name ) <EOL> exit ( <NUM_LIT:1> ) <EOL> return arch <EOL> def installUbuntu ( iso , image , logfilename = '<STR_LIT>' , memory = <NUM_LIT> ) : <EOL> "<STR_LIT>" <EOL> kvm = '<STR_LIT>' + archFor ( iso ) <EOL> floppy , kickstart , preseed = makeKickstartFloppy ( ) <EOL> mnt = mkdtemp ( ) <EOL> srun ( '<STR_LIT>' % ( iso , mnt ) ) <EOL> kernel = path . join ( mnt , '<STR_LIT>' ) <EOL> initrd = path . join ( mnt , '<STR_LIT>' ) <EOL> if NoKVM : <EOL> accel = '<STR_LIT>' <EOL> else : <EOL> accel = '<STR_LIT>' <EOL> cmd = [ '<STR_LIT>' , kvm , <EOL> '<STR_LIT>' , '<STR_LIT>' % accel , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , str ( memory ) , <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , floppy , <EOL> '<STR_LIT>' , '<STR_LIT>' % image , <EOL> '<STR_LIT>' , iso , <EOL> '<STR_LIT>' , kernel , <EOL> '<STR_LIT>' , initrd , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' + kickstart + <EOL> '<STR_LIT>' + preseed + <EOL> '<STR_LIT>' ] <EOL> ubuntuStart = time ( ) <EOL> log ( '<STR_LIT>' , iso , '<STR_LIT>' , image ) <EOL> log ( '<STR_LIT:U+0020>' . join ( cmd ) ) <EOL> log ( '<STR_LIT>' , abspath ( logfilename ) ) <EOL> params = { } <EOL> if not LogToConsole : <EOL> logfile = open ( logfilename , '<STR_LIT:w>' ) <EOL> params = { '<STR_LIT>' : logfile , '<STR_LIT>' : logfile } <EOL> vm = Popen ( cmd , ** params ) <EOL> log ( '<STR_LIT>' ) <EOL> vm . wait ( ) <EOL> if not LogToConsole : <EOL> logfile . close ( ) <EOL> elapsed = time ( ) - ubuntuStart <EOL> srun ( '<STR_LIT>' + mnt ) <EOL> run ( '<STR_LIT>' + mnt ) <EOL> if vm . returncode != <NUM_LIT:0> : <EOL> raise Exception ( '<STR_LIT>' % <EOL> vm . returncode ) <EOL> log ( '<STR_LIT>' , image ) <EOL> log ( '<STR_LIT>' % elapsed ) <EOL> def boot ( cow , kernel , initrd , logfile , memory = <NUM_LIT> , cpuCores = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> global pexpect <EOL> if not pexpect : <EOL> import pexpect <EOL> class Spawn ( pexpect . spawn ) : <EOL> "<STR_LIT>" <EOL> def close ( self , force = False ) : <EOL> srun ( '<STR_LIT>' % self . pid ) <EOL> arch = archFor ( kernel ) <EOL> log ( '<STR_LIT>' , arch ) <EOL> if NoKVM : <EOL> accel = '<STR_LIT>' <EOL> else : <EOL> accel = '<STR_LIT>' <EOL> cmd = [ '<STR_LIT>' , '<STR_LIT>' + arch , <EOL> '<STR_LIT>' % accel , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' % memory , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , kernel , <EOL> '<STR_LIT>' , initrd , <EOL> '<STR_LIT>' % cow , <EOL> '<STR_LIT>' ] <EOL> if Forward : <EOL> cmd += sum ( [ [ '<STR_LIT>' , f ] for f in Forward ] , [ ] ) <EOL> if cpuCores > <NUM_LIT:1> : <EOL> cmd += [ '<STR_LIT>' % cpuCores ] <EOL> cmd = '<STR_LIT:U+0020>' . join ( cmd ) <EOL> log ( '<STR_LIT>' , cow ) <EOL> log ( cmd ) <EOL> vm = Spawn ( cmd , timeout = TIMEOUT , logfile = logfile ) <EOL> return vm <EOL> def login ( vm , user = '<STR_LIT>' , password = '<STR_LIT>' ) : <EOL> "<STR_LIT>" <EOL> log ( '<STR_LIT>' ) <EOL> vm . expect ( '<STR_LIT>' ) <EOL> log ( '<STR_LIT>' ) <EOL> vm . sendline ( user ) <EOL> log ( '<STR_LIT>' ) <EOL> vm . expect ( '<STR_LIT>' ) <EOL> log ( '<STR_LIT>' ) <EOL> vm . sendline ( password ) <EOL> log ( '<STR_LIT>' ) <EOL> def removeNtpd ( vm , prompt = Prompt , ntpPackage = '<STR_LIT>' ) : <EOL> "<STR_LIT>" <EOL> log ( '<STR_LIT>' ) <EOL> vm . sendline ( '<STR_LIT>' + ntpPackage ) <EOL> vm . expect ( prompt ) <EOL> vm . sendline ( '<STR_LIT>' ) <EOL> vm . expect ( prompt ) <EOL> log ( '<STR_LIT>' ) <EOL> seconds = int ( run ( r'<STR_LIT>' ) ) <EOL> log ( '<STR_LIT>' ) <EOL> vm . sendline ( '<STR_LIT>' % seconds ) <EOL> def sanityTest ( vm ) : <EOL> "<STR_LIT>" <EOL> vm . sendline ( '<STR_LIT>' ) <EOL> if vm . expect ( [ '<STR_LIT>' , pexpect . TIMEOUT ] , timeout = <NUM_LIT> ) == <NUM_LIT:0> : <EOL> log ( '<STR_LIT>' ) <EOL> else : <EOL> log ( '<STR_LIT>' ) <EOL> log ( '<STR_LIT>' ) <EOL> log ( vm . before ) <EOL> def coreTest ( vm , prompt = Prompt ) : <EOL> "<STR_LIT>" <EOL> log ( '<STR_LIT>' ) <EOL> vm . sendline ( '<STR_LIT>' ) <EOL> vm . expect ( prompt ) <EOL> vm . sendline ( '<STR_LIT>' ) <EOL> vm . expect ( prompt ) <EOL> log ( '<STR_LIT>' ) <EOL> vm . sendline ( '<STR_LIT>' ) <EOL> for test in range ( <NUM_LIT:0> , <NUM_LIT:2> ) : <EOL> if vm . expect ( [ '<STR_LIT>' , '<STR_LIT>' , pexpect . TIMEOUT ] , timeout = <NUM_LIT> ) == <NUM_LIT:0> : <EOL> log ( '<STR_LIT>' , test , '<STR_LIT:OK>' ) <EOL> else : <EOL> log ( '<STR_LIT>' , test , '<STR_LIT>' ) <EOL> log ( '<STR_LIT>' , test , '<STR_LIT>' ) <EOL> log ( vm . before ) <EOL> def installPexpect ( vm , prompt = Prompt ) : <EOL> "<STR_LIT>" <EOL> vm . sendline ( '<STR_LIT>' ) <EOL> vm . expect ( prompt ) <EOL> def noneTest ( vm , prompt = Prompt ) : <EOL> "<STR_LIT>" <EOL> installPexpect ( vm , prompt ) <EOL> vm . sendline ( '<STR_LIT>' ) <EOL> def examplesquickTest ( vm , prompt = Prompt ) : <EOL> "<STR_LIT>" <EOL> installPexpect ( vm , prompt ) <EOL> vm . sendline ( '<STR_LIT>' ) <EOL> def examplesfullTest ( vm , prompt = Prompt ) : <EOL> "<STR_LIT>" <EOL> installPexpect ( vm , prompt ) <EOL> vm . sendline ( '<STR_LIT>' ) <EOL> def walkthroughTest ( vm , prompt = Prompt ) : <EOL> "<STR_LIT>" <EOL> installPexpect ( vm , prompt ) <EOL> vm . sendline ( '<STR_LIT>' ) <EOL> def useTest ( vm , prompt = Prompt ) : <EOL> "<STR_LIT>" <EOL> old = vm . logfile <EOL> if old == stdout : <EOL> log ( '<STR_LIT>' ) <EOL> vm . logfile = None <EOL> log ( '<STR_LIT>' ) <EOL> vm . interact ( ) <EOL> if old == stdout : <EOL> log ( '<STR_LIT>' ) <EOL> vm . logfile = stdout <EOL> runTest = useTest <EOL> def checkOutBranch ( vm , branch , prompt = Prompt ) : <EOL> vm . sendline ( '<STR_LIT>' <EOL> + branch + '<STR_LIT>' + branch ) <EOL> vm . expect ( prompt ) <EOL> vm . sendline ( '<STR_LIT>' ) <EOL> def interact ( vm , tests , pre = '<STR_LIT>' , post = '<STR_LIT>' , prompt = Prompt ) : <EOL> "<STR_LIT>" <EOL> login ( vm ) <EOL> log ( '<STR_LIT>' ) <EOL> vm . expect ( prompt ) <EOL> log ( '<STR_LIT>' ) <EOL> vm . sendline ( '<STR_LIT>' ) <EOL> log ( '<STR_LIT>' ) <EOL> vm . expect ( prompt ) <EOL> log ( '<STR_LIT>' ) <EOL> branch = Branch if Branch else '<STR_LIT>' <EOL> vm . sendline ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' % branch ) <EOL> vm . expect ( prompt ) <EOL> log ( '<STR_LIT>' ) <EOL> installcmd = '<STR_LIT>' <EOL> if Branch : <EOL> installcmd += '<STR_LIT:U+0020>' + Branch <EOL> vm . sendline ( installcmd ) <EOL> vm . expect ( '<STR_LIT>' ) <EOL> vm . sendline ( '<STR_LIT>' ) <EOL> log ( '<STR_LIT>' ) <EOL> vm . expect ( '<STR_LIT>' , timeout = <NUM_LIT> ) <EOL> log ( '<STR_LIT>' ) <EOL> vm . expect ( prompt ) <EOL> version = getMininetVersion ( vm ) <EOL> vm . expect ( prompt ) <EOL> log ( '<STR_LIT>' , version ) <EOL> log ( '<STR_LIT>' ) <EOL> runTests ( vm , tests = tests , pre = pre , post = post ) <EOL> log ( '<STR_LIT>' ) <EOL> vm . sendline ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> vm . expect ( prompt ) <EOL> log ( '<STR_LIT>' ) <EOL> vm . sendline ( '<STR_LIT>' ) <EOL> log ( '<STR_LIT>' ) <EOL> vm . read ( ) <EOL> log ( '<STR_LIT>' ) <EOL> return version <EOL> def cleanup ( ) : <EOL> "<STR_LIT>" <EOL> call ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def convert ( cow , basename ) : <EOL> """<STR_LIT>""" <EOL> vmdk = basename + '<STR_LIT>' <EOL> log ( '<STR_LIT>' ) <EOL> run ( '<STR_LIT>' % ( cow , vmdk ) ) <EOL> return vmdk <EOL> OVFTemplate = """<STR_LIT>""" <EOL> def generateOVF ( name , osname , osid , diskname , disksize , mem = <NUM_LIT> , cpus = <NUM_LIT:1> , <EOL> vmname = '<STR_LIT>' , vminfo = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> ovf = name + '<STR_LIT>' <EOL> filesize = stat ( diskname ) [ ST_SIZE ] <EOL> params = dict ( osname = osname , osid = osid , diskname = diskname , <EOL> filesize = filesize , disksize = disksize , name = name , <EOL> mem = mem , cpus = cpus , vmname = vmname , vminfo = vminfo ) <EOL> xmltext = OVFTemplate % params <EOL> with open ( ovf , '<STR_LIT>' ) as f : <EOL> f . write ( xmltext ) <EOL> return ovf <EOL> def qcow2size ( qcow2 ) : <EOL> "<STR_LIT>" <EOL> output = check_output ( [ '<STR_LIT>' , '<STR_LIT:info>' , qcow2 ] ) <EOL> try : <EOL> assert '<STR_LIT>' in output <EOL> bytes = int ( re . findall ( '<STR_LIT>' , output ) [ <NUM_LIT:0> ] ) <EOL> except : <EOL> raise Exception ( '<STR_LIT>' % qcow2 ) <EOL> return bytes <EOL> def build ( flavor = '<STR_LIT>' , tests = None , pre = '<STR_LIT>' , post = '<STR_LIT>' , memory = <NUM_LIT> ) : <EOL> """<STR_LIT>""" <EOL> global LogFile , Zip , Chown <EOL> start = time ( ) <EOL> lstart = localtime ( ) <EOL> date = strftime ( '<STR_LIT>' , lstart ) <EOL> ovfdate = strftime ( '<STR_LIT>' , lstart ) <EOL> dir = '<STR_LIT>' % ( flavor , date ) <EOL> if Branch : <EOL> dirname = '<STR_LIT>' % ( Branch , flavor , date ) <EOL> try : <EOL> os . mkdir ( dir ) <EOL> except : <EOL> raise Exception ( "<STR_LIT>" % dir ) <EOL> if Chown : <EOL> run ( '<STR_LIT>' % ( Chown , dir ) ) <EOL> os . chdir ( dir ) <EOL> LogFile = open ( '<STR_LIT>' , '<STR_LIT:w>' ) <EOL> log ( '<STR_LIT>' , abspath ( LogFile . name ) ) <EOL> log ( '<STR_LIT>' , dir ) <EOL> image , kernel , initrd = findBaseImage ( flavor ) <EOL> basename = '<STR_LIT>' + flavor <EOL> volume = basename + '<STR_LIT>' <EOL> run ( '<STR_LIT>' % ( image , volume ) ) <EOL> log ( '<STR_LIT>' , flavor , '<STR_LIT>' , volume ) <EOL> if LogToConsole : <EOL> logfile = stdout <EOL> else : <EOL> logfile = open ( flavor + '<STR_LIT>' , '<STR_LIT>' ) <EOL> log ( '<STR_LIT>' , abspath ( logfile . name ) ) <EOL> vm = boot ( volume , kernel , initrd , logfile , memory = memory ) <EOL> version = interact ( vm , tests = tests , pre = pre , post = post ) <EOL> size = qcow2size ( volume ) <EOL> arch = archFor ( flavor ) <EOL> vmdk = convert ( volume , basename = '<STR_LIT>' + arch ) <EOL> if not SaveQCOW2 : <EOL> log ( '<STR_LIT>' , volume ) <EOL> os . remove ( volume ) <EOL> log ( '<STR_LIT>' , abspath ( vmdk ) ) <EOL> ovfname = '<STR_LIT>' % ( version , ovfdate , OSVersion ( flavor ) ) <EOL> osname , osid = OVFOSNameID ( flavor ) <EOL> ovf = generateOVF ( name = ovfname , osname = osname , osid = osid , <EOL> diskname = vmdk , disksize = size ) <EOL> log ( '<STR_LIT>' , ovf ) <EOL> if Zip : <EOL> log ( '<STR_LIT>' ) <EOL> run ( '<STR_LIT>' % ( ovfname , ovf , vmdk ) ) <EOL> end = time ( ) <EOL> elapsed = end - start <EOL> log ( '<STR_LIT>' , abspath ( logfile . name ) ) <EOL> log ( '<STR_LIT>' % elapsed ) <EOL> log ( '<STR_LIT>' % flavor ) <EOL> os . chdir ( '<STR_LIT:..>' ) <EOL> def runTests ( vm , tests = None , pre = '<STR_LIT>' , post = '<STR_LIT>' , prompt = Prompt , uninstallNtpd = False ) : <EOL> "<STR_LIT>" <EOL> if uninstallNtpd : <EOL> removeNtpd ( vm ) <EOL> vm . expect ( prompt ) <EOL> if Branch : <EOL> checkOutBranch ( vm , branch = Branch ) <EOL> vm . expect ( prompt ) <EOL> if not tests : <EOL> tests = [ ] <EOL> if pre : <EOL> log ( '<STR_LIT>' , pre ) <EOL> vm . sendline ( pre ) <EOL> vm . expect ( prompt ) <EOL> testfns = testDict ( ) <EOL> if tests : <EOL> log ( '<STR_LIT>' ) <EOL> for test in tests : <EOL> if test not in testfns : <EOL> raise Exception ( '<STR_LIT>' + test ) <EOL> log ( '<STR_LIT>' , test ) <EOL> fn = testfns [ test ] <EOL> fn ( vm ) <EOL> vm . expect ( prompt ) <EOL> if post : <EOL> log ( '<STR_LIT>' , post ) <EOL> vm . sendline ( post ) <EOL> vm . expect ( prompt ) <EOL> def getMininetVersion ( vm ) : <EOL> "<STR_LIT>" <EOL> vm . sendline ( '<STR_LIT>' ) <EOL> vm . readline ( ) <EOL> version = vm . readline ( ) . strip ( ) <EOL> return version <EOL> def bootAndRun ( image , prompt = Prompt , memory = <NUM_LIT> , cpuCores = <NUM_LIT:1> , outputFile = None , <EOL> runFunction = None , ** runArgs ) : <EOL> """<STR_LIT>""" <EOL> bootTestStart = time ( ) <EOL> basename = path . basename ( image ) <EOL> image = abspath ( image ) <EOL> tmpdir = mkdtemp ( prefix = '<STR_LIT>' + basename ) <EOL> log ( '<STR_LIT>' , tmpdir ) <EOL> cow = path . join ( tmpdir , basename + '<STR_LIT>' ) <EOL> log ( '<STR_LIT>' , cow ) <EOL> run ( '<STR_LIT>' % ( image , cow ) ) <EOL> log ( '<STR_LIT>' ) <EOL> kernel , initrd = extractKernel ( image , flavor = basename , imageDir = tmpdir ) <EOL> if LogToConsole : <EOL> logfile = stdout <EOL> else : <EOL> logfile = NamedTemporaryFile ( prefix = basename , <EOL> suffix = '<STR_LIT>' , delete = False ) <EOL> log ( '<STR_LIT>' , logfile . name ) <EOL> vm = boot ( cow = cow , kernel = kernel , initrd = initrd , logfile = logfile , <EOL> memory = memory , cpuCores = cpuCores ) <EOL> login ( vm ) <EOL> log ( '<STR_LIT>' ) <EOL> vm . expect ( prompt ) <EOL> if runFunction : <EOL> runFunction ( vm , ** runArgs ) <EOL> log ( '<STR_LIT>' ) <EOL> vm . sendline ( '<STR_LIT>' ) <EOL> log ( '<STR_LIT>' ) <EOL> vm . wait ( ) <EOL> if outputFile : <EOL> log ( '<STR_LIT>' % outputFile ) <EOL> convert ( cow , outputFile ) <EOL> log ( '<STR_LIT>' , tmpdir ) <EOL> srun ( '<STR_LIT>' + tmpdir ) <EOL> elapsed = time ( ) - bootTestStart <EOL> log ( '<STR_LIT>' % elapsed ) <EOL> def buildFlavorString ( ) : <EOL> "<STR_LIT>" <EOL> return '<STR_LIT>' % '<STR_LIT:U+0020>' . join ( sorted ( isoURLs ) ) <EOL> def testDict ( ) : <EOL> "<STR_LIT>" <EOL> suffix = '<STR_LIT>' <EOL> trim = len ( suffix ) <EOL> fdict = dict ( [ ( fname [ : - trim ] , f ) for fname , f in <EOL> inspect . getmembers ( modules [ __name__ ] , <EOL> inspect . isfunction ) <EOL> if fname . endswith ( suffix ) ] ) <EOL> return fdict <EOL> def testString ( ) : <EOL> "<STR_LIT>" <EOL> tests = [ '<STR_LIT>' % ( name , func . __doc__ ) <EOL> for name , func in testDict ( ) . iteritems ( ) ] <EOL> return '<STR_LIT>' % '<STR_LIT:U+002CU+0020>' . join ( tests ) <EOL> def parseArgs ( ) : <EOL> "<STR_LIT>" <EOL> global LogToConsole , NoKVM , Branch , Zip , TIMEOUT , Forward , Chown <EOL> parser = argparse . ArgumentParser ( description = '<STR_LIT>' , <EOL> epilog = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT:-c>' , '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , metavar = '<STR_LIT>' , type = int , <EOL> default = <NUM_LIT> , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , metavar = '<STR_LIT:image>' , default = [ ] , <EOL> action = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , metavar = '<STR_LIT:test>' , default = [ ] , <EOL> action = '<STR_LIT>' , <EOL> help = '<STR_LIT>' + testString ( ) ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , metavar = '<STR_LIT>' , type = int , <EOL> default = <NUM_LIT:0> , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , metavar = '<STR_LIT>' , default = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , metavar = '<STR_LIT>' , default = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , metavar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , nargs = '<STR_LIT:*>' , <EOL> help = '<STR_LIT>' + buildFlavorString ( ) ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , action = '<STR_LIT:store_true>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , default = [ ] , action = '<STR_LIT>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , '<STR_LIT>' , metavar = '<STR_LIT:user>' , <EOL> help = '<STR_LIT>' ) <EOL> args = parser . parse_args ( ) <EOL> if args . depend : <EOL> depend ( ) <EOL> if args . list : <EOL> print buildFlavorString ( ) <EOL> if args . clean : <EOL> cleanup ( ) <EOL> if args . verbose : <EOL> LogToConsole = True <EOL> if args . nokvm : <EOL> NoKVM = True <EOL> if args . branch : <EOL> Branch = args . branch <EOL> if args . zip : <EOL> Zip = True <EOL> if args . timeout : <EOL> TIMEOUT = args . timeout <EOL> if args . forward : <EOL> Forward = args . forward <EOL> if not args . test and not args . run and not args . post : <EOL> args . test = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> if args . chown : <EOL> Chown = args . chown <EOL> for flavor in args . flavor : <EOL> if flavor not in isoURLs : <EOL> print "<STR_LIT>" , flavor <EOL> print buildFlavorString ( ) <EOL> break <EOL> try : <EOL> build ( flavor , tests = args . test , pre = args . run , post = args . post , <EOL> memory = args . memory ) <EOL> except Exception as e : <EOL> log ( '<STR_LIT>' , e ) <EOL> exit ( <NUM_LIT:1> ) <EOL> for image in args . image : <EOL> bootAndRun ( image , runFunction = runTests , tests = args . test , pre = args . run , <EOL> post = args . post , memory = args . memory , outputFile = args . out , <EOL> uninstallNtpd = True ) <EOL> if not ( args . depend or args . list or args . clean or args . flavor <EOL> or args . image ) : <EOL> parser . print_help ( ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> parseArgs ( ) </s>
