def doCheck(self):
        MemSwap = 0
        self.result.raw = ""
        result_swap = g_file.readFile('/proc/meminfo', "SwapTotal")[0]
        self.result.raw += result_swap
        swapInfo = result_swap.strip().split(' ')
        val = int(swapInfo[len(swapInfo) - 2])
        factor = swapInfo[len(swapInfo) - 1]
        if factor == 'kB':
            MemSwap = val * 1024
        elif (factor == ''):
            MemSwap = val

        result_mem = g_file.readFile('/proc/meminfo', "MemTotal")[0]
        self.result.raw += "\n%s" % result_mem
        memInfo = result_mem.strip().split()
        val = int(memInfo[len(memInfo) - 2])
        factor = memInfo[len(memInfo) - 1]
        if factor == 'kB':
            MemTotal = val * 1024
        elif (factor == ''):
            MemTotal = val

        if (MemSwap > MemTotal):
            self.result.rst = ResultStatus.NG
            self.result.val = "SwapMemory(%d) must be 0.\nMemTotal: %d." % (
                MemSwap, MemTotal)
        elif (MemSwap != 0):
            self.result.rst = ResultStatus.WARNING
            self.result.val = "SwapMemory(%d) must be 0.\nMemTotal: %d." % (
                MemSwap, MemTotal)
        else:
            self.result.rst = ResultStatus.OK
            self.result.val = "SwapMemory %d\nMemTotal %d." % (MemSwap,
                                                               MemTotal)
Beispiel #2
0
    def doCheck(self):
        global networkCards
        if (self.cluster):
            # Get node information
            LocalNodeInfo = self.cluster.getDbNodeByName(self.host)
            # Get the IP address
            serviceIP = LocalNodeInfo.backIps[0]
        elif (self.ipAddr):
            serviceIP = self.ipAddr
        else:
            serviceIP = SharedFuncs.getIpByHostName(self.host)
        networkCards = g_network.getAllNetworkInfo()
        for network in networkCards:
            if (network.ipAddress == serviceIP):
                networkCardNum = network.NICNum
                netBondMode = network.networkBondModeInfo
                break

        self.result.val = netBondMode
        self.result.rst = ResultStatus.OK
        self.result.raw = "%s\n%s\n" % (networkCardNum, netBondMode)

        bondFile = '/proc/net/bonding/%s' % networkCardNum
        if (os.path.exists(bondFile)):
            self.result.raw += bondFile
            flag1 = g_file.readFile(bondFile, 'BONDING_OPTS')
            flag2 = g_file.readFile(bondFile, 'BONDING_MODULE_OPTS')
            if (not flag1 and not flag2):
                self.result.rst = ResultStatus.NG
                self.result.val += "\nNo 'BONDING_OPTS' or" \
                                   " 'BONDING_MODULE_OPTS' in bond" \
                                   " config file[%s]." % bondFile
Beispiel #3
0
    def doCheck(self):
        flag = "open"
        idList = []
        idCount = 0
        cores = 0
        cpuCount = 0
        cpuInfo = g_file.readFile('/proc/cpuinfo')
        for eachLine in cpuInfo:
            if (eachLine.find('physical id') >= 0):
                # get different CPU id
                cpuID = eachLine.split(':')[1].strip()
                if (not cpuID in idList):
                    idList.append(cpuID)
                    # Calculate the number of CPUs
                    idCount += 1
            if (eachLine.find('cores') >= 0):
                cores = int(eachLine.split(':')[1].strip())
            if (eachLine.find('processor') >= 0):
                cpuCount += 1

        if (cpuCount == 2 * idCount * cores):
            self.result.rst = ResultStatus.OK
        else:
            if DefaultValue.checkDockerEnv():
                return
            flag = "down"
            self.result.rst = ResultStatus.NG

        self.result.val = "Hyper-threading is %s." % flag
        self.result.raw = "the number of physical id: %d, cores: %d," \
                          " cpu counts: %d" % (idCount, cores, cpuCount)
 def __checkRandomPortRange(self, port):
     """
     function: Check if port is in the range of random port
     input : port
     output: NA
     """
     res = []
     try:
         rangeFile = "/proc/sys/net/ipv4/ip_local_port_range"
         output = g_file.readFile(rangeFile)
         res = output[0].split()
     except Exception as e:
         self.logger.debug(
             "Warning: Failed to get the range of random port."
             " Detail: \n%s" % str(e))
         return
     if (len(res) != 2):
         self.logger.debug("Warning: The range of random port is invalid. "
                           "Detail: \n%s" % str(output))
         return
     minPort = int(res[0])
     maxPort = int(res[1])
     if (port >= minPort and port <= maxPort):
         self.logger.debug("Warning: Current instance port is in the "
                           "range of random port(%d - %d)." % (minPort,
                                                               maxPort))
    def collectIOschedulers(self):
        devices = set()
        data = dict()
        files = self.getDevices()
        for f in files:
            fname = "/sys/block/%s/queue/scheduler" % f
            words = fname.split("/")
            if len(words) != 6:
                continue
            devices.add(words[3].strip())

        for d in devices:
            if (not d):
                continue
            device = {}
            scheduler = g_file.readFile("/sys/block/%s/queue/scheduler" % d)[0]
            words = scheduler.split("[")
            if len(words) != 2:
                continue
            words = words[1].split("]")
            if len(words) != 2:
                continue
            device["request"] = words[0].strip()
            for dead in scheduler.split():
                if dead.find("deadline") >= 0:
                    device["deadvalue"] = dead.split("[")[-1].split("]")[0]
                else:
                    continue
            data[d] = device
        return data
Beispiel #6
0
    def getPortRange(self):
        portRangeValue = \
            g_file.readFile('/proc/sys/net/ipv4/ip_local_port_range')[0]
        (startPort, endPort) = portRangeValue.split()
        portRange = int(endPort) - int(startPort)

        return portRange
Beispiel #7
0
    def doCheck(self):
        global rmDir
        parRes = ""
        flag = 0
        mountDir = []
        mountList = g_file.readFile(g_Platform.getMtablFile())
        for line in mountList:
            mountInfo = line.strip()
            if (not mountInfo.startswith('#') and len(mountInfo.split()) > 5):
                mountDir.append(mountInfo.split()[1])
        for dirName in self.directoryList:
            if (os.path.exists(dirName)):
                flagNumber = True
                for mdir in mountDir:
                    if (len(mdir) >= len(dirName)):
                        if (mdir[0:len(dirName)] == dirName):
                            flagNumber = False
                            break
                if (not flagNumber):
                    continue

                parRes += "\nThe directory of %s exists." % dirName
                rmDir.append(dirName)
                flag = 1

        if (flag == 1):
            self.result.rst = ResultStatus.NG
        else:
            self.result.rst = ResultStatus.OK
        self.result.val = parRes
        self.result.raw = "mount directory: %s" % mountDir
    def collectIORequest(self):
        """
        function : Collector ioRequest
        input    : NA
        output   : Dict
        """
        devices = []
        pathList = []

        if (self.cluster):
            pathList = self.obtainDataDir(
                self.cluster.getDbNodeByName(self.host))
        else:
            pathList = self.obtainDiskDir()
        diskDict = self.obtainDisk()
        for path in pathList:
            cmd = "df -h %s" % path
            output = SharedFuncs.runShellCmd(cmd)
            partitionInfo = output.split('\n')[-1]
            partitionName = partitionInfo.split()[0]
            if (partitionName in devices):
                continue
            else:
                devices.append(partitionName)
        result = {}
        for d in devices:
            for item in diskDict.items():
                if d in item[1]:
                    request = g_file.readFile(
                        "/sys/block/%s/queue/nr_requests" % item[0])[0]
                    result[item[0]] = request.strip()

        return result
Beispiel #9
0
def getIpByHostName(host):
    """
    function: get ip by hostname
    input  : NA
    output : NA
    """
    ipList = g_file.readFile("/etc/hosts", host)

    pattern = re.compile(
        r'^[1-9 \t].*%s[ \t]*#Gauss.* IP Hosts Mapping' % host)
    for ipInfo in ipList:
        match = pattern.match(ipInfo.strip())
        if (match):
            return match.group().split(' ')[0].strip()
    #If no ip address is found, the first ip address
    # that is not commented out is returned
    for ip_info in ipList:
        ip_info = ip_info.replace("\t", " ").strip()
        if not ip_info.startswith("#"):
            return ip_info.split(' ')[0]

    # get local host by os function
    # Replace host with the IP address.
    hostIp = host
    return hostIp
 def checkPreEnv(self):
     """
     function: Check if LD path and path in preinstall had been changed.
     input : NA
     output: NA
     """
     g_opts.logger.log("Checking preinstall enviroment value.")
     # Check $GAUSS_ENV.
     try:
         # get mpp file by env parameter MPPDB_ENV_SEPARATE_PATH
         mpprcFile = DefaultValue.getEnv(DefaultValue.MPPRC_FILE_ENV)
         if (mpprcFile != "" and mpprcFile is not None):
             userProfile = mpprcFile
             if (not os.path.isabs(userProfile)):
                 raise Exception(ErrorCode.GAUSS_512["GAUSS_51206"] %
                                 userProfile)
             if (not os.path.exists(userProfile)):
                 raise Exception(ErrorCode.GAUSS_502["GAUSS_50201"] %
                                 userProfile)
         else:
             userpath = pwd.getpwnam(self.user).pw_dir
             userProfile = os.path.join(userpath, ".bashrc")
         reEnvList = g_file.readFile(userProfile)
         checkList = [
             "export PATH=$GPHOME/script/gspylib/pssh/bin:$GPHOME/script"
             ":$PATH", "export LD_LIBRARY_PATH=$GPHOME/lib:$LD_LIBRARY_PATH"
         ]
         for check in checkList:
             if (check not in reEnvList
                     and (check + '\n') not in reEnvList):
                 self.logger.logExit(ErrorCode.GAUSS_518["GAUSS_51802"] %
                                     check)
     except Exception as e:
         g_opts.logger.logExit(str(e))
     g_opts.logger.log("Successfully checked preinstall enviroment value.")
def getFileInfo(fileName):
    """
    function:
    input : filename
    output: file context
    """
    res = g_file.readFile(fileName)
    if (len(res) != 1):
        raise Exception(ErrorCode.GAUSS_502["GAUSS_50204"] % fileName)
    return res[0].strip()
Beispiel #12
0
 def checkSingleParaFile(self, inst, desc, INDENTATION_VALUE_INT):
     """
     function: Check the log_min_messages parameter for each instance
     input: String, String, int
     output: int
     """
     # The instance directory must exist
     if (not os.path.exists(inst.datadir)
             or len(os.listdir(inst.datadir)) == 0):
         g_result.append(
             "%s: Abnormal reason: The directory doesn't exist"
             " or is empty." %
             ("%s(%s) log_min_messages parameter" %
              (desc, inst.datadir)).ljust(INDENTATION_VALUE_INT))
         return -1
     paraPath = ""
     # Gets the database node configuration file
     if inst.instanceRole == INSTANCE_ROLE_DATANODE:
         paraPath = os.path.join(inst.datadir, POSTGRESQL_CONF)
     else:
         g_result.append(
             "%s: Abnormal reason: Invalid instance type: %s." %
             (("%s(%s) log_min_messages parameter " %
               (desc, inst.datadir)).ljust(INDENTATION_VALUE_INT),
              inst.instanceRole))
         return -1
     # The instance configuration file must exist
     if (not os.path.exists(paraPath)):
         g_result.append("%s: Abnormal reason: %s does not exist." % (
             ("%s(%s) log_min_messages parameter " %
              (desc, inst.datadir)).ljust(INDENTATION_VALUE_INT), paraPath))
         return -1
     # Gets the log_min_messages parameter in the configuration file
     output = g_file.readFile(paraPath, "log_min_messages")
     value = None
     for line in output:
         line = line.split('#')[0].strip()
         if (line.find('log_min_messages') >= 0 and line.find('=') > 0):
             value = line.split('=')[1].strip()
             break
     if not value:
         value = "warning"
     # Determines whether the log_min_messages parameter is valid
     if (value.lower() != "warning"):
         g_result.append(
             "%s: Warning reason: The parameter 'log_min_messages(%s)'"
             " value is incorrect. It should be 'warning'." %
             (("%s(%s) log_min_messages parameter(%s)" %
               (desc, paraPath, value)).ljust(INDENTATION_VALUE_INT),
              value))
         return -1
     g_result.append("%s: Normal" %
                     ("%s(%s) log_min_messages parameter(%s)" %
                      (desc, paraPath, value)).ljust(INDENTATION_VALUE_INT))
     return 0
    def doCheck(self):
        flag = True
        parRes = ""
        # Determine if it is an ELK environment
        elk_env = DefaultValue.getEnv("ELK_SYSTEM_TABLESPACE")
        if (elk_env):
            expand_value = 640000
        else:
            expand_value = 1000000
        # Check system open files parameter
        output = g_OSlib.getUserLimits('open files')
        self.result.raw = output
        if (output != ""):
            self.result.val += output + "\n"
            resList = output.split(' ')
            limitValue = resList[-1].strip()
            # Unlimited check is passed
            if limitValue == 'unlimited':
                pass
            # Open file parameter value is less than 640000 will not pass
            if int(limitValue) < int(expand_value):
                flag = False
            else:
                pass
            # Write check results
            parRes += "Max open files: %s\n" % limitValue
        else:
            #
            flag = False
            parRes += "Failed to get system open files parameter.\n"

        # Check cluster process open files parameter
        if (self.cluster):
            pidList = g_OSlib.getProcess(
                os.path.join(self.cluster.appPath, 'bin/gaussdb'))
            for pid in pidList:
                if (not os.path.isfile("/proc/%s/limits" % pid)
                        or not os.access("/proc/%s/limits" % pid, os.R_OK)):
                    continue
                openFileInfo = \
                    g_file.readFile('/proc/%s/limits' % pid, 'Max open files')[
                        0]
                if (openFileInfo):
                    value = openFileInfo.split()[3]
                if (int(value.strip()) < expand_value):
                    flag = False
                    parRes += "The value of " \
                              "max open files is %s on pid %s. " \
                              "it must not be less than %d.\n" % (
                                  value.strip(), pid, expand_value)
        if (flag):
            self.result.rst = ResultStatus.OK
        else:
            self.result.rst = ResultStatus.NG
        self.result.val = parRes
 def collectTHPServer(self):
     if (os.path.exists(THPFile)):
         output = g_file.readFile(THPFile)[0]
         self.result.raw = output
         if (output.find('[never]') > 0):
             THPstatus = "disabled"
         else:
             THPstatus = "enabled"
     else:
         THPstatus = "disabled"
     return THPstatus
Beispiel #15
0
    def doCheck(self):
        flag = "Normal"
        networkCardNums = []
        if (self.cluster):
            LocalNodeInfo = self.cluster.getDbNodeByName(self.host)
            backIP = LocalNodeInfo.backIps[0]
        else:
            backIP = SharedFuncs.getIpByHostName(self.host)

        allNetworkInfo = g_network.getAllNetworkInfo()
        for network in allNetworkInfo:
            if (network.ipAddress == backIP):
                networkNum = network.NICNum
                BondMode = network.networkBondModeInfo
                confFile = network.networkConfigFile
                break

        if (not networkNum or not BondMode or not confFile):
            raise Exception(ErrorCode.GAUSS_506["GAUSS_50619"])
        if (BondMode != "BondMode Null"):
            bondFile = '/proc/net/bonding/%s' % networkNum
            bondInfoList = g_file.readFile(bondFile, "Slave Interface")
            for bondInfo in bondInfoList:
                networkNum = bondInfo.split(':')[-1].strip()
                networkCardNums.append(networkNum)
        else:
            networkCardNums.append(networkNum)

        for networkCardNum in networkCardNums:
            RXvalue = ""
            TXvalue = ""
            for network in allNetworkInfo:
                if (network.NICNum == networkCardNum
                        and str(network.RXValue).strip() != ""
                        and str(network.TXValue).strip() != ""):
                    RXvalue = network.RXValue
                    TXvalue = network.TXValue
            if (not RXvalue or not TXvalue):
                flag = "Error"
                self.result.val += "Failed to obtain network card [%s]" \
                                   " RX or TX value." % networkCardNum
                continue

            if (int(RXvalue) < int(EXPECTED_RXTX)) or (int(TXvalue) <
                                                       int(EXPECTED_RXTX)):
                flag = "Error"
                self.result.val += "NetWork[%s]\nRX: %s\nTX: %s\n" % (
                    networkCardNum, RXvalue, RXvalue)

        self.result.raw = self.result.val
        if (flag == "Normal"):
            self.result.rst = ResultStatus.OK
        else:
            self.result.rst = ResultStatus.NG
    def getProcessEnv(self, ProcessNum, Process):
        abnormal_flag = False
        processEnvDist = {}
        # Get environment variables
        if (os.path.isfile("/proc/%s/environ" % ProcessNum)):
            envInfoList = g_file.readFile("/proc/%s/environ" % ProcessNum)[
                0].split('\0')
            for env in envInfoList:
                envName = env.split('=')[0].strip()
                processEnvDist[envName] = env.split('=')[-1].strip()
            for env in g_envProfileDist.keys():
                # environment variables if exist
                if (not env in processEnvDist.keys() or
                        not processEnvDist[env]):
                    abnormal_flag = True
                    self.result.val += "There is no env[%s] in " \
                                       "process %s[%s].\n " \
                                       % (env, Process, ProcessNum)
                    continue
                # environment variables is GAUSSHOME
                if (env == "GAUSSHOME"):
                    if (g_envProfileDist[env] != processEnvDist[env]):
                        abnormal_flag = True
                        self.result.val += "The env[GAUSSHOME] is " \
                                           "inconsistent in process %s[%s] " \
                                           "and system.\nProcess: %s\n" \
                                           % (Process, ProcessNum,
                                              processEnvDist[env])
                ##environment variables is PATH
                elif (env == "PATH"):
                    binPath = "%s/bin" % g_envProfileDist["GAUSSHOME"]
                    ProcessEnvList = processEnvDist[env].split(':')
                    if (binPath not in ProcessEnvList):
                        abnormal_flag = True
                        self.result.val += "There is no [%s] in " \
                                           "process %s[%s]'s environment " \
                                           "variable [%s].\n " \
                                           % (binPath, Process,
                                              ProcessNum, env)
                else:
                    libPath = "%s/lib" % g_envProfileDist["GAUSSHOME"]
                    ProcessEnvList = processEnvDist[env].split(':')
                    if (libPath not in ProcessEnvList):
                        abnormal_flag = True
                        self.result.val += "There is no [%s] in process" \
                                           " %s[%s]'s environment variable" \
                                           " [%s].\n " % (libPath, Process,
                                                          ProcessNum, env)

        return abnormal_flag
Beispiel #17
0
    def checkSingleSysTable(self, Instance):
        tablelist = [
            "pg_attribute", "pg_class", "pg_constraint", "pg_partition",
            "pgxc_class", "pg_index", "pg_stats"
        ]
        localPath = os.path.dirname(os.path.realpath(__file__))
        resultMap = {}
        try:
            for i in tablelist:
                sqlFile = "%s/sqlFile_%s_%s.sql" % (self.tmpPath, i,
                                                    Instance.instanceId)
                resFile = "%s/resFile_%s_%s.out" % (self.tmpPath, i,
                                                    Instance.instanceId)
                g_file.createFile(sqlFile, True, DefaultValue.SQL_FILE_MODE)
                g_file.createFile(resFile, True, DefaultValue.SQL_FILE_MODE)
                g_file.changeOwner(self.user, sqlFile)
                g_file.changeOwner(self.user, resFile)
                sql = "select * from pg_table_size('%s');" % i
                sql += "select count(*) from %s;" % i
                sql += "select * from pg_column_size('%s');" % i
                g_file.writeFile(sqlFile, [sql])

                cmd = "gsql -d %s -p %s -f %s --output %s -t -A -X" % (
                    self.database, Instance.port, sqlFile, resFile)
                if (self.mpprcFile != "" and self.mpprcFile is not None):
                    cmd = "source '%s' && %s" % (self.mpprcFile, cmd)
                SharedFuncs.runShellCmd(cmd, self.user)

                restule = g_file.readFile(resFile)
                g_file.removeFile(sqlFile)
                g_file.removeFile(resFile)

                size = restule[0].strip()
                line = restule[1].strip()
                width = restule[2].strip()
                Role = ""
                if (Instance.instanceRole == INSTANCE_ROLE_COODINATOR):
                    Role = "CN"
                elif (Instance.instanceRole == INSTANCE_ROLE_DATANODE):
                    Role = "DN"
                instanceName = "%s_%s" % (Role, Instance.instanceId)
                resultMap[i] = [instanceName, size, line, width]
            return resultMap
        except Exception as e:
            if os.path.exists(sqlFile):
                g_file.removeFile(sqlFile)
            if os.path.exists(resFile):
                g_file.removeFile(resFile)
            raise Exception(str(e))
Beispiel #18
0
def getIpByHostName(host):
    """
    function: get ip by hostname
    input  : NA
    output : NA
    """
    ipList = g_file.readFile("/etc/hosts", host)
    pattern = re.compile(r'^[1-9 \t].*%s[ \t]*#Gauss.* IP Hosts Mapping' %
                         host)
    for ipInfo in ipList:
        match = pattern.match(ipInfo.strip())
        if (match):
            return match.group().split(' ')[0].strip()
    # get local host by os function
    # Replace host with the IP address.
    hostIp = host
    return hostIp
Beispiel #19
0
 def doCheck(self):
     output = g_file.readFile('/proc/sys/net/ipv4/ip_local_port_range')[0]
     smallValue = output.split()[0].strip()
     bigValue = output.split()[1].strip()
     if (int(bigValue) > PORT_RANGE[1] or int(smallValue) < PORT_RANGE[0]):
         self.result.val = "The value of net.ipv4.ip_local_port_range " \
                           "is %d %d. it should be %d %d" % (
                               int(smallValue), int(bigValue),
                               int(PORT_RANGE[0]),
                               int(PORT_RANGE[1]))
         self.result.rst = ResultStatus.NG
     else:
         self.result.rst = ResultStatus.OK
         self.result.val = "The value of net.ipv4." \
                           "ip_local_port_range is %d %d." % (
                               int(smallValue), int(bigValue))
     self.result.raw = output
Beispiel #20
0
 def start(self,
           time_out=DefaultValue.TIMEOUT_CLUSTER_START,
           security_mode="off",
           cluster_number=None):
     """
     """
     if cluster_number:
         cmd = "%s/gs_ctl start -o '-u %s' -D %s " % (
             self.binPath, int(
                 float(cluster_number) * 1000), self.instInfo.datadir)
     else:
         cmd = "%s/gs_ctl start -D %s " % (self.binPath,
                                           self.instInfo.datadir)
     if self.instInfo.instanceType == DefaultValue.MASTER_INSTANCE:
         if len(self.instInfo.peerInstanceInfos) > 0:
             cmd += "-M primary"
     elif self.instInfo.instanceType == DefaultValue.CASCADE_STANDBY:
         cmd += "-M cascade_standby"
     elif self.instInfo.instanceType == DefaultValue.STANDBY_INSTANCE:
         cmd += "-M standby"
     if time_out is not None:
         cmd += " -t %s" % time_out
     if security_mode == "on":
         cmd += " -o \'--securitymode\'"
     configFile = "%s/postgresql.conf" % self.instInfo.datadir
     output = g_file.readFile(configFile, "logging_collector")
     value = None
     for line in output:
         line = line.split('#')[0].strip()
         if line.find('logging_collector') >= 0 and line.find('=') > 0:
             value = line.split('=')[1].strip()
             break
     if value == "off":
         cmd += " >/dev/null 2>&1"
     self.logger.debug("start cmd = %s" % cmd)
     (status, output) = subprocess.getstatusoutput(cmd)
     if status != 0 or re.search("start failed", output):
         raise Exception(ErrorCode.GAUSS_516["GAUSS_51607"] % "instance" +
                         " Error: Please check the gs_ctl log for "
                         "failure details." + "\n" + output)
     if value == "off":
         output = "[BACKEND] WARNING: The parameter logging_collector is " \
                  "set to off. The log will not be recorded to file. " \
                  "Please check any error manually."
     self.logger.log(output)
    def doCheck(self):
        parRes = ""
        flag = 0
        output = g_OSlib.getUserLimits('stack size')
        self.result.raw = output
        StackValue = output.split()[-1]
        if (StackValue == 'unlimited'):
            pass
        elif (int(StackValue) < STACK):
            flag = 1
            parRes += "The value of stack depth is %d. " \
                      "it can not be less than 3072" % int(
                StackValue)

        if (self.cluster):
            pidList = g_OSlib.getProcess(
                os.path.join(self.cluster.appPath, 'bin/gaussdb'))
            for pid in pidList:
                limitsFile = "/proc/%s/limits" % pid
                if (not os.path.isfile(limitsFile)
                        or not os.access(limitsFile, os.R_OK)):
                    continue
                output = g_file.readFile(limitsFile,
                                         'Max stack size')[0].strip()
                self.result.raw += '\n[pid]%s: %s' % (pid, output)
                Stack = output.split()[4]
                if (Stack == 'unlimited'):
                    pass
                else:
                    value = int(Stack) / 1024
                    if (int(value) < STACK):
                        flag = 1
                        parRes += \
                            "The value of stack depth is %s on pid %s. " \
                            "it must be larger than 3072.\n" % (
                                value, pid)

        if (flag == 1):
            self.result.rst = ResultStatus.NG
            self.result.val = parRes
        else:
            self.result.rst = ResultStatus.OK
            self.result.val = StackValue
Beispiel #22
0
    def getFileSHA256Info(self):
        """
        function: get file sha256 info
        input:  NA
        output: str, str
        """
        try:
            bz2Path = self.getBz2FilePath()
            sha256Path = self.getSHA256FilePath()

            fileSHA256 = g_file.getFileSHA256(bz2Path)
            valueList = g_file.readFile(sha256Path)
            if len(valueList) != 1:
                raise Exception(ErrorCode.GAUSS_502["GAUSS_50204"] %
                                sha256Path)
            sha256Value = valueList[0].strip()
            return fileSHA256, sha256Value
        except Exception as e:
            raise Exception(str(e))
Beispiel #23
0
    def doCheck(self):
        global result
        devices = set()
        self.result.val = ""

        files = glob.glob("/sys/block/*/queue/logical_block_size")
        for f in files:
            words = f.split("/")
            if len(words) != 6:
                continue
            devices.add(words[3].strip())

        for d in devices:
            request = \
                g_file.readFile("/sys/block/%s/queue/logical_block_size" % d)[
                    0]
            result[d] = request.strip()

        if len(result) == 0:
            self.result.val = "Warning:Not find logical block file," \
                              "please check it."
            self.result.rst = ResultStatus.WARNING

        flag = True
        for i in result.keys():
            reuqest = result[i]
            self.result.raw += "%s %s\n" % (i, reuqest)
            if (i.startswith('loop') or i.startswith('ram')):
                continue
            if int(reuqest) < int(g_expectedScheduler):
                flag = False
                self.result.val += "\nWarning:On device (%s) '" \
                                   "logicalBlock Request' RealValue '%d' " \
                                   "ExpectedValue '%d'" % (
                                       i, int(reuqest),
                                       int(g_expectedScheduler))

        if flag:
            self.result.rst = ResultStatus.OK
            self.result.val = "All disk LogicalBlock values are correct."
        else:
            self.result.rst = ResultStatus.NG
    def doCheck(self):
        parRes = ""
        flag = None
        instance = {
            0: "CMSERVER",
            1: "GTM",
            2: "ETCD",
            3: "COODINATOR",
            4: "DATANODE",
            5: "CMAGENT"
        }
        portList = self.getPort()
        # Check the port range
        output = g_file.readFile(
            '/proc/sys/net/ipv4/ip_local_port_range')[0].strip()
        smallValue = output.split('\t')[0].strip()
        bigValue = output.split('\t')[1].strip()
        expect = self.ip_local_port_range.split()
        if (int(smallValue) < int(expect[0].strip())
                or int(bigValue) > int(expect[1].strip())):
            parRes += "The value of net.ipv4.ip_local_port_range is" \
                      " incorrect, expect value is %s.\n" \
                      % self.ip_local_port_range
        parRes += "The value of net.ipv4.ip_local_port_range is %d %d." \
                  % (int(smallValue), int(bigValue))

        for port in portList.keys():
            if (int(port) <= int(bigValue) and int(port) >= int(smallValue)):
                flag = 1
                parRes += "\n            %s" \
                          % ("The instance %s port \"%d\" is incorrect."
                             % (instance[portList[port]], int(port)))
        if (flag == 1):
            self.result.rst = ResultStatus.NG
        else:
            self.result.rst = ResultStatus.OK
        self.result.val = parRes
        self.result.raw = output
Beispiel #25
0
    def doCheck(self):
        if (not os.path.isfile("/sys/module/sctp/parameters/no_checksums")):
            self.result.rst = ResultStatus.OK
            self.result.val = "The SCTP service is not used and the" \
                              " check item is skipped"
            return
        expect = "N"
        if (self.cluster):
            LocalNodeInfo = self.cluster.getDbNodeByName(self.host)
            serviceIP = LocalNodeInfo.backIps[0]
        else:
            serviceIP = SharedFuncs.getIpByHostName(self.host)
        for network in g_network.getAllNetworkInfo():
            if (network.ipAddress == serviceIP):
                networkCardNum = network.NICNum
                networkBond = network.networkBondModeInfo
                break
        if (not networkCardNum or not networkBond):
            raise Exception(ErrorCode.GAUSS_506["GAUSS_50619"])
        (distname, version) = self.getOSversion()
        if ((distname in ("redhat", "centos")) and
                (version in ("6.4", "6.5")) and
                networkBond != "BondMode Null"):
            expect = "Y"

        output = \
            g_file.readFile('/sys/module/sctp/parameters/no_checksums')[0]
        if (output.strip() == expect):
            self.result.rst = ResultStatus.OK
            self.result.val = "Nochecksum value is %s,Check items pass." \
                              % output.strip()
        else:
            self.result.rst = ResultStatus.NG
            self.result.val = "Nochecksum value(%s) is not %s," \
                              "Check items are not passed." \
                              % (output.strip(), expect)
 def collectAsynchronousIORequest(self):
     result = []
     request = g_file.readFile("/proc/sys/fs/aio-max-nr")[0]
     result.append(request.strip())
     return result
    def doCheck(self):
        flag = "Normal"
        conflictsMapping = []
        commentsMapping = []
        IPMapping = {}
        IpList = []

        mappingList = g_file.readFile('/etc/hosts')
        for eachLine in mappingList:
            eachLine = eachLine.strip()
            if (eachLine == ""):
                continue
            if (not eachLine.startswith('#') and '::' not in eachLine):
                mappingInfo = " ".join(eachLine.split())
                IpList.append(mappingInfo)
        IpList.sort()
        self.result.raw = "\n".join(IpList)

        # Check localhost Mapping
        localHost = False
        for eachIP in IpList:
            if (eachIP.find("127.0.0.1 localhost") == 0):
                localHost = True
                break
        if (not localHost):
            self.result.rst = ResultStatus.NG
            self.result.val = "The /etc/hosts does not match localhosts."
            return

        # Check conflicts Mapping and GAUSS comments Mapping
        for IPInfo in IpList:
            ipHost = IPInfo.split()
            if (len(ipHost) < 2):
                continue
            ip = IPInfo.split()[0]
            host = IPInfo.split()[1]
            if (ip == "127.0.0.1"):
                continue
            if (ip in IPMapping.keys() and host != IPMapping[ip]):
                conflictsMapping.append(IPInfo)
                conflictsMapping.append("%s %s" % (ip, IPMapping[ip]))
                flag = "Error_conflicts"
            else:
                IPMapping[ip] = host
            if (len(IPInfo.split()) > 2 and IPInfo.split()[2] == "#Gauss"):
                commentsMapping.append(IPInfo + " IP Hosts Mapping")
                flag = "Error_comments"

        if (flag == "Normal"):
            self.result.rst = ResultStatus.OK
            self.result.val = "The /etc/hosts is configured correctly."
        elif (flag == "Error_comments"):
            self.result.rst = ResultStatus.NG
            self.result.val = "The /etc/hosts has comments Mapping:\n" \
                              + "\n".join(
                commentsMapping)
        else:
            self.result.rst = ResultStatus.NG
            self.result.val = "The /etc/hosts has conflicts Mapping:\n" \
                              + "\n".join(
                conflictsMapping)
            if (len(commentsMapping) > 0):
                self.result.val += "\n\nThe /etc/hosts has " \
                                   "comments Mapping:\n" + "\n".join(
                    commentsMapping)
 def doCheck(self):
     packageFile = os.path.realpath(
         os.path.join(self.upgradepath, "version.cfg"))
     output = g_file.readFile(packageFile)
     self.result.rst = ResultStatus.OK
     self.result.val = "".join(output)
    def doCheck(self):
        global needRepairNetworkCardNum
        global networkCardNums
        flag = "Normal"

        self.result.val = ""
        self.result.raw = ""
        if self.cluster:
            LocalNodeInfo = self.cluster.getDbNodeByName(self.host)
            backIP = LocalNodeInfo.backIps[0]
        elif self.ipAddr:
            backIP = self.ipAddr
        else:
            backIP = SharedFuncs.getIpByHostName(self.host)
        # Get the network card number
        allNetworkInfo = g_network.getAllNetworkInfo()
        for network in allNetworkInfo:
            if network.ipAddress == backIP:
                networkNum = network.NICNum
                BondMode = network.networkBondModeInfo
                confFile = network.networkConfigFile
                break

        if not networkNum or not BondMode or not confFile:
            if DefaultValue.checkDockerEnv():
                return
            raise Exception(ErrorCode.GAUSS_506["GAUSS_50619"])
        if BondMode != "BondMode Null":
            bondFile = '/proc/net/bonding/%s' % networkNum
            bondInfoList = g_file.readFile(bondFile, "Slave Interface")
            for bondInfo in bondInfoList:
                networkNum = bondInfo.split(':')[-1].strip()
                networkCardNums.append(networkNum)
        else:
            networkCardNums.append(networkNum)

        for networkCardNum in networkCardNums:
            cmdGetSpeedStr = "/sbin/ethtool %s | grep 'Speed:'" \
                             % networkCardNum
            (status, output) = subprocess.getstatusoutput(cmdGetSpeedStr)
            if len(output.split('\n')) > 1:
                for line in output.split('\n'):
                    if line.find("Speed:") >= 0:
                        output = line
                        break
            if output.find("Speed:") >= 0 and output.find("Mb/s") >= 0:
                netLevel = int(output.split(':')[1].strip()[:-4])
                if netLevel >= int(netWorkLevel):
                    cmd = "for i in `cat /proc/interrupts | grep '%s-' |" \
                          " awk -F ' ' '{print $1}' | " \
                          "awk -F ':' '{print $1}'`; " \
                          "do cat /proc/irq/$i/smp_affinity ; done" \
                          % networkCardNum
                    (status, output) = subprocess.getstatusoutput(cmd)
                    if status != 0:
                        self.result.val += "Failed to obtain network card" \
                                           " [%s] interrupt value. " \
                                           "Commands for getting interrupt" \
                                           " value: %s.\n" % (networkCardNum,
                                                              cmd)
                        if networkCardNum not in needRepairNetworkCardNum:
                            needRepairNetworkCardNum.append(networkCardNum)
                        flag = "Error"
                        continue

                    # cpu core number followed by 1 2 4 8,every 4 left shift 1
                    Mapping = {0: "1", 1: "2", 2: "4", 3: "8"}
                    for index, eachLine in enumerate(output.split()):
                        # Remove the ','
                        eachLine = eachLine.replace(",", "")
                        # Replace 0000,00001000 to 1,Remove invalid content
                        validValue = eachLine.replace("0", "")
                        # Convert the row index to the expected value
                        expandNum = Mapping[index % 4]
                        # Convert line index to expected position
                        expandBit = index / 4 * -1 - 1
                        # value and position is correct
                        if (len(eachLine) * -1) > expandBit:
                            self.result.val += "Network card [%s] " \
                                               "multi-queue support is not" \
                                               " enabled.\n" % networkCardNum
                            flag = "Error"
                            break
                        if (eachLine[expandBit] == expandNum
                                and validValue == expandNum):
                            continue
                        else:
                            self.result.val += "Network card [%s] " \
                                               "multi-queue support is " \
                                               "not enabled.\n" \
                                               % networkCardNum
                            if (networkCardNum
                                    not in needRepairNetworkCardNum):
                                needRepairNetworkCardNum.append(networkCardNum)
                            flag = "Error"
                            break

                    self.result.raw += "%s: \n %s \n" \
                                       % (networkCardNum, output)
                else:
                    self.result.val += "Warning: The speed of current card" \
                                       " \"%s\" is less than %s Mb/s.\n" \
                                       % (networkCardNum, netWorkLevel)
            else:
                if output.find("Speed:") >= 0:
                    if (networkCardNum not in needRepairNetworkCardNum):
                        needRepairNetworkCardNum.append(networkCardNum)
                    flag = "Error"
                    self.result.val += "Failed to obtain the network card" \
                                       " [%s] speed value. Maybe the network" \
                                       " card is not working.\n" \
                                       % networkCardNum
                else:
                    self.result.val += "Failed to obtain the network" \
                                       " card [%s] speed value. Commands" \
                                       " for obtain the network card speed:" \
                                       " %s. Error:\n%s\n" \
                                       % (networkCardNum, cmdGetSpeedStr,
                                          output)
        if flag == "Normal":
            self.result.rst = ResultStatus.OK
        elif flag == "Warning":
            self.result.rst = ResultStatus.WARNING
        else:
            self.result.rst = ResultStatus.NG
Beispiel #30
0
def readFile(fileName):
    # Get the contents of the file
    text = g_file.readFile(fileName)
    return "\n".join(text)