Example #1
0
    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()
Example #2
0
    def waitCheck(self, minutes, dataPoints, allowedVariances):
        """Wait until <minutes> after starting the VM and check we have the
           expected number of data points in each category"""

        self.waitUntil((minutes * 60) + 10)

        # Check the RRDs
        rrd = self.getGuestRRD()
        # Find the requisite rras
        rras = rrd.getElementsByTagName("rra")
        dataPointsChecked = 0
        for rra in rras:
            # We only look at AVERAGE for now
            cfs = rra.getElementsByTagName("cf")
            if cfs[0].childNodes[0].data != "AVERAGE":
                continue
            pprs = rra.getElementsByTagName("pdp_per_row")
            ppr = int(pprs[0].childNodes[0].data)
            db = rra.getElementsByTagName("database")[0]
            rows = db.getElementsByTagName("row")
            timescale = (len(rows),ppr)
            expect = 0
            variance = 0
            desc = ""
            if timescale == (120,1):
                desc = "5s/10m"
                expect = dataPoints[0]
                variance = allowedVariances[0]
            elif timescale == (20,12):
                desc = "1m/20m"
                expect = dataPoints[1]
                variance = allowedVariances[1]
            elif timescale == (15,24):
                desc = "2m/30m"
                expect = dataPoints[2]
                variance = allowedVariances[2]
            elif timescale == (10,36):
                desc = "3m/30m"
                expect = dataPoints[3]
                variance = allowedVariances[3]
            else:
                raise xenrt.XRTError("Unknown RRA timescale (%u,%u) found" % 
                                     timescale)
            found = 0
            for row in rows:
                val = row.childNodes[0].childNodes[0].data
                xenrt.log("Value is %s" % val)
                if val != "NaN":
                    found += 1
            if (found < expect and (found + variance) < expect) or \
               (found > expect and (found - variance) > expect): 
                raise xenrt.XRTFailure("Incorrect number of data points for "
                                       "%s timescale" % (desc),
                                       data="Expecting %u, found %u" % 
                                            (expect, found))
            xenrt.TEC().logverbose("Checked timescale %s" % (desc))
            dataPointsChecked += 1
        if dataPointsChecked != 4:
            raise xenrt.XRTFailure("Only found %u/4 timescales" % 
                                   (dataPointsChecked))
Example #3
0
    def getRawVDISize(self, vdi):
        """
        Find size of VDI and return it.

        @param: vdi: UUID of VDI to check.

        @return: size of VDI
        """

        try:
            filename = self.host.genParamGet("vdi", vdi, "location")
        except:
            warning("VDI %s does not have location property" % vdi)
            filename = vdi

        info = None
        try:
            info = eval(self.host.execdom0("cat %s/%s.json" % (self.srPath, filename)))
        except:
            warning("VDI %s does not have valid json file." % vdi)

        if info:
            log("VDI %s INFO: %s" % (vdi, str(info)))
            if "uuid" in info:
                if info["uuid"] != vdi:
                    raise xenrt.XRTError("JSON file of VDI %s includes wrong UUID info.")
            else:
                warning("JSON file of VDI %s does not have UUID field. Skipping sanity check." % vdi)

        try:
            lsstr = self.host.execdom0("ls -l %s/%s" % (self.srPath, filename))
        except:
            lsstr = self.host.execdom0("ls -l %s/%s.vhd" % (self.srPath, filename))

        return int(lsstr.split()[4])
Example #4
0
    def __verifyBasicProperties(self, checkPU=True):

        self.host.execdom0("xe sr-scan uuid=%s" % self.xsr.uuid)

        log("Collect local status.")
        rawStatus = self.getRawProperties()

        log("Verify basic properties.")
        physicalSize = self.xsr.physicalSize
        if rawStatus[0] != physicalSize:
            raise xenrt.XRTFailure(
                "Physical Size mismatched. %s from df / %s in SR property." %
                (rawStatus[0], physicalSize))

        virtualAlloc = self.xsr.virtualAllocation
        if rawStatus[2] != virtualAlloc:
            raise xenrt.XRTFailure(
                "Vitual allocation mismatched. %d from %d VDIs / %s in SR property."
                % (rawStatus[2], len(self.xsr.VDIs), virtualAlloc))

        if checkPU:
            physicalUtil = self.xsr.physicalUtilisation
            if rawStatus[1] != physicalUtil:
                raise xenrt.XRTFailure(
                    "Physical Utilisation mismatched. %d from df / %s in SR property."
                    % (rawStatus[1], physicalUtil))
Example #5
0
    def setNewUploadSchedule(self, pool, hcparams=None):
        cli = pool.master.getCLIInstance()

        currTimeStamp = time.strftime("%Y-%m-%dT%H:%M:%S",
                                      time.gmtime(self.guest.getTime()))
        t = time.strptime(currTimeStamp, "%Y-%m-%dT%H:%M:%S")
        if not hcparams:
            hcparams = {}
            #Adjust the dayofWeek as Monday is 1 as per XenCenter
            hcparams["Schedule.DayOfWeek"] = str((t.tm_wday + 1) % 7)
            #We are setting the new schedule so that upload happens in the very next hour at the time of the execution of the testcase
            hcparams["Schedule.TimeOfDay"] = str(t.tm_hour + 1)
            hcparams["Schedule.IntervalInDays"] = str(7)
            hcparams["Schedule.RetryInterval"] = str(1)
            hcparams["NewUploadRequest"] = ""
        xenrt.log("Set the new schedule for upload")
        for health_check_key in hcparams:
            cli.execute(
                "pool-param-set", "uuid=%s health-check-config:%s=%s" %
                (pool.getUUID(), health_check_key, hcparams[health_check_key]))

        #get the timestamp based on the new schedule
        nextUploadTs = str(t.tm_year) + "-" + str(t.tm_mon) + "-" + str(
            t.tm_mday) + "T" + str(hcparams["Schedule.TimeOfDay"])
        nextUploadAbs = int(
            calendar.timegm(time.strptime(nextUploadTs, "%Y-%m-%dT%H")))
        return nextUploadAbs
Example #6
0
    def run(self, arglist=None):
        # Leave the VM so it's been running for at least 10 minutes
        time.sleep(600)

        # Now migrate it
        self.guest.migrateVM(self.slave, live="true")

        # Now get the stats and see what happens
        rrd = self.getGuestRRD()
        # Check we have a full 10 minute RRA
        rras = rrd.getElementsByTagName("rra")
        found = 0
        for rra in rras:
            cfs = rra.getElementsByTagName("cf")
            if cfs[0].childNodes[0].data != "AVERAGE":
                continue
            pprs = rra.getElementsByTagName("pdp_per_row")
            ppr = int(pprs[0].childNodes[0].data)
            db = rra.getElementsByTagName("database")[0]
            rows = db.getElementsByTagName("row")
            timescale = (len(rows),ppr)
            if timescale != (120, 1):
                continue
            for row in rows:
                val = row.childNodes[0].childNodes[0].data
                xenrt.log("Value is %s" % val)
                if val != "NaN":
                    found += 1
            break

        if found != 120:
            raise xenrt.XRTFailure("RRD does not appear to have been correctly "
                                   "synced across after live migrate",
                                   data="Found %u points in 5s/10m RRA, "
                                        "expecting 120" % (found))
Example #7
0
    def runCommand(self, guest, script, method="cli", timeout=60):
        """ Run given commands

        @param guest: guest instance to run with.
        @param script: script to run
        @param timeout: timeout value for async call. Ignored in other calls.

        @return: dict from execution result.
        """

        log("Running command \"\"\"%s\"\"\" with %s" % (script, method))

        method = method.lower()
        if method == "cli":
            status = self.executeCommandCLI(guest, script)
        elif method == "api":
            status = self.executeCommandAPI(guest, script)
        elif method == "async":
            status = self.executeCommandAPIAsync(guest, script, timeout)
        else:
            raise xenrt.XRTError("Unknown running method: %s" % method)

        log("Result: %s" % status)

        return status
Example #8
0
    def runCommand(self, guest, script, method="cli", timeout = 60):
        """ Run given commands

        @param guest: guest instance to run with.
        @param script: script to run
        @param timeout: timeout value for async call. Ignored in other calls.

        @return: dict from execution result.
        """

        log("Running command \"\"\"%s\"\"\" with %s" %
            (script, method))

        method = method.lower()
        if method == "cli":
            status = self.executeCommandCLI(guest, script)
        elif method == "api":
            status = self.executeCommandAPI(guest, script)
        elif method == "async":
            status = self.executeCommandAPIAsync(guest, script, timeout)
        else:
            raise xenrt.XRTError("Unknown running method: %s" % method)

        log("Result: %s" % status)

        return status
Example #9
0
    def waitCheck(self, minutes, dataPoints, allowedVariances):
        """Wait until <minutes> after starting the VM and check we have the
           expected number of data points in each category"""

        self.waitUntil((minutes * 60) + 10)

        # Check the RRDs
        rrd = self.getGuestRRD()
        # Find the requisite rras
        rras = rrd.getElementsByTagName("rra")
        dataPointsChecked = 0
        for rra in rras:
            # We only look at AVERAGE for now
            cfs = rra.getElementsByTagName("cf")
            if cfs[0].childNodes[0].data != "AVERAGE":
                continue
            pprs = rra.getElementsByTagName("pdp_per_row")
            ppr = int(pprs[0].childNodes[0].data)
            db = rra.getElementsByTagName("database")[0]
            rows = db.getElementsByTagName("row")
            timescale = (len(rows), ppr)
            expect = 0
            variance = 0
            desc = ""
            if timescale == (120, 1):
                desc = "5s/10m"
                expect = dataPoints[0]
                variance = allowedVariances[0]
            elif timescale == (20, 12):
                desc = "1m/20m"
                expect = dataPoints[1]
                variance = allowedVariances[1]
            elif timescale == (15, 24):
                desc = "2m/30m"
                expect = dataPoints[2]
                variance = allowedVariances[2]
            elif timescale == (10, 36):
                desc = "3m/30m"
                expect = dataPoints[3]
                variance = allowedVariances[3]
            else:
                raise xenrt.XRTError("Unknown RRA timescale (%u,%u) found" %
                                     timescale)
            found = 0
            for row in rows:
                val = row.childNodes[0].childNodes[0].data
                xenrt.log("Value is %s" % val)
                if val != "NaN":
                    found += 1
            if (found < expect and (found + variance) < expect) or \
               (found > expect and (found - variance) > expect):
                raise xenrt.XRTFailure("Incorrect number of data points for "
                                       "%s timescale" % (desc),
                                       data="Expecting %u, found %u" %
                                       (expect, found))
            xenrt.TEC().logverbose("Checked timescale %s" % (desc))
            dataPointsChecked += 1
        if dataPointsChecked != 4:
            raise xenrt.XRTFailure("Only found %u/4 timescales" %
                                   (dataPointsChecked))
Example #10
0
    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()
Example #11
0
    def enableAlertonHost(self, host, perfmon=PERFMON, alarmLevel="4E30", alarmTriggerPeriod="60", alarmAutoInhibitPeriod="300"):
        """This defaults to setting an alert with repeat time of 1 min and perfmon poll time of 5 min 
        xe host-param-set other-config:
        perfmon='<config><variable><name value="network_usage" /><alarm_trigger_level value="2" />
        <alarm_trigger_period value="30" /><alarm_auto_inhibit_period value="300" /></variable></config>' """

        # Start on a clean slate
        self.deleteAllAlarms(host)

        # Check if alarm of requested type is already enabled
        try:
            enableFlag=host.getHostParam("other-config","perfmon")
        except:
            enableFlag = ""
        if re.search(perfmon, enableFlag, re.IGNORECASE):
            self.origXrtTime = xenrt.timenow()
            return

        cmdXML ="<config><variable><name value=\'%s\' />" \
                "<alarm_trigger_level value=\'%s\' />" \
                "<alarm_trigger_period value=\'%s\' />" \
                "<alarm_auto_inhibit_period value=\'%s\' />" \
                "</variable></config>" % \
                (perfmon, alarmLevel, alarmTriggerPeriod, alarmAutoInhibitPeriod)
        param="other-config:perfmon"
        host.setHostParam(param, cmdXML)

        self.origXrtTime = xenrt.timenow()
        xenrt.log("Alert enabled at time - %s" % self.origXrtTime)

        xenrt.log("Verify the other-config parameters for perfmon")
        self.verifyOtherConfigCmd(host)
Example #12
0
    def verifyAlertIntervals(self,
                             host,
                             alarmAutoInhibitPeriod,
                             mesages=MESSAGES):
        if len(self.MESSAGES) < 2:
            # Fail if alerts generated is less than 2
            raise xenrt.XRTFailure(
                "Alerts not getting generated at the configured interval, only one present so far"
            )
        cli = host.getCLIInstance()
        xenrt.log(
            "Alerts available for the specified perfmon, verifying repeat interval %s sec"
            % alarmAutoInhibitPeriod)

        t1 = cli.execute("message-param-get", "param-name=timestamp uuid=%s" %
                         self.MESSAGES[0]).strip()
        t2 = cli.execute("message-param-get", "param-name=timestamp uuid=%s" %
                         self.MESSAGES[1]).strip()

        xenrt.TEC().logverbose(
            "Timestamps for the first and second alert are %s and %s " %
            (t1, t2))
        # Get the relevant substring out of the timestamps for minutes passed
        interval = int(t1[t1.find("T") + 1:t1.find("Z")].split(":")[1]) - int(
            t2[t2.find("T") + 1:t2.find("Z")].split(":")[1])

        if interval <= (alarmAutoInhibitPeriod + self.VARIANCE) / 60:
            xenrt.TEC().logverbose("verifyAlertIntervals: Check passed, alerts are getting generated at the right" \
                                    "interval (includng the variance of %s secs" % self.VARIANCE)
        else:
            xenrt.TEC().warning(
                "Expected alert interval of %s seconds, instead they are generated at %s minutes"
                % (alarmAutoInhibitPeriod, interval))
Example #13
0
    def verifyDualCommandProhibited(self, guest):
        """Check second command is not accepted when first one is running."""

        try:
            self.runCommand(guest, "dir")
        except:
            log("Second command is blocked while first command is running.")
        else:
            raise xenrt.XRTFailure("Succeeded to run a command while another is running.")
Example #14
0
    def deleteAllAlarms(self, host):
        alarms = host.minimalList("message-list name=ALARM class=Host")
        for id in alarms:
            host.execdom0('xe message-destroy uuid=%s' % id)

        xenrt.log("Checking if all the messages of type ALARM are deleted")
        alarms = host.minimalList("message-list name=ALARM class=Host")
        if alarms:
            raise xenrt.XRTFailure("Messages of type ALARM are not entirely removed")
Example #15
0
 def deleteVDIs(self):
     for uuid in self.created:
         xenrt.TEC().logverbose("Deleting created vdis to make more space")
         xenrt.log("Remaining vdis: %s " % self.created)
         try:
             self.cli.execute("vdi-destroy", "uuid=%s" % uuid)
         except Exception, e:
             xenrt.TEC().logverbose("Caught exception in delete vdi " + str(e))
         finally:
Example #16
0
    def deleteAllAlarms(self, host):
        alarms = host.minimalList("message-list name=ALARM class=Host")
        for id in alarms:
            host.execdom0('xe message-destroy uuid=%s' % id)

        xenrt.log("Checking if all the messages of type ALARM are deleted")
        alarms = host.minimalList("message-list name=ALARM class=Host")
        if alarms:
            raise xenrt.XRTFailure(
                "Messages of type ALARM are not entirely removed")
Example #17
0
    def verifyDualCommandProhibited(self, guest):
        """Check second command is not accepted when first one is running."""

        try:
            self.runCommand(guest, "dir")
        except:
            log("Second command is blocked while first command is running.")
        else:
            raise xenrt.XRTFailure(
                "Succeeded to run a command while another is running.")
Example #18
0
 def deleteVDIs(self):
     for uuid in self.created:
         xenrt.TEC().logverbose("Deleting created vdis to make more space")
         xenrt.log("Remaining vdis: %s " % self.created)
         try:
             self.cli.execute("vdi-destroy", "uuid=%s" % uuid)
         except Exception, e:
             xenrt.TEC().logverbose("Caught exception in delete vdi " +
                                    str(e))
         finally:
Example #19
0
    def getSRObjByUuid(self, uuid):
        """
        Find SR by UUID and return Object model instance.

        @param: uuid: string. UUID of SR to find.

        @return: uuid of SR.
        """
        log("Finding SR of which uuid is %s" % uuid)

        return self.__getSRObj(lambda sr: sr.uuid == uuid)
Example #20
0
    def getSRObjByName(self, name):
        """
        Find SR by name and return Object model instance.

        @param: name: string. Name of SR to find.

        @return: uuid of SR.
        """
        log("Finding SR of which name is %s" % name)

        return self.__getSRObj(lambda sr: sr.name == name)
Example #21
0
    def getSRObjByName(self, name):
        """
        Find SR by name and return Object model instance.

        @param: name: string. Name of SR to find.

        @return: uuid of SR.
        """
        log("Finding SR of which name is %s" % name)

        return self.__getSRObj(lambda sr: sr.name == name)
Example #22
0
    def getSRObjByUuid(self, uuid):
        """
        Find SR by UUID and return Object model instance.

        @param: uuid: string. UUID of SR to find.

        @return: uuid of SR.
        """
        log("Finding SR of which uuid is %s" % uuid)

        return self.__getSRObj(lambda sr: sr.uuid == uuid)
Example #23
0
 def verifyNoMulUpload(self):
     cli = self.pool.master.getCLIInstance()
     lastSucUploadTs=cli.execute("pool-param-get","uuid=%s param-name=\"%s\" param-key=\"%s\"" % (self.pool.getUUID(),"health-check-config","LastSuccessfulUpload"),strip=True)
     xenrt.log(lastSucUploadTs)
     now = xenrt.timenow() 
     while xenrt.timenow() < (now + self.services[0].UPLOAD_TIMEINT_MINS*60 ):
         curSucUploadTs=cli.execute("pool-param-get","uuid=%s param-name=\"%s\" param-key=\"%s\"" % (self.pool.getUUID(),"health-check-config","LastSuccessfulUpload"),strip=True)
         if curSucUploadTs == lastSucUploadTs:
             xenrt.log("No new upload observed as Expected")
             xenrt.sleep(120)
         else:
             raise xenrt.XRTFailure("New upload observed at timestamp %s"%lastSucUploadTs)
Example #24
0
    def verifyServiceFailure(self, pool, abstime, timeout=300):
        cli = pool.master.getCLIInstance()
        scheduledUpload = abstime
        uploadTimeLimit = scheduledUpload + self.UPLOAD_TIMEINT_MINS * 60 + timeout

        try:
            lastFailedUploadTs = cli.execute(
                "pool-param-get",
                "uuid=%s param-name=\"%s\" param-key=\"%s\"" %
                (pool.getUUID(), "health-check-config", "LastFailedUpload"),
                strip=True)
        except:
            xenrt.log(
                "LastFqailedUpload field didnt get populated  in health-chcek-config by the service"
            )
            return False

        lastFailedUploadAbs = int(
            calendar.timegm(
                time.strptime(
                    lastFailedUploadTs.split('.')[0], "%Y-%m-%dT%H:%M:%S")))
        xenrt.log(lastFailedUploadTs)
        if lastFailedUploadAbs and lastFailedUploadAbs > scheduledUpload and lastFailedUploadAbs < uploadTimeLimit:
            xenrt.log(
                "Upload Attempt for pool %s failed indeed.Service acknowledge the upload failure at %s"
                % (pool.getName(), lastFailedUploadTs))
            return True
        else:
            xenrt.log(
                "Upload Attempt for pool %s failed zat some different timestamp.Service acknowledge the upload failure at %s"
                % (pool.getName(), lastFailedUploadTs))
            return False
Example #25
0
    def verifyService(self, pool, abstime, timeout=300):
        #return true or False as per the upload
        cli = pool.master.getCLIInstance()
        scheduledUpload = abstime
        uploadTimeLimit = scheduledUpload + self.UPLOAD_TIMEINT_MINS * 60 + timeout

        #Between uploadtime  and uploadtime+Uploadinterval+Buffer I expect upload to happen
        while xenrt.timenow() < uploadTimeLimit:
            lastSucUploadTs = cli.execute(
                "pool-param-get",
                "uuid=%s param-name=\"%s\" param-key=\"%s\"" %
                (pool.getUUID(), "health-check-config",
                 "LastSuccessfulUpload"),
                strip=True)
            xenrt.log(lastSucUploadTs)
            lastSucUploadAbs = int(
                calendar.timegm(
                    time.strptime(
                        lastSucUploadTs.split('.')[0], "%Y-%m-%dT%H:%M:%S")))
            if lastSucUploadAbs and lastSucUploadAbs > scheduledUpload and lastSucUploadAbs < uploadTimeLimit:
                xenrt.log("Upload for pool %s successfully took place at %s" %
                          (pool.getName(), lastSucUploadTs))
                return True
            else:
                xenrt.sleep(30)
        xenrt.log(
            "No upload observed for pool %s during the expected timeframe" %
            pool.getName())
        xenrt.log("Last Successful Upload for pool %s took place at %s" %
                  (pool.getName(), lastSucUploadTs))
        return False
Example #26
0
    def getGuestAgentRamUsage(self, guest):
        """Return size of RAM that guest agent is using."""

        ps = guest.xmlrpcExec("tasklist /FI \"IMAGENAME eq xenguestagent.exe\"", returndata = True)
        log("Found process info: %s" % ps)
        if ps:
            for line in reversed(ps.splitlines()):
                line = line.strip()
                if len(line):
                    try:
                        return int(line.split()[4].replace(",", ""))
                    except:
                        pass
        raise xenrt.XRTError("Cannot find guest agent process from guest %s" % guest.getName())
Example #27
0
    def run(self, arglist=[]):
        log("Running Basic functionality with %s method." % self.METHOD)

        step("Running valid command.")
        self.runSubcase("runCase", (self.verifyBasicFuncPosCase,), "Positive case", self.METHOD)
        xenrt.sleep(self.COMMAND_INTERVAL)

        step("Running invlaid command.")
        self.runSubcase("runCase", (self.verifyBasicFuncNegCase,), "Negative case", self.METHOD)
        xenrt.sleep(self.COMMAND_INTERVAL)

        step("Running empty command.")
        self.runSubcase("runCase", (self.verifyBasicFuncEmptyCommand,), "Empty command", self.METHOD)
        xenrt.sleep(self.COMMAND_INTERVAL)
Example #28
0
    def verifyAfterVDIFilled(self):

        before = self.xsr.physicalUtilisation

        log("Attaching VDI to guest.")
        dev = self.guest.createDisk(vdiuuid=self.vdi, returnDevice=True)

        log("Fillig 1 GiB.")
        self.guest.execguest(
            "dd if=/dev/urandom of=/dev/%s oflag=direct bs=1M count=1024" %
            dev)

        self.__verifyBasicProperties(False)

        log("Verifying physical utilisation is increased about 1 GiB")
        physicalUtil = self.xsr.physicalUtilisation
        if physicalUtil - before > xenrt.GIGA + 20 * xenrt.MEGA or physicalUtil - before < xenrt.GIGA - 20 * xenrt.MEGA:
            raise xenrt.XRTFailure(
                "Physical utilisazion is different more than 20 MiB after 1 GiB writing."
            )

        log("Verifying raw file size is about 1 GiB.")
        vdiSize = self.getRawVDISize(self.vdi)
        if vdiSize > xenrt.GIGA + 20 * xenrt.MEGA or vdiSize < xenrt.GIGA - 20 * xenrt.MEGA:
            raise xenrt.XRTFailure(
                "VDI size is different more than 20 MiB after 1 GiB filling.")
Example #29
0
    def executeCommandCLI(self,
                          guest,
                          script,
                          forcewrap=False,
                          username=None,
                          password=None):
        """Executing script(batch file) from guest using
        Remote command execution API for CLM

        @param guest: Guest object that to run command.
        @param script: Content of script to run.
        @param forcewrap: When true, script is saved in a text file and called via $(cat ~)
        @param username: RBAC username, root/admin by default.
        @param password: password for username

        @return: Dict of return value of exitcode, stdout and stderr.
        """

        host = guest.host
        if guest.host.pool:
            host = guest.host.pool.master

        # shell scripts parser needs to escaped.
        script = script.replace("\\", "\\\\")
        if forcewrap:
            # Get the host. Use master if VM is in the pool.
            path = host.execdom0("mktemp").strip()
            for line in script.split("\n"):
                host.execdom0("echo \"%s\" >> %s" % (line.strip(), path))
            script = "$(cat %s)" % (path)

        rbac = ""
        if username and password:
            rbac = "-u \"%s\" -pw \"%s\"" % (username, password)

        param = "args:username=\"%s\" args:password=\"%s\" args:script=\"%s\"" % \
            (self.GUEST_USER, self.GUEST_PWD, script)

        log("Executing script...")
        cmd = "xe vm-call-plugin %s vm-uuid=%s plugin=guest-agent-operation fn=run-script %s" % \
            (rbac, guest.getUUID(), param)
        ret = host.execdom0(cmd)
        log("Output: %s" % ret)
        status = eval(ret)

        if forcewrap:
            host.execdom0("rm -f %s" % (path))

        return status
Example #30
0
    def executeCommandAPIAsync(self, guest, script, timeout=60, username=None, password=None):
        """Executing script(batch file) from guest using
        Remote command execution API for CLM

        @param guest: Guest object that to run command.
        @param script: Content of script to run.
        @param timeout: Time out for checking status of execution.
        @param username: RBAC username, root/admin by default.
        @param password: password for username

        @return: Dict of return value of exitcode, stdout and stderr.
        """

        log("Prepare APICall")
        session = self._getSession(guest, username, password)
        guestRef = self._getGuestRef(session, guest)
        session = self._getSession(guest)
        param = {"script": script, "username": self.GUEST_USER, "password": self.GUEST_PWD}

        log("Executing script...")
        task = session.xenapi.Async.VM.call_plugin(guestRef, self.PLUGIN, self.PLUGIN_FUNC, param)

        if timeout == 0:
            return task

        start = xenrt.util.timenow()
        while xenrt.util.timenow() < start + timeout:
            status = session.xenapi.task.get_status(task)
            if status == "success":
                log("%s has finished" % task)
                result = session.xenapi.task.get_result(task)
                break
            elif status == "failure":
                #The task has failed, and the error should be propogated upwards.
                raise Exception("Async call failed with error: %s" % session.xenapi.task.get_error_info(task))
            else:
                log("Task Status: %s" % status)

            if start + timeout <= xenrt.util.timenow():
                raise xenrt.XRTError("task %d has failed to finish in %d time." % (task, timeout))

            xenrt.sleep(2)

        log("Output: %s" % result)
        result = self.__parseAsyncOutput(result)
        status = eval(result)

        return status
Example #31
0
    def messageGet(self, host, name="ALARM", aClass=CLASS, priority=PRIORITY, perfmon=PERFMON):
        """ Check if there is an alert of type perfmon"""
        cli = host.getCLIInstance()
        if not perfmon:
            raise xenrt.XRTError("Please specify perfmon type")
        out=cli.execute("message-list", "name=%s class=%s priority=%s --minimal" % 
                            (name, aClass, priority)).strip()
        for uuid in out.split(','):
            trueFlag = cli.execute('message-list', 'uuid=%s params=body | grep %s' % 
                                        (uuid, perfmon), ignoreerrors=True)
            if trueFlag:
                if uuid in self.MESSAGES:
                    return

                xenrt.log(cli.execute('message-list', 'uuid=%s' % uuid))
                self.MESSAGES.append(uuid)
Example #32
0
    def verifyCommandLength(self, guest):
        cmd1024 = "echo 67890" + ("1234567890" * 101) + "1234" # 10 + (10 * 101) + 4
        cmd1025 = "echo 67890" + ("1234567890" * 101) + "12345" # # 10 + (10 * 101) + 5

        try:
            status = self.executeCommandCLI(guest, cmd1024, forcewrap=True)
        except:
            raise xenrt.XRTFailure("Failed to execute 1024 byte length command")

        xenrt.sleep(self.COMMAND_INTERVAL) 
        try:
            status = self.executeCommandCLI(guest, cmd1025, forcewrap=True)
        except:
            log("Failed to execute longer than 1024 bytes command as expected.")
        else:
            raise xenrt.XRTFailure("XAPI accepted to run longer than 1024 bytes command.")
Example #33
0
    def runCase(self, func):
        """
        Utility function to run jobs simutanously.

        @param func: a refrence to member function that accept a guest as a param
        """

        # Use sub case to run command on all guest simultanously.
        tasks = []
        for guest in self.guests:
            tasks.append(xenrt.PTask(func, guest))
        xenrt.pfarm(tasks)
        for task in tasks:
            if task.exception:
                log("Sub task (%s with %s) has exception: %s" % \
                    (task.func.__name__, task.args[0].getName(), task.exception))
Example #34
0
    def getGuestAgentRamUsage(self, guest):
        """Return size of RAM that guest agent is using."""

        ps = guest.xmlrpcExec(
            "tasklist /FI \"IMAGENAME eq xenguestagent.exe\"", returndata=True)
        log("Found process info: %s" % ps)
        if ps:
            for line in reversed(ps.splitlines()):
                line = line.strip()
                if len(line):
                    try:
                        return int(line.split()[4].replace(",", ""))
                    except:
                        pass
        raise xenrt.XRTError("Cannot find guest agent process from guest %s" %
                             guest.getName())
Example #35
0
    def runCase(self, func):
        """
        Utility function to run jobs simutanously.

        @param func: a refrence to member function that accept a guest as a param
        """

        # Use sub case to run command on all guest simultanously.
        tasks = []
        for guest in self.guests:
            tasks.append(xenrt.PTask(func, guest))
        xenrt.pfarm(tasks)
        for task in tasks:
            if task.exception:
                log("Sub task (%s with %s) has exception: %s" % \
                    (task.func.__name__, task.args[0].getName(), task.exception))
Example #36
0
    def executeOnChariotConsole(self, cmd):
        return_code = xenrt.ssh.SSH(self.consoleAddress,
                                    cmd,
                                    username=self.consoleUser,
                                    level=xenrt.RC_FAIL,
                                    timeout=300,
                                    idempotent=False,
                                    newlineok=False,
                                    getreply=True,
                                    nolog=False,
                                    useThread=False,
                                    outfile=None,
                                    password=None)

        xenrt.log(return_code)
        return return_code
Example #37
0
    def run(self, arglist=[]):
        log("Running Basic functionality with %s method." % self.METHOD)

        step("Running valid command.")
        self.runSubcase("runCase", (self.verifyBasicFuncPosCase, ),
                        "Positive case", self.METHOD)
        xenrt.sleep(self.COMMAND_INTERVAL)

        step("Running invlaid command.")
        self.runSubcase("runCase", (self.verifyBasicFuncNegCase, ),
                        "Negative case", self.METHOD)
        xenrt.sleep(self.COMMAND_INTERVAL)

        step("Running empty command.")
        self.runSubcase("runCase", (self.verifyBasicFuncEmptyCommand, ),
                        "Empty command", self.METHOD)
        xenrt.sleep(self.COMMAND_INTERVAL)
Example #38
0
    def executeOnChariotConsole(self, cmd):
        return_code = xenrt.ssh.SSH(
            self.consoleAddress,
            cmd,
            username=self.consoleUser,
            level=xenrt.RC_FAIL,
            timeout=300,
            idempotent=False,
            newlineok=False,
            getreply=True,
            nolog=False,
            useThread=False,
            outfile=None,
            password=None)

        xenrt.log(return_code)
        return return_code
Example #39
0
    def run(self, arglist=[]):

        log("Using %s(%s) SR to test." % (self.xsr.name, self.xsr.uuid))

        step("Store initial status of local disk.")
        self.initialStatus = self.getRawProperties()

        step("Verify initial status of SR")
        self.verifyInitialProperties()

        step("Verify status of SR after a linux VM is installed.")
        self.verifyAfterGuestInstalled()

        step("Verify status of SR after an empty VDI is created.")
        self.verifyAfterVDICreated()

        step("Verify status of SR after fill VDI.")
        self.verifyAfterVDIFilled()
Example #40
0
    def run(self, arglist=[]):

        log ("Using %s(%s) SR to test." % (self.xsr.name, self.xsr.uuid))

        step("Store initial status of local disk.")
        self.initialStatus = self.getRawProperties()

        step("Verify initial status of SR")
        self.verifyInitialProperties()

        step("Verify status of SR after a linux VM is installed.")
        self.verifyAfterGuestInstalled()

        step("Verify status of SR after an empty VDI is created.")
        self.verifyAfterVDICreated()

        step("Verify status of SR after fill VDI.")
        self.verifyAfterVDIFilled()
Example #41
0
    def runLongRunningCommand(self, guest, time=0, script=None):
        """ Running a time consuming task on guest.

        @param guest: Guest instance to run command.
        @param time: running time in second. 0 indicate indefinite.

        @return: task id of XAPI async call.
        """

        if not script:
            script = "ping citrite.net -t"
            if time > 0:
                script = "ping citrite.net -n %d" % ((time + 1),)

        log("Running command %s on %s." % ("indefinite time" if time == 0 else "for %d seconds" % (time,), guest.getName()))
        task = self.executeCommandAPIAsync(guest, script, timeout=0)

        return task
Example #42
0
    def executeCommandCLI(self, guest, script, forcewrap=False, username=None, password=None):
        """Executing script(batch file) from guest using
        Remote command execution API for CLM

        @param guest: Guest object that to run command.
        @param script: Content of script to run.
        @param forcewrap: When true, script is saved in a text file and called via $(cat ~)
        @param username: RBAC username, root/admin by default.
        @param password: password for username

        @return: Dict of return value of exitcode, stdout and stderr.
        """

        host = guest.host
        if guest.host.pool:
            host = guest.host.pool.master

        # shell scripts parser needs to escaped.
        script = script.replace("\\", "\\\\")
        if forcewrap:
            # Get the host. Use master if VM is in the pool.
            path = host.execdom0("mktemp").strip()
            for line in script.split("\n"):
                host.execdom0("echo \"%s\" >> %s" % (line.strip(), path))
            script = "$(cat %s)" % (path)

        rbac = ""
        if username and password:
            rbac = "-u \"%s\" -pw \"%s\"" % (username, password)

        param = "args:username=\"%s\" args:password=\"%s\" args:script=\"%s\"" % \
            (self.GUEST_USER, self.GUEST_PWD, script)

        log("Executing script...")
        cmd = "xe vm-call-plugin %s vm-uuid=%s plugin=guest-agent-operation fn=run-script %s" % \
            (rbac, guest.getUUID(), param)
        ret = host.execdom0(cmd)
        log("Output: %s" % ret)
        status = eval(ret)

        if forcewrap:
            host.execdom0("rm -f %s" % (path))

        return status
Example #43
0
    def enableAlertonSR(self,
                        host,
                        sruuid,
                        perfmon=PERFMON,
                        alarmLevel="0.0009765625",
                        alarmTriggerPeriod="60",
                        alarmAutoInhibitPeriod="300"):
        """This defaults to setting an alert with repeat time of 1 min and perfmon poll time of 5 min for 1 KB/min
        xe sr-param-set other-config:
        perfmon='<config><variable><name value="sr_io_throughput_total_per_host" /><alarm_trigger_level value="0.0009765625" />
        <alarm_trigger_period value="60" /><alarm_auto_inhibit_period value="300" /></variable></config>' """

        cli = host.getCLIInstance()
        # Start on a clean slate
        self.deleteAllAlarms(host)

        # Check if alarm of requested type is already enabled
        try:
            enableFlag = cli.execute(
                'sr-param-get',
                'param-key="other-config" param-name="perfmon" uuid=%s' %
                sruuid)
        except:
            # We dont really want to do anything with the exception
            enableFlag = ""

        if re.search(perfmon, enableFlag, re.IGNORECASE):
            return

        cmdXML ="<config><variable><name value=\'%s\' />" \
                "<alarm_trigger_level value=\'%s\' />" \
                "<alarm_trigger_period value=\'%s\' />" \
                "<alarm_auto_inhibit_period value=\'%s\' />" \
                "</variable></config>" % \
                (perfmon, alarmLevel, alarmTriggerPeriod, alarmAutoInhibitPeriod)
        param = "other-config:perfmon"
        # Set param on sr
        cli.execute("sr-param-set",
                    "uuid=%s %s=\"%s\"" % (sruuid, param, cmdXML))
        self.origXrtTime = xenrt.timenow()
        xenrt.log("Alert enabled at time - %s" % self.origXrtTime)

        xenrt.log("Verify the other-config parameters for perfmon")
        self.verifyOtherConfigCmd(host, alertClass="sr", uuid=sruuid)
Example #44
0
    def verifyRateLimited(self, guest):
        """Verify XAPI blocks guest running command in short time."""
        script = "dir"
        self.runCommand(guest, script)

        try:
            self.runCommand(guest, script)
        except:
            log("Execution failed as expected.")
        else:
            raise xenrt.XRTFailure("XAPI accept a call during rate limit cool-down.")

        # Just to verify.
        xenrt.sleep(self.COMMAND_INTERVAL)

        try:
            self.runCommand(guest, script)
        except:
            raise xenrt.XRTFailure("XAPI blocked a call after rate limit cool-down.")
Example #45
0
    def getRawProperties(self):
        """
        From local SR, collect storage information and return information.

        @return: list of physical size, physical utilisation and accumlated virtual sizes of all VDIs in the SR.
        """
        host = self.host

        # Try search by uuid in local storage. If failed try check dev.
        dfoutput = host.execdom0("df -B 1 | grep '%s'" % self.srPath).split()

        rawPhysicalSize = int(dfoutput[1])
        rawPhysicalUtil = int(dfoutput[2])
        accumVirtualSize = 0
        accumVirtualSize = sum([vdi.size for vdi in self.xsr.VDIs])
        log("Current local status: physical size = %d, physical utilisation = %d, accumulated virtual size = %d" % \
            (rawPhysicalSize, rawPhysicalUtil, accumVirtualSize))

        return (rawPhysicalSize, rawPhysicalUtil, accumVirtualSize)
Example #46
0
    def getRawProperties(self):
        """
        From local SR, collect storage information and return information.

        @return: list of physical size, physical utilisation and accumlated virtual sizes of all VDIs in the SR.
        """
        host = self.host

        # Try search by uuid in local storage. If failed try check dev.
        dfoutput = host.execdom0("df -B 1 | grep '%s'" % self.srPath).split()

        rawPhysicalSize = int(dfoutput[1])
        rawPhysicalUtil = int(dfoutput[2])
        accumVirtualSize = 0
        accumVirtualSize = sum([vdi.size for vdi in self.xsr.VDIs])
        log("Current local status: physical size = %d, physical utilisation = %d, accumulated virtual size = %d" % \
            (rawPhysicalSize, rawPhysicalUtil, accumVirtualSize))

        return (rawPhysicalSize, rawPhysicalUtil, accumVirtualSize)
Example #47
0
    def runLongRunningCommand(self, guest, time=0, script=None):
        """ Running a time consuming task on guest.

        @param guest: Guest instance to run command.
        @param time: running time in second. 0 indicate indefinite.

        @return: task id of XAPI async call.
        """

        if not script:
            script = "ping citrite.net -t"
            if time > 0:
                script = "ping citrite.net -n %d" % ((time + 1), )

        log("Running command %s on %s." %
            ("indefinite time" if time == 0 else "for %d seconds" %
             (time, ), guest.getName()))
        task = self.executeCommandAPIAsync(guest, script, timeout=0)

        return task
Example #48
0
    def __verifyBasicProperties(self, checkPU=True):

        self.host.execdom0("xe sr-scan uuid=%s" % self.xsr.uuid)

        log("Collect local status.")
        rawStatus = self.getRawProperties()

        log("Verify basic properties.")
        physicalSize = self.xsr.physicalSize
        if rawStatus[0] != physicalSize:
            raise xenrt.XRTFailure("Physical Size mismatched. %s from df / %s in SR property." % (rawStatus[0], physicalSize))

        virtualAlloc = self.xsr.virtualAllocation
        if rawStatus[2] != virtualAlloc:
            raise xenrt.XRTFailure("Vitual allocation mismatched. %d from %d VDIs / %s in SR property." % (rawStatus[2], len(self.xsr.VDIs), virtualAlloc))

        if checkPU:
            physicalUtil = self.xsr.physicalUtilisation
            if rawStatus[1] != physicalUtil:
                raise xenrt.XRTFailure("Physical Utilisation mismatched. %d from df / %s in SR property." % (rawStatus[1], physicalUtil))
Example #49
0
    def verifyCommandLength(self, guest):
        cmd1024 = "echo 67890" + ("1234567890" *
                                  101) + "1234"  # 10 + (10 * 101) + 4
        cmd1025 = "echo 67890" + ("1234567890" *
                                  101) + "12345"  # # 10 + (10 * 101) + 5

        try:
            status = self.executeCommandCLI(guest, cmd1024, forcewrap=True)
        except:
            raise xenrt.XRTFailure(
                "Failed to execute 1024 byte length command")

        xenrt.sleep(self.COMMAND_INTERVAL)
        try:
            status = self.executeCommandCLI(guest, cmd1025, forcewrap=True)
        except:
            log("Failed to execute longer than 1024 bytes command as expected."
                )
        else:
            raise xenrt.XRTFailure(
                "XAPI accepted to run longer than 1024 bytes command.")
Example #50
0
 def additionalVerification(self, host, msglist):
     xenrt.log("Additional check to ensure the alerts"
               "are generated for the SR under test")
     xenrt.log(msglist)
     perfmon1 = host.execdom0(
         'xe message-param-get param-name=body uuid=%s | grep "configured_on" | cut -d\'"\' -f4'
         % msglist[0]).strip()
     xenrt.log("Perfmon name retrieved %s" % perfmon1)
     perfmon2 = host.execdom0(
         'xe message-param-get param-name=body uuid=%s | grep "configured_on" | cut -d\'"\' -f4'
         % msglist[1]).strip()
     xenrt.TEC().logverbose("Perfmon name retrieved %s" % perfmon2)
     # Verify uuid of sr in the perfmon
     if not re.search(perfmon1, self.uuid, re.IGNORECASE):
         xenrt.log(host.execdom0("xe message-list uuid=%s" % msglist[0]))
         raise xenrt.XRTFailure(
             "Generated alerts are not for the configured SR")
     if not re.search(perfmon2, self.uuid, re.IGNORECASE):
         xenrt.log(host.execdom0("xe message-list uuid=%s" % msglist[1]))
         raise xenrt.XRTFailure(
             "Generated alerts are not for the configured SR")
Example #51
0
    def verifyRateLimited(self, guest):
        """Verify XAPI blocks guest running command in short time."""
        script = "dir"
        self.runCommand(guest, script)

        try:
            self.runCommand(guest, script)
        except:
            log("Execution failed as expected.")
        else:
            raise xenrt.XRTFailure(
                "XAPI accept a call during rate limit cool-down.")

        # Just to verify.
        xenrt.sleep(self.COMMAND_INTERVAL)

        try:
            self.runCommand(guest, script)
        except:
            raise xenrt.XRTFailure(
                "XAPI blocked a call after rate limit cool-down.")
Example #52
0
 def additionalVerification(self, host, msglist):
     xenrt.log("Additional check to ensure the alerts"
                             "are generated for the SR under test")
     xenrt.log(msglist)
     perfmon1=host.execdom0('xe message-param-get param-name=body uuid=%s | grep "configured_on" | cut -d\'"\' -f4' % 
                             msglist[0]).strip()
     xenrt.log("Perfmon name retrieved %s" %
                             perfmon1)
     perfmon2=host.execdom0('xe message-param-get param-name=body uuid=%s | grep "configured_on" | cut -d\'"\' -f4' % 
                             msglist[1]).strip()
     xenrt.TEC().logverbose("Perfmon name retrieved %s" %
                             perfmon2)
     # Verify uuid of sr in the perfmon
     if not re.search(perfmon1, self.uuid, re.IGNORECASE):
         xenrt.log(host.execdom0("xe message-list uuid=%s" % 
                                 msglist[0]))
         raise xenrt.XRTFailure("Generated alerts are not for the configured SR")
     if not re.search(perfmon2, self.uuid, re.IGNORECASE):
         xenrt.log(host.execdom0("xe message-list uuid=%s" % 
                                 msglist[1]))
         raise xenrt.XRTFailure("Generated alerts are not for the configured SR")
Example #53
0
    def executeCommandAPI(self, guest, script, username=None, password=None):
        """Executing script(batch file) from guest using
        Remote command execution API for CLM

        @param guest: Guest object that to run command.
        @param script: Content of script to run.
        @param username: RBAC username, root/admin by default.
        @param password: password for username

        @return: Dict of return value of exitcode, stdout and stderr.
        """

        log("Prepare APICall")
        session = self._getSession(guest, username, password)
        guestRef = self._getGuestRef(session, guest)
        param = {
            "script": script,
            "username": self.GUEST_USER,
            "password": self.GUEST_PWD
        }

        log("Executing script...")
        ret = session.xenapi.VM.call_plugin(guestRef, self.PLUGIN,
                                            self.PLUGIN_FUNC, param)
        log("Output: %s" % ret)
        status = eval(ret)

        return status
Example #54
0
    def verifyVMOPsProhibited(self, guest):
        """Check VM power operations are blocked by XAPI during command is running."""

        try:
            guest.suspend()
        except:
            log("Suspend is blocked as expected.")
        else:
            raise xenrt.XRTFailure("Guest rebooted while a command is running.")

        try:
            guest.shutdown()
        except:
            log("Shutdown is blocked as expected.")
        else:
            raise xenrt.XRTFailure("Guest rebooted while a command is running.")

        pool = guest.host.pool
        if not pool:
            pool = self.getDefaultPool()
        if not pool:
            raise xenrt.XRTError("VM OPs test requires a pool.")
        target = None
        for host in pool.getHosts():
            if host != guest.host:
                target = host
                break
        try:
            guest.migrateVM(target, live="true")
        except:
            log("VM migration is blocked as expected.")
        else:
            raise xenrt.XRTFailure("VM migration is allowed while a command is running.")
Example #55
0
    def run(self, arglist=None):
        # Initialize Service settings on pool and Enrol pool for Service
        self.service.initializeService(self.pool)
        self.service.activateService(self.pool)

        step("Now Attach the host to XenCenter")
        self.guest.attachXenCenterToHost(self.pool.master)

        step("Enable Firewall so that the upload fails")
        self.blockService(self.guest)

        triggerTime = self.service.triggerService(self.pool, self.options)
        if self.service.verifyService(self.pool, triggerTime):
            raise xenrt.XRTFailure(
                "Upload Successful inspite of blocking access to MockServer")
        else:
            xenrt.log(
                "Upload would have failed as expected.Lets check the trace of Failed Upload"
            )
            if self.service.verifyServiceFailure(self.pool, triggerTime):
                xenrt.log("Upload Failed at predictable timestamp as Expected")
            else:
                raise xenrt.XRTFailure(
                    "Couldnt find the trace of Failed Upload")

        step(
            "So upload failed. Now disable firewall so the failed upload goes through"
        )
        self.unblockService(self.guest)

        if self.service.verifyService(self.pool, triggerTime, timeout=2000):
            xenrt.log("Previous Upload attempt is finally successful")
        else:
            raise xenrt.XRTFailure("Previous Upload attempt is still pending")
Example #56
0
    def run(self, arglist=None):
        # Initialize Service settings on pool and Enrol pool for Service
        self.service.initializeService(self.pool)
        self.service.activateService(self.pool)

        step("Now Attach the host to XenCenter")
        self.guest.attachXenCenterToHost(self.pool.master)

        step("Enable Firewall so that the upload fails")
        self.blockService(self.guest)

        triggerTime=self.service.triggerService(self.pool,self.options)
        if self.service.verifyService(self.pool,triggerTime):
            raise xenrt.XRTFailure("Upload Successful inspite of blocking access to MockServer")
        else:
            xenrt.log("Upload would have failed as expected.Lets check the trace of Failed Upload")
            if self.service.verifyServiceFailure(self.pool,triggerTime):
                xenrt.log("Upload Failed at predictable timestamp as Expected")
            else:
                raise xenrt.XRTFailure("Couldnt find the trace of Failed Upload")

        step("So upload failed. Now disable firewall so the failed upload goes through")
        self.unblockService(self.guest)


        if self.service.verifyService(self.pool,triggerTime,timeout=2000):
            xenrt.log("Previous Upload attempt is finally successful")
        else :
            raise xenrt.XRTFailure("Previous Upload attempt is still pending")
Example #57
0
    def setNewUploadSchedule(self,pool,hcparams=None):
        cli = pool.master.getCLIInstance()

        currTimeStamp=time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime(self.guest.getTime()))
        t=time.strptime(currTimeStamp, "%Y-%m-%dT%H:%M:%S")
        if not hcparams:
            hcparams={}
            #Adjust the dayofWeek as Monday is 1 as per XenCenter
            hcparams["Schedule.DayOfWeek"]=str((t.tm_wday+1)%7)
            #We are setting the new schedule so that upload happens in the very next hour at the time of the execution of the testcase
            hcparams["Schedule.TimeOfDay"]=str(t.tm_hour+1)
            hcparams["Schedule.IntervalInDays"]=str(7)
            hcparams["Schedule.RetryInterval"]=str(1)
            hcparams["NewUploadRequest"]=""
        xenrt.log("Set the new schedule for upload")
        for health_check_key in hcparams:
            cli.execute("pool-param-set","uuid=%s health-check-config:%s=%s" % (pool.getUUID(),health_check_key,hcparams[health_check_key]))

        #get the timestamp based on the new schedule
        nextUploadTs=str(t.tm_year)+"-"+ str(t.tm_mon)+"-"+ str(t.tm_mday)+"T"+str(hcparams["Schedule.TimeOfDay"])
        nextUploadAbs=int(calendar.timegm(time.strptime(nextUploadTs, "%Y-%m-%dT%H")))
        return nextUploadAbs
Example #58
0
    def enableAlertonHost(self,
                          host,
                          perfmon=PERFMON,
                          alarmLevel="4E30",
                          alarmTriggerPeriod="60",
                          alarmAutoInhibitPeriod="300"):
        """This defaults to setting an alert with repeat time of 1 min and perfmon poll time of 5 min 
        xe host-param-set other-config:
        perfmon='<config><variable><name value="network_usage" /><alarm_trigger_level value="2" />
        <alarm_trigger_period value="30" /><alarm_auto_inhibit_period value="300" /></variable></config>' """

        # Start on a clean slate
        self.deleteAllAlarms(host)

        # Check if alarm of requested type is already enabled
        try:
            enableFlag = host.getHostParam("other-config", "perfmon")
        except:
            enableFlag = ""
        if re.search(perfmon, enableFlag, re.IGNORECASE):
            self.origXrtTime = xenrt.timenow()
            return

        cmdXML ="<config><variable><name value=\'%s\' />" \
                "<alarm_trigger_level value=\'%s\' />" \
                "<alarm_trigger_period value=\'%s\' />" \
                "<alarm_auto_inhibit_period value=\'%s\' />" \
                "</variable></config>" % \
                (perfmon, alarmLevel, alarmTriggerPeriod, alarmAutoInhibitPeriod)
        param = "other-config:perfmon"
        host.setHostParam(param, cmdXML)

        self.origXrtTime = xenrt.timenow()
        xenrt.log("Alert enabled at time - %s" % self.origXrtTime)

        xenrt.log("Verify the other-config parameters for perfmon")
        self.verifyOtherConfigCmd(host)
Example #59
0
    def run(self, arglist=None):

        log("Creating VDI.")
        vdi = self.host.createVDI(1 * xenrt.GIGA, self.sr.uuid).strip()

        log("Forget and introduce SR.")
        self.sr.forget()
        self.sr.introduce()

        log("Verify VDI is present.")
        if not vdi in self.sr.listVDIs():
            raise xenrt.XRTFailure("Reintroduced SR does not have the VDI before forget.")

        log("Distroying SR.")
        self.sr.destroy()
        if not self.sr.uuid in self.host.minimalList("sm-list"):
            raise xenrt.XRTFailure("SR info has been disappeared after destroying SR.")