fix 环境不分离root用户校验hostname问题
This commit is contained in:
@ -212,57 +212,6 @@ class OMCommand():
|
|||||||
TempfileManagement.removeTempFile(statusFile)
|
TempfileManagement.removeTempFile(statusFile)
|
||||||
return clusterStatus
|
return clusterStatus
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def checkHostname(nodename):
|
|
||||||
"""
|
|
||||||
function: check host name
|
|
||||||
input : NA
|
|
||||||
output: NA
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
retry = 1
|
|
||||||
cmd = "pssh -s -H %s hostname" % (nodename)
|
|
||||||
while True:
|
|
||||||
(status, output) = subprocess.getstatusoutput(cmd)
|
|
||||||
if status == 0 and output.find("%s" % nodename) >= 0:
|
|
||||||
break
|
|
||||||
if retry >= 3:
|
|
||||||
raise Exception(ErrorCode.GAUSS_512["GAUSS_51222"]
|
|
||||||
+ " Command: \"%s\". Error: \n%s"
|
|
||||||
% (cmd, output))
|
|
||||||
retry += 1
|
|
||||||
time.sleep(1)
|
|
||||||
|
|
||||||
if os.getuid() == 0:
|
|
||||||
hostnameCmd = "pssh -s -H %s 'cat /etc/hostname'" % (nodename)
|
|
||||||
(status, output) = subprocess.getstatusoutput(hostnameCmd)
|
|
||||||
if status == 0 and output.strip() == nodename:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
raise Exception(ErrorCode.GAUSS_512["GAUSS_51248"] % nodename
|
|
||||||
+ " Command: \"%s\". Error: \n%s"
|
|
||||||
% (hostnameCmd, output))
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
raise Exception(str(e))
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def checkHostnameMapping(clusterInfo):
|
|
||||||
"""
|
|
||||||
function: check host name mapping
|
|
||||||
input: NA
|
|
||||||
output: NA
|
|
||||||
"""
|
|
||||||
nodes = clusterInfo.getClusterNodeNames()
|
|
||||||
if len(nodes) > 0:
|
|
||||||
try:
|
|
||||||
pool = ThreadPool(DefaultValue.getCpuSet())
|
|
||||||
pool.map(OMCommand.checkHostname, nodes)
|
|
||||||
pool.close()
|
|
||||||
pool.join()
|
|
||||||
except Exception as e:
|
|
||||||
raise Exception(str(e))
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def wait_for_normal(logger, user, timeout=300, delta=5):
|
def wait_for_normal(logger, user, timeout=300, delta=5):
|
||||||
|
|
||||||
|
@ -673,11 +673,7 @@ class PreinstallImpl:
|
|||||||
self.context.user,
|
self.context.user,
|
||||||
self.context.xmlFile,
|
self.context.xmlFile,
|
||||||
self.context.localLog)
|
self.context.localLog)
|
||||||
self.context.sshTool.executeCommand(cmd,
|
subprocess.getstatusoutput(cmd)
|
||||||
DefaultValue.SUCCESS,
|
|
||||||
[],
|
|
||||||
self.context.mpprcFile,
|
|
||||||
DefaultValue.getCpuSet())
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise Exception(str(e))
|
raise Exception(str(e))
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ import grp
|
|||||||
import configparser
|
import configparser
|
||||||
import re
|
import re
|
||||||
import platform
|
import platform
|
||||||
|
from multiprocessing.dummy import Pool as ThreadPool
|
||||||
|
|
||||||
|
|
||||||
sys.path.append(sys.path[0] + "/../")
|
sys.path.append(sys.path[0] + "/../")
|
||||||
@ -316,6 +317,8 @@ Common options:
|
|||||||
if not os.path.exists(self.mpprcFile):
|
if not os.path.exists(self.mpprcFile):
|
||||||
GaussLog.exitWithError(
|
GaussLog.exitWithError(
|
||||||
ErrorCode.GAUSS_502["GAUSS_50201"] % self.mpprcFile)
|
ErrorCode.GAUSS_502["GAUSS_50201"] % self.mpprcFile)
|
||||||
|
else:
|
||||||
|
self.mpprcFile = os.path.normpath(os.path.join(os.path.expanduser("~%s" % self.user), ".bashrc"))
|
||||||
|
|
||||||
if self.logFile == "":
|
if self.logFile == "":
|
||||||
self.logFile = ClusterLog.getOMLogPath(
|
self.logFile = ClusterLog.getOMLogPath(
|
||||||
@ -628,18 +631,41 @@ Common options:
|
|||||||
input : NA
|
input : NA
|
||||||
output: NA
|
output: NA
|
||||||
"""
|
"""
|
||||||
if not self.current_user_root:
|
|
||||||
return
|
|
||||||
self.logger.debug("Checking hostname mapping.")
|
self.logger.debug("Checking hostname mapping.")
|
||||||
try:
|
if os.getuid() == 0:
|
||||||
self.logger.debug("Change file[/etc/hosts] mode.")
|
self.logger.debug("Change file[/etc/hosts] mode.")
|
||||||
FileUtil.changeMode(DefaultValue.HOSTS_FILE, "/etc/hosts")
|
FileUtil.changeMode(DefaultValue.HOSTS_FILE, "/etc/hosts")
|
||||||
OMCommand.checkHostnameMapping(self.clusterInfo)
|
try:
|
||||||
|
node_names = self.clusterInfo.getClusterNodeNames()
|
||||||
|
pool = ThreadPool(DefaultValue.getCpuSet())
|
||||||
|
pool.map(self.check_hostname, node_names)
|
||||||
|
pool.close()
|
||||||
|
pool.join()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.logExit(str(e))
|
self.logger.logExit(str(e))
|
||||||
|
|
||||||
self.logger.debug("Successfully checked hostname mapping.")
|
self.logger.debug("Successfully checked hostname mapping.")
|
||||||
|
|
||||||
|
def check_hostname(self, node_name):
|
||||||
|
"""
|
||||||
|
function: Checking hostname mapping
|
||||||
|
input : NA
|
||||||
|
output: NA
|
||||||
|
"""
|
||||||
|
retry = 1
|
||||||
|
cmd = "source %s;pssh -s -H %s hostname" % (self.mpprcFile, node_name)
|
||||||
|
while True:
|
||||||
|
(status, output) = subprocess.getstatusoutput(cmd)
|
||||||
|
self.logger.debug("Checking hostname mapping for node [%s]. output: %s" % (node_name, output))
|
||||||
|
if status == 0 and output.find(node_name) >= 0:
|
||||||
|
break
|
||||||
|
if retry >= 3:
|
||||||
|
raise Exception(ErrorCode.GAUSS_512["GAUSS_51222"]
|
||||||
|
+ " Command: \"%s\". Error: \n%s"
|
||||||
|
% (cmd, output))
|
||||||
|
retry += 1
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
def checkPasswdIsExpires(self):
|
def checkPasswdIsExpires(self):
|
||||||
"""
|
"""
|
||||||
function: Check if user password is expires
|
function: Check if user password is expires
|
||||||
|
Reference in New Issue
Block a user