fix 互信时找不到gs_sshexkey
This commit is contained in:
@ -347,6 +347,7 @@ General options:
|
||||
# get cluster info from xml file
|
||||
# Initialize the self.clusterInfo variable
|
||||
self.initClusterInfo()
|
||||
os.environ[ClusterConstants.TOOL_PATH_ENV] = self.clusterToolPath
|
||||
# Initialize the self.sshTool variable
|
||||
self.initSshTool(self.clusterInfo.getClusterNodeNames(),
|
||||
DefaultValue.TIMEOUT_PSSH_POSTPREINSTALL)
|
||||
|
@ -3864,7 +3864,7 @@ class ClusterCommand():
|
||||
if status != 0 and "encrypt success" not in output:
|
||||
raise Exception(ErrorCode.GAUSS_511["GAUSS_51103"] % "encrypt ..."
|
||||
+ "Error is:%s" % SensitiveMask.mask_pwd(output))
|
||||
logger.log("Generate cluster user password files successfully.\n")
|
||||
logger.log("Generate cluster user password files successfully.")
|
||||
|
||||
@staticmethod
|
||||
def executeSQLOnRemoteHost(hostName, port, sql, outputfile,
|
||||
|
@ -58,6 +58,27 @@ except ImportError as ex:
|
||||
except ImportError as ex:
|
||||
raise Exception(ErrorCode.GAUSS_522["GAUSS_52200"] % str(ex))
|
||||
|
||||
def get_package_path():
|
||||
"""
|
||||
get package path, then can get script path, /package_path/script/
|
||||
:return:
|
||||
"""
|
||||
dir_name = os.path.dirname(os.path.realpath(__file__))
|
||||
package_dir = os.path.join(dir_name, "./../../")
|
||||
return os.path.realpath(package_dir)
|
||||
|
||||
def get_sshexkey_file():
|
||||
"""
|
||||
get gs_sshexkey file
|
||||
"""
|
||||
gphome = os.environ.get("GPHOME")
|
||||
if gphome:
|
||||
trust_file = os.path.normpath(os.path.join(gphome, "script", "gs_sshexkey"))
|
||||
else:
|
||||
package_path = get_package_path()
|
||||
trust_file = os.path.normpath(os.path.join(package_path, "gs_sshexkey"))
|
||||
return trust_file
|
||||
|
||||
class SshTool():
|
||||
"""
|
||||
Class for controling multi-hosts
|
||||
@ -143,12 +164,12 @@ class SshTool():
|
||||
"""
|
||||
self._finalizer()
|
||||
|
||||
def createTrust(self, user, ips=[], mpprcFile="", skipHostnameSet=False, action=''):
|
||||
def createTrust(self, user, ips=[], skipHostnameSet=False, action=''):
|
||||
"""
|
||||
function: create trust for specified user with both ip and hostname,
|
||||
when using N9000 tool create trust failed
|
||||
do not support using a normal user to create trust for another user.
|
||||
input : user, pwd, ips, mpprcFile, skipHostnameSet
|
||||
input : user, pwd, ips, skipHostnameSet
|
||||
output: NA
|
||||
"""
|
||||
tmp_log_file = copy.deepcopy(self.__logFile)
|
||||
@ -175,30 +196,8 @@ class SshTool():
|
||||
"python")
|
||||
|
||||
# 2.call createtrust script
|
||||
create_trust_file = "gs_sshexkey"
|
||||
gphome = os.getenv("GPHOME")
|
||||
if user == "root":
|
||||
if mpprcFile != "" and FileUtil.check_file_permission(mpprcFile, True) and \
|
||||
self.checkMpprcfile(user, mpprcFile):
|
||||
cmd = "source %s; %s -f %s -l '%s'" % (
|
||||
mpprcFile, create_trust_file, tmp_hosts, tmp_log_file)
|
||||
elif mpprcFile == "" and FileUtil.check_file_permission(
|
||||
ClusterConstants.ETC_PROFILE, True):
|
||||
cmd = "source %s; %s -f %s -l '%s'" % (
|
||||
ClusterConstants.ETC_PROFILE, create_trust_file,
|
||||
tmp_hosts, tmp_log_file)
|
||||
else:
|
||||
if mpprcFile != "" and FileUtil.check_file_permission(mpprcFile, True) and \
|
||||
self.checkMpprcfile(user, mpprcFile):
|
||||
cmd = "source %s; %s/script/%s -f %s -l '%s'" % (
|
||||
mpprcFile, gphome, create_trust_file, tmp_hosts,
|
||||
tmp_log_file)
|
||||
elif mpprcFile == "" and FileUtil.check_file_permission(
|
||||
ClusterConstants.ETC_PROFILE, True):
|
||||
cmd = "source %s; %s/script/%s -f %s -l '%s'" % (
|
||||
ClusterConstants.ETC_PROFILE, gphome,
|
||||
create_trust_file, tmp_hosts, tmp_log_file)
|
||||
|
||||
trust_file = get_sshexkey_file()
|
||||
cmd = "%s -f %s -l '%s'" % (trust_file, tmp_hosts, tmp_log_file)
|
||||
if skipHostnameSet:
|
||||
cmd += " --skip-hostname-set"
|
||||
|
||||
@ -728,7 +727,6 @@ class SshTool():
|
||||
input : srcFile, targetDir, hostList, env_file, gp_path, parallel_num
|
||||
output: NA
|
||||
"""
|
||||
scpCmd = "source /etc/profile"
|
||||
outputCollect = ""
|
||||
localMode = False
|
||||
resultMap = {}
|
||||
@ -740,19 +738,19 @@ class SshTool():
|
||||
mpprcFile = env_file
|
||||
else:
|
||||
mpprcFile = EnvUtil.getEnv(DefaultValue.MPPRC_FILE_ENV)
|
||||
if mpprcFile != "" and mpprcFile is not None:
|
||||
scpCmd += " && source %s" % mpprcFile
|
||||
|
||||
if gp_path == "":
|
||||
cmdpre = "%s && echo $GPHOME" % scpCmd
|
||||
(status, output) = subprocess.getstatusoutput(cmdpre)
|
||||
if mpprcFile and os.path.isfile(mpprcFile):
|
||||
cmd = "source %s && echo $GPHOME" % mpprcFile
|
||||
(status, output) = subprocess.getstatusoutput(cmd)
|
||||
if status != 0 or not output or output.strip() == "":
|
||||
raise Exception(ErrorCode.GAUSS_518["GAUSS_51802"]
|
||||
% "GPHOME" + "The cmd is %s" % cmdpre)
|
||||
GPHOME = output.strip()
|
||||
% "GPHOME" + "The cmd is %s" % cmd)
|
||||
gp_home = output.strip()
|
||||
else:
|
||||
GPHOME = gp_path.strip()
|
||||
pscppre = "python3 %s/script/gspylib/pssh/bin/pscp" % GPHOME
|
||||
gp_home = os.environ.get('GPHOME')
|
||||
if gp_path != "":
|
||||
gp_home = gp_path.strip()
|
||||
pscppre = "python3 %s/script/gspylib/pssh/bin/pscp" % gp_home
|
||||
|
||||
if len(hostList) == 0:
|
||||
ssh_hosts = copy.deepcopy(self.hostNames)
|
||||
@ -777,7 +775,7 @@ class SshTool():
|
||||
resultMap[socket.gethostname()] = DefaultValue.FAILURE
|
||||
if not ssh_hosts:
|
||||
return
|
||||
scpCmd += " && %s -r -v -t %s -p %s -H %s -o %s -e %s %s %s" \
|
||||
scpCmd = "%s -r -v -t %s -p %s -H %s -o %s -e %s %s %s" \
|
||||
" 2>&1 | tee %s" % (pscppre, self.__timeout,
|
||||
parallel_num,
|
||||
" -H ".join(ssh_hosts),
|
||||
|
@ -859,11 +859,14 @@ class PostUninstallImpl:
|
||||
|
||||
self.logger.log("Please enter password for root.")
|
||||
retry_times = 0
|
||||
user_profile = self.context.mpprcFile
|
||||
if not self.context.mpprcFile:
|
||||
user_profile = ProfileFile.get_user_bashrc(self.context.user)
|
||||
while True:
|
||||
try:
|
||||
self.sshTool.createTrust(username,
|
||||
user_profile,
|
||||
Ips,
|
||||
self.mpprcFile,
|
||||
action='gs_postuninstall')
|
||||
break
|
||||
except Exception as err_msg:
|
||||
|
@ -220,26 +220,6 @@ class PreinstallImplOLAP(PreinstallImpl):
|
||||
# check the current storage package path is legal
|
||||
Current_Path = os.path.dirname(os.path.realpath(__file__))
|
||||
DefaultValue.checkPathVaild(os.path.normpath(Current_Path))
|
||||
# set ENV
|
||||
cmd = "%s -t %s -u %s -l %s -X '%s' -Q %s" % (
|
||||
OMCommand.getLocalScript("Local_PreInstall"),
|
||||
ACTION_SET_TOOL_ENV,
|
||||
self.context.user,
|
||||
self.context.localLog,
|
||||
self.context.xmlFile,
|
||||
self.context.clusterToolPath)
|
||||
if self.context.mpprcFile != "":
|
||||
cmd += " -s '%s' " % self.context.mpprcFile
|
||||
#check the localmode,if mode is local then modify user group
|
||||
if self.context.localMode:
|
||||
cmd += "-g %s" % self.context.group
|
||||
(status, output) = subprocess.getstatusoutput(cmd)
|
||||
# if cmd failed, then exit
|
||||
if status != 0:
|
||||
self.context.logger.debug(
|
||||
"Command for setting %s tool environment variables: %s" % (
|
||||
VersionInfo.PRODUCT_NAME, cmd))
|
||||
raise Exception(output)
|
||||
|
||||
except Exception as e:
|
||||
raise Exception(str(e))
|
||||
|
@ -38,6 +38,7 @@ from base_utils.os.password_util import PasswordUtil
|
||||
from base_utils.os.net_util import NetUtil
|
||||
from base_utils.os.env_util import EnvUtil
|
||||
from domain_utils.cluster_file.profile_file import ProfileFile
|
||||
from domain_utils.cluster_file.version_info import VersionInfo
|
||||
|
||||
# action name
|
||||
# prepare cluster tool package path
|
||||
@ -215,7 +216,7 @@ class PreinstallImpl:
|
||||
retry_times = 0
|
||||
while True:
|
||||
try:
|
||||
self.context.sshTool.createTrust(username, ip_list, self.context.mpprcFile,
|
||||
self.context.sshTool.createTrust(username, ip_list,
|
||||
self.context.skipHostnameSet)
|
||||
break
|
||||
except Exception as err_msg:
|
||||
@ -604,21 +605,6 @@ class PreinstallImpl:
|
||||
raise Exception(ErrorCode.GAUSS_514["GAUSS_51400"] % cmd
|
||||
+ " Error: \n%s" % output)
|
||||
|
||||
# set tool env on all hosts
|
||||
cmd = "%s -t %s -u %s -l %s -X '%s' -Q %s" % (
|
||||
OMCommand.getLocalScript("Local_PreInstall"),
|
||||
ACTION_SET_TOOL_ENV,
|
||||
self.context.user,
|
||||
self.context.localLog,
|
||||
self.context.xmlFile,
|
||||
self.context.clusterToolPath)
|
||||
if self.context.mpprcFile != "":
|
||||
cmd += " -s '%s' -g %s" % (
|
||||
self.context.mpprcFile, self.context.group)
|
||||
self.context.sshTool.executeCommand(cmd,
|
||||
DefaultValue.SUCCESS,
|
||||
[],
|
||||
self.context.mpprcFile)
|
||||
cmd = "%s -t %s -u %s -g %s -P %s -l %s" % (
|
||||
OMCommand.getLocalScript("Local_PreInstall"),
|
||||
ACTION_PREPARE_PATH,
|
||||
@ -722,7 +708,7 @@ class PreinstallImpl:
|
||||
for ips in sshIps:
|
||||
allIps.extend(ips)
|
||||
# create trust
|
||||
self.context.sshTool.createTrust(self.context.user, allIps, self.context.mpprcFile)
|
||||
self.context.sshTool.createTrust(self.context.user, allIps)
|
||||
self.context.user_ssh_agent_flag = True
|
||||
self.context.logger.debug("{debug exception010} Finished execute sshTool."
|
||||
"createTrust for common user.")
|
||||
@ -929,6 +915,30 @@ class PreinstallImpl:
|
||||
if (error_message.find("GAUSS-50305") > 0):
|
||||
raise Exception(str(error_message))
|
||||
|
||||
def set_tool_env(self):
|
||||
# set tool env on all hosts
|
||||
cmd = "%s -t %s -u %s -l %s -X '%s' -Q %s" % (
|
||||
OMCommand.getLocalScript("Local_PreInstall"),
|
||||
ACTION_SET_TOOL_ENV,
|
||||
self.context.user,
|
||||
self.context.localLog,
|
||||
self.context.xmlFile,
|
||||
self.context.clusterToolPath)
|
||||
if self.context.mpprcFile != "":
|
||||
cmd += " -s '%s' -g %s" % (
|
||||
self.context.mpprcFile, self.context.group)
|
||||
(status, output) = subprocess.getstatusoutput(cmd)
|
||||
if status != 0:
|
||||
self.context.logger.debug(
|
||||
"Command for setting %s tool environment variables: %s" % (
|
||||
VersionInfo.PRODUCT_NAME, cmd))
|
||||
raise Exception(output)
|
||||
|
||||
self.context.sshTool.executeCommand(cmd,
|
||||
DefaultValue.SUCCESS,
|
||||
[],
|
||||
self.context.mpprcFile)
|
||||
|
||||
def createDirs(self):
|
||||
"""
|
||||
function: create directorys
|
||||
@ -1617,12 +1627,14 @@ class PreinstallImpl:
|
||||
self.installToolsPhase1()
|
||||
# exchange user key for root user
|
||||
self.createTrustForRoot()
|
||||
# distribute server package
|
||||
# set HOST_IP env
|
||||
self.setHostIpEnv()
|
||||
# distribute server package
|
||||
self.distributePackages()
|
||||
# create user and exchange keys for database user
|
||||
self.createOSUser()
|
||||
# set tool env on all host
|
||||
self.set_tool_env()
|
||||
# prepare sshd service for user.
|
||||
# This step must be nearly after createOSUser,
|
||||
# which needs sshd service to be restarted.
|
||||
|
@ -1541,6 +1541,10 @@ Common options:
|
||||
# have check its exists when check parameters,
|
||||
# so it should exist here
|
||||
user_profile = self.mpprcFile
|
||||
if not os.path.exists(user_profile):
|
||||
FileUtil.createFile(user_profile)
|
||||
FileUtil.changeMode(DefaultValue.DIRECTORY_MODE, user_profile)
|
||||
FileUtil.changeOwner(self.user, user_profile)
|
||||
else:
|
||||
# check if os profile exist
|
||||
user_profile = ProfileFile.get_user_bashrc(self.user)
|
||||
|
Reference in New Issue
Block a user