卸载CM前增加互信校验

This commit is contained in:
xue_meng_en 2022-11-05 10:40:15 +08:00
parent 2b88920078
commit f48f950513
3 changed files with 24 additions and 16 deletions

View File

@ -60,3 +60,19 @@ def checkXMLFile(xmlFile):
CMLog.exitWithError(ErrorCode.GAUSS_502["GAUSS_50210"] % "xmlFile")
if not os.access(xmlFile, os.R_OK):
CMLog.exitWithError(ErrorCode.GAUSS_501["GAUSS_50100"] % (xmlFile, "current user"))
def checkHostsTrust(hosts, localhost = ""):
"""
check trust between current host and the given hosts
"""
hostsWithoutTrust = []
for host in hosts:
if host == localhost:
continue
checkTrustCmd = "ssh -o ConnectTimeout=3 -o ConnectionAttempts=5 -o PasswordAuthentication=no " \
"-o StrictHostKeyChecking=no %s 'pwd > /dev/null'" % host
status, output = subprocess.getstatusoutput(checkTrustCmd)
if status != 0:
hostsWithoutTrust.append(host)
if hostsWithoutTrust != []:
CMLog.exitWithError(ErrorCode.GAUSS_511["GAUSS_51100"] % ','.join(hostsWithoutTrust))

View File

@ -46,7 +46,7 @@ class Install:
self.toolPath = ""
self.tmpPath = ""
self.cmDirs = []
self.hostNames = []
self.hostnames = []
self.localhostName = ""
self.cmpkg = ""
@ -207,23 +207,11 @@ General options:
CMLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50024"] % 'cmServerPortBase')
if cmDict['cmServerPortStandby'] != "" and not cmDict['cmServerPortStandby'].isdigit():
CMLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50024"] % 'cmServerPortStandby')
if len(self.hostNames) != len(self.cmDirs):
if len(self.hostnames) != len(self.cmDirs):
CMLog.exitWithError("\"cmDir\" of all nodes must be provided.")
def _checkTrust(self, host):
"""
check trust between current host and the given host
"""
checkTrustCmd = "source %s; pssh -s -H %s 'pwd'" % (self.envFile, host)
status, output = subprocess.getstatusoutput(checkTrustCmd)
return status
def checkHostTrust(self):
for host in self.hostNames:
if host == self.localhostName:
continue
if self._checkTrust(host) != 0:
CMLog.exitWithError(ErrorCode.GAUSS_511["GAUSS_51100"] % host)
checkHostsTrust(self.hostnames, self.localhostName)
def initLogger(self):
logPath = os.path.join(self.gaussLog, "cm", "cm_tool")

View File

@ -247,14 +247,18 @@ General options:
if os.getuid() == 0:
CMLog.exitWithError(ErrorCode.GAUSS_501["GAUSS_50105"])
def checkHostTrust(self):
checkHostsTrust(self.hostnames, self.localhostName)
def run(self):
self.checkExeUser()
self.parseCommandLine()
self.checkParam()
self.checkXMLContainCMInfo()
self.initLogger()
self.logger.log("Start to uninstall CM.")
self.getHostnames()
self.checkHostTrust()
self.logger.log("Start to uninstall CM.")
self.getCMDataPaths()
self.cancleMonitorCrontab()
self.stopCMProcess()