def install(self, startOnBoot=False): if self.skip: xenrt.TEC().logverbose("Skipping workload %s." % (self.name)) return xenrt.TEC().logverbose("Installing workload %s." % (self.name)) self.workdir = self.guest.execguest( "mktemp -d /tmp/workXXXXXX").strip() sftp = self.guest.sftpClient() t = xenrt.TempDirectory() script = """#!/usr/bin/env python import time interval = 0.1 while True: print time.time() time.sleep(interval) """ file("%s/checktime.py" % (t.path()), "w").write(script) sftp.copyTo("%s/checktime.py" % (t.path()), "%s/checktime.py" % (self.workdir)) self.guest.execguest("chmod +x %s/checktime.py" % (self.workdir))
def install(self, startOnBoot=False): LinuxWorkload.install(self, startOnBoot) if self.guest.execguest("test -e /etc/debian_version", retval="code") == 0: self.guest.execguest("apt-get install -y --force-yes zlib1g-dev") elif self.guest.execguest("test -e /etc/redhat-release", retval="code") == 0: self.guest.execguest("yum install -y zlib-devel") else: raise xenrt.XRTError("Guest is not supported") self.guest.execguest("cd %s/src && ./configure" % self.workdir) self.guest.execguest("cd %s/src && make" % self.workdir) self.guest.execguest("cd %s/src && make install" % self.workdir) inifile = """[workload] rw=randrw size=512m runtime=1382400 time_based numjobs=4 """ t = xenrt.TempDirectory() sftp = self.guest.sftpClient() file("%s/workload.fio" % (t.path()), "w").write(inifile) sftp.copyTo("%s/workload.fio" % (t.path()), "/root/workload.fio") self.guest.execguest( "echo 'fio /root/workload.fio' > /root/startfio.sh") self.guest.execguest("chmod a+x /root/startfio.sh")
def run(self, arglist): alltcs = [] sftp = self.runner.sftpClient() files = [x.strip() for x in self.runner.execguest("ls /root/marvin*/results.xml").splitlines()] t = xenrt.TempDirectory() for f in files: sftp.copyFrom(f, "%s/results.xml" % t.path()) dom = xml.dom.minidom.parse("%s/results.xml" % t.path()) suites = dom.getElementsByTagName("testsuite") for s in suites: tcs = s.getElementsByTagName("testcase") alltcs.extend(tcs) failcount = len([x for x in alltcs if x.getElementsByTagName("failure")]) skipcount = len([x for x in alltcs if x.getElementsByTagName("skipped")]) errorcount = len([x for x in alltcs if x.getElementsByTagName("error")]) totalcount = len(alltcs) d = xml.dom.minidom.Document() s = d.createElement("testsuite") s.setAttribute("name", "nosetests") s.setAttribute("tests", str(totalcount)) s.setAttribute("errors", str(errorcount)) s.setAttribute("failures", str(failcount)) s.setAttribute("skip", str(skipcount)) d.appendChild(s) for t in alltcs: s.appendChild(t) os.mkdir("%s/marvin" % (xenrt.TEC().getLogdir())) with open("%s/marvin/results.xml" % xenrt.TEC().getLogdir(), "w") as f: f.write(d.toprettyxml())
def getHyperVMsi(self): if xenrt.TEC().lookup("HYPERV_AGENT", None): self.hyperVMsi = xenrt.TEC().getFile( xenrt.TEC().lookup("HYPERV_AGENT")) elif xenrt.TEC().lookup("ACS_BUILD", None): artifacts = xenrt.lib.cloud.getACSArtifacts( None, [], ["hypervagent.zip"]) if len(artifacts) > 0: self.hyperVMsi = artifacts[0] if not self.hyperVMsi: # Install CloudPlatform packages cloudInputDir = self.marvin.mgtSvr.getCCPInputs() if not cloudInputDir: raise xenrt.XRTError("No CLOUDINPUTDIR specified") xenrt.TEC().logverbose("Downloading %s" % cloudInputDir) ccpTar = xenrt.TEC().getFile(cloudInputDir) xenrt.TEC().logverbose("Got %s" % ccpTar) t = xenrt.TempDirectory() xenrt.command("tar -xvzf %s -C %s" % (ccpTar, t.path())) self.hyperVMsi = xenrt.command( "find %s -type f -name *hypervagent.msi" % t.path()).strip() if not self.hyperVMsi: self.hyperVMsi = xenrt.TEC().getFile(xenrt.TEC().lookup( "HYPERV_AGENT_FALLBACK", "http://repo-ccp.citrix.com/releases/ASF/hyperv/ccp-4.5/CloudPlatform-4.5.0.0-19-hypervagent.msi" )) if not self.hyperVMsi: raise xenrt.XRTError("Could not find Hyper-V agent in build")
def __init__(self, hosts, iscsiHost=None): self.hosts = hosts for host in self.hosts: host.melioHelper = self self.lun = None self._scsiid = None self.guid = None self._iscsiHost = iscsiHost self.logNames = [] # Get a checkout of the Melio Python library if not xenrt.TEC().lookup("MELIO_PYTHON_LOCAL_PATH", None): d = xenrt.TempDirectory() xenrt.util.command("cd %s && git clone %s melio-python" % (d.path(), xenrt.TEC().lookup("MELIO_PYTHON_REPO", "https://gitlab.citrite.net/xs-melio/python-melio-linux.git"))) xenrt.util.command("cd %s/melio-python && git checkout %s" % (d.path(), xenrt.TEC().lookup("MELIO_PYTHON_BRANCH", "master"))) xenrt.GEC().config.setVariable("MELIO_PYTHON_LOCAL_PATH", "%s/melio-python" % d.path()) sys.path.append("%s/melio-python/lib" % d.path()) xenrt.setupLogging("sanbolic") import sanbolic self._MelioClient = sanbolic.Client
def getResults(self): logpath = self.getLogDir("specviewperf") logpathhtml = "%s/%s" % (logpath, self.guest.name) if not os.path.exists(logpathhtml): os.makedirs(logpathhtml) d = xenrt.TempDirectory() self.guest.xmlrpcFetchRecursive("%s\\results" % self.SVP_PATH, d.path()) respath = "%s/%s/results" % (d.path(), self.SVP_PATH.replace("\\","/")[3:]) # Save the results in a tar file, and also produce a JSON summary if not xenrt.TEC().lookup("OPTION_SAVE_SVP_GRABS", False, boolean=True): xenrt.util.command("rm -rf %s/*/grabs" % respath) xenrt.util.command("tar -cvzf %s/%s.tar.gz -C %s ./" % (logpath, self.guest.name, respath)) xenrt.util.command("tar -xvzf %s/%s.tar.gz -C %s --exclude '*.txt' --exclude '*grabs*'" % (logpath, self.guest.name, logpathhtml)) (x,y) = self._getAppResolution() gpu = self.guest.findGPUMake().split(None, 1)[1].strip() files = glob.glob("%s/*/viewperfresult.txt" % respath) results = {"resolution": {"x":x, "y":y}, "winversion": self.guest.distro, "gpu":gpu, "results": {}} for f in files: benchmark = f.split("/")[-2] results['results'][benchmark] = {"tests":{}} for l in file(f).xreadlines(): if l[0] == "#": continue if l[0] == "*": # Composite score lines begin with "*" results['results'][benchmark]["score"] = l.split()[-1] else: (test, weight, fps) = l.split() results['results'][benchmark]["tests"][test] = {} results['results'][benchmark]["tests"][test]["weight"]=weight results['results'][benchmark]["tests"][test]["fps"]=fps f = open("%s/%s.json" % (logpath, self.guest.name), "w") f.write(json.dumps(results)) f.close() return results
def installWindows(self, version, build, arch): self.windows = True if not os.path.exists( "%s/%s/%s/autoinstall-%s.zip" % (xenrt.TEC().lookup("IMAGES_ROOT"), version, build, arch)): if not os.path.exists( "%s/%s/%s/autoinstall-%s.tar" % (xenrt.TEC().lookup("IMAGES_ROOT"), version, build, arch)): raise xenrt.XRTError("No install files found for %s build %s" % (version, build)) if version == "longhorn" or version[0:7] == "vistaee": method = "longhorn" else: method = "normal" self.distro = version xenrt.TEC().progress("Preparing TFTP...") tftp = "%s/xenrt/native" % (xenrt.TEC().lookup("TFTP_BASE")) if not os.path.exists(tftp): xenrt.sudo("mkdir -p %s" % (tftp)) xenrt.getTestTarball("native", extract=True) xenrt.sudo("rsync -avxl %s/winpe32.wim %s/winpe.wim" % (xenrt.TEC().lookup("IMAGES_ROOT"), tftp)) # Get a PXE directory to put boot files in. xenrt.TEC().progress("Preparing PXE...") serport = xenrt.TEC().lookup("SERIAL_CONSOLE_PORT", "0") serbaud = xenrt.TEC().lookup("SERIAL_CONSOLE_BAUD", "115200") pxe = xenrt.PXEBoot() pxe.copyIn("%s/native/pxe/pxeboot.0" % (xenrt.TEC().getWorkdir())) xenrt.sudo("rsync -avxl %s/native/pxe/32/BCD %s/BCD" % (xenrt.TEC().getWorkdir(), tftp)) xenrt.sudo("rsync -avxl %s/native/pxe/boot.sdi %s/boot.sdi" % (xenrt.TEC().getWorkdir(), tftp)) xenrt.sudo("rsync -avxl %s/native/pxe/bootmgr.exe %s/bootmgr.exe" % (xenrt.TEC().getWorkdir(), tftp)) # Set the boot files and options for PXE pxe.setSerial(serport, serbaud) pxe.addEntry("local", boot="local") pxecfg = pxe.addEntry("winpe", default=1, boot="linux") pxecfg.linuxSetKernel("pxeboot.0") xenrt.TEC().progress("Preparing web directory") w = xenrt.WebDirectory() f = file("%s/native/pe/perun.cmd" % (xenrt.TEC().getWorkdir()), "r") perun = f.read() f.close() if method == "longhorn": t = xenrt.TempDirectory() xenrt.command("tar xf %s/%s/%s/autoinstall-%s.tar -C %s" % (xenrt.TEC().lookup("IMAGES_ROOT"), version, build, arch, t.path())) w.copyIn("%s/install/unattend.xml" % (t.path())) perun += "wget %FILES%/unattend.xml\n" # Count the number of install.wim fragments. catcmd = "cat " partpath = "%s/install/install.part" % (t.path()) numparts = len(glob.glob("%s*" % (partpath))) for i in range(1, numparts + 1): # Download install.wim fragment. perun += "wget %%FILES%%/%s%d\n" % (os.path.basename(partpath), i) # Make sure fragments get recombined. catcmd += "%s%d " % (os.path.basename(partpath), i) # Make fragment available over the network. w.copyIn("%s%d" % (partpath, i)) catcmd += "> c:\\win\\sources\\install.wim\n" perun += catcmd w.copyIn("%s/install/install.zip" % (t.path()), target="win.zip") t.remove() # 32-bit installs just require the one stage. if arch == "x86-32": perun += "c:\\win\\sources\\setup.exe /unattend:c:\\unattend.xml" else: t = xenrt.TempDirectory() xenrt.command( "unzip %s/%s/%s/autoinstall-%s.zip unattend.txt -d %s" % (xenrt.TEC().lookup("IMAGES_ROOT"), version, build, arch, t.path())) try: xenrt.command( "unzip %s/%s/%s/autoinstall-%s.zip runonce.cmd -d %s" % (xenrt.TEC().lookup("IMAGES_ROOT"), version, build, arch, t.path())) except: try: xenrt.command( "unzip %s/%s/%s/autoinstall-%s.zip win/i386/runonce.cmd -d %s" % (xenrt.TEC().lookup("IMAGES_ROOT"), version, build, arch, t.path())) except: xenrt.command( "unzip %s/%s/%s/autoinstall-%s.zip win/I386/runonce.cmd -d %s" % (xenrt.TEC().lookup("IMAGES_ROOT"), version, build, arch, t.path())) xenrt.command("mv %s/win/?386/runonce.cmd %s/runonce.cmd" % (t.path(), t.path())) xenrt.command("chmod a+rwx %s/runonce.cmd" % (t.path())) perun += """ wget %FILES%/runonce.cmd wget %FILES%/unattend.txt bootsect /nt52 c: /force c:\win\i386\winnt32.exe /makelocalsource /syspart:c: /s:c:\win\i386 /unattend:c:\unattend.txt /cmd:c:\runonce.cmd wpeutil reboot """ f = file("%s/runonce.cmd" % (t.path()), "r") data = f.read() f.close() # HACK to support Broadcom NICs on those machines that have them. if xenrt.TEC().lookup("BROADCOM_POSTINSTALL", False, boolean=True): data = string.replace(data, "EXIT", "") data = data + 'REG ADD %KEY%\\050 /VE /D "Broadcom Driver" /f\n' data = data + 'REG ADD %KEY%\\050 /V 1 /D ' \ '"%systemdrive%\\win\\post\\Broadcom\\setup.exe ' \ '/s /v/qn" /f\n' data = data + "EXIT\n" xenrt.TEC().copyToLogDir("%s/runonce.cmd" % (t.path())) f = file("%s/runonce.cmd" % (t.path()), "w") f.write(data) f.close() w.copyIn("%s/unattend.txt" % (t.path())) w.copyIn("%s/runonce.cmd" % (t.path())) w.copyIn("%s/%s/%s/autoinstall-%s.zip" % (xenrt.TEC().lookup("IMAGES_ROOT"), version, build, arch), target="win.zip") t.remove() # Copy common files. w.copyIn("%s/native/pe/makepart.txt" % (xenrt.TEC().getWorkdir())) perun_dir = os.path.dirname(xenrt.TEC().lookup("WINPE_START_FILE")) if not os.path.exists(perun_dir): xenrt.sudo("mkdir -p %s" % (perun_dir)) # Replace variables in perun.cmd. perun = string.replace(perun, "%FILES%", "%s" % (w.getURL("/"))) f = file("%s/perun.cmd" % (xenrt.TEC().getWorkdir()), "w") f.write(perun) f.close() xenrt.TEC().copyToLogDir("%s/perun.cmd" % (xenrt.TEC().getWorkdir())) # Put perun.cmd where WinPE expects it. lock = xenrt.resources.CentralResource() for i in range(10): try: lock.acquire("WINPE_START_FILE") break except: if i == 9: raise xenrt.XRTError("Couldn't get lock on WINPE " "bootstrap file.") xenrt.sleep(60) xenrt.sudo( "cp %s/perun.cmd %s" % (xenrt.TEC().getWorkdir(), xenrt.TEC().lookup("WINPE_START_FILE"))) # Start install. xenrt.TEC().progress("Starting installation") pxefile = pxe.writeOut(self.machine) pfname = os.path.basename(pxefile) xenrt.TEC().copyToLogDir(pxefile, target="%s.pxe.txt" % (pfname)) self.machine.powerctl.cycle() xenrt.TEC().progress("Rebooted host to start installation.") xenrt.sleep(120) lock.release() # 64-bit requires a two-stage installation. if arch == "x86-64": # Wait for first stage to complete. xenrt.sleep(360) xenrt.TEC().progress("Preparing TFTP for second stage.") xenrt.sudo("rsync -avxl %s/native/pxe/64/ %s/" % (xenrt.TEC().getWorkdir(), tftp)) xenrt.sudo("rsync -avxl %s/winpe64.wim %s/winpe.wim" % (xenrt.TEC().lookup("IMAGES_ROOT"), tftp)) self.machine.powerctl.cycle() xenrt.TEC().progress( "Rebooted host into second installation stage.") # Wait for PXE boot. xenrt.sleep(120) pxe.setDefault("local") pxe.writeOut(self.machine) # Wait for Windows to boot. xenrt.TEC().progress("Waiting for host to boot") self.waitforxmlrpc(7200) w.remove() if method == "longhorn": self.winRegAdd( "HKLM", "SYSTEM\\CurrentControlSet\\Control\\Terminal Server", "fDenyTSConnections", "DWORD", 0) self.winRegAdd("HKLM", "SYSTEM\\CurrentControlSet\\Control\\Lsa", "LMCompatibilityLevel", "DWORD", 1) if not method == "longhorn": bootini = self.xmlrpcReadFile("c:\\boot.ini").strip() if self.memory: bootini += " /MAXMEM=%d" % (self.memory) if self.vcpus: bootini += " /NUMPROC=%d" % (self.vcpus) self.xmlrpcRemoveFile("c:\\boot.ini") self.xmlrpcCreateFile("c:\\boot.ini", xmlrpclib.Binary(bootini)) self.xmlrpcReboot() xenrt.sleep(180) self.waitforxmlrpc(300) self.tailor()
def __init__(self): self.cachedir = xenrt.TempDirectory().path() self.lock = threading.Lock() self.defaultFetchTimeout = 3600 self.externalFetchTimeout = 6 * 3600
def __init__(self, machine, username="******", password=None, cd=None, cached=False): self.username = username if password: self.password = password elif machine.host: self.password = machine.host.password else: self.password = None self.machine = machine self.cached = cached self.dir = None self.tempDir = None self.winguest = None self.debug_on_fail = False if not self.password: self.password = xenrt.TEC().lookup("ROOT_PASSWORD") if xenrt.TEC().registry.read("/xenrt/cli/windows"): self.winguest = xenrt.TEC().registry.read(\ "/xenrt/cli/windows_guest") if not self.winguest: raise xenrt.XRTError("Could not find guest in registry.") # Install xe.exe self.winguest.installCarbonWindowsCLI() else: if xenrt.command("which xe", retval="code") == 0 and not xenrt.TEC().lookup( "OPTION_USE_XE_FROM_XS", False, boolean=True): # Use the version in the distro self.dir = os.path.dirname(xenrt.command("which xe")) else: self.tempDir = xenrt.TempDirectory() self.dir = self.tempDir.path() mount = None # Places we'll look for the CLI binary. cds = [] if cd: cds.append(cd) else: imageName = xenrt.TEC().lookup("CARBON_CD_IMAGE_NAME", 'main.iso') xenrt.TEC().logverbose("Using XS install image name: %s" % (imageName)) try: cd = xenrt.TEC().getFile("xe-phase-1/%s" % (imageName), imageName) if cd: cds.append(cd) except: pass if machine.host: ecds = machine.host.getDefaultAdditionalCDList() if ecds: for ecd in string.split(ecds, ","): if os.path.exists(ecd): cds.append(ecd) else: try: cd = xenrt.TEC().getFile( "xe-phase-1/%s" % (os.path.basename(ecd)), os.path.basename(ecd)) if cd: cds.append(cd) except: pass else: try: cd = xenrt.TEC().getFile("xe-phase-1/linux.iso", "linux.iso") if cd: cds.append(cd) except: pass # Get a CLI binary from the CD. rpm = None localarch = xenrt.command("uname -m").strip() remotearch = machine.getHost().execdom0("uname -m").strip() if remotearch == "x86_64" and localarch != "x86_64": xenrt.TEC().logverbose("Using local CLI binary") rpm = "%s/tests/xe/xe-cli.i686.rpm" % xenrt.TEC().lookup( "XENRT_BASE") else: for cd in cds: xenrt.checkFileExists(cd) mount = xenrt.MountISO(cd) mountpoint = mount.getMount() fl = glob.glob("%s/xe-cli-[0-9]*i?86.rpm" % (mountpoint)) if len(fl) != 0: xenrt.TEC().logverbose( "Using CLI binary from ISO %s" % (cd)) rpm = fl[-1] break if localarch == "x86_64": fl = glob.glob( "%s/client_install/xe-cli-[0-9]*x86_64.rpm" % (mountpoint)) else: fl = glob.glob( "%s/client_install/xe-cli-[0-9]*i?86.rpm" % (mountpoint)) fl.extend( glob.glob( "%s/client_install/xenenterprise-cli-[0-9]*i?86.rpm" % (mountpoint))) if len(fl) != 0: xenrt.TEC().logverbose( "Using CLI binary from ISO %s" % (cd)) rpm = fl[-1] break mount.unmount() mount = None # Try a client_install subdir next to the main ISO. if not rpm: if len(cds) > 0: cd = cds[0] p = "%s/client_install" % (os.path.dirname(cd)) if os.path.exists(p): fl = glob.glob("%s/xe-cli-[0-9]*i?86.rpm" % (p)) if len(fl) != 0: xenrt.TEC().logverbose( "Using CLI binary from " "split directory") rpm = fl[-1] if not rpm: # Fallback is to copy the binary from the dom0. h = machine.getHost() if not h: raise xenrt.XRTError("No host associate with %s, " "cannot get CLI" % (machine.name)) xenrt.TEC().logverbose("Copying CLI binary from host") sftp = h.sftpClient() sftp.copyFrom("/opt/xensource/bin/xe", "%s/xe" % (self.tempDir.path())) sftp.close() else: xenrt.TEC().logverbose("Using CLI RPM %s" % (os.path.basename(rpm))) if xenrt.command("cd %s && rpm2cpio %s | cpio -idv" % (self.tempDir.path(), rpm), retval="code") != 0: raise xenrt.XRTError( "Error extracting CLI binary from %s" % (rpm)) if xenrt.command( "mv %s/opt/xensource/bin/xe %s" % (self.tempDir.path(), self.tempDir.path()), retval="code") == 0: pass elif xenrt.command( "mv %s/usr/bin/xe %s" % (self.tempDir.path(), self.tempDir.path()), retval="code") != 0: raise xenrt.XRTError("Couldn't find xe in RPM") xenrt.TEC().logverbose( "Test whether xe supports --debug-on-fail") if mount: mount.unmount() if xenrt.command("%s/xe --debug-on-fail" % self.dir, retval="code", level=xenrt.RC_OK) == 0: self.debug_on_fail = True xenrt.TEC().logverbose( "xe supports --debug-on-fail, now available " "for use in any cli calls.") else: xenrt.TEC().logverbose("xe doesn't support --debug-on-fail")