示例#1
0
文件: stress.py 项目: thomassa/xenrt
    def run(self, arglist=None):

        i = 0
        try:
            while i < self.ITERATIONS:
                xenrt.TEC().logdelimit("reboot loop iteration %u" % (i))
                self.guest.reboot()
                i = i + 1
                if xenrt.GEC().abort:
                    xenrt.TEC().warning("Aborting on command")
                    break
        finally:
            xenrt.TEC().comment("%u/%u reboot iterations successful" %
                                (i, self.ITERATIONS))

        i = 0
        try:
            while i < self.ITERATIONS:
                xenrt.TEC().logdelimit("start/stop loop iteration %u" % (i))
                self.guest.shutdown()
                self.guest.start()
                i = i + 1
                if xenrt.GEC().abort:
                    xenrt.TEC().warning("Aborting on command")
                    break
        finally:
            xenrt.TEC().comment("%u/%u start/stop iterations successful" %
                                (i, self.ITERATIONS))

        self.guest.shutdown()
示例#2
0
def getFileManager(basevar="INPUTDIR", remote=False):
    """Return a file manager object suitable for the local site."""
    id = xenrt.TEC().lookup(basevar, "")
    if id[0:7] == "http://":
        return RemoteFileManager(basevar=basevar)
    elif remote:
        urlpref = xenrt.TEC().lookup("FORCE_HTTP_FETCH", "")
        forceremotehttp = xenrt.TEC().lookup("FORCE_REMOTE_HTTP",
                                             False,
                                             boolean=True)
        if urlpref and len(id) > 0 and id[0] == "/":
            xenrt.GEC().config.setVariable(basevar, "%s%s" % (urlpref, id))
            r = RemoteFileManager(basevar=basevar)
            r.forceHTTPHack = True
            return r
        elif urlpref and forceremotehttp:
            xenrt.GEC().config.setVariable(basevar, urlpref)
            r = RemoteFileManager(basevar=basevar)
            r.forceHTTPHack = True
            return r
        elif xenrt.TEC().lookup("FORCE_LOCAL_FETCH", False, boolean=True):
            return FileManager(basevar=basevar)
        else:
            return RemoteFileManager(basevar=basevar)
    else:
        return FileManager(basevar=basevar)
示例#3
0
    def getNetworkDevices(self, key, ref):
        ret = None
        if ref.has_key('XRT_NetscalerVM'):
            networks = ref['XRT_NetscalerNetworks']
            netscaler = xenrt.lib.netscaler.NetScaler.setupNetScalerVpx(
                ref['XRT_NetscalerVM'], networks=networks)
            xenrt.GEC().registry.objPut("netscaler", ref['XRT_NetscalerVM'],
                                        netscaler)
            xenrt.GEC().registry.dump()
            netscaler.applyLicense(netscaler.getLicenseFileFromXenRT())
            netscaler.disableL3()
            for n in networks[1:]:
                netscaler.setupOutboundNAT(n, networks[0])
            ret = [{
                "username": "******",
                "publicinterface": "1/1",
                "hostname": netscaler.managementIp,
                "privateinterface": "1/2",
                "lbdevicecapacity": "50",
                "networkdevicetype": "NetscalerVPXLoadBalancer",
                "lbdevicededicated": "false",
                "password": "******",
                "numretries": "2"
            }]

        return ret
示例#4
0
文件: srpervm.py 项目: thomassa/xenrt
    def run(self, arglist=[]):

        wingold = self.getGuest("wingold")
        if wingold:
            wingold.setState("DOWN")
        lingold = self.getGuest("lingold")
        if lingold:
            lingold.setState("DOWN")
        host = self.getDefaultHost()

        i = 0
        while True:
            srs = host.minimalList("sr-list",
                                   args="name-label=\"LinuxRootSR_%d\"" % i)
            if not srs:
                break
            sr = srs[0]

            g = lingold.copyVM(name="linclone-%d" % i, sruuid=sr)
            xenrt.GEC().registry.guestPut("linclone-%d" % i, g)

            j = 0
            while True:
                srs = host.minimalList(
                    "sr-list",
                    args="name-label=\"LinuxDataSR_%d_%d\"" % (j, i))
                if not srs:
                    break
                sr = srs[0]
                g.createDisk(4 * xenrt.GIGA, sruuid=sr)
                j += 1

            g.start(specifyOn=False)
            i += 1

        i = 0
        while True:
            srs = host.minimalList("sr-list",
                                   args="name-label=\"WindowsRootSR_%d\"" % i)
            if not srs:
                break
            sr = srs[0]

            g = wingold.copyVM(name="winclone-%d" % i, sruuid=sr)
            xenrt.GEC().registry.guestPut("winclone-%d" % i, g)

            j = 0
            while True:
                srs = host.minimalList(
                    "sr-list",
                    args="name-label=\"WindowsDataSR_%d_%d\"" % (j, i))
                if not srs:
                    break
                sr = srs[0]
                g.createDisk(4 * xenrt.GIGA, sruuid=sr)
                j += 1

            g.start(specifyOn=False)
            i += 1
示例#5
0
 def pause(self, msg):
     if xenrt.GEC().jobid():
         xenrt.GEC().dbconnect.jobUpdate("PREPARE_PAUSED", "yes")
         xenrt.TEC().tc.pause(msg)
         xenrt.GEC().dbconnect.jobUpdate("PREPARE_PAUSED", "no")
         return True
     else:
         return False
示例#6
0
文件: gui.py 项目: thomassa/xenrt
    def prepare(self, arglist):

        # Prepare a VM to run XenCenter
        self.host = self.getDefaultHost()
        self.guest = xenrt.GEC().registry.guestGet(self.DISTRO)

        if not self.guest:
            self.guest = xenrt.lib.xenserver.guest.createVM(\
                self.host,
                self.DISTRO,
                distro=self.DISTRO,
                memory=self.MEMORY,
                vifs=xenrt.lib.xenserver.Guest.DEFAULT)
            xenrt.GEC().registry.guestPut(self.DISTRO, self.guest)

            self.guest.installDrivers()
            self.getLogsFrom(self.guest)
            self.guest.installNUnit()

            # The tests need the Windows machine to be using British date format
            self.guest.winRegAdd("HKCU", "Control Panel\\International",
                                 "sShortDate", "SZ", "dd/MM/yyyy")
            self.guest.winRegAdd("HKCU", "Control Panel\\International",
                                 "sLongDate", "SZ", "dd MMMM yyyy")
            self.guest.winRegAdd("HKCU", "Control Panel\\International",
                                 "sTimeFormat", "SZ", "HH:mm:ss")

            # Install XenCenter
            self.guest.installCarbonWindowsGUI(
                noAutoDotNetInstall=self.NODOTNETAUTO)

        # Find where we installed the thing
        x = self.guest.findCarbonWindowsGUI()
        if not x:
            raise xenrt.XRTError("Could not find the installed GUI")
        self.xenadmindir, self.xenadminexe = x

        # Fetch and copy the tarball containing the tests
        testtar = xenrt.TEC().getFile("xe-phase-1/XenAdminTests.tgz",
                                      "XenAdminTests.tgz")
        if not testtar:
            raise xenrt.XRTError("Could not retrieve the test tarball")
        tdir = self.guest.tempDir()
        self.tdir = tdir
        self.guest.xmlrpcSendFile(testtar, "%s\\XenAdminTests.tgz" % (tdir))
        self.guest.xmlrpcExtractTarball("%s\\XenAdminTests.tgz" % (tdir), tdir)
        if not self.guest.xmlrpcFileExists("%s\\Release\\xenadmintests.sh" %
                                           (tdir)):
            raise xenrt.XRTError("Test tarball does not contain "
                                 "Release/xenadmintests.sh")

        # Determine the clock skew between the guest and the controller
        # (if any) so we can correlate logs accurately
        xenrt.TEC().logverbose("Clock skew is %s seconds (positive value "
                               "means guest clock is fast)" %
                               (self.guest.getClockSkew()))
示例#7
0
 def getGateway(self, key, ref):
     if ref.has_key("XRT_NetscalerGateway"):
         xenrt.GEC().registry.dump()
         xenrt.TEC().logverbose("XRT_NetscalerGateway")
         ns = xenrt.GEC().registry.objGet("netscaler",
                                          ref['XRT_NetscalerGateway'])
         return ns.subnetIp(ref.get("XRT_VlanName", "NPRI"))
     else:
         return xenrt.getNetworkParam(ref.get("XRT_VlanName", "NPRI"),
                                      "GATEWAY")
示例#8
0
    def getGuests(self):
        g1 = xenrt.GEC().registry.guestGet(self.GUEST1NAME)
        if not g1:
            g1 = self._createGuest(self.master, self.GUEST1NAME)

        g2 = xenrt.GEC().registry.guestGet(self.GUEST2NAME)
        if not g2:
            g2 = self._createGuest(self.slave, self.GUEST2NAME)

        return [g1, g2]
示例#9
0
def getRackTablesInstance():
    global _rackTablesInstance
    if not _rackTablesInstance:
        rtHost = xenrt.GEC().config.lookup("RACKTABLES_DB_HOST", None)
        if not rtHost:
            return None
        rtUser = xenrt.GEC().config.lookup("RACKTABLES_DB_USER", None)
        rtDB = xenrt.GEC().config.lookup("RACKTABLES_DB_NAME", None)
        rtPassword = xenrt.GEC().config.lookup("RACKTABLES_DB_PASSWORD", None)
        _rackTablesInstance = RackTables(rtHost, rtDB, rtUser, rtPassword)
    return _rackTablesInstance
示例#10
0
def setDiskConfig(diskstring, path):
    m = re.match("CCISS:/dev/(.*) SCSI:/dev/(.*)", diskstring)
    if m:
        xenrt.GEC().config.setVariable(path + ["SCSI"], m.group(2))
        xenrt.GEC().config.setVariable(path + ["CCISS"], m.group(1))
    m = re.match("SCSI:/dev/(.*) CCISS:/dev/(.*)", diskstring)
    if m:
        xenrt.GEC().config.setVariable(path + ["SCSI"], m.group(1))
        xenrt.GEC().config.setVariable(path + ["CCISS"], m.group(2))
    m = re.match("/dev/(.*)", diskstring)
    if m:
        xenrt.GEC().config.setVariable(path, m.group(1))
示例#11
0
    def run(self, arglist=None):
        # Check the BIOS status of the VM is reported as customized
        cli = self.pool.getCLIInstance()
        guestBiosStatus = cli.execute("vm-is-bios-customized",
                                      "vm=%s" % (self.guest.getName()),
                                      strip=True)
        if guestBiosStatus != CUSTOM_BIOS_STATUS:
            raise xenrt.XRTFailure("The VM is not BIOS-customized")

        # Check it's happy
        self.guest.check()

        # Do a shutdown/start/reboot loop
        success = 0
        try:
            for i in range(self.ITERATIONS):
                self.guest.shutdown()
                self.guest.start()
                self.guest.check()
                self.guest.reboot()
                self.guest.check()
                success += 1
                if xenrt.GEC().abort:
                    xenrt.TEC().warning("Aborting on command")
                    break
        finally:
            xenrt.TEC().comment("%u/%u iterations successful" %
                                (success, self.ITERATIONS))
示例#12
0
    def getPrimaryStorageUrl(self, key, ref):
        if not ref.has_key("XRT_PriStorageType"):
            storageType = "NFS"
        else:
            storageType = ref['XRT_PriStorageType']

        if storageType == "NFS":
            if ref.has_key('XRT_Guest_NFS'):
                ssGuest = xenrt.TEC().registry.guestGet(ref['XRT_Guest_NFS'])
                xenrt.TEC().logverbose(
                    'Using guest %s for primary NFS storage' % (ssGuest.name))
                shareName = 'PS-%s-%s' % (self.currentClusterName, ''.join(
                    random.sample(
                        string.ascii_lowercase + string.ascii_uppercase, 6)))
                storagePath = ssGuest.createLinuxNfsShare(shareName)
                url = 'nfs://%s' % (storagePath.replace(':', ''))
            else:
                primaryStorage = xenrt.ExternalNFSShare()
                url = 'nfs://%s' % (primaryStorage.getMount().replace(':', ''))
        elif storageType == "SMB":
            h = xenrt.GEC().registry.hostGet("RESOURCE_HOST_%s" %
                                             ref['XRT_SMBHostId'])
            ip = h.getFQDN()
            url = "cifs://%s/storage/primary" % (ip)
            ad = xenrt.getADConfig()
        return url
示例#13
0
    def run(self, arglist=None):
        # Check the BIOS status of the VM is reported as customized
        cli = self.pool.getCLIInstance()
        guestBiosStatus = cli.execute("vm-is-bios-customized",
                                      "vm=%s" % (self.guest.getName()),
                                      strip=True)
        if guestBiosStatus != CUSTOM_BIOS_STATUS:
            raise xenrt.XRTFailure("The VM is not BIOS-customized")

        # Check it's happy
        self.guest.check()

        # Do a live migrate loop
        success = 0
        current = self.pool.master
        dest = self.pool.slaves[self.pool.slaves.keys()[0]]
        try:
            for i in range(self.ITERATIONS):
                xenrt.TEC().logverbose("Live migrating from %s to %s" %
                                       (current.getName(), dest.getName()))
                self.guest.pretendToHaveXenTools()
                self.guest.migrateVM(dest, live="true")
                self.guest.check()
                temp = current
                current = dest
                dest = temp
                success += 1
                if xenrt.GEC().abort:
                    xenrt.TEC().warning("Aborting on command")
                    break
        finally:
            xenrt.TEC().comment("%u/%u iterations successful" %
                                (success, self.ITERATIONS))
示例#14
0
 def runThis(self):
     try:
         t = xenrt.GEC().runTC(self.tc,
                               self.args,
                               blocked=self.blocked,
                               blockedticket=self.blockedticket,
                               name=self.tcname,
                               host=self.locationHost,
                               guest=self.locationGuest,
                               runon=self.runon,
                               group=self.group,
                               prio=self.prio,
                               ttype=self.ttype,
                               depend=self.depend,
                               isfinally=self.isfinally,
                               blocker=self.blocker,
                               jiratc=self.jiratc,
                               tcsku=self.tcsku,
                               marvinTestConfig=self.marvinTestConfig)
         if t and t.ticket:
             self.ticket = t.ticket
             self.ticketIsFailure = t.ticketIsFailure
     except xenrt.XRTBlocker, e:
         self.blocked = e
         t = e.testcase
         if t and t.ticket:
             self.ticket = t.ticket
             self.ticketIsFailure = t.ticketIsFailure
         raise e
示例#15
0
 def getSocketsFromXenrt(self, host):
     resources = xenrt.GEC().dbconnect.api.get_machine(
         host.getName())['resources']
     if "sockets" in resources:
         return int(resources['sockets'])
     else:
         raise xenrt.XRTError("Number of sockets not defined in XenRT")
示例#16
0
文件: stress.py 项目: thomassa/xenrt
    def run(self, arglist):
        workloadsExecd = self.guest.startWorkloads()

        mt = xenrt.Timer()
        success = 0
        loops = int(xenrt.TEC().lookup("TC7007_ITERATIONS", 1000))
        try:
            for i in range(loops):
                self.guest.migrateVM(self.guest.host,
                                     live="True",
                                     fast=True,
                                     timer=mt)
                success += 1
                if xenrt.GEC().abort:
                    xenrt.TEC().warning("Aborting on command")
                    break
        finally:
            xenrt.TEC().comment("%u/%u iterations successful" %
                                (success, loops))
            if mt.count() > 0:
                xenrt.TEC().logverbose("Migrate times: %s" % (mt.measurements))
                xenrt.TEC().value("MIGRATE_MAX", mt.max())
                xenrt.TEC().value("MIGRATE_MIN", mt.min())
                xenrt.TEC().value("MIGRATE_AVG", mt.mean())
                xenrt.TEC().value("MIGRATE_DEV", mt.stddev())

        self.guest.stopWorkloads(workloadsExecd)
        self.guest.check()
        self.guest.checkHealth()
示例#17
0
文件: results.py 项目: thomassa/xenrt
    def generateXML(self, filename):
        """Generate an XML file containing all result data."""
        xenrt.TEC().progress("Writing test results to %s" % (filename))
        impl = xml.dom.minidom.getDOMImplementation()
        newdoc = impl.createDocument(None, "sequenceresults", None)

        config = xenrt.GEC().config

        # Put name of sequence in if available
        if (config.defined("SEQUENCE_NAME")):
            n = newdoc.createElement("name")
            newdoc.documentElement.appendChild(n)
            na = newdoc.createTextNode(config.lookup("SEQUENCE_NAME"))
            n.appendChild(na)

        # Job details (machines used, versions etc)
        t = newdoc.createElement("jobdetails")
        newdoc.documentElement.appendChild(t)
        hosts = config.getWithPrefix("RESOURCE_HOST_")
        for host in hosts:
            h = newdoc.createElement("host")
            t.appendChild(h)
            ho = newdoc.createTextNode(host[1])
            h.appendChild(ho)

        # Version and revision
        if (config.defined("VERSION")):
            v = newdoc.createElement("version")
            t.appendChild(v)
            ve = newdoc.createTextNode(config.lookup("VERSION"))
            v.appendChild(ve)
        if (config.defined("REVISION")):
            r = newdoc.createElement("revision")
            t.appendChild(r)
            re = newdoc.createTextNode(config.lookup("REVISION"))
            r.appendChild(re)

        ok, regok, rates = self.check()
        t = newdoc.createElement("sequence")
        newdoc.documentElement.appendChild(t)
        if ok:
            to = newdoc.createTextNode("PASS")
        else:
            to = newdoc.createTextNode("FAIL")
        t.appendChild(to)
        t = newdoc.createElement("regression")
        newdoc.documentElement.appendChild(t)
        if regok:
            to = newdoc.createTextNode("PASS")
        else:
            to = newdoc.createTextNode("FAIL")
        t.appendChild(to)
        for gn in self.groupsOrder:
            g = self.groups[gn]
            gnode = g.createXMLNode(newdoc)
            newdoc.documentElement.appendChild(gnode)
        f = file(filename, "w")
        newdoc.writexml(f, addindent="  ", newl="\n")
        f.close()
示例#18
0
def createHost(id=0,
               version=None,
               pool=None,
               name=None,
               dhcp=True,
               license=True,
               diskid=0,
               diskCount=1,
               productType=None,
               productVersion=None,
               withisos=False,
               noisos=None,
               overlay=None,
               installSRType=None,
               suppackcds=None,
               addToLogCollectionList=False,
               noAutoPatch=False,
               disablefw=False,
               cpufreqgovernor=None,
               defaultlicense=True,
               ipv6=None,
               noipv4=False,
               basicNetwork=True,
               extraConfig=None,
               containerHost=None,
               vHostName=None,
               vHostCpus=2,
               vHostMemory=4096,
               vHostDiskSize=50,
               vHostSR=None,
               vNetworks=None,
               **kwargs):

    if containerHost != None:
        raise xenrt.XRTError("Nested hosts not supported for this host type")

    machine = str("RESOURCE_HOST_%s" % (id))

    m = xenrt.PhysicalHost(xenrt.TEC().lookup(machine, machine))
    xenrt.GEC().startLogger(m)

    if not productVersion:
        productVersion = xenrt.TEC().lookup("HYPERV_DISTRO", "ws12r2-x64")

    host = HyperVHost(m,
                      productVersion=productVersion,
                      productType=productType)

    host.cloudstack = extraConfig.get("cloudstack", False)

    host.install()

    xenrt.TEC().registry.hostPut(machine, host)
    xenrt.TEC().registry.hostPut(name, host)

    if basicNetwork:
        host.createBasicNetwork()

    return host
示例#19
0
文件: stress.py 项目: thomassa/xenrt
    def run(self, arglist=None):

        i = 0
        try:
            while i < self.ITERATIONS:
                xenrt.TEC().logdelimit("start/stop loop iteration %u" % (i))
                self.host.listDomains()
                c = copy.copy(self.guests)
                xenrt.lib.xenserver.shutdownMulti(c,
                                                  clitimeout=self.CLITIMEOUT)
                if len(c) != len(self.guests):
                    raise xenrt.XRTFailure("One or more VMs did not shutdown",
                                           str(len(self.guests) - len(c)))
                self.host.listDomains()
                c = copy.copy(self.guests)
                xenrt.lib.xenserver.startMulti(c, clitimeout=self.CLITIMEOUT)
                if len(c) != len(self.guests):
                    raise xenrt.XRTFailure("One or more VMs did not start",
                                           str(len(self.guests) - len(c)))
                i = i + 1
                if xenrt.GEC().abort:
                    xenrt.TEC().warning("Aborting on command")
                    break
        finally:
            xenrt.TEC().comment("%u/%u start/stop iterations successful" %
                                (i, self.ITERATIONS))

        i = 0
        try:
            while i < self.ITERATIONS:
                xenrt.TEC().logdelimit("reboot loop iteration %u" % (i))
                self.host.listDomains()
                c = copy.copy(self.guests)
                xenrt.lib.xenserver.startMulti(c,
                                               reboot=True,
                                               clitimeout=self.CLITIMEOUT)
                if len(c) != len(self.guests):
                    raise xenrt.XRTFailure("One or more VMs did not reboot",
                                           str(len(self.guests) - len(c)))
                i = i + 1
                if xenrt.GEC().abort:
                    xenrt.TEC().warning("Aborting on command")
                    break
        finally:
            xenrt.TEC().comment("%u/%u reboot iterations successful" %
                                (i, self.ITERATIONS))
示例#20
0
文件: vcenter.py 项目: thomassa/xenrt
def getVCenter(guest=None, vCenterVersion="5.5.0-update02"):
    if not guest:
        global _vcenter
        with xenrt.GEC().getLock("VCENTER"):
            if not _vcenter:
                _vcenter = VCenter()
        return _vcenter
    else:
        return VCenter(guest=guest, vCenterVersion=vCenterVersion)
示例#21
0
    def run(self, arglist=None):
        pool = self.getDefaultPool()
        cli = pool.getCLIInstance()
        guests = []

        # Install BIOS-customized guests
        for i in range(self.NUM_CUSTOM_VMS):
            guest = pool.master.installHVMLinux(
                memory=self.MEMORY,
                biosHostUUID=pool.master.getMyHostUUID(),
                ramdisk_size=self.RAMDISK_SIZE,
                start=True)
            self.uninstallOnCleanup(guest)
            guests.append(guest)

            guestBiosStatus = cli.execute("vm-is-bios-customized",
                                          "vm=%s" % (guest.getName()),
                                          strip=True)
            if guestBiosStatus != CUSTOM_BIOS_STATUS:
                raise xenrt.XRTFailure("The VM is not BIOS-customized")

        # Install BIOS-generic VMs
        for i in range(self.NUM_GENERIC_VMS):
            guest = pool.master.createGenericLinuxGuest(
                memory=self.GENERIC_MEM)
            self.uninstallOnCleanup(guest)
            guests.append(guest)

            guestBiosStatus = cli.execute("vm-is-bios-customized",
                                          "vm=%s" % (guest.getName()),
                                          strip=True)
            if guestBiosStatus != GENERIC_BIOS_STATUS:
                raise xenrt.XRTFailure("The VM is not BIOS-generic")

        success = 0
        abort = False
        try:
            for i in range(self.ITERATIONS):
                xenrt.TEC().logdelimit("loop iteration %u..." % (i))
                for j in range(len(guests)):
                    if j < self.NUM_CUSTOM_VMS:
                        guests[j].pretendToHaveXenTools()
                        time.sleep(5)
                    guests[j].suspend()
                    guests[j].resume()
                    guests[j].reboot()
                    guests[j].check()
                    if xenrt.GEC().abort:
                        xenrt.TEC().warning("Aborting on command")
                        abort = True
                        break
                if abort:
                    break
                success += 1
        finally:
            xenrt.TEC().comment("%u/%u iterations successful" %
                                (success, self.ITERATIONS))
示例#22
0
文件: host.py 项目: thomassa/xenrt
 def addToVCenter(self, dc=None, cluster=None):
     if not dc:
         job = xenrt.GEC().jobid() or "nojob"
         dc = 'dc-%s-%s' % (uuid.uuid4().hex, job)
     if not cluster:
         cluster = 'cluster-%s' % (uuid.uuid4().hex)
     xenrt.lib.esx.getVCenter().addHost(self, dc, cluster)
     self.datacenter = dc
     self.cluster = cluster
示例#23
0
文件: results.py 项目: thomassa/xenrt
    def check(self):
        res = self.getTopLevelTests()
        if len(res) == 0:
            if not xenrt.GEC().prepareonly:
                return False, False, None
        regok = True
        for tc in res:
            if tc.getOverallResult() == xenrt.RESULT_FAIL or \
                   tc.getOverallResult() == xenrt.RESULT_ERROR:
                if not tc.results.allowed:
                    regok = False
        counterror = xenrt.TEC().lookup("PASS_RATE_STRICT", True, boolean=True)
        rates = self.byPriority(counterror=counterror)
        c*k = True
        # Check pass criteria
        criteria = string.split(xenrt.TEC().lookup("PASS_CRITERIA", ""), ",")
        for i in range(max(len(criteria), len(rates))):
            if i < len(criteria):
                if criteria[i] == "":
                    c = 100.0
                else:
                    c = float(criteria[i])
            else:
                c = 100.0
            if i < len(rates):
                if rates[i] == None:
                    r = 100.0
                else:
                    r = float(rates[i])
            else:
                r = 100.0
            if c > r:
                c*k = False
            #print "P%u %f %f" % (i + 1, c, r)

        # Pretty print the actual pass rates
        pprates = []
        for i in range(len(rates)):
            if rates[i] != None:
                pprates.append("P%u:%.1f%%" % (i + 1, float(rates[i])))
        if xenrt.GEC().preparefailed:
            c*k = False
            regok = False
        return c*k, regok, string.join(pprates)
示例#24
0
def generateLabCostPerTechArea(suiteId,
                               outputDir=None,
                               clearOutputDirContent=False):
    if outputDir and xenrt.TEC().lookup("GENERATE_STATS_BASEDIR").rstrip(
            "/") not in outputDir:
        # this part will ensure we only modify dir falling under base dir for stats.
        raise xenrt.XRTError(
            "permission denied [ dir not under base stat dir] '%s'" %
            outputDir)
    if clearOutputDirContent and outputDir:
        shutil.rmtree("%s" % outputDir.rstrip("/"))
    elif suiteId:
        if outputDir:
            outputDir = outputDir.rstrip("/")
            if os.path.exists("%s/%s.generating" % (outputDir, suiteId)):
                raise xenrt.XRTError(
                    "Another process is already generating data")
            else:
                if not os.path.exists(outputDir):
                    os.makedirs(outputDir)
                with open("%s/%s.generating" % (outputDir, suiteId), "w") as f:
                    f.write(str(xenrt.GEC().jobid()) or "nojob")
        try:
            cls = xenrt.generatestats.LabCostPerTechArea(
                suiteId, nbrOfSuiteRunsToCheck=10)
            data, tcMissingData = cls.generate()
            tempDir = xenrt.TEC().tempDir()
            with open("%s/%s.json" % (tempDir, suiteId), "w") as f:
                f.write(json.dumps(data, indent=2))
            with open(
                    "%s/%s_tcs_missing_run_history.json" % (tempDir, suiteId),
                    "w") as f:
                f.write(json.dumps(tcMissingData, indent=2))
            if outputDir:
                xenrt.command("cp -f -r %s/* %s" % (tempDir, outputDir))
            print "Data saved in directory '%s'" % (outputDir
                                                    if outputDir else tempDir)
        except Exception, e:
            errorLogDir = "%s/logs" % outputDir
            if not os.path.exists(errorLogDir):
                os.makedirs(errorLogDir)
            with open("%s/%s.error" % (errorLogDir, suiteId), "w") as f:
                f.write("[%s] %s" % (str(xenrt.GEC().jobid()) or "nojob", e))
        finally:
示例#25
0
 def incFile(self, filename):
     """Parse an include file"""
     f = self.findFile(filename)
     cfg = xml.dom.minidom.parse(f)
     for i in cfg.childNodes:
         if i.nodeType == i.ELEMENT_NODE:
             if i.localName == "xenrt":
                 for n in i.childNodes:
                     if n.nodeType == n.ELEMENT_NODE:
                         if n.localName == "variables":
                             if not xenrt.TEC().lookup("SEQ_PARSING_ONLY",
                                                       False,
                                                       boolean=True):
                                 xenrt.TEC().config.parseXMLNode(n)
                         elif n.localName == "semaphores":
                             for s in n.childNodes:
                                 if s.nodeType == s.ELEMENT_NODE:
                                     semclass = str(s.localName)
                                     count = expand(s.getAttribute("count"),
                                                    self.params)
                                     if not count:
                                         count = "1"
                                     xenrt.GEC().semaphoreCreate(
                                         semclass, int(count))
                         elif n.localName == "collection":
                             name = n.getAttribute("name")
                             if not name:
                                 raise xenrt.XRTError("Found collection "
                                                      "without name in "
                                                      "sequence file.")
                             self.collections[name] = n
                         elif n.localName == "default":
                             name = n.getAttribute("name")
                             value = n.getAttribute("value")
                             if not name:
                                 raise xenrt.XRTError("Found default "
                                                      "without name in "
                                                      "sequence file.")
                             if value == None:
                                 raise xenrt.XRTError("Found default "
                                                      "without value in "
                                                      "sequence file.")
                             if value != None:
                                 value = expand(value, self.params)
                             if name and value != None:
                                 self.params[str(name)] = \
                                                        xenrt.TEC().lookup(\
                                     str(name), str(value))
                         elif n.localName == "include":
                             iname = n.getAttribute("filename")
                             if not iname:
                                 raise xenrt.XRTError("Found include "
                                                      "without filename.")
                             self.incFile(iname)
             else:
                 raise xenrt.XRTError("No 'xenrt' tag found.")
示例#26
0
    def __init__(self, jobid):
        if jobid == None:
            self._jobid = None
        else:
            self._jobid = int(jobid)
        self._bufferdir = xenrt.GEC().config.lookup("DB_BUFFER_DIR", None)
        if self._bufferdir and not os.path.exists(self._bufferdir):
            os.makedirs(self._bufferdir)

        self._api = None
示例#27
0
 def _createGuest(self, host, name):
     himnNetwork = host.parseListForUUID(
         "network-list", "name-label", "Host internal management network")
     himnBridge = host.genParamGet("network", himnNetwork, "bridge")
     g = host.createGenericLinuxGuest(name=name)
     g.createVIF(bridge=himnBridge, plug=True)
     g.execguest("ifconfig eth1 up")
     g.execguest("dhclient eth1")
     xenrt.GEC().registry.guestPut(name, g)
     return g
示例#28
0
 def runThis(self):
     try:
         if xenrt.GEC().abort:
             raise xenrt.XRTError("Aborting on command")
         if self.action == "sleep":
             if self.args and len(self.args) > 0:
                 d = int(self.args[0])
             xenrt.TEC().logverbose("Sleeping for %u seconds..." % (d))
             xenrt.sleep(d)
         elif self.action == "prepare":
             xenrt.TEC().logverbose("Re-preparing system...")
             xenrt.GEC().reprepare()
         else:
             raise xenrt.XRTError("Unknown action '%s'" % (self.action))
     except Exception, e:
         xenrt.TEC().logverbose("Action '%s' got exception %s" %
                                (self.action, str(e)))
         if self.blocker:
             raise xenrt.XRTBlocker("Blocked by action: %s" % (self.action))
示例#29
0
文件: stress.py 项目: thomassa/xenrt
    def stepup(self):

        # Test start/shutdown using --multiple. Start with 1 VM and work up
        # to the max
        timer1 = xenrt.Timer()
        timer2 = xenrt.Timer()
        try:
            for number in range(1, len(self.guests) + 1, 10):
                xenrt.TEC().logverbose("Testing parallel start of %u VMs..." %
                                       (number))
                guestlist = self.guests[:number]
                fail = 0

                for host in self.hosts:
                    host.listDomains()
                c = copy.copy(guestlist)

                # Work out appropriate timeout
                if self.PERVMTIMEOUT:
                    tout = self.PERVMTIMEOUT * number
                else:
                    tout = self.CLITIMEOUT

                xenrt.lib.xenserver.startMulti(guestlist,
                                               no_on=True,
                                               clitimeout=tout,
                                               timer=timer1)
                for g in c:
                    if not g in guestlist:
                        fail = fail + 1
                for host in self.hosts:
                    host.checkHealth()
                    host.listDomains()
                c = copy.copy(guestlist)
                xenrt.lib.xenserver.shutdownMulti(guestlist,
                                                  clitimeout=tout,
                                                  timer=timer2)
                for g in c:
                    if not g in guestlist:
                        fail = fail + 1
                for host in self.hosts:
                    host.checkHealth()
                if guestlist == []:
                    break
                if xenrt.GEC().abort:
                    xenrt.TEC().warning("Aborting on command")
                    break

                if fail > 0:
                    raise xenrt.XRTFailure("%d guests failed." % (fail))
        finally:
            xenrt.TEC().logverbose("Start times: %s" % (timer1.measurements))
            xenrt.TEC().logverbose("Shutdown times: %s" %
                                   (timer2.measurements))
示例#30
0
    def getFile(self, filename, multiple=False, replaceExistingIfDiffers=False):
        try:
            xenrt.TEC().logverbose("getFile %s" % filename)
            self.lock.acquire()
            sharedLocation = None
            isUsingExternalCache = False
            fnr = FileNameResolver(filename, multiple)
            url = fnr.url
            localName = fnr.localName
            cache = self.__availableInCache(fnr, replaceExistingIfDiffers=replaceExistingIfDiffers)
            if cache:
                return cache

            else:
                sharedLocation = self._sharedCacheLocation(localName)
                # Check file size and decide which global cache to use. If file size is greater than
                # FILE_SIZE_CACHE_LIMIT, we cache file on external storage.
                try:
                    fileSizeThreshold = float(xenrt.TEC().lookup("FILE_SIZE_CACHE_LIMIT", str(1 * xenrt.GIGA)))
                    if fnr.isSimpleFile:
                        r = requests.head(fnr.url, allow_redirects=True)
                        if r.status_code == 200 and 'content-length' in r.headers and \
                            float(r.headers['content-length']) > fileSizeThreshold:
                            xenrt.TEC().logverbose("Using external cache")
                            sharedLocation = self._externalCacheLocation(localName)
                            isUsingExternalCache = True
                except Exception, e:
                    xenrt.TEC().warning('Reverting:Using internal shared cache. File Manager failed: %s' % e)

                perJobLocation = self._perJobCacheLocation(localName)
                f = open("%s.fetching" % sharedLocation, "w")
                f.write(str(xenrt.GEC().jobid()) or "nojob")
                f.close()

                if multiple:
                    self.getMultipleFiles(url, sharedLocation)
                elif fnr.directory:
                    self.getDirectory(url, sharedLocation)
                elif fnr.singleFileWithWildcard:
                    self.getSingleFileWithWildcard(url, sharedLocation)
                elif filename.startswith("sftp://"):
                    self.getSingleFileViaSftp(filename, sharedLocation)
                else:
                    self.getSingleFile(url, sharedLocation, isUsingExternalCache)
                os.chmod(sharedLocation, stat.S_IRWXU | stat.S_IRWXG | stat.S_IROTH | stat.S_IXOTH)

                if isUsingExternalCache:
                    os.symlink(sharedLocation, perJobLocation)
                else:
                    os.link(sharedLocation, perJobLocation)
                return perJobLocation
        except Exception, e:
            xenrt.TEC().logverbose("Warning - could not fetch %s - %s" % (filename, e))
            return None