def writeResultsFile(self): if not self.results: raise xenrt.XRTFailure( "An omnishambles has occured - no results to report") file("%s/%s" % (xenrt.TEC().getLogdir(), self.RESULT_FILE_NAME), "w").write(self.results) log("Output file written: %s" % self.RESULT_FILE_NAME)
def __runCommand(self, hostRef, session, command, args): try: self.__logDebug("HostRef: " + hostRef, "Plugin: " + self.__PLUGIN_NAME, "Command: " + command, "Args: " + str(args)) output = session.xenapi.host.call_plugin(hostRef, self.__PLUGIN_NAME, command, args) return output except: traceback.print_exc(file=sys.stderr) exc_type, exc_value, exc_traceback = sys.exc_info() xenrt.TEC().logverbose("HostRef: %s, Plugin: %s, Command: %s Args: %s" % (hostRef, self.__PLUGIN_NAME, command, str(args))) hostName = session.xenapi.host.get_record(hostRef)['hostname'] log("Host name %s" % hostName) hosts = xenrt.TEC().registry.hostFind(hostName) if len(hosts) < 1: xenrt.TEC().logverbose("Hostname not found") raise host = hosts[0] if host: xenrt.TEC().logverbose(host.execdom0("find /etc/xapi.d/plugins -name tpm")) xenrt.TEC().logverbose("Host is %s" % hostName) m = re.search('xentpm\[[0-9]*\]', str(exc_value)) if m: xenrt.TEC().logverbose(host.execdom0("grep -F '%s' /var/log/messages" % m.group(0))) errorMessage = self.__attemptLogParse(host) if errorMessage: raise xenrt.XRTFailure(errorMessage) raise
def run(self, arglist=[]): if self.updateMachineWithAutoFlaggerTag: params = xenrt.APIFactory().get_machine(self.machineName)['params'] if "AUTOFLAGGERTAG" in params and params["AUTOFLAGGERTAG"] == self.updateMachineWithAutoFlaggerTag: comment("Machine %s has already been checked. Exiting." % self.machineName) return for flag,flagData in self.flags.iteritems(): if "seqFile" in flagData: seqFile=flagData["seqFile"] elif "productType" in flagData or "productVersion" in flagData or "version" in flagData: seqFile = self.createTempSeq(**flagData) else: warning("Unimplemented") log("Using Temp Seq File : %s" % seqFile) passed = False try: self.doSequence(seqFile) passed = True except Exception, e: warning(str(e)) if passed == flagData["isSetIfPass"] and not self.isPropAlreadySet(flag): comment("Adding flag '%s' to machine '%s'" % (flag, self.machineName)) xenrt.APIFactory().update_machine(self.machineName, addflags=[flag]) elif passed != flagData["isSetIfPass"] and self.isPropAlreadySet(flag): comment("Removing flag '%s' from machine '%s'" % (flag, self.machineName)) xenrt.APIFactory().update_machine(self.machineName, delflags=[flag]) else: comment("Machine '%s' %s flag '%s'" % (self.machineName,"is already having required" if self.isPropAlreadySet(flag) else "neither need nor has", flag))
def run(self, arglist=None): """Do testing tasks in run""" xenrt.TEC().logverbose("Importing WinPDB libs.") #install rpdb2 to enable WinPDB remote debugging session. #os.system("scp [email protected]:~/debugger_test/rpdb2.py /tmp/") os.system("wget https://winpdb.googlecode.com/hg/rpdb2.py -O /tmp/rpdb2.py") sys.path.append(r"/tmp") import rpdb2 xenrt.TEC().logverbose("Import done. Trying wait remote debugger.") rpdb2.start_embedded_debugger('abc', fAllowRemote = True) log("Hello, world!") log("My host name is %s" % self.host.getName()) a = 10 b = 0 log("print a + b = %d" % a + b); log("print a - b = %d" % a - b); log("print a / b = %d" % a / b); # you can SSH to a guest by doing: ret = self.guest0.execguest("ls") # or to a host by doing: ret = self.host.execdom0("ls")
def getExistingLAGs(self, setChRange=False, quiet=False): lines = self.commandWithResponse('show interfaces port-channel') re_ch = re.compile("%s\d+" % self.CHANNELPREFIX) re_no_ch = re.compile('[^c]') re_wrapped = re.compile("\s+((?:%s,?\s?)+)" % self.PORTREGEX) # fix wrapped second column of the list for i in range(1, len(lines)): if re_no_ch.match(lines[i]) and re_ch.match(lines[i - 1]): m = re_wrapped.match(lines[i]) if m: wrapped = m.group(1).strip() s1, s2 = lines[i - 1].rsplit(None, 1) lines[i - 1] = s1 + ", " + wrapped + s2 lines = filter(re_ch.match, lines) if setChRange is True: # find last chX line and set maxCh to X self.maxCh = int( re.match("%s(\d+)" % self.CHANNELPREFIX, lines[-1]).group(1)) re_noports = re.compile("%s\d+\s+No Configured Ports" % self.CHANNELPREFIX) lines = filter(lambda x: not re_noports.match(x), lines) LAGs = [] members = [] if len(lines) > 0: log("Existing configured channels found: \n%s" % "\n".join(lines)) # convert \d+ into integers and return list of existing LAG numbers LAGs = map( lambda line: int( re.match("%s(\d+)" % self.CHANNELPREFIX, line).group(1)), lines) members = [re.findall(self.PORTREGEX, line) for line in lines] return (LAGs, members)
def getExistingLAGs(self, setChRange=False, quiet=False): lines = self.commandWithResponse('show interfaces port-channel') re_ch = re.compile("%s\d+" % self.CHANNELPREFIX) re_no_ch = re.compile('[^c]') re_wrapped = re.compile("\s+((?:%s,?\s?)+)" % self.PORTREGEX) # fix wrapped second column of the list for i in range(1,len(lines)): if re_no_ch.match(lines[i]) and re_ch.match(lines[i-1]): m = re_wrapped.match(lines[i]) if m: wrapped = m.group(1).strip() s1, s2 = lines[i-1].rsplit(None, 1) lines[i-1] = s1 + ", " + wrapped + s2 lines = filter(re_ch.match,lines) if setChRange is True: # find last chX line and set maxCh to X self.maxCh = int(re.match("%s(\d+)" % self.CHANNELPREFIX, lines[-1]).group(1)) re_noports = re.compile("%s\d+\s+No Configured Ports" % self.CHANNELPREFIX) lines = filter(lambda x: not re_noports.match(x) , lines) LAGs = [] members = [] if len(lines)>0: log("Existing configured channels found: \n%s" % "\n".join(lines)) # convert \d+ into integers and return list of existing LAG numbers LAGs = map(lambda line : int(re.match("%s(\d+)" % self.CHANNELPREFIX, line).group(1)), lines) members = [re.findall(self.PORTREGEX, line) for line in lines] return (LAGs, members)
def setLACP(self): # Check that no port has LAG/LACP already set for port in self.ports: self.checkPortHasNoLagSet(port) # Set LAG and enable LACP on all the ports proposedLAG = self.proposeLAG() ports = self.ports[:] firstPort = ports.pop(0) # Avoid the (unlikely) situation where two TCs try to set up the same LAG # (let the other TC win, revert and re-propose LAG) for i in range(self.MAX_ATTEMPTS): log("Trying LAG number %s." % proposedLAG) self.setLagOnPort(firstPort, proposedLAG) if self.checkLagIsOnlyOnPort(proposedLAG, firstPort): break else: log("Reverting, LAG %s seems to be used by another port." % proposedLAG) self.unsetLagOnPort(firstPort) proposedLAG = self.proposeLAG() else: raise xenrt.XRTError("%s attempts to set up LAC on port %s failed." % (self.MAX_ATTEMPTS, firstPort) ) # Set up chosen LAG on the remaining ports self.lag = proposedLAG for port in ports: self.setLagOnPort(port, self.lag) # Set the port-channel interface self.portChannelInterfaceConfigure() self.disconnect()
def run(self, arglist=None): """Do testing tasks in run""" xenrt.TEC().logverbose("Importing WinPDB libs.") #install rpdb2 to enable WinPDB remote debugging session. #os.system("scp [email protected]:~/debugger_test/rpdb2.py /tmp/") os.system( "wget https://winpdb.googlecode.com/hg/rpdb2.py -O /tmp/rpdb2.py") sys.path.append(r"/tmp") import rpdb2 xenrt.TEC().logverbose("Import done. Trying wait remote debugger.") rpdb2.start_embedded_debugger('abc', fAllowRemote=True) log("Hello, world!") log("My host name is %s" % self.host.getName()) a = 10 b = 0 log("print a + b = %d" % a + b) log("print a - b = %d" % a - b) log("print a / b = %d" % a / b) # you can SSH to a guest by doing: ret = self.guest0.execguest("ls") # or to a host by doing: ret = self.host.execdom0("ls")
def getExistingLAGs(self, setChRange=False, quiet=False): lines = self.commandWithResponse('show etherchannel summary') re_ch = re.compile("\d+\s+%s\d+" % self.CHANNELPREFIX) re_no_ch = re.compile('[^0-9]') re_wrapped = re.compile("\s+((?:%s,?\s?)+)" % self.PORTREGEX) # fix wrapped second column of the list for i in range(1, len(lines)): if re_no_ch.match(lines[i]) and re_ch.match(lines[i - 1]): m = re_wrapped.match(lines[i]) if m: wrapped = m.group(1).strip() s1, s2 = lines[i - 1].rsplit(None, 1) lines[i - 1] = s1 + ", " + wrapped + s2 lines = filter(re_ch.match, lines) lines = filter(lambda x: len(x.split()) > 3, lines) LAGs = [] members = [] if len(lines) > 0: log("Existing configured channels found: \n%s" % "\n".join(lines)) # convert \d+ into integers and return list of existing LAG numbers LAGs = map( lambda line: int( re.search("%s(\d+)" % self.CHANNELPREFIX, line).group(1)), lines) members = [re.findall(self.PORTREGEX, line) for line in lines] return (LAGs, members)
def setLACP(self): # Check that no port has LAG/LACP already set for port in self.ports: self.checkPortHasNoLagSet(port) # Set LAG and enable LACP on all the ports proposedLAG = self.proposeLAG() ports = self.ports[:] firstPort = ports.pop(0) # Avoid the (unlikely) situation where two TCs try to set up the same LAG # (let the other TC win, revert and re-propose LAG) for i in range(self.MAX_ATTEMPTS): log("Trying LAG number %s." % proposedLAG) self.setLagOnPort(firstPort, proposedLAG) if self.checkLagIsOnlyOnPort(proposedLAG, firstPort): break else: log("Reverting, LAG %s seems to be used by another port." % proposedLAG) self.unsetLagOnPort(firstPort) proposedLAG = self.proposeLAG() else: raise xenrt.XRTError( "%s attempts to set up LAC on port %s failed." % (self.MAX_ATTEMPTS, firstPort)) # Set up chosen LAG on the remaining ports self.lag = proposedLAG for port in ports: self.setLagOnPort(port, self.lag) # Set the port-channel interface self.portChannelInterfaceConfigure() self.disconnect()
def __writeOnDom0(self): """Run writing concurrently.""" # prepare scripts if self.sequential: cmd = "dd if=/dev/zero of=/dev/\\${DEVICE} bs=1M count=%d" % \ (self.vdisize / xenrt.MEGA) chkcmd = "ps -efl | grep '[d]d if=/dev/zero'" else: cmd = "%s/remote/patterns.py /dev/\\${DEVICE} %d write 3" % \ (xenrt.TEC().lookup("REMOTE_SCRIPTDIR"), self.vdisize) chkcmd = "ps -efl | grep '[p]atterns.py'" cmd = "while [ -f /tmp/hold_running ] ; do sleep 0.1 ; done ; %s" % cmd self.host.execdom0("echo \"%s\" > /tmp/cmd.sh" % cmd) self.host.execdom0("chmod u+x /tmp/cmd.sh") # Run all commands with bash scripts first. self.host.execdom0("touch /tmp/hold_running") for vdi in self.vdis: self.host.execdom0("(/opt/xensource/debug/with-vdi %s /tmp/cmd.sh) >/dev/null 2>&1 </dev/null &" % vdi) # Triggering all the process at once. self.host.execdom0("rm -f /tmp/hold_running") waiting = 120 # mins. while waiting > 0: xenrt.sleep(300, log=False) waiting -= 5 try: pslist = self.host.execdom0(chkcmd).strip().splitlines() except: pslist = [] if len(pslist) == 0: log("Cannot find running process.") break log("Found %d processes running." % len(pslist)) log("Checking processes.") ptotal = [] pkilled = [] pfailed = [] try: pslist = self.host.execdom0(chkcmd).strip().splitlines() except: palist = [] for line in pslist: pid = line.split()[3] ptotal.append(pid) try: self.host.dom0("kill -9 %s" % pid) pkilled.append(pid) except: pfailed.append(pid) if ptotal: warning("Found %d processes are still running." % len(ptotal)) log("Killed: %s" % pkilled) log("Failed to killed: %s" % pfailed)
def getArgs(self, arglist): args = self.parseArgsKeyValue(arglist) log("Args: %s" % args) lowlevel = args["lowlevel"] in ( "yes", "true") if "lowlevel" in args else False both = args["bothChecks"] in ( "yes", "true") if "bothChecks" in args else False return lowlevel, both
def triageTestOutput(self): for bad in self.__BADNESS: if bad in self.results: log("Found the horror: %s in the output" % bad) raise xenrt.XRTFailure("A failure message was found in the output") if self.__vmCount + 1 != len(self._host.listGuests()): raise xenrt.XRTFailure("Unexpected guest count: expecting 1 VM more than the test started with")
def runTests(self): localSrName = next(sr for sr in self._host.xapiObject.localSRs if sr.isLocalStorage).name try: self.__results[self.__currentTest] = self.__runVmOps(localSrName) self.__results[self.__currentTest] = self.__runGetRecords() except xenrt.XRTFailure, e: log("Test failed: %s" % e) self.__results[self.__currentTest] = (e.data)
def run(self, instance): migrateToList = instance.canMigrateTo if not migrateToList: msg = "The toolstack cannot find a suitable location to migrate to" raise xenrt.XRTError(msg) migrateTo = instance.canMigrateTo[0] log("Instance migrating to %s" % migrateTo) instance.migrate(migrateTo)
def runTests(self): try: self.__results = self._runner.execguest( "cd %s && java -cp .:*: %s %s root xenroot" % (self._srcPath, self.__TEST_RUNNER, str(self._host.getIP()))) except xenrt.XRTFailure, e: log("Running the tests has failed - caputuring the errors for later triage" ) self.__results = str(e.data)
def startFuzzing(self, guest, seed = None): if not seed: seed = "%x" % random.randint(0, 0xffffffff) log("Starting Fuzzing with random seed: " + seed) self.host.xenstoreWrite("demufuzzer/randomseed", seed) # 1 is default. accpets unsigned long in C. # cannot use guest.start() as it run healthCheck, which will fail. self.host.getCLIInstance().execute("vm-start uuid=%s" % guest.getUUID()) xenrt.sleep(10)
def __chooseSR(self, arglist, host): """Select the zeroth sr from the SR_INSTALL_NAME variable :returns: sr-uuid -- of the named sr else local as default """ srName = xenrt.TEC().lookup("SR_INSTALL_NAME", None) if srName: log("Attempting to use SR called {srname}".format(srname=srName)) return host.getSRByName(srName)[0] if srName else host.getLocalSR()
def guest2guestPing(self, srcGuest, destIP): # ping a guest from another guest try: data = srcGuest.xmlrpcExec("ping -6 -n 3 -l 2000 %s" % destIP, returndata=True) if (not re.search("\(0% loss\)", data) or re.search("Destination host unreachable", data)) : raise xenrt.XRTFailure("Pinging target failed.") except Exception, e: log('Exception encountered: \n%s\n' % e) raise xenrt.XRTFailure('Sending a large ping packet to %s failed' % destIP)
def pingGuest(self, ip6): try: # ping a guest on its IPv6 address from the controller command = "ping6 -c 3 -w 10 -s 2000 %s" retCode = xenrt.command((command % ip6), retval="code") if retCode != 0: raise xenrt.XRTFailure('Command "%s" returned code %s' % (command, retCode) ) except Exception, e: log('Exception encountered: \n%s\n' % e) raise xenrt.XRTFailure('Sending a large ping packet to %s failed' % ip6)
def __get_sdk_location(self): """ Look for the SDK location in a named flag otherwise provide the default """ log("Look for override in %s" % self.SDK_OVERRIDE) try: location = xenrt.TEC().lookup(self.SDK_OVERRIDE) log("Found override.....") return location except: return "xe-phase-2/%s" % self._packageName
def _getSdk(self): self.removePackage() step("Getting SDK....") target = self.__get_sdk_location() sdkfile = xenrt.TEC().getFile(target) sftp = self._runner.sftpClient() targetLocation = os.path.join(self.TARGET_ROOT, self._packageName) sftp.copyTo(sdkfile, targetLocation) log("Target location: %s" % targetLocation) sftp.close() return targetLocation
def triageTestOutput(self): for bad in self.__BADNESS: if bad in self.results: log("Found the horror: %s in the output" % bad) raise xenrt.XRTFailure( "A failure message was found in the output") if self.__vmCount + 1 != len(self._host.listGuests()): raise xenrt.XRTFailure( "Unexpected guest count: expecting 1 VM more than the test started with" )
def __rawXSUninstallVMSerial(self): log("Uninstalling %d VMs." % len(self.cloneGuests)) self.logs.append("Uninstalling %d VMs" % len(self.cloneGuests)) for guest in self.cloneGuests: result = self.host.execdom0("%s %s" % (self.SCRIPT_UNINSTALL_PATH, guest), retval="code") output = self.host.execdom0("cat %s" % self.OUTPUT_PATH).splitlines() if result: logline = "%s Failed uninstalling %s with error: %s" % (output[-1], guest, " ".join(output[:-1])) else: logline = "%s Uninstalled: %s" % (output[-1], " ".join(output[:-1])) self.logs.append(logline)
def createTempSeq(self, productType=None, productVersion=None, version=None, **kargs): seqContent = """<xenrt><prepare><host id="0" """ seqContent += 'productType="%s" ' % productType if productType else "" seqContent += 'productVersion="%s" '% productVersion if productVersion else "" seqContent += 'version="%s" ' % version if version else "" seqContent += """/></prepare></xenrt>""" seqFile =xenrt.TEC().tempFile() with open(seqFile, 'w') as file: file.write(seqContent) log("Temp Seq file content : %s" % seqContent) return seqFile
def clearPrompt(self): regex = re.compile('\s*' + self.prompt + '#') prompt = self.command('') for i in range(5): if not regex.match(prompt): prompt = self.command('exit') else: break else: log("Failed to clear switch patch, reconnecting.") self.disconnect() self.connectToSwitch()
def createTempSeq(self, productType=None, productVersion=None, version=None, **kargs): seqContent = """<xenrt><prepare><host id="0" """ seqContent += 'productType="%s" ' % productType if productType else "" seqContent += 'productVersion="%s" ' % productVersion if productVersion else "" seqContent += 'version="%s" ' % version if version else "" seqContent += """/></prepare></xenrt>""" seqFile = xenrt.TEC().tempFile() with open(seqFile, "w") as file: file.write(seqContent) log("Temp Seq file content : %s" % seqContent) return seqFile
def startFuzzing(self, guest, seed=None): if not seed: seed = "%x" % random.randint(0, 0xffffffff) log("Starting Fuzzing with random seed: " + seed) self.host.xenstoreWrite( "demufuzzer/randomseed", seed) # 1 is default. accpets unsigned long in C. # cannot use guest.start() as it run healthCheck, which will fail. self.host.getCLIInstance().execute("vm-start uuid=%s" % guest.getUUID()) xenrt.sleep(10)
def clearPrompt(self): regex = re.compile('\s*'+self.prompt+'#') prompt = self.command('') for i in range(5): if not regex.match(prompt): prompt = self.command('exit') else: break else: log("Failed to clear switch patch, reconnecting." ) self.disconnect() self.connectToSwitch()
def __rawXSCloneVMSerial(self): # Avoiding using lib code to overhead of xenrt/python log("Cloning the %d guests" % self.numvms) self.logs.append("Start cloning %d VMs" % self.numvms) for i in xrange(self.numvms): result = self.host.execdom0(self.SCRIPT_CLONE_PATH, retval="code") output = self.host.execdom0("cat %s" % self.OUTPUT_PATH).splitlines() if result: logline = "%s Failed cloning with error: %s" % (output[-1], " ".join(output[:-1])) else: logline = "%s Cloned: %s" % (output[-1], " ".join(output[:-1])) self.cloneGuests.append(output[0]) self.logs.append(logline)
def command(self, command): # execute a quiet command - one that should not produce any output but prompt self.checkForPrompt() if command != '' or self.DEBUG: log("Executing switch command '%s'" % command) self.telnet.write('%s\r' % command) out = self.telnet.read_until('#', timeout=self.TIMEOUT) self.checkPrompt(out, subtract=command) out = self.telnet.read_eager() if out.strip(): log("Remaining output read from switch console '%s'" % out) raise xenrt.XRTError("Unexpected output read from switch console!") prompt = self.checkForPrompt() return prompt
def run(self, arglist): host = self.getDefaultHost() guest = host.getGuest("winguest2") try: guest.createDisk("1073741824", sruuid=host.getLocalSR(), plug=True, mode="RO") except Exception, ex: if "All VBDs of type 'disk' must be read/write for HVM guests" in str( ex): log("Read only disk failed to attach to the Windows machine") else: raise
def __noneXSUninstallVMSerial(self): log("Uninstalling %d VMs." % len(self.cloneGuests)) for guest in self.cloneGuests: try: before = xenrt.util.timenow(float=True) guest = self.guest.uninstall() after = xenrt.util.timenow(float=True) message = "Uninstalled %s" % guest.getUUID() except Exception as e: after = xenrt.util.timenow(float=True) message = "Uninstalling '%s' of uuid '%s' failed with exception '%s': " % (guest, guest.getUUID(), str(e)) finally: logline = "%.6f %s" % ((after - before), message) self.logs.append(logline)
def __noneXSCloneVMSerial(self): log("Cloning the %d guests" % self.numvms) for i in xrange(self.numvms): try: before = xenrt.util.timenow(float=True) guest = self.guest.cloneVM() after = xenrt.util.timenow(float=True) self.cloneGuests.append(guest) message = "Cloned %s" % guest.getUUID() except Exception as e: after = xenrt.util.timenow(float=True) message = "Cloning the VM '%s' of uuid '%s' failed with exception '%s': " % (self.guest, self.guest.getUUID(), str(e)) finally: logline = "%.6f %s" % ((after - before), message) self.logs.append(logline)
def prepare(self, arglist): self.vmName = self.parseArgsKeyValue(arglist)["vm"] log("Using vm %s" % self.vmName) self.vm = self.getGuest(self.vmName) self.srtype = self.vm.xapiObject.VDIs[0].SR.srType if self.vm.getState() != "UP": self.vm.start() self._applyMaxLicense() host = self.getDefaultHost() rcc = host.getReadCachingController() rcc.setVM(self.vm) rcc.enable() self._defaultLifeCycle(self.vm)
def createVLANs(self): durkeys = ["network-create"] for h in self.normalHosts: durkeys.append("%s_vlan-create" % h) durkeys.append("%s_pif-plug" % h) durkeys.append("vif-create") durkeys.append("vif-plug") self.log(self.createLog, "# vlan %s total" % (",".join(durkeys))) for i in range(1, self.numvlans+1): if i%200 == 0 and xenrt.TEC().lookup("WORKAROUND_CA95084", False, boolean=True): log("rebooting vm after creating %s vlans" % i) self.testVM.reboot() dur = self.createSingleVLAN(i) xenrt.TEC().logverbose("total duration for creating VLAN %d was %f" % (i, dur))
def run(self, arglist): self.host = self.getDefaultHost() session = self.host.getAPISession() hostRef = session.xenapi.host.get_all()[0] end = time.time() + self.__DURATION log("This test will end in %s secs" % str(end)) try: while time.time() < end: step("Fetch the attestation id....") log(xenrt.txt.TXTCommand().getAttestationId(hostRef, session)) step("Reboot host....") self.host.reboot() except: raise xenrt.XRTFailure("Failure occurred whilst calling the attestation id api repeatedly")
def prepare(self, arglist=[]): self.host = self.getDefaultHost() self.pool = self.host.pool if self.pool: self.host = self.pool.master self.sr = self.host.lookupDefaultSR() self.timeout = 180 * 60 # timeout of 3 hours per iteration. self.__obtainTestVars(arglist, printAfterObtain = True) self.guests = [] if self.runOnGuest: xenrt.pfarm([xenrt.PTask(self.prepareGuests, host) for host in self.pool.getHosts()]) else: log("Test are running on the host.")
def fromHostFile(cls, host, *filename): """ Alt. constructor. Read marker matches from the log on the host and then construct this class host: a host object filename: the file name on the host to parse """ data = [] for fname in filename: for m in cls.MARKERS: grep = "grep '%s' %s" % (m, fname) if host.execcmd(grep, retval="code") < 1: data += host.execcmd(grep).split('\n') else: log("grep failed for %s in file %s - no data found" % (m, fname)) return cls(data)
def createVLANs(self): durkeys = ["network-create"] for h in self.normalHosts: durkeys.append("%s_vlan-create" % h) durkeys.append("%s_pif-plug" % h) durkeys.append("vif-create") durkeys.append("vif-plug") self.log(self.createLog, "# vlan %s total" % (",".join(durkeys))) for i in range(1, self.numvlans + 1): if i % 200 == 0 and xenrt.TEC().lookup( "WORKAROUND_CA95084", False, boolean=True): log("rebooting vm after creating %s vlans" % i) self.testVM.reboot() dur = self.createSingleVLAN(i) xenrt.TEC().logverbose( "total duration for creating VLAN %d was %f" % (i, dur))
def run(self,arglist): pool = self.getDefaultPool() master = pool.master slave = pool.getSlaves()[0] step("Execute host_rrd on slave") startTime = xenrt.util.timenow() while xenrt.util.timenow() < startTime + 10: slave.execdom0("wget http://root:%s@%s/host_rrd" %(slave.password, slave.getIP())) step("Searching for the HOST_IS_SLAVE exception in xensource.log") msg = "Got exception HOST_IS_SLAVE" grepReturnValue = slave.execdom0("grep '%s' /var/log/xensource.log" %(msg),retval = "code") if grepReturnValue == 0: raise xenrt.XRTFailure("host_rrd request for slave causes HOST_IS_SLAVE exception.") else: log("host_rrd request for slave doesn't cause any HOST_IS_SLAVE exception")
def _checkContent(self, content): # Check that we have three fields in every line # This check was implemented, as occasionally we see malformatted lines # It can be removed once we get to root cause of this behaviour candidateContent = content content = content.rstrip() if len(content) == 0: return lines = content.rstrip().split("\n") for l in lines: fields = l.split() if len(fields) != 3: warning('Problem in switch.py library - attempt to write a malformatted line') current = self._readAll() log('current data:\n%s' % current) log('candidate data:\n"%s"' % candidateContent) raise xenrt.XRTError('Attempted to write a malformatted line "%s" ' 'in LACP clean-up flags file.' % l)
def prepare(self, arglist): self.snappoint = None self.host = self.getDefaultHost() self.sr = self.__chooseSR(arglist, self.host) log("SR UUID is {sruuid}".format(sruuid=self.sr)) self.host.addExtraLogFile("/var/log/SMlog") if not self.EXISTING_GUEST: self.guest = None for arg in arglist: l = string.split(arg, "=", 1) if l[0] == "guest": self.guest = self.getGuest("%s" % l[1]) self.guest.setName(l[1]) if not self.guest and not self.SMOKETEST: name = "%s-%s" % (self.VM, self.DISTRO) self.guest = self.getGuest(name) if not self.guest: if self.SMOKETEST: self.guest = xenrt.lib.xenserver.guest.createVM(\ self.host, xenrt.randomGuestName(), distro=self.DISTRO, arch=self.ARCH, memory=1024, sr=self.sr, vifs=xenrt.lib.xenserver.Guest.DEFAULT) elif self.DISTRO == "DEFAULT": self.guest = self.host.createGenericLinuxGuest(name=name, sr=self.sr) else: self.guest = self.host.createGenericWindowsGuest( distro=self.DISTRO, memory=1024, sr=self.sr) self.guest.setName(name) if not self.SMOKETEST: xenrt.TEC().registry.guestPut(name, self.guest) try: if self.guest.getState() == "DOWN": self.guest.start() else: self.guest.reboot() self.guest.checkHealth() except xenrt.XRTFailure, e: raise xenrt.XRTError("Guest broken before we started: %s" % (str(e)))
def run(self, arglist=[]): if self.IS_VALID_CLIENTTHREADS or self.IS_VALID_CLIENTPARALLELCONN: for t,p in self.clientTnP: step("Test segment started") if self.IS_VALID_CLIENTTHREADS: self.httpClientThreads=int(t) log("Test Parameter: httpClientThreads = %d" % (self.httpClientThreads)) if self.IS_VALID_CLIENTPARALLELCONN: self.httpClientParallelconn=int(p) log("Test Parameter: httpClientParallelconn = %d" % (self.httpClientParallelconn)) self.startWorkload() self.runTest() self.stopWorkload() step("Test segment finished") else: self.startWorkload() self.runTest() self.stopWorkload()
def installIpv6WinGuest(self, host): guest = host.createBasicGuest(distro=self.DISTRO, use_ipv6=True ) self._guestsToUninstall.append(guest) # check IPv4 address - assume that we'll just have "eth0 VIF on the guest mac, ip, network = guest.getVIFs()["eth0"] if ip is None: raise xenrt.XRTFailure("IPv4 not found on freshly installed guest") else: if re.match('\d+\.\d+.\d+\.\d+', ip): log("IPv4 address of the guest: %s" % ip) else: raise xenrt.XRTFailure("Unexpected IP format: '%s'" % ip) # disable IPv4 guest.disableIPv4() mac, ip, network = guest.getVIFs()["eth0"] if ip: raise xenrt.XRTFailure("IPv4 address still seems to exist on the guest: %s" % ip) return guest