def enableNonDefaultDS(self, host): xenrt.TEC().logverbose("Get the number of data sources in a fresh install") numBeforeEnable=self.getNumberofDS(host=host) xenrt.TEC().logverbose("The number of data sources in a fresh install is %s" % numBeforeEnable) # Enable the non-default DS, the number should then go up host.execdom0("xe-enable-all-plugin-metrics true") # Sleep for sometime to let the changes take effect xenrt.sleep(120) numAfterEnable=self.getNumberofDS(host) xenrt.TEC().logverbose("The number of data sources when non-default DS enabled is %s" % numAfterEnable) com=[] noncom=[] # Compare the ones that are same and print the extra metrics newDSList=self.getDSList(host=host) for item in newDSList: if item in self.dsList: com.append(item) else: noncom.append(item) xenrt.TEC().logverbose("The extra DS after enabling the epic metrics are %s " % noncom) if not noncom and numAfterEnable<=numBeforeEnable: raise xenrt.XRTFailure("No extra data sources found after anabling the non-default metrics")
def boot(self): if self.host.productVersion.endswith("-x64"): arch = "amd64" else: arch = "x86" # Construct a PXE target pxe1 = xenrt.PXEBoot() serport = self.host.lookup("SERIAL_CONSOLE_PORT", "0") serbaud = self.host.lookup("SERIAL_CONSOLE_BAUD", "115200") pxe1.setSerial(serport, serbaud) pxe2 = xenrt.PXEBoot() serport = self.host.lookup("SERIAL_CONSOLE_PORT", "0") serbaud = self.host.lookup("SERIAL_CONSOLE_BAUD", "115200") pxe2.setSerial(serport, serbaud) pxe1.addEntry("ipxe", boot="ipxe") pxe1.setDefault("ipxe") pxe1.writeOut(self.host.machine) winpe = pxe2.addEntry("winpe", boot="memdisk") winpe.setInitrd("%s/tftp/winpe/winpe-%s.iso" % (xenrt.TEC().lookup("LOCALURL"), arch)) winpe.setArgs("iso raw") pxe2.setDefault("winpe") filename = pxe2.writeOut(self.host.machine, suffix="_ipxe") ipxescript = """set 209:string pxelinux.cfg/%s chain tftp://${next-server}/%s """ % (os.path.basename(filename), xenrt.TEC().lookup("PXELINUX_PATH", "pxelinux.0")) pxe2.writeIPXEConfig(self.host.machine, ipxescript) self.host.machine.powerctl.cycle() xenrt.sleep(60) self.waitForBoot()
def checkManagementServerHealth(self, timeout=120): managementServerOk = False maxRetries = timeout/60 maxReboots = 2 rebootChecks = 0 while(rebootChecks <= maxReboots and not managementServerOk): retries = 0 while(retries < maxRetries): retries += 1 xenrt.TEC().logverbose('Check Management Server Ports: Attempt: %d of %d' % (retries, maxRetries)) # Check the management server ports are reachable port = 8080 try: for m in self.readyManagementServers: urllib.urlopen('http://%s:%s' % (m.getIP(), port)) except IOError, ioErr: xenrt.TEC().logverbose('Attempt to reach Management Server [%s] on Port: %d failed with error: %s' % (m.getIP(), port, ioErr.strerror)) xenrt.sleep(60) continue port = 8096 try: for m in self.readyManagementServers: urllib.urlopen('http://%s:%s' % (m.getIP(), port)) managementServerOk = True break except IOError, ioErr: xenrt.TEC().logverbose('Attempt to reach Management Server [%s] on Port: %d failed with error: %s' % (m.getIP(), port, ioErr.strerror)) xenrt.sleep(60)
def waitForSystemVmsReady(self): deadline = xenrt.timenow() + 1200 while True: systemvms = self.cloudApi.listSystemVms() or [] startingvms = [x for x in systemvms if x.state == "Starting"] systemvmhosts = [ x for x in self.cloudApi.listHosts() or [] if x.name in [y.name for y in systemvms] ] if systemvmhosts: # At least one host object has been created downhosts = [x for x in systemvmhosts if x.state != "Up"] if not downhosts and not startingvms: # All up, complete xenrt.TEC().logverbose("All System VMs ready") return else: if downhosts: xenrt.TEC().logverbose( "%s not up" % ", ".join([x.name for x in downhosts])) if startingvms: xenrt.TEC().logverbose( "%s starting" % ", ".join([x.name for x in startingvms])) else: xenrt.TEC().logverbose("No system VMs present yet") if xenrt.timenow() > deadline: raise xenrt.XRTError("Waiting for system VMs timed out") xenrt.sleep(15)
def connect(self, ip, port, username, password, timeout): if self.debug: xenrt.TEC().logverbose("connect") sock = socket.create_connection((ip, port), timeout) # Create SSH transport. if self.debug: xenrt.TEC().logverbose("transport") self.trans = paramiko.Transport(sock) self.trans.set_log_channel("") # Negotiate SSH session synchronously. if xenrt.TEC().lookup("OPTION_RETRY_SSH2", False, boolean=True): goes = 3 else: goes = 1 while goes > 0: try: if self.debug: xenrt.TEC().logverbose("start_client") self.trans.start_client() goes = 0 except Exception, e: goes = goes - 1 if goes > 0: xenrt.TEC().warning("Retrying SSHSession connection") xenrt.sleep(10) else: raise e
def cycle(self, fallback=False): xenrt.TEC().logverbose("Power cycling machine %s" % (self.machine.name)) # Wait a random delay to try to avoid power surges when testing # with multiple machines. if self.antiSurge: xenrt.sleep(random.randint(0, 20)) self.ilo("reboot")
def postOutageCheck(self): xenrt.sleep(900) if self.csHost.state != 'Down': raise xenrt.XRTFailure("Host %s is not reported Down by Cloud" % self.csHost.name) self.cloud.healthCheck(ignoreHosts=[self.csHost])
def waitForInstallCompleteAndFirstBoot(self): # Install is complete when the guest shuts down # Using the signalling mechanism to monitor for installation complete. if xenrt.TEC().lookup("EXTRA_TIME", False, boolean=True): installtime = 7200 else: installtime = 3600 xenrt.waitForFile("%s/.xenrtsuccess" % (self.nfsdir.path()), installtime, desc="RHEL based installation") if self.distro.startswith("rhel7") or self.distro.startswith( "centos7") or self.distro.startswith( "oel7") or self.distro.startswith("fedora"): # This is likely to be a force stop, so we'll sleep to allow the disk to sync xenrt.sleep(60) self.parent._osParent_stop() self.parent._osParent_pollPowerState(xenrt.PowerState.down, timeout=1800) if self.installMethod == xenrt.InstallMethod.IsoWithAnswerFile: self.cleanupIsoAnswerfile() self.parent._osParent_ejectIso() self.parent._osParent_start() self.waitForBoot(600)
def waitForHostState(self, podid, state, timeout=300, pollPeriod=20): """Wait for all Hosts (associated with the Pod) to reach the specified state""" allHostsReachedState = False startTime = datetime.now() while (datetime.now() - startTime).seconds < timeout: hostData = self.cloud.marvin.cloudApi.listHosts(type='Routing', podid=podid) allHypervisorsUp = True for host in hostData: if host.hypervisor == 'XenServer': try: h = filter(lambda x:x.getName() == host.name, self.getAllHosts())[0] h.checkHealth() except Exception, e: xenrt.TEC().logverbose('Health check for host: %s failed' % (host.name)) allHypervisorsUp = False hostsNotInState = filter(lambda x:x.state != state, hostData) if len(hostsNotInState) == 0 and allHypervisorsUp: allHostsReachedState = True break if len(hostsNotInState) > 0: xenrt.TEC().logverbose('Waiting for the following Hosts to reach state %s: %s' % (state, pformat(map(lambda x:(x.name, x.state), hostsNotInState)))) self.logCloudHostInfo() xenrt.sleep(pollPeriod)
def waitForReady(self, timeout=600, pollPeriod=20): """This method check the CP host state, CP System VM state and checks that the agent is running""" isReady = False startTime = datetime.now() msAgentState = None msVMState = None agentRunning = None while (datetime.now() - startTime).seconds < timeout: systemVmData = self.getSystemVMData() if msVMState != systemVmData.state: xenrt.TEC().logverbose('[%s] MS VM state changed from %s to %s' % (self.name, msVMState, systemVmData.state)) msVMState = systemVmData.state hostData = self.getManSvrVMData() if msAgentState != hostData.state: xenrt.TEC().logverbose('[%s] MS Agent state changed from %s to %s' % (self.name, msAgentState, hostData.state)) msAgentState = hostData.state running = self.isAgentRunning() if agentRunning != running: xenrt.TEC().logverbose('[%s] Agent transitioned from Running: %s to Running: %s' % (self.name, agentRunning, running)) agentRunning = running if msVMState == 'Running' and msAgentState == 'Up' and agentRunning: xenrt.TEC().logverbose('System VM [%s] reached ready state in %d seconds' % (self.name, (datetime.now() - startTime).seconds)) isReady = True break xenrt.sleep(pollPeriod) if not isReady: raise xenrt.XRTFailure('System VM [%s] failed to reach ready state in %d seconds' % (self.name, timeout))
def run(self, arglist=None): xapiRdpObj = XapiRdp(self.guest) # Enable RDP on the guest if not xapiRdpObj.enableRdp(): raise xenrt.XRTFailure("XAPI failed to enable the RDP on the guest %s with tools installed" % (self.guest)) xenrt.TEC().logverbose("XAPI successfully enabled the RDP for the guest: %s " % (self.guest)) # win_guest_agent takes at max 10 seconds to update RDP status change to XAPI xenrt.sleep(10) if not xapiRdpObj.isRdpEnabled(): raise xenrt.XRTFailure("Guest agent does not updated data/ts about the RDP status change for the guest %s " % (self.guest)) xenrt.TEC().logverbose("Guest agent updated the RDP status in data/ts successfully for the guest %s" % (self.guest)) # Disable the RDP on the guest step("Test trying to disable RDP on the guest by setting windows registry key fDenyTSConnections to 1") self.guest.winRegAdd('HKLM', 'System\\CurrentControlSet\\Control\\Terminal Server\\', 'fDenyTSConnections',"DWORD", 1) xenrt.sleep(10) if xapiRdpObj.isRdpEnabled(): raise xenrt.XRTFailure("Guest agent does not updated data/ts about the RDP status change for the guest %s " % (self.guest)) xenrt.TEC().logverbose("Guest agent updated the RDP status in data/ts successfully for the guest %s" % (self.guest)) self.guest.checkHealth()
def run(self): xenrt.sleep(90) self.shutdownAllVMs() while self.getAvailableSpace(self.sr): xenrt.TEC().logverbose( "Starting to move vdis to generate IO on SR %s" % self.sr) vdis = self.cli.execute( "vdi-list", "name-label=\"Created by XenRT\" sr-uuid=%s --minimal" % self.sr).strip() xenrt.TEC().logverbose( "Found the following vdis to be moved - %s " % vdis) if not vdis: sys.exit() try: vdis = vdis.split(",") for uuid in vdis: newvdi = self.cli.execute( "vdi-copy", "sr-uuid=%s uuid=%s" % (self.sr, uuid)).strip() self.created.append(newvdi) xenrt.sleep(20) xenrt.TEC().logverbose("Created so many vdis - %s " % self.created) if len(self.created) > 10: # Delete vdis self.deleteVDIs() except SystemExit, e: xenrt.log("Thread is here, it is a stale thread") return except Exception, e: xenrt.TEC().logverbose("Caught exception in thread " + str(e)) # Delete all the created vdis to create more space self.deleteVDIs()
def run(self, arglist=None): host = self.getDefaultHost() host.execdom0("xe-enable-all-plugin-metrics true") self.guest.workloads = self.guest.startWorkloads(self.WORKLOADS) xenrt.sleep(10) xenrt.TEC().logverbose("Check rrd2csv iops_total output.") host.execdom0("nohup rrd2csv iops_total_%s > iopslog.txt &" % (self.sr[0].split('-')[0])) xenrt.sleep(60) host.execdom0("pkill rrd2csv") self.guest.stopWorkloads(self.guest.workloads) results = [] try: for i in range(int(host.execdom0("cat iopslog.txt | wc -l"))-1): parsedReply = host.execdom0("head -%s iopslog.txt | tail -1" % (str(i+2))).split('Z, ')[1] # Unexpected result in log sometimes. if parsedReply != 'N/A': iops = float(parsedReply) results.append(iops) except Exception, e: if "list index out of range" in str(e): raise xenrt.XRTFailure("iops_total metric not found: %s" % (str(e))) else: raise xenrt.XRTFailure("Exception occured while fetching iops_total metric.. %s" % (str(e)))
def _pingServer(self,trigger,server): startTime = datetime.datetime.now().time() trigger.execute() xenrt.sleep(60) pinged = server.isPinged(startTime) xenrt.TEC().logverbose("-----Server was pinged: %s-----"%str(pinged)) return pinged
def run(self, arglist): host = self.getHost("RESOURCE_HOST_0") host.melioHelper.checkMount("/mnt") for i in range(20): xenrt.sleep(30) host.execdom0("python %s/remote/sparsewrite.py /mnt 1000" % xenrt.TEC().lookup("REMOTE_SCRIPTDIR"))
def installAgent(self): """Install agent on vm""" if not self.__agentVM: raise xenrt.XRTError("Agent VM is not assigned.") self.__agentVM.setState("UP") url = self.__getAgentURL() if url.endswith(".deb"): self.__executeOnAgent("wget %s -O agent.deb" % url) try: self.__executeOnAgent("dpkg -i agent.deb") except: # SSH command failure can be ignored. # installation will be verified in code below. pass elif url.endswith(".bin"): self.__executeOnAgent("wget %s -O agent.bin" % url) try: self.__executeOnAgent("chmod +x agent.bin; ./agent.bin") except: # SSH command failure can be ignored. # installation will be verified in code below. pass else: raise xenrt.XRTError("Unknown agent format") # Try and find the nodeid (this may take some time) starttime = xenrt.util.timenow() nodeid = None while nodeid is None: if (xenrt.util.timenow() - starttime) > 600: raise xenrt.XRTError( "Cannot find connector in node API after 10 minutes") xenrt.sleep(30) nodes = [] offset = 0 while True: newnodes = self.apiHandler.execute(category="nodes", params={ 'offset': offset, 'status': 'online' }) nodes.extend(newnodes) if len(newnodes) < 100: # We get max 100 per request, so if we got less than 100 we know we've now run out of nodes break offset += 100 xenrt.sleep(5) # This is to avoid spamming SX with requests for node in nodes: for attr in node["nodeAttrList"]: if attr["attributeName"] == "ip" and attr[ "attributeValue"] == self.agentIP: nodeid = node["nodeId"] break else: continue break self.__nodeid = nodeid
def _pollForCompletion(self): # Wait until we see a reduction in uptime deadline = xenrt.util.timenow() + 3600 while True: self.instance.os.waitForDaemon(deadline - xenrt.util.timenow()) try: newUptime = self.instance.os.uptime if newUptime < self.vmuptime: break except: pass if xenrt.util.timenow() > deadline: raise xenrt.XRTError("VM did not reboot") xenrt.sleep(30) # Now wait for the necessary XenStore key to appear while True: try: if self.instance.os.xenstoreRead( "attr/PVAddons/Installed").strip() == "1": xenrt.TEC().logverbose( "Found PVAddons evidence, sleeping 5 seconds to allow Xapi to settle" ) xenrt.sleep(5) break except: pass if xenrt.util.timenow() > deadline: raise xenrt.XRTError("Couldn't find PV driver evidence")
def postLicenseApplyAction(self): sampleGuest = self.getGuest("linux") host = sampleGuest.host licenseInfo = host.getLicenseDetails() expiry = xenrt.util.parseXapiTime(licenseInfo['expiry']) oldexpiry = time.gmtime(expiry) licensefile = "valid-persocket-expire-later" self.v6.addLicense(licensefile) host.execdom0("echo 300 > /tmp/fist_set_reapply_period") host.restartToolstack() xenrt.sleep(600) self.verifySystemLicenseState(licensed=True) licenseInfo = host.getLicenseDetails() expiry = xenrt.util.parseXapiTime(licenseInfo['expiry']) newexpiry = time.gmtime(expiry) if newexpiry <= oldexpiry: raise xenrt.XRTFailure("Host is still licensed with old license") try: sampleGuest.reboot() except Exception as e: raise xenrt.XRTFailure("Exception occurred while restarting VM")
def setupMelioDisk(self): # Setup a melio disk on the scsi device disk = self.hosts[0].execdom0("realpath %s" % self.device).strip()[5:] with self.getMelioClient(self.hosts[0]) as melioClient: deadline = xenrt.timenow() + 600 while True: data = melioClient.get_all() unmanaged = data.get('unmanaged_disk') xenrt.TEC().logverbose("Unmanaged disks: %s" % json.dumps(unmanaged, indent=2)) if unmanaged: disksToManage = [x for x in unmanaged if x['system_name'] == disk] else: disksToManage = [] if disksToManage: diskToManage = disksToManage[0] break if xenrt.timenow() > deadline: raise xenrt.XRTError("Timed out waiting for disk to appear") xenrt.sleep(10) melioClient.manage_disk(diskToManage['system_name']) deadline = xenrt.timenow() + 600 while True: managedDisks = melioClient.get_all()['managed_disk'] guid = [x for x in managedDisks.keys() if managedDisks[x]['system_name'] == disk][0] if int(managedDisks[guid]['state']) == 2: break if xenrt.timenow() > deadline: raise xenrt.XRTError("Timed out waiting for disk to get to state 2") xenrt.sleep(10) self.guid = melioClient.create_volume(guid.lstrip("_"), managedDisks[guid]['free_space']) self.getSanDeviceForHost(self.hosts[0]) tasks = [xenrt.PTask(self.rebootAndWait, x) for x in self.hosts[1:]] xenrt.pfarm(tasks)
def snmp(self,value): if len(self.pdus) == 0: raise xenrt.XRTError("No PDU found for %s" % (self.machine.name)) for p in self.pdus: (address, comm, oidbase, pduport, values) = p command = "snmpset -v1 -c %s %s %s.%s i %d" % \ (comm, address, oidbase, pduport, values[value]) pdulock = xenrt.resources.CentralResource() attempts = 0 while True: try: pdulock.acquire("SNMP_PDU") break except: xenrt.sleep(10) attempts += 1 if attempts > 6: raise xenrt.XRTError("Couldn't get SNMP PDU lock.") try: attempts = 0 while True: try: self.command(command) break except Exception, e: if self.verbose: sys.stderr.write("SNMP failed, waiting 30 seconds before retry\n") attempts += 1 if attempts >= 3: raise xenrt.sleep(30) finally: pdulock.release()
def checkCluster(self): # Check every host can see every other host in the cluster if len(self.hosts) == 1: return deadline = xenrt.timenow() + 600 while True: ready = True for checkHost in self.hosts: with self.getMelioClient(checkHost) as melioClient: # See which other servers we're connected to servers = melioClient.get_all()['network_session'] # We don't always get a dictionary back if it's empty if not isinstance(servers, dict): ready = False else: # Check we're connected to every other host (except ourselves) for expectedHost in self.hosts: if expectedHost == checkHost: continue if not expectedHost.getName() in [x['computer_name'] for x in servers.values()]: ready = False # No point in continuing break if not ready: # No point in continuing break if ready: # All done break if xenrt.timenow() > deadline: raise xenrt.XRTError("Timed out waiting for all of the cluster to appear") # Sleep for 20 seconds before trying again xenrt.sleep(20)
def createWindowsVM(self, host, distro="win7-x64", memory=4000, arch="x86-64", disksize=28843545600, srtype="DEFAULT", waitForStart=False): """Trigger a windows install without having to wait for it to install completely""" if not waitForStart: template = xenrt.lib.xenserver.getTemplate(host, distro=distro, arch=arch) xenrt.TEC().logverbose("Setup for %s" % (distro)) guest=host.createGenericEmptyGuest(memory=memory, name=xenrt.randomGuestName()) device=guest.createDisk(sizebytes=disksize, bootable=True, sruuid=srtype) guest.changeCD(distro + ".iso") guest.start() # Allow some time for the vm to start xenrt.sleep(20) else: device=0 disksize=disksize/xenrt.MEGA guest=host.createGenericWindowsGuest(sr=srtype, distro=distro,disksize=disksize,memory=memory) if self.INTELLICACHE: cli=host.getCLIInstance() if guest.getState() != "DOWN": guest.shutdown(force=True) vbd=cli.execute("vbd-list", "userdevice=%s vm-uuid=%s --minimal" % (device, guest.uuid)).strip() vdi=cli.execute("vdi-list","vbd-uuids=%s --minimal" % vbd).strip() cli.execute("vdi-param-set","allow-caching=true uuid=%s" % vdi) guest.start()
def enableNonDefaultDS(self, host): xenrt.TEC().logverbose( "Get the number of data sources in a fresh install") numBeforeEnable = self.getNumberofDS(host=host) xenrt.TEC().logverbose( "The number of data sources in a fresh install is %s" % numBeforeEnable) # Enable the non-default DS, the number should then go up host.execdom0("xe-enable-all-plugin-metrics true") # Sleep for sometime to let the changes take effect xenrt.sleep(120) numAfterEnable = self.getNumberofDS(host) xenrt.TEC().logverbose( "The number of data sources when non-default DS enabled is %s" % numAfterEnable) com = [] noncom = [] # Compare the ones that are same and print the extra metrics newDSList = self.getDSList(host=host) for item in newDSList: if item in self.dsList: com.append(item) else: noncom.append(item) xenrt.TEC().logverbose( "The extra DS after enabling the epic metrics are %s " % noncom) if not noncom and numAfterEnable <= numBeforeEnable: raise xenrt.XRTFailure( "No extra data sources found after anabling the non-default metrics" )
def run(self, arglist=None): # We can't use start() as this expects a VM to boot and do 'normal' things self.guest.lifecycleOperation("vm-start", timeout=30) domid = self.guest.getDomid() qpid = self.host.xenstoreRead("/local/domain/%u/qemu-pid" % domid) starttime = xenrt.util.timenow() while True: if xenrt.util.timenow() - starttime > 1800: raise xenrt.XRTError("Timed out waiting for XSA-133 test") qemuRunning = (self.host.execdom0("test -d /proc/%s" % (qpid), retval="code") == 0) state = self.guest.getState() # Check if we have a successful run data = self.host.execdom0("grep qemu-dm-%s /var/log/messages /var/log/daemon.log || true" % (domid)) if "XSA-133 PoC done - not vulnerable" in data: xenrt.TEC().logverbose("Test completed successfully") break if state == "DOWN" or not qemuRunning: raise xenrt.XRTFailure("Host appears vulnerable to XSA-133") xenrt.sleep(30)
def run(self, arglist=None): host = self.getDefaultHost() host.execdom0("xe-enable-all-plugin-metrics true") self.guest.workloads = self.guest.startWorkloads(self.WORKLOADS) xenrt.sleep(10) xenrt.TEC().logverbose("Check rrd2csv iops_total output.") host.execdom0("nohup rrd2csv iops_total_%s > iopslog.txt &" % (self.sr[0].split('-')[0])) xenrt.sleep(60) host.execdom0("pkill rrd2csv") self.guest.stopWorkloads(self.guest.workloads) results = [] try: for i in range(int(host.execdom0("cat iopslog.txt | wc -l")) - 1): parsedReply = host.execdom0("head -%s iopslog.txt | tail -1" % (str(i + 2))).split('Z, ')[1] # Unexpected result in log sometimes. if parsedReply != 'N/A': iops = float(parsedReply) results.append(iops) except Exception, e: if "list index out of range" in str(e): raise xenrt.XRTFailure("iops_total metric not found: %s" % (str(e))) else: raise xenrt.XRTFailure( "Exception occured while fetching iops_total metric.. %s" % (str(e)))
def run(self, arglist=None): xapiRdpObj = XapiRdp(self.guest) #Disable RDP self.guest.winRegAdd( 'HKLM', 'System\\CurrentControlSet\\Control\\Terminal Server\\', 'fDenyTSConnections', "DWORD", 1) xenrt.sleep(10) # Check that XAPI can switch RDP with tools installed if not xapiRdpObj.enableRdp(): raise xenrt.XRTFailure( "XAPI failed to enable the RDP on the guest %s with tools installed " % (self.guest)) xenrt.TEC().logverbose( "XAPI successfully enabled the RDP for the guest: %s " % (self.guest)) # win_guest_agent takes at max 10 seconds to update RDP status to data/ts xenrt.sleep(10) # Ensure that data/ts updated with latest RDP status if not xapiRdpObj.isRdpEnabled(): raise xenrt.XRTFailure( "Guest agent does not updated data/ts about the RDP status change for the guest %s " % (self.guest)) xenrt.TEC().logverbose( "Guest agent updated the RDP status in data/ts successfully for the guest %s" % (self.guest))
def _installVCenter(self): isoUrl=xenrt.TEC().lookup(["VCENTER","ISO","_%s" % self.vCenterVersion.upper()]) isoName = isoUrl.rsplit("/",1)[1] if isoName not in self.guest.host.findISOs(): srPath = None isoPath=xenrt.TEC().getFile(isoUrl) isoPath = xenrt.command("readlink -f %s" % isoPath).strip() if xenrt.command("stat --file-system --format=%%T %s" % isoPath).strip()=="nfs": nfsMountInfo=xenrt.command("df %s" % isoPath).strip().split("\n")[-1].split(" ") # nfsMountInfo will look like ['10.220.254.45:/vol/xenrtdata/cache', '2147483648', '1678503168', '468980480', '', '79%', '/misc/cache_nfs'] srPath=isoPath.rsplit("/",1)[0].replace(nfsMountInfo[-1], nfsMountInfo[0]) else: ip=xenrt.command("/sbin/ifconfig eth0 | grep 'inet addr' | awk -F: '{print $2}' | awk '{print $1}'" ).strip() srPath=ip+":"+isoPath.rsplit("/",1)[0] self.guest.host.createISOSR(srPath) self.guest.changeCD(isoName) xenrt.sleep(30) if "ws12" in self.guest.distro and "5.5" in self.vCenterVersion: self._installVCenter55onWs12() else: raise xenrt.XRTError("Unimplemented") self.guest.changeCD(None) self._installpowerCLI()
def reconfigureToStatic(self, ad=False): data = self.getWindowsIPConfigData() ifname = [ x for x in data.keys() if data[x].has_key('IPv4 Address') and ( data[x]['IPv4 Address'] == self.machine.ipaddr or data[x] ['IPv4 Address'] == "%s(Preferred)" % self.machine.ipaddr) ][0] netcfg = xenrt.TEC().lookup(["NETWORK_CONFIG", "DEFAULT"]) cmd = "netsh interface ip set address \"%s\" static %s %s %s 1" % ( ifname, self.machine.ipaddr, data[ifname]['Subnet Mask'], [ x for x in data[ifname]['Default Gateway'].split() if re.match("\d+\.\d+\.\d+\.\d+", x) ][0]) ref = self.xmlrpcStart(cmd) deadline = xenrt.timenow() + 120 while True: try: if self.xmlrpcPoll(ref): break except: pass if xenrt.timenow() > deadline: raise xenrt.XRTError("Timed out setting IP to static") xenrt.sleep(5) if ad: dns = xenrt.getADConfig().dns else: dns = xenrt.TEC().config.lookup("XENRT_SERVER_ADDRESS") cmd = "netsh interface ipv4 add dnsservers \"%s\" %s" % (ifname, dns) self.xmlrpcExec(cmd)
def reconfigureToStatic(self, ad=False): data = self.getWindowsIPConfigData() ifname = [x for x in data.keys() if data[x].has_key('IPv4 Address') and (data[x]['IPv4 Address'] == self.machine.ipaddr or data[x]['IPv4 Address'] == "%s(Preferred)" % self.machine.ipaddr)][0] netcfg = xenrt.TEC().lookup(["NETWORK_CONFIG", "DEFAULT"]) cmd = "netsh interface ip set address \"%s\" static %s %s %s 1" % (ifname, self.machine.ipaddr, data[ifname]['Subnet Mask'], [x for x in data[ifname]['Default Gateway'].split() if re.match("\d+\.\d+\.\d+\.\d+", x)][0]) ref = self.xmlrpcStart(cmd) deadline = xenrt.timenow() + 120 while True: try: if self.xmlrpcPoll(ref): break except: pass if xenrt.timenow() > deadline: raise xenrt.XRTError("Timed out setting IP to static") xenrt.sleep(5) if ad: dns = xenrt.getADConfig().dns else: dns = xenrt.TEC().config.lookup("XENRT_SERVER_ADDRESS") cmd = "netsh interface ipv4 add dnsservers \"%s\" %s" % (ifname, dns) self.xmlrpcExec(cmd)
def callTrimOnSR(self): """Testing TRIM functionality on a storage repository""" spaceUsedByGuests = {} spaceFreedByGuests = {} delta = 5 #CA-179207:Keep delta as 5% space on NetApp lun which is not freed after deleting a VM. # Workaround for CA-139518 # Creating few linux guests. for i in range(1,self.vmsCount+1): step("Creating Guest %s on SR : %s" % (i, self.SRTYPE)) initialUsedSpace = self.lun.sizeUsed() try: vmName = "vm%02d" % i guest = self.goldenVM.copyVM(vmName, sruuid=self.sruuid) # much quicker than installing another one. except Exception, e: raise xenrt.XRTFailure("Cloning vm: %s on %s SR failed with error: %s" % (vmName, self.SRTYPE, str(e))) xenrt.sleep(120) usedSpaceAfter = self.lun.sizeUsed() diff = usedSpaceAfter - initialUsedSpace spaceUsedByGuests.update({guest:[initialUsedSpace,usedSpaceAfter,diff]}) log("TRIM on %s SR: Space used in bytes: Before creating guest %s, After creating guest %s, Difference %s" % (self.SRTYPE, initialUsedSpace,usedSpaceAfter,diff))
def setupWindows(self, index, ips): win = self.getGuest("win%d" % index) if self.shared: iscsitarget = self.getGuest("iscsi") else: iscsitarget = self.getGuest("iscsi%d" % index) iqn = iscsitarget.installLinuxISCSITarget(targetType="LIO") iscsitarget.createISCSITargetLun(lunid=0, sizemb=20*xenrt.KILO) iscsitarget.createISCSITargetLun(lunid=1, sizemb=20*xenrt.KILO) win.installWindowsMelio(renameHost=True) config = win.getWindowsMelioConfig() config['network_settings']['current']['subnet_ranges'] = " ".join(["%s/32" % x for x in ips]) win.reboot() win.writeWindowsMelioConfig(config) win.enablePowerShellUnrestricted() win.xmlrpcExec("$ErrorActionPreference = \"Stop\"\nStart-Service msiscsi", powershell=True) win.xmlrpcExec("$ErrorActionPreference = \"Stop\"\nSet-Service -Name msiscsi -StartupType Automatic", powershell=True) win.xmlrpcExec("$ErrorActionPreference = \"Stop\"\nNew-IscsiTargetPortal -TargetPortalAddress %s" % iscsitarget.mainip, powershell=True) xenrt.sleep(30) win.xmlrpcExec("$ErrorActionPreference = \"Stop\"\nGet-IscsiTarget | Connect-IscsiTarget", powershell=True) xenrt.sleep(30) disks = win.xmlrpcListDisks()[-2:] if int(disks[0]) == 0: raise xenrt.XRTFailure("iSCSI disk has not been connected") win.xmlrpcExec("$ErrorActionPreference = \"Stop\"\nGet-IscsiSession | Register-IscsiSession", powershell=True) if not self.shared: for disk in disks: win.xmlrpcDiskpartCommand("select disk %s\nattributes disk clear readonly\nconvert gpt" % disk)
def waitForHostState(self, podid, state, timeout=300, pollPeriod=20): """Wait for all Hosts (associated with the Pod) to reach the specified state""" allHostsReachedState = False startTime = datetime.now() while (datetime.now() - startTime).seconds < timeout: hostData = self.cloud.marvin.cloudApi.listHosts(type='Routing', podid=podid) allHypervisorsUp = True for host in hostData: if host.hypervisor == 'XenServer': try: h = filter(lambda x: x.getName() == host.name, self.getAllHosts())[0] h.checkHealth() except Exception, e: xenrt.TEC().logverbose( 'Health check for host: %s failed' % (host.name)) allHypervisorsUp = False hostsNotInState = filter(lambda x: x.state != state, hostData) if len(hostsNotInState) == 0 and allHypervisorsUp: allHostsReachedState = True break if len(hostsNotInState) > 0: xenrt.TEC().logverbose( 'Waiting for the following Hosts to reach state %s: %s' % (state, pformat(map(lambda x: (x.name, x.state), hostsNotInState)))) self.logCloudHostInfo() xenrt.sleep(pollPeriod)
def connectToSwitch(self): log("initialising telnet to switch (%s)" % self.ip) i = 0 while True: i += 1 try: self.telnet = Telnet(self.ip, 23, timeout=self.CONNECT_TIMEOUT) break except: if i >= self.CONNECT_ATTEMPTS: raise xenrt.sleep(self.CONNECT_TIMEOUT) log("Connected, sending username") self.telnet.read_until('Username:'******'%s\r' % self.login) log("Sending password") self.telnet.read_until('Password:'******'%s\r' % self.password) log("Waiting for prompt") out = self.telnet.read_until('#', timeout=self.TIMEOUT) re_prompt = re.compile('^([a-zA-Z0-9-]+)#$', re.MULTILINE) m_prompt = re_prompt.search(out) if m_prompt: self.prompt = m_prompt.group(1) else: log("Unexpected output returned by the switch:\n'%s'" % out) raise xenrt.XRTError("Unexpected string returned by the switch") log("Sending enable") self.sendEnable() log("Setting terminal settings") self.command("terminal length 0") self.command("terminal width 0") log("Successfully connected to the switch.")
def setClusterManaged(self, clusterid, managed): self.cloud.marvin.cloudApi.updateCluster( id=clusterid, managedstate=managed and 'Managed' or 'Unmanaged') expectedClusterState = managed and 'Managed' or 'Unmanaged' expectedHostState = managed and 'Up' or 'Disconnected' correctStateReached = False while (not correctStateReached): xenrt.sleep(10) cluster = self.cloud.marvin.cloudApi.listClusters(id=clusterid)[0] xenrt.TEC().logverbose( 'Waiting for Cluster %s, Current state: Managed=%s, Alloc=%s, expected state: %s' % (cluster.name, cluster.managedstate, cluster.allocationstate, expectedClusterState)) hostList = self.cloud.marvin.cloudApi.listHosts( clusterid=clusterid, type='Routing') hostListState = map(lambda x: x.state, hostList) xenrt.TEC().logverbose( 'Waiting for host(s) %s, Current State(s): %s' % (map(lambda x: x.name, hostList), hostListState)) correctStateReached = ( cluster.managedstate == expectedClusterState) if managed and correctStateReached: correctStateReached = len(hostList) == hostListState.count( expectedHostState)
def postLicenseApplyAction(self): guest = self.getGuest("linux") self.affectedHost = guest.host licenseInfo = self.affectedHost.getLicenseDetails() expiry = xenrt.util.parseXapiTime(licenseInfo['expiry']) self.affectedHost.execdom0("service ntpd stop") expiretarget = expiry - 300 expiretarget = time.gmtime(expiretarget) self.affectedHost.execdom0( "date -u %s" % (time.strftime("%m%d%H%M%Y.%S", expiretarget))) self.affectedHost.restartToolstack() xenrt.sleep(900) self.verifySystemLicense() #self.verifyLicenseServer(reset=True) if not self.hotfixStatus(): raise xenrt.XRTFailure( "Hotfix installation is allowed through Xencenter") licenseInfo = self.affectedHost.getLicenseDetails() if '19700101T00:00:00Z' != licenseInfo['expiry']: raise xenrt.XRTFailure( "Host License expiry time is not epoch time") try: guest.reboot() except Exception as e: raise xenrt.XRTFailure("Exception occurred while restarting VM")
def start(self, reboot=False): if reboot: self.lifecycleOperation("vm-reboot") time.sleep(20) else: self.lifecycleOperation("vm-start") xenrt.TEC().progress("Waiting for the VM to enter the UP state") self.poll("UP") xenrt.sleep(5) # get the mac address vifname, bridge, mac, c = self.vifs[0] self.mainip = self.getHost().arpwatch(bridge, mac, timeout=300) if not self.mainip: raise xenrt.XRTFailure("Did not find an IP address.") if self.hasSSH: self.waitForSSH(600, desc="Guest boot") else: self.waitForDaemon(600, desc="Guest boot") if not self.tailored: # Tailor the VM for future test use. xenrt.TEC().progress("Tailoring the VM for test use.") self.tailor() self.tailored = True
def installLegacyTools(self, reboot=False, updateKernel=True): self.insertToolsCD() # Assume that the CD drive is at /dev/sr0 in the VM device = "sr0" mountpoint = "/mnt" self.execguest("mkdir -p %s || true" % (mountpoint)) installed = False for dev in [device, device, "cdrom"]: try: self.execguest("mount /dev/%s %s" % (dev, mountpoint)) installed = True break except: xenrt.TEC().warning( "Mounting tools ISO failed on the first attempt.") xenrt.sleep(30) if not installed: raise xenrt.XRTFailure("Couldn't mount tools ISO") # Install linux headers self.installKernelHeaders() # Run the VMware tools installer unpackdir = self.execguest("mktemp -d").strip() self.execguest("cd %s && tar xvfz %s/VMwareTools*.tar.gz" % (unpackdir, mountpoint)) output = self.execguest( "cd %s/vmware-tools-distrib && ./vmware-install.pl -d" % (unpackdir)) # '-d' means accept all defaults xenrt.TEC().logverbose("vmware tools installation output: %s" % (output)) self.execguest("rm -rf %s" % (unpackdir))
def waitForSSH(self, timeout, level=xenrt.RC_FAIL, desc="Operation", username="******", cmd="true"): now = xenrt.util.timenow() deadline = now + timeout while 1: if not self.password: self.findPassword() if xenrt.ssh.SSH(self.getIP(trafficType="SSH"), cmd, port=self.getPort(trafficType="SSH"), password=self.password, level=xenrt.RC_OK, timeout=20, username=username, nowarn=True) == xenrt.RC_OK: xenrt.TEC().logverbose(" ... OK reply from %s:%s" % (self.getIP(trafficType="SSH"), self.getPort(trafficType="SSH"))) return xenrt.RC_OK now = xenrt.util.timenow() if now > deadline: # if level == xenrt.RC_FAIL: # self.checkHealth(unreachable=True) return xenrt.XRT("%s timed out" % (desc), level) xenrt.sleep(15, log=False)
def run(self, arglist=None): self.guest.lifecycleOperation("vm-start", timeout=30) domId = self.guest.getDomid() qPid = self.host.xenstoreRead("/local/domain/%u/qemu-pid" % domId) startTime = xenrt.util.timenow() while True: if xenrt.util.timenow() - startTime > 1800: raise xenrt.XRTError("Timed out waiting for XSA-138 test") qemuRunning = (self.host.execdom0("test -d /proc/%s" % (qPid), retval="code") == 0) state = self.guest.getState() # Check if we have a successful run data = self.host.execdom0( "grep qemu-dm-%s /var/log/messages /var/log/daemon.log || true" % (domId)) if "XSA-138 PoC done - probably not vulnerable" in data and state == "DOWN": xenrt.TEC().logverbose("Test completed successfully") break if not qemuRunning: raise xenrt.XRTFailure("Host appears vulnerable to XSA-138") xenrt.sleep(30)
def on(self): xenrt.TEC().logverbose("Turning on machine %s" % (self.machine.name)) # Wait a random delay to try to avoid power surges when testing # with multiple machines. if self.antiSurge: xenrt.sleep(random.randint(0, 20)) self.ilo("on")
def _pingServer(self, trigger, server): startTime = datetime.datetime.now().time() trigger.execute() xenrt.sleep(60) pinged = server.isPinged(startTime) xenrt.TEC().logverbose("-----Server was pinged: %s-----" % str(pinged)) return pinged
def prioMsgEmailChk(self, host, pool, testname, testPriority, isReceived, mailMinPriority= None): # Set other-config:mail-min-priority to options.get("mail-min-priority") if mailMinPriority != None: pool.setPoolParam("other-config:mail-min-priority", mailMinPriority) # Create a message of priority level 'priority' host.messageCreate(testname, "Test message (priority %d)" % testPriority, priority=testPriority) #wait then check for mail and clear mailbox. xenrt.sleep(30) mail = self.smtpServer.getMail() self.smtpServer.clearMail() if isReceived == True: # verify an email is received if len(mail) == 0: raise xenrt.XRTFailure("%s : No email sent for priority %d message" % (testname, testPriority)) elif len(mail) > 1: raise xenrt.XRTFailure("%s : Received multiple emails for one message" % testname) self.check(host, mail[0], testname) else: # verify email is not recieved if len(mail) > 0: raise xenrt.XRTFailure("%s : Received email for priority %d message" % (testname, testPriority))
def disableLicenseServer(self): """Disconnect license server""" self.v6.stop() xenrt.sleep(120) # Restart toostack on every hosts. [host.restartToolstack() for host in self.hosts]
def run(self): xenrt.sleep(90) self.shutdownAllVMs() while self.getAvailableSpace(self.sr): xenrt.TEC().logverbose("Starting to move vdis to generate IO on SR %s" % self.sr) vdis=self.cli.execute("vdi-list", "name-label=\"Created by XenRT\" sr-uuid=%s --minimal" % self.sr ).strip() xenrt.TEC().logverbose("Found the following vdis to be moved - %s " % vdis) if not vdis: sys.exit() try: vdis=vdis.split(",") for uuid in vdis: newvdi=self.cli.execute("vdi-copy", "sr-uuid=%s uuid=%s" % (self.sr, uuid)).strip() self.created.append(newvdi) xenrt.sleep(20) xenrt.TEC().logverbose("Created so many vdis - %s " % self.created) if len(self.created) > 10: # Delete vdis self.deleteVDIs() except SystemExit, e: xenrt.log("Thread is here, it is a stale thread") return except Exception, e: xenrt.TEC().logverbose("Caught exception in thread " + str(e)) # Delete all the created vdis to create more space self.deleteVDIs()
def snmp(self, value): if len(self.pdus) == 0: raise xenrt.XRTError("No PDU found for %s" % (self.machine.name)) for p in self.pdus: (address, comm, oidbase, pduport, values) = p command = "snmpset -v1 -c %s %s %s.%s i %d" % \ (comm, address, oidbase, pduport, values[value]) pdulock = xenrt.resources.CentralResource() attempts = 0 while True: try: pdulock.acquire("SNMP_PDU") break except: xenrt.sleep(10) attempts += 1 if attempts > 6: raise xenrt.XRTError("Couldn't get SNMP PDU lock.") try: attempts = 0 while True: try: self.command(command) break except Exception, e: if self.verbose: sys.stderr.write( "SNMP failed, waiting 30 seconds before retry\n" ) attempts += 1 if attempts >= 3: raise xenrt.sleep(30) finally: pdulock.release()
def __init__(self, device, options=None, mtype=None, retry=True): self.mounted = 0 exceptiondata = None try: self.mountpoint = tempfile.mkdtemp("", "xenrt", "/tmp") xenrt.TEC().logverbose("Created mountpoint %s" % (self.mountpoint)) xenrt.TEC().gec.registerCallback(self) os.chmod(self.mountpoint, stat.S_IRWXU | stat.S_IRWXG | stat.S_IROTH | stat.S_IXOTH) for i in range(6): cmd = ["sudo", "mount"] if options: cmd.append("-o%s" % (options)) if mtype: cmd.append("-t %s" % (mtype)) cmd.append(device) cmd.append(self.mountpoint) try: xenrt.util.command(string.join(cmd)) self.mounted = 1 except xenrt.XRTFailure, e: exceptiondata = e.data if self.mounted == 1: break if not retry: break # wait a bit then try again xenrt.sleep(120) if not self.mounted: xenrt.TEC().logverbose("Error mounting %s at %s" % (device, self.mountpoint)) raise xenrt.XRTError("Unable to mount %s" % (device), exceptiondata) xenrt.TEC().logverbose("Mounted %s at %s" % (device, self.mountpoint))
def prepare(self, arglist=None): #Get the Host 0 self.targetHost = self.getHost("RESOURCE_HOST_0") self.host0 = self.getHost("RESOURCE_HOST_1") self.MAXLUNS = int(self.host0.lookup("MAX_MULTIPATH_LUN")) self.CONCURRENT_MAXLUNS = int(self.host0.lookup("CONCURRENT_MAX_MULTIPATH_LUN")) #Loop created to have MAXLUNS luns for i in range(self.MAXLUNS): #This will create an iSCSI VM along with LUNS lun = xenrt.ISCSIVMLun(sizeMB = self.LUNSIZE, totalSizeMB = (self.MAXLUNS * self.LUNSIZE)) self.LUNs.append(lun) #This will take the instance of SR for host0 sr = xenrt.lib.xenserver.ISCSIStorageRepository(self.host0, "iscsi%d" % i) self.SRs.append(sr) #This will attach the iSCSI SR to the host0 sr.create(lun, subtype="lvm", multipathing=True, noiqnset=True, findSCSIID=True) pbd = self.host0.parseListForUUID("pbd-list", "sr-uuid", sr.uuid, "host-uuid=%s" % (self.host0.getMyHostUUID())) scsiID = self.host0.genParamGet("pbd", pbd, "device-config", "SCSIid") xenrt.sleep(60) #Check Multipathing mp = self.host0.getMultipathInfo() if len(mp[scsiID]) != self.MAXPATHS: raise xenrt.XRTError("Only found %u/%u paths in multipath output" % (len(mp[scsiID]),self.MAXPATHS)) #Check the multiple active paths mp = self.host0.getMultipathInfo(onlyActive=True) if len(mp[scsiID]) != self.MAXPATHS: raise xenrt.XRTError("Only %u/%u paths active before test started" % (len(mp[scsiID]),self.MAXPATHS))
def on(self): xenrt.TEC().logverbose("Turning on machine %s" % (self.machine.name)) # Some ILO controllers have broken serial on boot if xenrt.TEC().lookupHost( self.machine.name, "SERIAL_DISABLE_ON_BOOT", False, boolean=True) and self.machine.consoleLogger: self.machine.consoleLogger.pauseLogging() # Wait a random delay to try to avoid power surges when testing # with multiple machines. if xenrt.TEC().lookupHost( self.machine.name, "IPMI_IGNORE_STATUS", False, boolean=True) or self.getPower() != "on": if xenrt.TEC().lookupHost(self.machine.name, "IPMI_SET_PXE", True, boolean=True): try: self.setBootDev("pxe", True) except: xenrt.TEC().logverbose( "Warning: failed to set boot dwvice to PXE") if self.antiSurge: xenrt.sleep(random.randint(0, 20)) self.ipmi("chassis power on")
def waitForTemplateReady(self, name, zoneId=None): templateReady = False startTime = datetime.now() timeout = 1800 while ((datetime.now() - startTime).seconds < timeout): templateList = self.cloudApi.listTemplates(templatefilter='all', name=name, zoneid=zoneId) if not templateList: xenrt.TEC().logverbose('Template %s not found' % (name)) elif len(templateList) == 1: xenrt.TEC().logverbose( 'Template %s, is ready: %s, status: %s' % (name, templateList[0].isready, templateList[0].status)) templateReady = templateList[0].isready if templateReady: break if templateList[0].hypervisor.lower() == "hyperv": # CS-20595 - Hyper-V downloads are very slow timeout = 10800 else: raise xenrt.XRTFailure('>1 template found with name %s' % (name)) xenrt.sleep(60) if not templateReady: raise xenrt.XRTFailure('Timeout expired waiting for template %s' % (name)) xenrt.TEC().logverbose('Template %s ready after %d seconds' % (name, (datetime.now() - startTime).seconds))
def waitForTemplateReady(self, name, zoneId=None): templateReady = False startTime = datetime.now() timeout = 1800 while((datetime.now() - startTime).seconds < timeout): templateList = self.cloudApi.listTemplates(templatefilter='all', name=name, zoneid=zoneId) if not templateList: xenrt.TEC().logverbose('Template %s not found' % (name)) elif len(templateList) == 1: xenrt.TEC().logverbose('Template %s, is ready: %s, status: %s' % (name, templateList[0].isready, templateList[0].status)) templateReady = templateList[0].isready if templateReady: break if templateList[0].hypervisor.lower() == "hyperv": # CS-20595 - Hyper-V downloads are very slow timeout = 10800 else: raise xenrt.XRTFailure('>1 template found with name %s' % (name)) xenrt.sleep(60) if not templateReady: raise xenrt.XRTFailure('Timeout expired waiting for template %s' % (name)) xenrt.TEC().logverbose('Template %s ready after %d seconds' % (name, (datetime.now() - startTime).seconds))
def run(self,arglist=None): host = self.getDefaultHost() sessions_open = {} max_iterations = 10 count = 0 values = [] #Stores the number of sessions found open at every iteration step("Checking the number of open sessions every 20 minutes") for i in range(max_iterations): #Define the number of iterations xenrt.sleep(1200) #20 minutes of sleep step("Iteration number: %d" %(i+1)) log("Checking which sessions get created in iteration %d" %(i+1)) sessions_started = host.execdom0("grep 'Session.create.*uname=__dom0__vmpr' /var/log/xensource.log | true") for entry in sessions_started.strip().splitlines(): track = re.search("trackid=(?P<id>[a-z0-9]+)", entry) if not sessions_open.has_key(track.group('id')): sessions_open[track.group('id')] = "open" count = count+1 log("Checking which sessions are closed in iteration %d" %(i+1)) for session in sessions_open: if sessions_open[session] == "open" and not host.execdom0("grep 'Session.destroy trackid=%s' /var/log/xensource.log" %session, retval="code"): #The session has been successfully closed sessions_open[session] = "closed" count = count-1 log("At the end of iteration %d, noticed that %d number of vmpr sessions are still open" %(i+1, count)) values.append(count) #If the number of open sessions grows over time then we can say there's a leak. leak = True for i in range(1,len(values)): leak = leak and values[i]>values[i-1] #Check if the list is strictly increasing if leak: raise xenrt.XRTFailure("VMPR sessions leaked")
def _pollForCompletion(self): # Wait until we see a reduction in uptime deadline = xenrt.util.timenow() + 3600 while True: self.instance.os.waitForDaemon(deadline - xenrt.util.timenow()) try: newUptime = self.instance.os.uptime if newUptime < self.vmuptime: break except: pass if xenrt.util.timenow() > deadline: raise xenrt.XRTError("VM did not reboot") xenrt.sleep(30) # Now wait for the necessary XenStore key to appear while True: try: if self.instance.os.xenstoreRead("attr/PVAddons/Installed").strip() == "1": xenrt.TEC().logverbose("Found PVAddons evidence, sleeping 5 seconds to allow Xapi to settle") xenrt.sleep(5) break except: pass if xenrt.util.timenow() > deadline: raise xenrt.XRTError("Couldn't find PV driver evidence")