diff --git a/tool/cm_tool/Common.py b/tool/cm_tool/Common.py index 1763e4a..a4aa83f 100644 --- a/tool/cm_tool/Common.py +++ b/tool/cm_tool/Common.py @@ -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)) diff --git a/tool/cm_tool/cm_install b/tool/cm_tool/cm_install index 399bd9f..a2a117f 100644 --- a/tool/cm_tool/cm_install +++ b/tool/cm_tool/cm_install @@ -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") diff --git a/tool/cm_tool/cm_uninstall b/tool/cm_tool/cm_uninstall index 218bda6..a1f007a 100644 --- a/tool/cm_tool/cm_uninstall +++ b/tool/cm_tool/cm_uninstall @@ -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()