def cleanSyslogConfig(self): """ function: clean syslog config input : NA output: NA """ try: # only suse11/suse12 can support it distname = g_Platform.dist()[0] if (distname.upper() != "SUSE"): return # clean syslog-ng/rsyslog config cmd = "%s -t %s -u %s -l '%s' -X '%s'" % ( OMCommand.getLocalScript("Local_UnPreInstall"), ACTION_CLEAN_SYSLOG_CONFIG, self.user, self.localLog, self.xmlFile) self.logger.debug( "Command for clean syslog-ng/rsyslog config: %s" % cmd) DefaultValue.execCommandWithMode( cmd, "clean syslog-ng/rsyslog config", self.sshTool, self.localMode, self.mpprcFile, self.clusterInfo.getClusterNodeNames()) except Exception as e: self.logger.logExit(str(e))
def isSupportSystemOs(): """ function: check whether is or not redhat input : NA output : NA """ osName = g_Platform.dist()[0] if osName in ["redhat", "centos", "euleros", "openEuler"]: return True else: return False
def doSet(self): ifcfgFileSuse = "/etc/sysconfig/network/ifcfg-%s" % networkCards ifcfgFileRedhat = "/etc/sysconfig/network-scripts/ifcfg-%s" \ % networkCards distname, version, idnum = g_Platform.dist() if (distname in ["redhat", "centos", "euleros", "openEuler"]): cmd = "echo BONDING_MODULE_OPTS='mode=%d " \ "miimon=100 use_carrier=0' >> %s " % (1, ifcfgFileRedhat) else: cmd = "echo BONDING_MODULE_OPTS='mode=%d miimon=100" \ " use_carrier=0' >> %s" % (1, ifcfgFileSuse) (status, output) = subprocess.getstatusoutput(cmd) if (status != 0): self.result.val = "Failed to set bond mode.\n" + \ "The cmd is %s " % cmd else: self.result.val = "set bond mode successfully.\n"
def doSet(self): self.result.val = "" parRes = "" sctpFile = "" initFileSuse = "/etc/init.d/boot.local" initFileRedhat = "/etc/rc.d/rc.local" cmd = "ls -l /lib/modules/`uname -r`/kernel/net/sctp/sctp.ko*" (status, output) = subprocess.getstatusoutput(cmd) if (status != 0 or output == "" or output.find( "No such file or directory") > 0): parRes = "There is no sctp service.\n" else: sctpFile = output.split()[-1] cmd = "modprobe sctp;" (status, output) = subprocess.getstatusoutput(cmd) if (status != 0): cmd = "insmod %s >/dev/null 2>&1;lsmod |grep sctp" % sctpFile (status, output) = subprocess.getstatusoutput(cmd) if status != 0 or output == "": parRes = "Failed to load sctp service.\n" distname, version, idnum = g_Platform.dist() if (distname in ["redhat", "centos", "euleros", "openEuler"]): cmd = "cat %s | grep sctp" % initFileRedhat (status, output) = subprocess.getstatusoutput(cmd) if (status != 0 or output == ""): cmd = "echo 'modprobe sctp' >> /etc/rc.d/rc.local;" cmd += "echo" \ " 'insmod %s >/dev/null 2>&1' >> /etc/rc.d/rc.local " \ % sctpFile (status, output) = subprocess.getstatusoutput(cmd) if (status != 0): parRes += "Failed to add sctp service to boot.\n" else: cmd = "cat %s | grep stcp" % initFileSuse (status, output) = subprocess.getstatusoutput(cmd) if (status != 0 or output == ""): cmd = "echo 'modprobe sctp' >> /etc/init.d/boot.local;" cmd += "echo '%s >/dev/null 2>&1' >> /etc/init.d/boot.local " \ % sctpFile (status, output) = subprocess.getstatusoutput(cmd) if (status != 0): parRes += "Failed to add sctp service to boot." self.result.val = parRes
def getOSInitFile(): """ function : Get the OS initialization file input : NA output : String """ distname = g_Platform.dist()[0] systemd_system_dir = "/usr/lib/systemd/system/" systemd_system_file = "/usr/lib/systemd/system/gs-OS-set.service" # OS init file # now we only support SuSE and RHEL initFileSuse = "/etc/init.d/boot.local" initFileRedhat = "/etc/rc.d/rc.local" # system init file initSystemFile = "/usr/local/gauss/script/gauss-OS-set.sh" dirName = os.path.dirname(os.path.realpath(__file__)) # Get the startup file of suse or redhat os if (os.path.isdir(systemd_system_dir)): if (not os.path.exists(systemd_system_file)): cmd = "cp '%s'/gs-OS-set.service '%s'; chmod %s '%s'" % ( dirName, systemd_system_file, DefaultValue.KEY_FILE_MODE, systemd_system_file) runShellCmd(cmd) cmd = "systemctl enable gs-OS-set.service" runShellCmd(cmd) if (not os.path.exists(initSystemFile)): cmd = "mkdir -p '%s'" % os.path.dirname(initSystemFile) runShellCmd(cmd) g_file.createFileInSafeMode(initSystemFile) with open(initSystemFile, "w") as fp: fp.write("#!/bin/bash\n") cmd = "chmod %s '%s'" % (DefaultValue.KEY_FILE_MODE, initSystemFile) runShellCmd(cmd) return initSystemFile if (distname == "SuSE" and os.path.isfile(initFileSuse)): initFile = initFileSuse elif (distname in ( "redhat", "centos", "euleros", "openEuler") and os.path.isfile( initFileRedhat)): initFile = initFileRedhat else: initFile = "" return initFile
def checkSysctlParameter(kernelParameter, isSet): """ function: check and set the OS parameters input: kernelParameter: OS parameters list will be check and set isSet: the flag, when it is only True then will set OS parameters output: NA """ setParameterList = {} patchlevel = "" # get the suggest parameters and updata kernelParameter suggestParameterList = DefaultValue.getConfigFilePara( configFile, 'SUGGEST:%s' % actioItemMap["Check_SysCtl_Parameter"][0]) kernelParameter.update(suggestParameterList) # check the OS parameters if ("fs.aio-max-nr" in kernelParameter): g_logger.log(" Warning reason: Checking or setting the" " parameter 'fs.aio-max-nr' should be use " "'gs_checkos -i A10' or 'gs_checkos -i B4'.") kernelParameter.pop("fs.aio-max-nr") # Get OS version distname, version = g_Platform.dist()[0:2] if (distname == "SuSE" and version == "11"): cmd = "grep -i 'PATCHLEVEL' /etc/SuSE-release |" \ " awk -F '=' '{print $2}'" (status, output) = subprocess.getstatusoutput(cmd) if (status == 0 and output != ""): patchlevel = output.strip() # Gs_check get NetWork card MTU if (g_opts.action == "osKernelParameterCheck"): checkrestult = checkNetWorkMTU() if checkrestult != 0: resultList.append(checkrestult) for key in kernelParameter: # The SuSE 11 SP1 operating system # does not have vm.extfrag_threshold parameter, skip check if (patchlevel == "1" and key == "vm.extfrag_threshold"): continue sysFile = "/proc/sys/%s" % key.replace('.', '/') # High version of linux no longer supports tcp_tw_recycle if not os.path.exists( sysFile) and key == "net.ipv4.tcp_tw_recycle": continue if (DefaultValue.checkDockerEnv() and key in docker_no_need_check): continue # The parameter sctpchecksumerrors check method is independent if (key == "sctpchecksumerrors"): cmd = "cat /proc/net/sctp/snmp | grep SctpChecksumErrors" \ " | awk '{print $2}'" else: cmd = "cat %s" % ("/proc/sys/%s" % key.replace('.', '/')) (status, output) = subprocess.getstatusoutput(cmd) if (status == 0): if (key == "vm.min_free_kbytes" and output.split() != kernelParameter[key].split()): expected_min = float(kernelParameter[key].split()[0]) * 0.9 expected_max = float(kernelParameter[key].split()[0]) * 1.1 if (int(output.split()[0]) > expected_max or int(output.split()[0]) < expected_min): resultList.append(1) g_logger.log(" Abnormal reason: variable '%s'" " RealValue '%s' ExpectedValue '%s'." % (key, output, kernelParameter[key])) setParameterList[key] = kernelParameter[key] elif (key == "net.ipv4.ip_local_port_range" and output.split() != kernelParameter[key].split()): expected_min = int(kernelParameter[key].split()[0]) expected_max = int(kernelParameter[key].split()[1]) if (int(output.split()[0]) < expected_min or int(output.split()[1]) > expected_max): resultList.append(2) g_logger.log(" Warning reason: variable '%s'" " RealValue '%s' ExpectedValue '%s'." % (key, output, kernelParameter[key])) elif (output.split() != kernelParameter[key].split() and key not in list(suggestParameterList.keys())): resultList.append(1) g_logger.log(" Abnormal reason: variable '%s'" " RealValue '%s' ExpectedValue '%s'." % (key, output, kernelParameter[key])) setParameterList[key] = kernelParameter[key] elif output.split() != kernelParameter[key].split(): if (key == "vm.overcommit_ratio"): cmd = "cat /proc/sys/vm/overcommit_memory" (status, value) = subprocess.getstatusoutput(cmd) if (status == 0 and value == "0"): continue resultList.append(2) g_logger.log(" Warning reason: variable '%s' RealValue" " '%s' ExpectedValue '%s'." % (key, output, kernelParameter[key])) else: resultList.append(1) g_logger.log(" Abnormal reason: Failed to obtain the OS " "kernel parameter [%s]. Error: \n %s" % (key, output)) setParameterList[key] = kernelParameter[key] if (1 in resultList and 'Check' in g_opts.action): g_logger.log(" %s failed." % g_opts.action) elif (2 in resultList and 'Check' in g_opts.action): g_logger.log(" %s warning." % g_opts.action) else: g_logger.log(" All values about system control" " parameters are correct: Normal") # set the OS parameters if isSet: setOSParameter(setParameterList, patchlevel)
def doCheck(self): global setParameterList patchlevel = "" resultList = [] informationlist = [] dirName = os.path.dirname(os.path.realpath(__file__)) configFile = "%s/../../config/check_list_%s.conf" % ( dirName, self.version) suggestParameterList = self.getConfigFilePara( configFile, 'SUGGEST:/etc/sysctl.conf') kernelParameter = self.getConfigFilePara(configFile, '/etc/sysctl.conf') kernelParameter.update(suggestParameterList) distname, version, idnum = g_Platform.dist() if (distname == "SuSE" and version == "11"): patInfo = g_file.readFile("/etc/SuSE-release", 'PATCHLEVEL')[0] if (patInfo.find('=') > 0): output = patInfo.split('=')[1].strip() if (output != ""): patchlevel = output for key in kernelParameter: if (patchlevel == "1" and key == "vm.extfrag_threshold"): continue if (key == "sctpchecksumerrors"): snmpFile = "/proc/net/sctp/snmp" if (os.path.isfile(snmpFile)): output = \ g_file.readFile(snmpFile, 'SctpChecksumErrors')[ 0].split()[1].strip() else: continue else: sysFile = "/proc/sys/%s" % key.replace('.', '/') # High version of linux no longer supports tcp_tw_recycle if (not os.path.exists( sysFile) and key == "net.ipv4.tcp_tw_recycle"): continue output = g_file.readFile(sysFile)[0].strip() if (len(output.split()) > 1): output = ' '.join(output.split()) if (output != kernelParameter[key].strip() and key not in list( suggestParameterList.keys())): resultList.append(1) informationlist.append( "Abnormal reason: variable '%s' " "RealValue '%s' ExpectedValue '%s'." % ( key, output, kernelParameter[key])) setParameterList[key] = kernelParameter[key] elif output != kernelParameter[key].strip(): if (key == "vm.overcommit_ratio"): output = g_file.readFile("/proc/sys/vm/overcommit_memory")[ 0].strip() if (output == "0"): continue resultList.append(2) informationlist.append( "Warning reason: variable '%s' RealValue '%s' " "ExpectedValue '%s'." % ( key, output, kernelParameter[key])) if (1 in resultList): self.result.rst = ResultStatus.NG elif (2 in resultList): self.result.rst = ResultStatus.WARNING else: self.result.rst = ResultStatus.OK self.result.val = "" for info in informationlist: self.result.val = self.result.val + '%s\n' % info
def getOSversion(self): distname, version, idnum = g_Platform.dist() return distname, version