Пример #1
0
 def __init__(self, json, guest, depth=0):
     self.reader = CommandsReader(json, guest)
     self.output = ""
     self.__depth = depth
     if depth > self.DEPTH_LIMIT:
         xenrt.warning(
             "Shell script runner is running in deeper depth than allowed. This may cause low memory issue."
         )
Пример #2
0
    def createGuestFromTemplate(self, 
                                template, 
                                sruuid, 
                                ni=False, 
                                db=True, 
                                guestparams=[],
                                rootdisk=None):
        if self.memory is None:
            self.memory = 512
        if self.memory % 4 != 0:
            self.memory -= (self.memory % 4)
            xenrt.warning("ESX: Memory must be a multiple of 4MB. Rounding to %dMB" % self.memory)
        if self.vcpus is None:
            self.vcpus = 1
        if self.vcpus != 1 and self.vcpus % 2 == 1:
            self.vcpus -= (self.vcpus % 2)
            xenrt.warning("ESX: VCPUs must be a multiple of 2 (or 1). Rounding to %d VCPUs" % self.memory)
        if rootdisk == self.DEFAULT or rootdisk is None:
            rootdisk = 16*xenrt.GIGA

        # create disks
        # FIXME: hard-coded
        vdiname = "%s/%s.%s" % (self.name, self.name, self.DEFAULT_DISK_FORMAT)
        self.host.createVDI(rootdisk, sruuid, name=vdiname, format=self.DEFAULT_DISK_FORMAT)

        srobj = self.host.srs[self.host.getSRName(sruuid)]
        domain  = "<domain type='vmware'>"
        domain += "  <name>%s</name>" % self.name
        domain += "  <memory unit='MiB'>%d</memory>" % self.memory
        domain += "  <currentMemory unit='MiB'>%d</currentMemory>" % self.memory
        domain += "  <vcpu placement='static'>%d</vcpu>" % self.vcpus
        domain += "  <os>"
        domain += "    <type arch='i686'>hvm</type>"
        domain += "    <boot dev='hd'/>"
        domain += "  </os>"
        domain += "  <clock offset='utc'/>"
        domain += "  <on_poweroff>destroy</on_poweroff>"
        domain += "  <on_reboot>restart</on_reboot>"
        domain += "  <on_crash>destroy</on_crash>"
        domain += "  <devices>"
        domain += "    <disk type='file' device='disk'>"
        domain += "      <source file='%s'/>" % srobj.getVDIPath(vdiname)
        domain += "      <target dev='%sa' bus='%s'/>" % (self._getDiskDevicePrefix(), self._getDiskDeviceBus())
        domain += "      <address type='drive' controller='0' bus='0' target='0' unit='0'/>"
        domain += "    </disk>"
        domain += "    <controller type='scsi' index='0' model='lsilogic'/>"
        domain += "    <controller type='ide' index='0'/>"
        domain += "    <input type='mouse' bus='ps2'/>"
        domain += "    <graphics type='vnc' autoport='yes'>"
        domain += "      <listen type='address' address='0.0.0.0'/>"
        domain += "    </graphics>"
        domain += "    <video>"
        domain += "      <model type='vmvga' vram='16384'/>"
        domain += "    </video>"
        domain += "  </devices>"
        domain += "</domain>"
        self._defineXML(domain)
Пример #3
0
    def execute(self, method="GET", category=None, sid=None, command=None, params={}, authFilter=False, tries=3):
        """Make an API request and return list/dict object"""
        method = method.upper()
        if method not in ["GET", "POST", "PUT", "DELETE", "PATCH"]:
            raise xenrt.XRTError("Unknown method: %s" % method)

        # if type(args) is not "dict":
        #     raise xenrt.XRTError("Parameters to REST API should be packed in a dictionary")
        if self.accessToken:
            params["access_token"] = self.accessToken

        uri = self.__buildURI(category, sid, command)

        while tries > 0:
            tries -= 1
            xenrt.TEC().logverbose("Running URI: %s" % uri)
            if authFilter:
                if method == "POST":                    
                    r = requests.post(uri, auth=(self.apikey, self.credential), data=urllib.urlencode(params), headers={"Content-type": "application/x-www-form-urlencoded"}, verify=False)
                else:
                    r = requests.request(method, uri, auth=(self.apikey, self.credential), params=params, verify=False)
            else:
                if method == "POST":
                    r = requests.post(uri, data=urllib.urlencode(params), headers={"Content-type": "application/x-www-form-urlencoded"}, verify=False)
                else:
                    r = requests.request(method, uri, params=params, verify=False)
            xenrt.TEC().logverbose("%d: %s" % (r.status_code, r.text))
            if r.status_code == 200:
                return json.loads(r.text)
            if r.status_code == 400:
                xenrt.TEC().logverbose(r.text)
                raise xenrt.XRTError("Bad input parameter or error message: %s" % params)
            if r.status_code == 401:
                xenrt.TEC().logverbose(r.text)
                xenrt.TEC().logverbose("Access Token is expired or invalid. Trying again... (%d attempt left)" % tries)
                # If access token was issued already, it can be expired. re-issue new one before retry.
                if self.accessToken:
                    self.accessToken = None
                    self.authenticate()
            if r.status_code == 500:
                xenrt.TEC().logverbose(r.text)
                xenrt.warning("Unknown server error. %d: %s (%d attempt left)" % (r.status_code, r.text, tries))

            xenrt.sleep(5)

        raise xenrt.XRTError("Failed to execute %s uri." % uri)
Пример #4
0
    def run(self, arglist=None):
        guest = self.guests[0]

        initialCnt = self.getTempFileCount()
        log("Initial file count of temp dir is %d" % initialCnt)

        self.runLongRunningCommand(guest, time=60)
        xenrt.sleep(10)
        runningCnt = self.getTempFileCount()
        log("File count while command is running is %d" % runningCnt)

        xenrt.sleep(60)
        finalCnt = self.getTempFileCount()
        log("File coutn after command is executed is %d" % finalCnt)

        if runningCnt <= initialCnt:
            warning("Temp file count has decreased while command is running.")
        if finalCnt >= runningCnt:
            raise xenrt.XRTFailure("Temp file count has not decreased after command is done.")
        if finalCnt != initialCnt:
            warning("Temp file count has been changed after command is executed.")
Пример #5
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])
Пример #6
0
    def run(self, arglist=None):
        guest = self.guests[0]

        initialCnt = self.getTempFileCount()
        log("Initial file count of temp dir is %d" % initialCnt)

        self.runLongRunningCommand(guest, time=60)
        xenrt.sleep(10)
        runningCnt = self.getTempFileCount()
        log("File count while command is running is %d" % runningCnt)

        xenrt.sleep(60)
        finalCnt = self.getTempFileCount()
        log("File coutn after command is executed is %d" % finalCnt)

        if runningCnt <= initialCnt:
            warning("Temp file count has decreased while command is running.")
        if finalCnt >= runningCnt:
            raise xenrt.XRTFailure(
                "Temp file count has not decreased after command is done.")
        if finalCnt != initialCnt:
            warning(
                "Temp file count has been changed after command is executed.")
Пример #7
0
    def createGuestFromTemplate(self,
                                template,
                                sruuid,
                                ni=False,
                                db=True,
                                guestparams=[],
                                rootdisk=None):
        if self.memory is None:
            self.memory = 512
        if self.memory % 4 != 0:
            self.memory -= (self.memory % 4)
            xenrt.warning(
                "ESX: Memory must be a multiple of 4MB. Rounding to %dMB" %
                self.memory)
        if self.vcpus is None:
            self.vcpus = 1
        if self.vcpus != 1 and self.vcpus % 2 == 1:
            self.vcpus -= (self.vcpus % 2)
            xenrt.warning(
                "ESX: VCPUs must be a multiple of 2 (or 1). Rounding to %d VCPUs"
                % self.memory)
        if rootdisk == self.DEFAULT or rootdisk is None:
            rootdisk = 16 * xenrt.GIGA

        # create disks
        # FIXME: hard-coded
        vdiname = "%s/%s.%s" % (self.name, self.name, self.DEFAULT_DISK_FORMAT)
        self.host.createVDI(rootdisk,
                            sruuid,
                            name=vdiname,
                            format=self.DEFAULT_DISK_FORMAT)

        srobj = self.host.srs[self.host.getSRName(sruuid)]
        domain = "<domain type='vmware'>"
        domain += "  <name>%s</name>" % self.name
        domain += "  <memory unit='MiB'>%d</memory>" % self.memory
        domain += "  <currentMemory unit='MiB'>%d</currentMemory>" % self.memory
        domain += "  <vcpu placement='static'>%d</vcpu>" % self.vcpus
        domain += "  <os>"
        domain += "    <type arch='i686'>hvm</type>"
        domain += "    <boot dev='hd'/>"
        domain += "  </os>"
        domain += "  <clock offset='utc'/>"
        domain += "  <on_poweroff>destroy</on_poweroff>"
        domain += "  <on_reboot>restart</on_reboot>"
        domain += "  <on_crash>destroy</on_crash>"
        domain += "  <devices>"
        domain += "    <disk type='file' device='disk'>"
        domain += "      <source file='%s'/>" % srobj.getVDIPath(vdiname)
        domain += "      <target dev='%sa' bus='%s'/>" % (
            self._getDiskDevicePrefix(), self._getDiskDeviceBus())
        domain += "      <address type='drive' controller='0' bus='0' target='0' unit='0'/>"
        domain += "    </disk>"
        domain += "    <controller type='scsi' index='0' model='lsilogic'/>"
        domain += "    <controller type='ide' index='0'/>"
        domain += "    <input type='mouse' bus='ps2'/>"
        domain += "    <graphics type='vnc' autoport='yes'>"
        domain += "      <listen type='address' address='0.0.0.0'/>"
        domain += "    </graphics>"
        domain += "    <video>"
        domain += "      <model type='vmvga' vram='16384'/>"
        domain += "    </video>"
        domain += "  </devices>"
        domain += "</domain>"
        self._defineXML(domain)
Пример #8
0
 def __init__(self, json, guest, depth = 0):
     self.reader = CommandsReader(json, guest)
     self.output = ""
     self.__depth = depth
     if depth > self.DEPTH_LIMIT:
         xenrt.warning("Shell script runner is running in deeper depth than allowed. This may cause low memory issue.")