diff --git a/build.sh b/build.sh index c6a106966d09bf3fabdfc581aefda05ef832d2e4..0bb80021ea85e4d82eb3bcaab3a9254a909bf308 100644 --- a/build.sh +++ b/build.sh @@ -67,7 +67,7 @@ elif [ X$(echo $PLAT_FORM_STR | grep "euleros") != X"" ]; then elif [ X$(echo $PLAT_FORM_STR | grep "ubuntu") != X"" ]; then dist_version="Ubuntu" else - echo "We only support openEuler(aarch64), EulerOS(aarch64), CentOS, Ubuntu(x86) platform." + echo "We only support openEuler(aarch64), EulerOS(aarch64), CentOS, Ubuntu(x86) platform." echo "Kernel is $kernel" exit 1 fi diff --git a/script/gspylib/common/Common.py b/script/gspylib/common/Common.py index 90f5e933d7ccd65805d94b2b6367c5f189ffa122..6aa8f147394b1e56bbc93922c651a455763dc5bc 100644 --- a/script/gspylib/common/Common.py +++ b/script/gspylib/common/Common.py @@ -894,8 +894,8 @@ class DefaultValue(): # get local host by os function hostIp = socket.gethostbyname(hostname) - # due to two loopback address in ubuntu, 127.0.1.1 are choosed by hostname. - # there is need to choose 127.0.0.1 + # due to two loopback address in ubuntu, 127.0.1.1 are choosed by hostname. + # there is need to choose 127.0.0.1 version = g_Platform.dist()[1].split('/')[0] if version == "buster" and hostIp == "127.0.1.1": hostIp = "127.0.0.1" @@ -1526,7 +1526,7 @@ class DefaultValue(): elif (distname in ("redhat", "centos", "euleros", "openEuler") and os.path.isfile(initFileRedhat)): initFile = initFileRedhat - elif (distname == "debian" and version == "buster/sid" and + elif (distname == "debian" and version == "buster/sid" and os.path.isfile(initFileUbuntu)): initFile = initFileUbuntu else: diff --git a/script/gspylib/common/DbClusterInfo.py b/script/gspylib/common/DbClusterInfo.py index 9f2ce3f7b4661d26f77cd8c11d9193f7ea0c42f3..fe082d4a276bc030cc20f8d0457fd4bc7b720379 100644 --- a/script/gspylib/common/DbClusterInfo.py +++ b/script/gspylib/common/DbClusterInfo.py @@ -1636,9 +1636,9 @@ class dbClusterInfo(): except Exception as e: raise Exception(ErrorCode.GAUSS_516["GAUSS_51652"] % str(e)) - def queryClsInfoParallel(self, hostName, sshtools, mpprcFile, cmd): + def queryClsInfoParallel(self, hostName, sshtools, mpprcFile): """ - function : queryClsInfoParallel + function : queryClsInfoParallel Query cluster information in parallel. input : String output : Map @@ -1669,7 +1669,7 @@ class dbClusterInfo(): status = 0 output = "" - if (dnName != hostName): + if dnName != hostName: (statusMap, output) = sshtool.getSshStatusOutput( command, [dnName], mpprcFile) if statusMap[dnName] != 'Success': @@ -1678,12 +1678,12 @@ class dbClusterInfo(): (status, output) = subprocess.getstatusoutput(command) global_cls_query_rst[dnName] = [status, output] - - global global_cls_query_rst; + + global global_cls_query_rst parallelTool.parallelExecute(queryInstance, dbInfoList) - + return global_cls_query_rst - + def queryClsInfo(self, hostName, sshtools, mpprcFile, cmd): try: clusterState = 'Normal' @@ -1699,7 +1699,7 @@ class dbClusterInfo(): primaryDbState = "" portMap = {} - queryClsResult = self.queryClsInfoParallel(hostName, sshtools, mpprcFile, cmd) + queryClsResult = self.queryClsInfoParallel(hostName, sshtools, mpprcFile) for dbNode in self.dbNodes: for dnInst in dbNode.datanodes: @@ -1718,8 +1718,8 @@ class dbClusterInfo(): res = re.findall(r'local_role\s*:\s*(\w+)', output) roleStatus = res[0] res = re.findall(r'db_state\s*:\s*(\w+)', output) - dbState = res[0] - + dbState = res[0] + if (dbState == "Need"): detailInformation = re.findall( r'detail_information\s*:\s*(\w+)', output) @@ -1748,7 +1748,7 @@ class dbClusterInfo(): clusterState = 'Degraded' if dbState != "Normal": clusterState = 'Degraded' - + # get port info by guc portMap[dbNode.name] = self.__getPortInfoLocal(dbNode.name, queryClsResult) if dnNodeCount == 1: @@ -1776,12 +1776,12 @@ class dbClusterInfo(): nodeLen = NODE_ID_LEN + SPACE_LEN + maxNodeNameLen + SPACE_LEN instanceLen = INSTANCE_ID_LEN + SPACE_LEN + ( maxDataPathLen if cmd.dataPathQuery else 4) - + if cmd.azNameQuery: nodeLen += maxAzNameLen + SPACE_LEN if cmd.portQuery: instanceLen += 7 - + outText = outText + "%-*s%-*s%-*s%-*s%s\n" % ( nodeLen, " node", IP_LEN, "node_ip", PORT_LEN, "port", instanceLen, "instance", "state") @@ -1799,7 +1799,7 @@ class dbClusterInfo(): outText = outText + ( "%-*s " % (maxNodeNameLen, dbNode.name)) outText = outText + ("%-15s " % dnInst.listenIps[0]) - + # port info port = "" if portMap[dbNode.name]: @@ -1809,7 +1809,7 @@ class dbClusterInfo(): outText = outText + ("%-10u " % port) outText = outText + ("%u " % dnInst.instanceId) - + if cmd.dataPathQuery: outText = outText + ( "%-*s " % (maxDataPathLen, dnInst.datadir)) @@ -1822,7 +1822,7 @@ class dbClusterInfo(): else: outText = outText + ("%-7s" % roleStatusArray[i]) outText = outText + (" %s" % dbStateArray[i]) - + outText = outText + "\n" i += 1 self.__fprintContent(outText, cmd.outputFile) @@ -1833,7 +1833,7 @@ class dbClusterInfo(): """ function: Get port info form guc result """ - + (status, output) = queryClsResult.get(nodeName) if status != 0: return None @@ -1856,7 +1856,7 @@ class dbClusterInfo(): """ portcmd = "gs_guc check -D %s -c port" % dnpath output = "" - if (nodeName != hostName): + if nodeName != hostName: (statusMap, output) = sshtool.getSshStatusOutput( portcmd, [nodeName], mpprcFile) if statusMap[nodeName] != "Success": @@ -1877,7 +1877,7 @@ class dbClusterInfo(): if portvalue != "NULL": return int(portvalue) return DEFAULT_PORT - + def __getDnRole(self, instanceType): """ diff --git a/script/gspylib/os/gsplatform.py b/script/gspylib/os/gsplatform.py index 176187d7c711cd7de545a37658fca8ce82c97ed5..2626556c0382dada560903ade92546242acdcff2 100644 --- a/script/gspylib/os/gsplatform.py +++ b/script/gspylib/os/gsplatform.py @@ -1864,7 +1864,7 @@ class RHELPlatform(LinuxPlatform): """ # get system information distname, version = g_Platform.dist()[0:2] - + if self.isSupportSystemctl(): return self.getSystemctlCmd("crond.service", action) elif distname == "debian" and version == "buster/sid": @@ -1937,7 +1937,7 @@ class RHELPlatform(LinuxPlatform): SUPPORT_EULEROS_VERSION_LIST) or (distName.lower() in SUPPORT_RHEL_SERIES_PLATFORM_LIST and version[0:3] in SUPPORT_RHEL_SERIES_VERSION_LIST)) or - (distName.lower() == OPENEULER) or + (distName.lower() == OPENEULER) or (distName.lower() == DEBIAN and version == "buster/sid") )): return distName.lower(), version[0:3] diff --git a/script/impl/dropnode/DropnodeImpl.py b/script/impl/dropnode/DropnodeImpl.py index 71750f2f688e3256f93151c57dac260e2f527cd5..2c843f782670da68d9caa92dcfcc0121fac6b527 100644 --- a/script/impl/dropnode/DropnodeImpl.py +++ b/script/impl/dropnode/DropnodeImpl.py @@ -26,16 +26,13 @@ import pwd import datetime import grp import socket -import stat sys.path.append(sys.path[0] + "/../../../../") from gspylib.threads.SshTool import SshTool from gspylib.common.ErrorCode import ErrorCode from gspylib.common.Common import DefaultValue, ClusterCommand from gspylib.common.GaussLog import GaussLog -from gspylib.inspection.common.SharedFuncs import cleanFile -from gspylib.inspection.common.Exception import CheckException, \ - SQLCommandException +from gspylib.inspection.common.Exception import CheckException from gspylib.common.OMCommand import OMCommand sys.path.append(sys.path[0] + "/../../../lib/") @@ -200,9 +197,6 @@ class DropnodeImpl(): resultDict['syncStandbyStr'], sshtool_host, self.userProfile, - self.context.hostMapForExist[ - hostNameLoop]['port'][ - indexForuse], '', self.context.flagOnlyPrimary) except ValueError: @@ -212,9 +206,6 @@ class DropnodeImpl(): resultDict['syncStandbyStr'], sshtool_host, self.userProfile, - self.context.hostMapForExist[ - hostNameLoop]['port'][ - indexForuse], resultDictForRollback[ 'rollbackReplStr']) indexForuse += 1 @@ -580,7 +571,7 @@ class OperCommon: return resultDict def SetPgsqlConf(self, replNo, host, dndir, syncStandbyValue, sshTool, envfile, - port, replValue='', singleLeft=False): + replValue='', singleLeft=False): """ Set the value of postgresql.conf """ diff --git a/script/impl/expansion/ExpansionImpl.py b/script/impl/expansion/ExpansionImpl.py index 2ebbd86eb019af45a367ef8effd1bd30308f3d81..5baae52ecc78c9638294a54118c251d6938c0f8e 100644 --- a/script/impl/expansion/ExpansionImpl.py +++ b/script/impl/expansion/ExpansionImpl.py @@ -139,7 +139,7 @@ class ExpansionImpl(): def final(self): """ - function: + function: 1. Make sure primary's wal_keep_segments is restored to its original value if it has been changed, 2. rollback, @@ -397,7 +397,7 @@ class ExpansionImpl(): self.logger.log("%s install success." % newHost) if notInstalledCascadeHosts: self.logger.log("OpenGauss won't be installed on cascade_standby" - " %s, because there is no Normal standby in the same azZone." % + " %s, because there is no Normal standby in the same azZone." % ", ".join(notInstalledCascadeHosts)) if failedInstallHosts: self.logger.log(ErrorCode.GAUSS_527["GAUSS_52707"] % @@ -607,7 +607,7 @@ gs_guc set -D {dn} -c "available_zone='{azName}'" if self.expansionSuccess[host]: hostList.append(host) - if (len(hostList) == 0): + if len(hostList) == 0: return self.logger.debug("Start to distribute cipher file.") @@ -639,7 +639,7 @@ gs_guc set -D {dn} -c "available_zone='{azName}'" command = "gs_ctl reload -D %s " % dataNode sshTool = SshTool([primaryHost]) self.logger.debug(command) - resultMap, outputCollect = sshTool.getSshStatusOutput(command, + resultMap, outputCollect = sshTool.getSshStatusOutput(command, [primaryHost], self.envFile) self.logger.debug(outputCollect) self.cleanSshToolFile(sshTool) @@ -680,7 +680,7 @@ gs_guc set -D {dn} -c "available_zone='{azName}'" walKeepSegmentsChanged = True self.reloadPrimaryConf() time.sleep(10) - insType, dbState = self.commonGsCtl.queryInstanceStatus( + insType, dbState = self.commonGsCtl.queryInstanceStatus( primaryHost, primaryDataNode, self.envFile) primaryExceptionInfo = "" if insType != ROLE_PRIMARY: @@ -717,7 +717,7 @@ gs_guc set -D {dn} -c "available_zone='{azName}'" self.checkTmpDir(hostName) # start new host as standby mode self.commonGsCtl.stopInstance(hostName, dataNode, self.envFile) - result, output = self.commonGsCtl.startInstanceWithMode(host, + result, output = self.commonGsCtl.startInstanceWithMode(host, dataNode, MODE_STANDBY, self.envFile) if result[host] != DefaultValue.SUCCESS: if "uncompleted build is detected" not in output: @@ -735,7 +735,7 @@ gs_guc set -D {dn} -c "available_zone='{azName}'" self.logger.log("Build %s failed." % host) self.expansionSuccess[host] = False continue - + # build new host sshTool = SshTool([host]) tempShFile = "%s/buildStandby.sh" % self.tempFileDir @@ -816,7 +816,7 @@ gs_guc set -D {dn} -c "available_zone='{azName}'" tmpDir = os.path.realpath(DefaultValue.getTmpDirFromEnv()) checkCmd = 'if [ ! -d "%s" ]; then exit 1;fi;' % (tmpDir) sshTool = SshTool([hostName]) - resultMap, outputCollect = sshTool.getSshStatusOutput(checkCmd, + resultMap, outputCollect = sshTool.getSshStatusOutput(checkCmd, [hostName], self.envFile) ret = resultMap[hostName] if ret == STATUS_FAIL: @@ -844,7 +844,7 @@ gs_guc set -D {dn} -c "available_zone='{azName}'" self.context.clusterInfo.dbNodes.remove(dbNode) if nodeIp in self.context.newHostList and not self.expansionSuccess[nodeIp]: self.context.clusterInfo.dbNodes.remove(dbNode) - + toolPath = self.context.clusterInfoDict["toolPath"] appPath = self.context.clusterInfoDict["appPath"] @@ -857,7 +857,7 @@ gs_guc set -D {dn} -c "available_zone='{azName}'" dynamic_file_exist = False if os.path.exists(dynamic_file): dynamic_file_exist = True - + for dbNode in self.context.clusterInfo.dbNodes: hostName = dbNode.name staticConfigPath = "%s/script/static_config_files/cluster_static_config_%s" % \ @@ -880,7 +880,7 @@ gs_guc set -D {dn} -c "available_zone='{azName}'" hostSsh.getSshStatusOutput(dynamic_opt_cmd, [hostName], self.envFile) self.cleanSshToolFile(hostSsh) self.logger.log("End to generate and send cluster static file.\n") - + self.logger.log("Expansion results:") self.getExistingHosts(False) for newHost in self.context.newHostList: @@ -902,7 +902,7 @@ gs_guc set -D {dn} -c "available_zone='{azName}'" hostNames = [] for host in hostIpList: hostNames.append(self.context.backIpNameMap[host]) - + gucDict = {} for hostName in hostNames: localeHostInfo = clusterInfoDict[hostName] @@ -1186,7 +1186,7 @@ remoteservice={remoteservice}'" if outputCollect.find("Primary Normal") == -1: GaussLog.exitWithError((ErrorCode.GAUSS_357["GAUSS_35709"] % ("status", "primary", "Normal")) + "\nExpansion failed.") - + self.logger.debug("The primary database is normal.\n") currentWalKeepSegments = self.queryPrimaryWalKeepSegments() if currentWalKeepSegments != "NULL": @@ -1196,7 +1196,7 @@ remoteservice={remoteservice}'" def _adjustOrderOfNewHostList(self): """ - Adjust the order of hostlist so that + Adjust the order of hostlist so that standby comes first and cascade standby comes last """ newHostList = self.context.newHostList @@ -1256,12 +1256,12 @@ remoteservice={remoteservice}'" def checkUserAndGroupExists(self): """ - check system user and group exists and be same + check system user and group exists and be same on primary and standby nodes """ inputUser = self.user inputGroup = self.group - + user_group_id = "" isUserExits = False localHost = socket.gethostname() @@ -1286,25 +1286,25 @@ remoteservice={remoteservice}'" if user_group_id != group_id: GaussLog.exitWithError(ErrorCode.GAUSS_357["GAUSS_35712"] % (self.user, self.group)) - + hostNames = self.context.newHostList envfile = self.envFile sshTool = SshTool(hostNames) - #get username in the other standy nodes + #get username in the other standy nodes getUserNameCmd = "cat /etc/passwd | grep -w %s" % inputUser - resultMap, outputCollect = sshTool.getSshStatusOutput(getUserNameCmd, + resultMap, outputCollect = sshTool.getSshStatusOutput(getUserNameCmd, [], envfile) - + for hostKey in resultMap: if resultMap[hostKey] == STATUS_FAIL: self.cleanSshToolFile(sshTool) GaussLog.exitWithError(ErrorCode.GAUSS_357["GAUSS_35704"] \ % ("User", self.user, hostKey)) - - #get groupname in the other standy nodes + + #get groupname in the other standy nodes getGroupNameCmd = "cat /etc/group | grep -w %s" % inputGroup - resultMap, outputCollect = sshTool.getSshStatusOutput(getGroupNameCmd, + resultMap, outputCollect = sshTool.getSshStatusOutput(getGroupNameCmd, [], envfile) for hostKey in resultMap: if resultMap[hostKey] == STATUS_FAIL: @@ -1319,7 +1319,7 @@ remoteservice={remoteservice}'" install database and expansion standby node with db om user """ pvalue = Value('i', 0) - proc = Process(target=self.installProcess, args=(pvalue,)) + proc = Process(target=self.installProcess, args=(pvalue,)) proc.start() proc.join() if not pvalue.value: @@ -1343,7 +1343,7 @@ remoteservice={remoteservice}'" def rollback(self): """ - rollback all hosts' replconninfo about failed hosts + rollback all hosts' replconninfo about failed hosts """ self.getExistingHosts() failedHosts = list(set(self.context.newHostList) - set(self.existingHosts)) @@ -1423,7 +1423,7 @@ class GsCtlCommon: """ command = "source %s ; gs_ctl query -D %s" % (env, datanode) sshTool = SshTool([datanode]) - resultMap, outputCollect = sshTool.getSshStatusOutput(command, + resultMap, outputCollect = sshTool.getSshStatusOutput(command, [host], env) self.logger.debug(outputCollect) localRole = re.findall(r"local_role.*: (.*?)\n", outputCollect) @@ -1435,7 +1435,7 @@ class GsCtlCommon: insType = "" else: insType = localRole[0] - + dbStatus = "" if(len(db_state)) == 0: dbStatus = "" @@ -1449,7 +1449,7 @@ class GsCtlCommon: """ command = "source %s ; gs_ctl stop -D %s" % (env, datanode) sshTool = SshTool([host]) - resultMap, outputCollect = sshTool.getSshStatusOutput(command, + resultMap, outputCollect = sshTool.getSshStatusOutput(command, [host], env) self.logger.debug(host) self.logger.debug(outputCollect) @@ -1461,7 +1461,7 @@ class GsCtlCommon: command = "source %s ; gs_ctl start -D %s -M %s" % (env, datanode, mode) self.logger.debug(command) sshTool = SshTool([host]) - resultMap, outputCollect = sshTool.getSshStatusOutput(command, + resultMap, outputCollect = sshTool.getSshStatusOutput(command, [host], env) self.logger.debug(host) self.logger.debug(outputCollect) @@ -1472,7 +1472,7 @@ class GsCtlCommon: command = "source %s ; gs_ctl build -D %s -M %s" % (env, datanode, mode) self.logger.debug(command) sshTool = SshTool([host]) - resultMap, outputCollect = sshTool.getSshStatusOutput(command, + resultMap, outputCollect = sshTool.getSshStatusOutput(command, [host], env) self.logger.debug(host) self.logger.debug(outputCollect) @@ -1485,7 +1485,7 @@ class GsCtlCommon: command = "source %s ; gs_om -t start" % env self.logger.debug(command) sshTool = SshTool([host]) - resultMap, outputCollect = sshTool.getSshStatusOutput(command, + resultMap, outputCollect = sshTool.getSshStatusOutput(command, [host], env) self.logger.debug(host) self.logger.debug(outputCollect) @@ -1498,7 +1498,7 @@ class GsCtlCommon: """ command = "source %s ; gs_om -t status --detail" % env sshTool = SshTool([host]) - resultMap, outputCollect = sshTool.getSshStatusOutput(command, + resultMap, outputCollect = sshTool.getSshStatusOutput(command, [host], env) self.logger.debug(host) self.logger.debug(outputCollect) diff --git a/script/impl/om/OLAP/OmImplOLAP.py b/script/impl/om/OLAP/OmImplOLAP.py index 548b61e583ad7f0321f705fbee1692d4d2098f09..6bda0fc41e2a532e3ced49f08d0ad65af3f42fe4 100644 --- a/script/impl/om/OLAP/OmImplOLAP.py +++ b/script/impl/om/OLAP/OmImplOLAP.py @@ -326,7 +326,7 @@ class OmImplOLAP(OmImpl): hostName = DefaultValue.GetHostIpOrName() dbNums = len(self.context.clusterInfo.dbNodes) sshtools = [] - for i in range(dbNums - 1): + for _ in range(dbNums - 1): sshtools.append(SshTool([], timeout=self.time_out)) cmd = queryCmd() if (self.context.g_opts.outFile != ""): diff --git a/script/impl/om/OmImpl.py b/script/impl/om/OmImpl.py index e1c2808cc753f80b527b3c748bd1f2c794ce54e4..24ef8f7157395486b0523cb79ef85401adedd6a0 100644 --- a/script/impl/om/OmImpl.py +++ b/script/impl/om/OmImpl.py @@ -215,7 +215,7 @@ class OmImpl: nodeId, cmd.outputFile) return az_name = self.context.g_opts.azName - if (az_name): + if az_name: self.context.clusterInfo.queryNodeInfo(sshtool, hostName, nodeId, cmd.outputFile, az_name) return @@ -224,11 +224,11 @@ class OmImpl: nodeId, cmd.outputFile) return cmd.clusterStateQuery = True - + dbNums = len(self.context.clusterInfo.dbNodes) sshtools = [] - for i in range(dbNums - 1): + for _ in range(dbNums - 1): sshtools.append(SshTool([], timeout=self.time_out)) self.context.clusterInfo.queryClsInfo(hostName, sshtools, self.context.mpprcFile, cmd) diff --git a/script/impl/preinstall/OLAP/PreinstallImplOLAP.py b/script/impl/preinstall/OLAP/PreinstallImplOLAP.py index 3626317b568d3566e6a5242464308675c6a8c00e..1a950b61c27475c4f526bbd0377e9449b6343618 100644 --- a/script/impl/preinstall/OLAP/PreinstallImplOLAP.py +++ b/script/impl/preinstall/OLAP/PreinstallImplOLAP.py @@ -421,7 +421,7 @@ class PreinstallImplOLAP(PreinstallImpl): except Exception as e: raise Exception(str(e)) self.context.logger.log("Successfully set core path.", "constant") - + def setCgroup(self): """ function: setting Cgroup @@ -431,25 +431,26 @@ class PreinstallImplOLAP(PreinstallImpl): self.context.logger.log("Setting Cgroup.", "addStep") try: # set the cgroup - cmd = "%s -t %s -u %s -X '%s' -l '%s' -Q %s" % (OMCommand.getLocalScript("Local_PreInstall"), - ACTION_SET_CGROUP, - self.context.user, - self.context.xmlFile, - self.context.localLog, - self.context.clusterToolPath) + cmd = "%s -t %s -u %s -X '%s' -l '%s' -Q %s" % ( + OMCommand.getLocalScript("Local_PreInstall"), + ACTION_SET_CGROUP, + self.context.user, + self.context.xmlFile, + self.context.localLog, + self.context.clusterToolPath) self.context.logger.debug("Command for setting Cgroup: %s." % cmd) # exec cmd fro set cgroup - DefaultValue.execCommandWithMode(cmd, - "set Cgroup", - self.context.sshTool, - self.context.localMode or self.context.isSingle, + DefaultValue.execCommandWithMode(cmd, + "set Cgroup", + self.context.sshTool, + self.context.localMode or self.context.isSingle, self.context.mpprcFile) except Exception as e: # failed set Cgroup self.context.logger.log("Error: Failed to set Cgroup.") self.context.logger.logExit(str(e)) # Successfully set Cgroup - self.context.logger.log("Successfully set Cgroup.", "constant") + self.context.logger.log("Successfully set Cgroup.", "constant") def setArmOptimization(self): """ diff --git a/script/impl/preinstall/PreinstallImpl.py b/script/impl/preinstall/PreinstallImpl.py index dcce6515994ac05e6adb69b13cf2b13a3f7b812c..413a282f0883ab46abb93c370787b44201607470 100644 --- a/script/impl/preinstall/PreinstallImpl.py +++ b/script/impl/preinstall/PreinstallImpl.py @@ -1474,7 +1474,7 @@ class PreinstallImpl: input: NA output: NA """ - pass + pass def setCorePath(self): """ diff --git a/script/impl/upgrade/UpgradeImpl.py b/script/impl/upgrade/UpgradeImpl.py index c07877ba322243f74dc54dac42183aad212cfed5..9e1a984dab5864a56320153651e72cdc3ad39048 100644 --- a/script/impl/upgrade/UpgradeImpl.py +++ b/script/impl/upgrade/UpgradeImpl.py @@ -2065,7 +2065,7 @@ class UpgradeImpl: with open(lcgroupfile, "w") as fp_json: json.dump({"lcgroupnamelist": lcgroupnames}, fp_json) # send file to remote nodes - if (not self.context.isSingle): + if not self.context.isSingle: self.context.sshTool.scpFiles(lcgroupfile, self.context.tmpDir) self.context.logger.debug( "Successfully to write and send logical cluster info file.") @@ -2668,7 +2668,7 @@ class UpgradeImpl: ErrorCode.GAUSS_502["GAUSS_50210"] % check_upgrade_sql) self.context.logger.debug("Scp {0} file to nodes {1}".format( check_upgrade_sql, dnNodeName)) - if (not self.context.isSingle): + if not self.context.isSingle: g_OSlib.scpFile(dnNodeName, check_upgrade_sql, self.context.upgradeBackupPath) if not os.path.isfile(maindb_sql): diff --git a/script/local/PreInstallUtility.py b/script/local/PreInstallUtility.py index 0ebca423a54eef8632473bfcf6068cf54cda81e6..581f18ac758be36514fde9bf1fd81e418233e183 100644 --- a/script/local/PreInstallUtility.py +++ b/script/local/PreInstallUtility.py @@ -367,15 +367,6 @@ Common options: if self.group == "": GaussLog.exitWithError( ErrorCode.GAUSS_500["GAUSS_50001"] % 'g' + ".") - - def checkSetCgroupParameter(self): - """ - function: check whether SetCgroup parameter is right - input : NA - output: NA - """ - if(self.clusterToolPath == ""): - GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50001"] % 'Q' + ".") def checkCreateClusterPathsParameter(self): """ @@ -681,7 +672,7 @@ Common options: sshd_config = "/etc/ssh/sshd_config" allow_item_cmd = "cat " + sshd_config + " | grep '\\<%s\\>'" % allow_item (status, output) = subprocess.getstatusoutput(allow_item_cmd) - + # No results found. "grep" returns non-zero if nothing grepped. # AllowItem in sshd_config is disabled. if (status != 0) and (output is None or len(output) == 0): @@ -1156,7 +1147,7 @@ Common options: # 3. add cluster owner to 'AllowUsers' or 'AllowGroups' to # /etc/ssh/sshd_config if necessary. - if self.addAllowItemValue(allow_item="AllowUsers", item_value=self.user) > 0: + if self.addAllowItemValue(allow_item="AllowUsers", item_value=self.user) > 0: sshdNeedReload = True if self.addAllowItemValue(allow_item="AllowGroups", item_value=self.group) > 0: @@ -1936,18 +1927,19 @@ Common options: """ #Determine whether action is expansion. hostName = DefaultValue.GetHostIpOrName() - if (len(self.clusterInfo.newNodes) == 0): + if len(self.clusterInfo.newNodes) == 0: return False #Determine whether the current node is a new node for node in self.clusterInfo.newNodes: - if (hostName == node.name): + if hostName == node.name: return False self.logger.debug("The current node is the old node for expansion, no need to set cgroup.") return True def decompressPkg2Cgroup(self): """ - function: decompress server package to libcgroup path. gs_cgroup will be used in preinstall step. + function: decompress server package to libcgroup path. gs_cgroup will be used in preinstall + step. input: NA output: NA """ @@ -1958,11 +1950,12 @@ Common options: libCgroupPath = os.path.realpath("%s/../../libcgroup" % curPath) if not os.path.exists(libCgroupPath): os.makedirs(libCgroupPath) - + cmd = "tar -xf %s -C %s" % (bz2FileName, libCgroupPath) (status, output) = subprocess.getstatusoutput(cmd) if status != 0: - self.logger.logExit(ErrorCode.GAUSS_502["GAUSS_50217"] % bz2FileName + " Error: \n%s" % output) + self.logger.logExit(ErrorCode.GAUSS_502["GAUSS_50217"] % bz2FileName + + " Error: \n%s" % output) # load library path env ld_path = os.path.join(libCgroupPath, "lib") @@ -1979,7 +1972,7 @@ Common options: input : NA output: NA """ - if (self.needSetCgroup()): + if self.needSetCgroup(): return self.logger.debug("Setting Cgroup.") # decompress server pakcage @@ -1991,39 +1984,50 @@ Common options: cgroup_exe_dir = os.path.realpath("%s/../../libcgroup/bin/gs_cgroup" % dirName) cmd = "rm -rf '%s/%s'" % (self.clusterToolPath, self.user) (status, output) = DefaultValue.retryGetstatusoutput(cmd) - if(status != 0): - self.logger.logExit(ErrorCode.GAUSS_502["GAUSS_50207"] % 'crash Cgroup congiguration file' + " Error: \n%s" % output) + if status != 0: + self.logger.logExit(ErrorCode.GAUSS_502["GAUSS_50207"] % + 'crash Cgroup congiguration file' + " Error: \n%s" % output) cmd = "if [ ! -d '%s' ];then mkdir -p '%s' && " % (cgroup_etc_dir, cgroup_etc_dir) - cmd += "chmod %s '%s'/../ -R && chown %s:%s '%s'/../ -R -h;fi" % (DefaultValue.KEY_DIRECTORY_MODE, cgroup_etc_dir, self.user, self.group, cgroup_etc_dir) + cmd += "chmod %s '%s'/../ -R && chown %s:%s '%s'/../ -R -h;fi" %\ + (DefaultValue.KEY_DIRECTORY_MODE, cgroup_etc_dir, + self.user, self.group, cgroup_etc_dir) (status, output) = subprocess.getstatusoutput(cmd) - if(status != 0): - self.logger.logExit(ErrorCode.GAUSS_502["GAUSS_50208"] % cgroup_etc_dir + " Error: \n%s" % output) + if status != 0: + self.logger.logExit(ErrorCode.GAUSS_502["GAUSS_50208"] % + cgroup_etc_dir + " Error: \n%s" % output) # check or prepare libcgroup lib libcgroup_target = "/usr/local/lib/libcgroup.so.1" cmd = "ldd %s | grep 'libcgroup.so.1'" % cgroup_exe_dir (status, output) = subprocess.getstatusoutput(cmd) - if(status != 0): + if status != 0: self.logger.logExit(ErrorCode.GAUSS_514["GAUSS_51400"] % cmd + " Error: \n%s" % output) elif str(output).find("not found") != -1: cmd = "cp '%s' '%s' && ldconfig" % (libcgroup_dir, libcgroup_target) - self.logger.debug("Need copy libcgroup.so.1 from %s to %s." % (libcgroup_dir, libcgroup_target)) + self.logger.debug("Need copy libcgroup.so.1 from %s to %s." % + (libcgroup_dir, libcgroup_target)) (status, output) = subprocess.getstatusoutput(cmd) - if(status != 0): - self.logger.logExit(ErrorCode.GAUSS_502["GAUSS_50214"] % libcgroup_target + " Error: \n%s" % output) + if status != 0: + self.logger.logExit(ErrorCode.GAUSS_502["GAUSS_50214"] % libcgroup_target + + " Error: \n%s" % output) - GPHOME_cgroupCfgFile = "%s/%s/etc/gscgroup_%s.cfg" % (self.clusterToolPath, self.user, self.user) + GPHOME_cgroupCfgFile = "%s/%s/etc/gscgroup_%s.cfg" % (self.clusterToolPath, self.user, + self.user) GAUSSHOME_cgroupCfgFile = "%s/etc/gscgroup_%s.cfg" % (self.clusterInfo.appPath, self.user) - cmd = "(if [ -f '%s' ]; then cp '%s' '%s';fi)" % (GAUSSHOME_cgroupCfgFile, GAUSSHOME_cgroupCfgFile, GPHOME_cgroupCfgFile) - self.logger.debug("Command for copying GAUSSHOME gscgroup's config file to GPHOME: %s\n" % cmd) + cmd = "(if [ -f '%s' ]; then cp '%s' '%s';fi)" % (GAUSSHOME_cgroupCfgFile, + GAUSSHOME_cgroupCfgFile, + GPHOME_cgroupCfgFile) + self.logger.debug("Command for copying GAUSSHOME gscgroup's config file to GPHOME: %s\n" + % cmd) (status, output) = subprocess.getstatusoutput(cmd) - if(status != 0): - self.logger.logExit(ErrorCode.GAUSS_502["GAUSS_50214"] % GAUSSHOME_cgroupCfgFile + " Error:\n%s" % output) + if status != 0: + self.logger.logExit(ErrorCode.GAUSS_502["GAUSS_50214"] % GAUSSHOME_cgroupCfgFile + + " Error:\n%s" % output) #create cgroup log file. binPath = self.clusterInfo.logPath + "/%s/bin/gs_cgroup/" % self.user - if (not os.path.exists(binPath)): + if not os.path.exists(binPath): g_file.createDirectory(binPath) cgroupLog = binPath + "gs_cgroup.log" c_logger = GaussLog(cgroupLog, "gs_cgroup") @@ -2031,11 +2035,14 @@ Common options: #Get OS startup file initFile = DefaultValue.getOSInitFile() if initFile == "": - raise Exception(ErrorCode.GAUSS_502["GAUSS_50201"] % "startup file of current OS" + "The startup file for euleros OS is /etc/rc.d/rc.local.") + raise Exception(ErrorCode.GAUSS_502["GAUSS_50201"] % "startup file of current OS" + + "The startup file for euleros OS is /etc/rc.d/rc.local.") # call cgroup - # generate cgroup config file under cluster tool path. and then copy it to GAUSSHOME path in gs_install step. - execute_cmd = "%s -U %s --upgrade -c -H %s/%s" % (cgroup_exe_dir, self.user, self.clusterToolPath, self.user) + # generate cgroup config file under cluster tool path. + # and then copy it to GAUSSHOME path in gs_install step. + execute_cmd = "%s -U %s --upgrade -c -H %s/%s" % (cgroup_exe_dir, self.user, + self.clusterToolPath, self.user) c_logger.debug("Command for executing gs_cgroup: %s\n" % execute_cmd) (status, output) = subprocess.getstatusoutput(execute_cmd) c_logger.debug("The result of execute gs_cgroup is:\n%s." % output) @@ -2060,7 +2067,7 @@ Common options: pre_bin_path = self.clusterInfo.logPath + "/%s/bin" % self.user g_file.changeOwner(self.user, pre_bin_path, True, retryFlag = True) c_logger.closeLog() - if(status != 0): + if status != 0: self.logger.logExit(str(output)) self.logger.debug("Successfully set Cgroup.") @@ -2069,13 +2076,14 @@ Common options: # check libaio.so file exist cmd = "ls /usr/local/lib | grep '^libaio.so' | wc -l" (status, output) = subprocess.getstatusoutput(cmd) - if (status != 0): + if status != 0: self.logger.logExit(ErrorCode.GAUSS_514["GAUSS_51400"] % cmd + " Error: \n%s" % output) elif int(output) == 0: cmd = "ls /usr/lib64 | grep '^libaio.so' | wc -l" (status, output) = subprocess.getstatusoutput(cmd) - if (status != 0): - self.logger.logExit(ErrorCode.GAUSS_514["GAUSS_51400"] % cmd + " Error: \n%s" % output) + if status != 0: + self.logger.logExit(ErrorCode.GAUSS_514["GAUSS_51400"] % cmd + + " Error: \n%s" % output) elif int(output) == 0: raise Exception(ErrorCode.GAUSS_502["GAUSS_50201"] % "libaio.so or libaio.so.*")