Пример #1
0
def compareResValue(res1, res2):
    res1 = str(res1)
    res2 = str(res2)
    res1Value = bit_change(res1)
    res2Value = bit_change(res2)
    if res1Value and res2Value:
        result = int(res1Value) - int(res2Value)
        if result == 0:
            return "equal"
        elif result > 0:
            return "greater"
        else:
            return "less"
    else:
        raise checkError("the format of param is error")
Пример #2
0
def compareMem(master, slave, timeout=60):
    '''
    the first host must be the one that run the autotest.
    '''
    print "begin compareMem"
    i = int(0)
    timeout = int(timeout)
    while True:
        cmd1 = "jhosts -l %s" % master
        stdout, stderr, exitcode = execCommand(cmd1, timeout)
        cmd2 = "jhosts -l %s" % slave
        stdout2, stderr2, exitcode2 = execCommand(cmd2, timeout)
        print stderr, stderr2
        if stderr or stderr2:
            raise RuntimeError
        else:
            ut_tmp = re.findall(
                r'\bResource.mem\s*=\s*Total:\s*(.+)\s*,\s*Reserved:', stdout)
            ut_tmp2 = re.findall(
                r'\bResource.mem\s*=\s*Total:\s*(.+)\s*,\s*Reserved:', stdout2)
            checkRange = int(5)
            ut1 = bit_change(str(ut_tmp[0]))
            ut2 = bit_change(str(ut_tmp2[0]))
            if (ut1 > int(-1)) and (ut2 > int(-1)):
                res_compare = (ut2 - ut1)
                if res_compare >= int(0):
                    if res_compare > checkRange:
                        return slave, master
                    else:
                        if i == int(0):
                            resumeMem("50")
                        try:
                            time.sleep(2)
                        except KeyboardInterrupt:
                            raise RuntimeError
                else:
                    if res_compare < int(-checkRange):
                        return master, slave
                    else:
                        if i == int(0):
                            resumeMem("50")
                        try:
                            time.sleep(2)
                        except KeyboardInterrupt:
                            raise RuntimeError
            else:
                raise checkError("the format of param is error")
            i = i + 1
Пример #3
0
def getHostReserved(host,resName):
    '''
    resName = { r15s | r1m | r15m | ut | pg | io | ls | it | tmp | swp | mem | cpuspeed }
    '''
    if host.hostResvRusage:
        return bit_change(get_value(resName,host.hostResvRusage))
    else:
        return ""
Пример #4
0
def getJobRusageInfo(job, resName):
    '''
    resName = { MEM | SWAP | PGID | PIDs }
    '''
    if job.jobResUsg:
        print job.jobResUsg
        print get_value(resName, job.jobResUsg)
        return bit_change(get_value(resName, job.jobResUsg))
    else:
        return ""
Пример #5
0
def checkRusageValue(total, reserved, used, checkRange=5):
    '''
    this function can check the value of the resource reservation within a certain range.
    '''
    checkRange = int(checkRange)
    print str(total)
    print str(used)
    print str(reserved)
    totalValue = bit_change(str(total))
    usedValue = bit_change(str(used))
    reservedValue = bit_change(str(reserved))
    if (totalValue > int(-1)) and (usedValue > int(-1)) and (reservedValue >
                                                             int(-1)):
        res_compare = (totalValue - usedValue - reservedValue)
        if abs(res_compare) <= checkRange:
            return "equal"
        else:
            raise checkError("unequal")
    else:
        raise checkError("the format of param is error")
Пример #6
0
def getHostThredStop(host,resName):
    if host.hostStopload:
        return bit_change(get_value(resName,host.hostStopload))
    else:
        return ""