Merge branch 'master' of gitee.com:hangjin2020/openGauss-OM

This commit is contained in:
hangjin2020 2021-01-26 17:25:11 +08:00
commit 94810cb0fe
27 changed files with 335 additions and 176 deletions

View File

@ -384,7 +384,7 @@ def checkParameter():
checkConfigFile()
if (len(g_opts.hostnameList) == 0):
g_opts.hostnameList = [DefaultValue.GetHostIpOrName()]
sorted(g_opts.hostnameList)
g_opts.hostnameList.sort()
checkHostnameList()
##########################################
# set logfile

View File

@ -152,6 +152,7 @@ class GaussCreateTrust():
self.id_rsa_pub_fname = self.id_rsa_fname + '.pub'
self.skipHostnameSet = False
self.isKeyboardPassword = False
self.nodeduplicate = False
def usage(self):
"""
@ -198,6 +199,8 @@ General options:
self.skipHostnameSet = paraDict.get("skipHostnameSet")
if ("passwords" in paraDict.keys()):
self.passwd = paraDict.get("passwords")
if ("noDeduplicate" in paraDict.keys()):
self.nodeduplicate = paraDict.get("noDeduplicate")
def checkParameter(self):
"""
@ -495,7 +498,7 @@ General options:
if (not os.path.exists("/etc/hosts")):
raise Exception(ErrorCode.GAUSS_512["GAUSS_51221"] +
" Error: \nThe /etc/hosts does not exist.")
cmd = "grep -v '" + HOSTS_MAPPING_FLAG + "' /etc/hosts"
cmd = "grep -v '" + HOSTS_MAPPING_FLAG + "' /etc/hosts| grep -v '^$'"
(status, output) = subprocess.getstatusoutput(cmd)
try:
g_file.createFile(tmpHostIpName)
@ -507,8 +510,16 @@ General options:
if os.path.exists(tmpHostIpName):
g_file.removeFile(tmpHostIpName)
raise Exception(str(e))
for (key, value) in result.items():
hostIPInfo += '%s %s %s\n' % (key, value, HOSTS_MAPPING_FLAG)
if not self.nodeduplicate:
tmpResult = {}
for s_key in list(result.keys()):
if s_key not in output:
tmpResult[s_key] = result[s_key]
for (key, value) in tmpResult.items():
hostIPInfo += '%s %s %s\n' % (key, value, HOSTS_MAPPING_FLAG)
else:
for (key, value) in result.items():
hostIPInfo += '%s %s %s\n' % (key, value, HOSTS_MAPPING_FLAG)
hostIPInfo = hostIPInfo[:-1]
ipInfoList = [hostIPInfo]
g_file.writeFile("/etc/hosts", ipInfoList)
@ -540,6 +551,7 @@ General options:
result = {}
tmpHostIpName = "./tmp_hostsiphostname_%d" % os.getpid()
username = pwd.getpwuid(os.getuid()).pw_name
global ipHostInfo
try:
ssh = paramiko.Transport((ip, 22))
except Exception as e:
@ -551,17 +563,30 @@ General options:
ssh.close()
raise Exception(ErrorCode.GAUSS_503["GAUSS_50317"]
+ " Error: \n%s" % str(e))
cmd = "grep -v '%s' %s > %s ; cp %s %s && rm -rf %s" \
% (" #Gauss.* IP Hosts Mapping", '/etc/hosts', tmpHostIpName,
tmpHostIpName, '/etc/hosts', tmpHostIpName)
cmd = "grep -v '%s' %s | grep -v '^$'" \
% (" #Gauss.* IP Hosts Mapping", '/etc/hosts')
channel = ssh.open_session()
channel.exec_command(cmd)
ipHosts = channel.recv(9999).decode().strip()
errInfo = channel.recv_stderr(9999).decode().strip()
if (errInfo):
writeResult.append(errInfo)
cmd = "echo \"%s\" > %s ; cp %s %s && rm -rf %s" \
% (ipHosts, tmpHostIpName, tmpHostIpName, '/etc/hosts', tmpHostIpName)
channel = ssh.open_session()
channel.exec_command(cmd)
ipHosts1 = channel.recv(9999).decode().strip()
errInfo1 = channel.recv_stderr(9999).decode().strip()
if ((errInfo + errInfo1)):
writeResult.append(errInfo + errInfo1)
else:
if (not ipHosts):
if (not ipHosts1):
if not self.nodeduplicate:
tmpIpHostInfo = ""
ipArray = ipHostInfo.split("\n")
for info in ipArray:
hostname = info.split(" ")[0]
if hostname not in ipHosts:
tmpIpHostInfo += info + "\n"
ipHostInfo = tmpIpHostInfo
cmd = "echo '%s' >> /etc/hosts" % (ipHostInfo)
channel = ssh.open_session()
channel.exec_command(cmd)
@ -570,7 +595,6 @@ General options:
writeResult.append(errInfo)
if channel:
channel.close()
result[ip] = writeResult
if (len(writeResult) > 0):
return (False, result)
@ -646,21 +670,34 @@ General options:
if (boolInvalidIp):
boolInvalidIp = False
continue
cmd = "grep -v '%s' %s > %s ; cp %s %s && rm -rf %s" % (
" #Gauss.* IP Hosts Mapping", '/etc/hosts', tmpHostIpName,
tmpHostIpName, '/etc/hosts', tmpHostIpName)
cmd = "grep -v '%s' %s | grep -v '^$'" % (
" #Gauss.* IP Hosts Mapping", '/etc/hosts')
channel = ssh.open_session()
channel.exec_command(cmd)
ipHosts = channel.recv(9999).decode().strip()
errInfo = channel.recv_stderr(9999).decode().strip()
if (errInfo):
writeResult.append(errInfo)
cmd = "echo \"%s\" > %s ; cp %s %s && rm -rf %s" % (
ipHosts, tmpHostIpName, tmpHostIpName,
'/etc/hosts', tmpHostIpName)
channel = ssh.open_session()
channel.exec_command(cmd)
ipHosts1 = channel.recv(9999).decode().strip()
errInfo1 = channel.recv_stderr(9999).decode().strip()
if (errInfo + errInfo1):
writeResult.append(errInfo + errInfo1)
else:
if (not ipHosts):
if (not ipHosts1):
ipHostInfo = ""
for (key1, value1) in result.items():
ipHostInfo += '%s %s %s\n' % (
key1, value1, HOSTS_MAPPING_FLAG)
if not self.nodeduplicate:
for (key1, value1) in result.items():
if key1 not in ipHosts:
ipHostInfo += '%s %s %s\n' % (
key1, value1, HOSTS_MAPPING_FLAG)
else:
for (key1, value1) in result.items():
ipHostInfo += '%s %s %s\n' % (
key1, value1, HOSTS_MAPPING_FLAG)
ipHostInfo = ipHostInfo[:-1]
cmd = "echo '%s' >> /etc/hosts" % ipHostInfo
channel = ssh.open_session()

View File

@ -141,7 +141,7 @@ General options:
clusterPath = []
try:
# get tool path
clusterPath.append(DefaultValue.getClusterToolPath())
clusterPath.append(DefaultValue.getClusterToolPath(self.user))
# get tmp path
tmpDir = DefaultValue.getTmpDirFromEnv()
clusterPath.append(tmpDir)

View File

@ -1259,7 +1259,7 @@ class DefaultValue():
raise Exception(ErrorCode.GAUSS_503["GAUSS_50307"])
@staticmethod
def getClusterToolPath():
def getClusterToolPath(user):
"""
function : Get the value of cluster's tool path.
The value can't be None or null
@ -1269,7 +1269,8 @@ class DefaultValue():
mpprcFile = DefaultValue.getEnv(DefaultValue.MPPRC_FILE_ENV)
echoEnvCmd = "echo $%s" % DefaultValue.TOOL_PATH_ENV
if not mpprcFile:
mpprcFile = "/etc/profile"
userpath = pwd.getpwnam(user).pw_dir
mpprcFile = os.path.join(userpath, ".bashrc")
cmd = g_Platform.getExecuteCmdWithUserProfile("", mpprcFile,
echoEnvCmd)
(status, output) = subprocess.getstatusoutput(cmd)
@ -1390,13 +1391,13 @@ class DefaultValue():
return os.path.realpath(path)
@staticmethod
def getBackupDir(subDir=""):
def getBackupDir(user, subDir=""):
"""
function : Get the cluster's default backup directory for upgrade
input : String
output : String
"""
bakDir = "%s/backup" % DefaultValue.getClusterToolPath()
bakDir = "%s/backup" % DefaultValue.getClusterToolPath(user)
if (subDir != ""):
bakDir = os.path.join(bakDir, subDir)
@ -2111,46 +2112,6 @@ class DefaultValue():
if (os.path.exists(path)):
os.remove(path)
@staticmethod
def distributeEncryptFiles(appPath, hostList):
"""
function : distribute encrypted files of server.key.cipher
and server.key.rand to remote host
input : String,[]
output : NA
"""
# init encrypt file
binPath = "%s/bin" % appPath
encryptFile1 = "%s/server.key.cipher" % binPath
encryptFile2 = "%s/server.key.rand" % binPath
if (not os.path.exists(encryptFile1) or not os.path.exists(
encryptFile2)):
raise Exception(ErrorCode.GAUSS_502["GAUSS_50201"] %
"encrypt files" + " Please check it.")
# get user and group
(user, group) = g_OSlib.getPathOwner(appPath)
if (user == "" or group == ""):
raise Exception(ErrorCode.GAUSS_503["GAUSS_50308"] + ".")
# copy encrypt file to host
for host in hostList:
targetPath = "'%s'/" % binPath
g_OSlib.scpFile(host, encryptFile1, targetPath)
g_OSlib.scpFile(host, encryptFile2, targetPath)
chownCmd1 = g_Platform.getChownCmd(user, group, encryptFile1)
chownCmd2 = g_Platform.getChownCmd(user, group, encryptFile2)
chmodCmd1 = g_Platform.getChmodCmd(str(DefaultValue.KEY_FILE_MODE),
encryptFile1)
chmodCmd2 = g_Platform.getChmodCmd(str(DefaultValue.KEY_FILE_MODE),
encryptFile2)
executeCmd = "%s && %s && %s && %s" % (chownCmd1,
chownCmd2,
chmodCmd1,
chmodCmd2)
cmd = g_OSlib.getSshCommand(host, executeCmd)
DefaultValue.execCommandLocally(cmd)
@staticmethod
def distributeDatasourceFiles(sshTool, appPath, hostList):
"""

View File

@ -79,7 +79,7 @@ gs_check = ["-?", "--help", "-V", "--version", "-e:", "-i:",
"--ShrinkNodes=", "--nodegroup-name=",
"--skip-root-items", "--set"]
gs_sshexkey = ["-?", "--help", "-V", "--version",
"-f:", "--skip-hostname-set", "-l:", "-h:", "-W:"]
"-f:", "--skip-hostname-set", "-l:", "-h:", "-W:", "--no-deduplicate"]
gs_backup = ["-?", "--help", "-V", "--version", "--backup-dir=",
"--parameter", "--force",
"--binary", "--all", "-l:", "-h:", "-t:", "-X:"]
@ -348,6 +348,7 @@ class Parameter():
"--non-interactive": "preMode",
"--skip-os-set": "skipOSSet",
"--skip-hostname-set": "skipHostnameSet",
"--no-deduplicate": "noDeduplicate",
"--reset": "reset",
"--parameter": "isParameter",
"--binary": "isBinary",

View File

@ -108,8 +108,8 @@ class diskInfo():
mountDisk[i_mountpoint] = [i_device, i_mountpoint]
mountList = mountDisk.keys()
sorted(mountList, reverse=True)
for mount in mountList:
sortedMountList = sorted(mountList, reverse=True)
for mount in sortedMountList:
i_mountpoint = mountDisk[mount][1]
if (i_mountpoint == '/'):
i_mount_dirlst = ['']

View File

@ -122,7 +122,7 @@ class CheckSysTable(BaseItem):
for result in results:
if (result):
outputList.append(result)
sorted(outputList)
outputList.sort()
return outputList
def doCheck(self):

View File

@ -34,8 +34,8 @@ class CheckDiskConfig(BaseItem):
diskInfo = disk.split()
DiskInfoDict[diskInfo[0]] = disk
keys = DiskInfoDict.keys()
sorted(keys)
for diskName in keys:
sortedKeys = sorted(keys)
for diskName in sortedKeys:
ResultStr += "%s\n" % DiskInfoDict[diskName]
self.result.val = ResultStr
self.result.rst = ResultStatus.OK

View File

@ -127,7 +127,7 @@ class CheckInodeUsage(BaseItem):
self.result.rst = ResultStatus.NG
keys = DiskInfoDict.keys()
sorted(keys)
sortedKeys = sorted(keys)
self.result.raw = "diskname inodeUsage"
for diskInfo in map(DiskInfoDict.get, keys):
for diskInfo in map(DiskInfoDict.get, sortedKeys):
self.result.raw += "\n%s" % diskInfo

View File

@ -168,10 +168,10 @@ class CheckSpaceUsage(BaseItem):
self.result.rst = ResultStatus.NG
keys = DiskInfoDict.keys()
sorted(keys)
MaxDisk = list(map(DiskInfoDict.get, keys))[-1]
MinDisk = list(map(DiskInfoDict.get, keys))[0]
sortedKeys = sorted(keys)
MaxDisk = list(map(DiskInfoDict.get, sortedKeys))[-1]
MinDisk = list(map(DiskInfoDict.get, sortedKeys))[0]
self.result.val += "\nDisk Filesystem spaceUsage\nMax " \
"free %s\nMin free %s" % (MaxDisk, MinDisk)
for diskInfo in list(map(DiskInfoDict.get, keys)):
for diskInfo in list(map(DiskInfoDict.get, sortedKeys)):
self.result.raw += "\n%s" % diskInfo

View File

@ -20,13 +20,11 @@ import subprocess
import _thread as thread
import time
import psutil
import platform
import multiprocessing
from multiprocessing.pool import ThreadPool
from gspylib.inspection.common import SharedFuncs
from gspylib.inspection.common.CheckItem import BaseItem
from gspylib.inspection.common.CheckResult import ResultStatus
from gspylib.os.gsOSlib import g_OSlib
from gspylib.os.gsnetwork import g_network
from gspylib.common.ErrorCode import ErrorCode
@ -185,31 +183,18 @@ class CheckNetSpeed(BaseItem):
def doClean(self):
currentUser = pwd.getpwuid(os.getuid())[0]
while True:
g_OSlib.killallProcess(currentUser, 'speed_test', '9')
ProcList = g_OSlib.getProcPidList('speed_test')
if (len(ProcList) == 0):
cmd = "ps -ef|grep speed_test|grep %s|grep -v grep|" \
"awk '{print $2}'|xargs kill -9" % currentUser
(status, _) = subprocess.getstatusoutput(cmd)
if (status == 0):
break
time.sleep(1)
return
def getTestFile(self):
machine = platform.machine()
testSpeedFile = "%s/lib/checknetspeed/speed_test" \
% self.context.basePath
if machine == "x86_64":
cmd = "cp -p %s_x86 %s" % (testSpeedFile, testSpeedFile)
# debian: deepin Maipo: NOE Kylin
elif machine == "aarch64":
cmd = "cp -p %s_arm %s" % (testSpeedFile, testSpeedFile)
else:
raise Exception(ErrorCode.GAUSS_530["GAUSS_53017"] % machine)
SharedFuncs.runShellCmd(cmd)
def doCheck(self):
global errorMsg
global serviceIP
global MaxDelayFailFlag
self.getTestFile()
serviceIP = SharedFuncs.getIpByHostName(self.host)
for network in g_network.getAllNetworkInfo():
if (network.ipAddress == serviceIP):

View File

@ -41,11 +41,11 @@ class CheckPing(BaseItem):
allIP += dbInstance.haIps
allIP += dbInstance.listenIps
sorted(allIP)
for i in range(len(allIP) - 2, -1, -1):
if allIP.count(allIP[i]) > 1:
del allIP[i]
noPassIPs = g_network.checkIpAddressList(allIP)
sortedAllIP = sorted(allIP)
for i in range(len(sortedAllIP) - 2, -1, -1):
if sortedAllIP.count(sortedAllIP[i]) > 1:
del sortedAllIP[i]
noPassIPs = g_network.checkIpAddressList(sortedAllIP)
if noPassIPs == []:
self.result.rst = ResultStatus.OK
self.result.raw = "All IP can pinged."

View File

@ -39,7 +39,7 @@ class CheckEtcHosts(BaseItem):
if (not eachLine.startswith('#') and '::' not in eachLine):
mappingInfo = " ".join(eachLine.split())
IpList.append(mappingInfo)
sorted(IpList)
IpList.sort()
self.result.raw = "\n".join(IpList)
# Check localhost Mapping

View File

@ -0,0 +1,98 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
#############################################################################
# Copyright (c) 2020 Huawei Technologies Co.,Ltd.
#
# openGauss is licensed under Mulan PSL v2.
# You can use this software according to the terms
# and conditions of the Mulan PSL v2.
# You may obtain a copy of Mulan PSL v2 at:
#
# http://license.coscl.org.cn/MulanPSL2
#
# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS,
# WITHOUT WARRANTIES OF ANY KIND,
# EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
# MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
# See the Mulan PSL v2 for more details.
# ----------------------------------------------------------------------------
import socket
import time
import sys
listen_ip = "localhost"
listen_port = 31111
run_mode = 0 # 0:connect, 1:send, 2:recv
def send_main():
global listen_ip
global listen_port
buf = "this is a test !" * 512 # buf 8192 block
sockets = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sockets.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
print(listen_ip+":"+listen_port)
while(sockets.connect_ex((listen_ip, int(listen_port))) != 0):
print("connect failed:%m\n")
time.sleep(1)
print("connect succeed, dest[%s:%d], mode[%s]\n", listen_ip, listen_port, "tcp")
print("send satrt, dest[%s:%d], mode[%s]\n", listen_ip, listen_port, "tcp")
i = 0
while True:
i = i + 1
n = sockets.send(buf.encode())
if n == 0:
print("send failed:%m\n")
break
print("%d send:%s, len=%d\n", i, buf, n)
def recv_main():
global listen_ip
global listen_port
sockets = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sockets.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
sockets.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
sockets.bind((listen_ip, int(listen_port)))
sockets.listen(128)
while True:
client, addr = sockets.accept()
print('client:', client)
print('addr:', addr)
while True:
data = client.recv(8192)
print(data.decode())
if not data:
client.close()
break
def connect_main():
sockets = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sockets.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
if sockets.connect_ex((listen_ip, int(listen_port))) != 0:
print("Failed to connect %s:%d on %s mode:%m.\n",
listen_ip, listen_port, "tcp")
else:
print("Succeed to connect %s:%d on %s mode.\n",
listen_ip, listen_port, "tcp")
def invalid_argument():
print("usage: ./speed_test recv/send/connect recv_ip "
"recv_port [sctp] [msg_len] [debug]\n")
print("example: ./speed_test recv 127.0.0.1 10001\n")
exit(1)
if __name__ == '__main__':
if len(sys.argv) < 5:
invalid_argument()
if sys.argv[1] == "send":
run_mode = 1
elif sys.argv[1] == "recv":
run_mode = 2
listen_ip = sys.argv[2]
listen_port = sys.argv[3]
if run_mode == 1:
send_main()
elif run_mode == 2:
recv_main()
else:
connect_main()

View File

@ -176,7 +176,6 @@ def _parse_release_file(firstline):
def linux_distribution(distname='', version='', idNum='',
supported_dists=_supported_dists,
full_distribution_name=1):
"""
@ -204,9 +203,9 @@ def linux_distribution(distname='', version='', idNum='',
except os.error:
# Probably not a Unix system
return distname, version, idNum
sorted(etc)
sortEtc = sorted(etc)
gFile = None
for file in etc:
for file in sortEtc:
if os.path.islink('/etc/' + file):
continue
m = _release_filename.match(file)

View File

@ -1821,7 +1821,10 @@ class CheckperfImplOLAP(CheckperfImpl):
cmd = "%s -t SSDPerfCheck -U %s -l %s" \
% (OMCommand.getLocalScript("LOCAL_PERFORMANCE_CHECK"),
self.opts.user, self.opts.localLog)
(status, output) = self.sshTool.getSshStatusOutput(cmd)
gp_path = os.path.join(
DefaultValue.ROOT_SCRIPTS_PATH, self.opts.user)
(status, output) = self.sshTool.getSshStatusOutput(cmd,
gp_path=gp_path)
outputMap = self.sshTool.parseSshOutput(self.sshTool.hostNames)
for node in status.keys():
if (status[node] == DefaultValue.SUCCESS):

View File

@ -85,7 +85,9 @@ class ExpansionImpl():
if envFile:
self.envFile = envFile
else:
self.envFile = "/etc/profile"
userpath = pwd.getpwnam(self.user).pw_dir
mpprcFile = os.path.join(userpath, ".bashrc")
self.envFile = mpprcFile
currentTime = str(datetime.datetime.now()).replace(" ", "_").replace(
".", "_")
@ -336,7 +338,9 @@ class ExpansionImpl():
envfile = self.envFile
tempXmlFile = "%s/clusterconfig.xml" % self.tempFileDir
if envfile == "/etc/profile":
userpath = pwd.getpwnam(self.user).pw_dir
mpprcFile = os.path.join(userpath, ".bashrc")
if envfile == mpprcFile:
preinstallCmd = "{softpath}/script/gs_preinstall -U {user} -G {group} \
-X {xmlfile} --non-interactive 2>&1\
".format(softpath=self.context.packagepath,user=self.user,

View File

@ -415,12 +415,6 @@ class InstallImpl:
"""
pass
def distributeEncryptFiles(self):
"""
function: distribute encrypt files
"""
pass
# for ap
def prepareConfigCluster(self):
"""

View File

@ -118,7 +118,6 @@ class InstallImplOLAP(InstallImpl):
"""
self.context.cleanNodeConfig()
self.checkNodeConfig()
self.distributeEncryptFiles()
def checkNodeConfig(self):
"""
@ -176,22 +175,6 @@ class InstallImplOLAP(InstallImpl):
self.context.logger.debug("Successfully checked node's installation.",
"constant")
def distributeEncryptFiles(self):
"""
function: distribute encrypt files
input: NA
output: NA
"""
# distribute encrypt files to remote host
# get local hostname
localHostName = DefaultValue.GetHostIpOrName()
# get all node names
hostList = self.context.clusterInfo.getClusterNodeNames()
# remove the local hostname from hostList
hostList.remove(localHostName)
DefaultValue.distributeEncryptFiles(self.context.clusterInfo.appPath,
hostList)
def initNodeInstance(self):
"""
function: init instance applications

View File

@ -79,7 +79,7 @@ class PostUninstallImpl:
try:
self.logger.log("Check log file path.", "addStep")
# get tool path
clusterPath.append(DefaultValue.getClusterToolPath())
clusterPath.append(DefaultValue.getClusterToolPath(self.user))
# get tmp path
tmpDir = DefaultValue.getTmpDir(self.user, self.xmlFile)
@ -109,6 +109,8 @@ class PostUninstallImpl:
"""
self.logger.debug("Do clean Environment.", "addStep")
try:
# set GPHOME env
self.setOrCleanGphomeEnv()
# check uninstall
self.checkUnPreInstall()
# clean app/log/data/temp dirs
@ -127,6 +129,18 @@ class PostUninstallImpl:
self.logger.logExit(str(e))
self.logger.debug("Do clean Environment succeeded.", "constant")
def setOrCleanGphomeEnv(self, setGphomeenv=True):
osProfile = "/etc/profile"
if setGphomeenv:
GphomePath = DefaultValue.getPreClusterToolPath(self.user,
self.xmlFile)
# set GPHOME
g_file.writeFile(osProfile, ["export GPHOME=%s" % GphomePath])
else:
g_file.deleteLine(osProfile, "^\\s*export\\s*GPHOME=.*$")
self.logger.debug(
"Deleting crash GPHOME in user environment variables.")
def checkUnPreInstall(self):
"""
function: check whether do uninstall before unpreinstall
@ -221,7 +235,7 @@ class PostUninstallImpl:
self.mpprcFile)
# clean upgrade temp backup path
cmd = "rm -rf '%s'" % DefaultValue.getBackupDir("upgrade")
cmd = "rm -rf '%s'" % DefaultValue.getBackupDir(self.user, "upgrade")
self.logger.debug(
"Command for deleting the upgrade temp backup path: %s" % cmd)
DefaultValue.execCommandWithMode(cmd,
@ -360,7 +374,7 @@ class PostUninstallImpl:
cmd = "rm -rf '%s/%s'; rm -rf /tmp/gauss_*;" % (
self.clusterInfo.logPath, self.user)
cmd += "rm -rf '%s/Python-2.7.9'" \
% DefaultValue.getClusterToolPath()
% DefaultValue.getClusterToolPath(self.user)
self.logger.debug(
"Command for deleting logs of other nodes: %s" % cmd)
DefaultValue.execCommandWithMode(cmd,
@ -388,7 +402,7 @@ class PostUninstallImpl:
"Deleting software packages "
"and environmental variables of the local node.")
try:
self.clusterToolPath = DefaultValue.getClusterToolPath()
self.clusterToolPath = DefaultValue.getClusterToolPath(self.user)
# clean local node environment software
path = "%s/%s" % (self.clusterToolPath, PSSHDIR)
@ -424,35 +438,15 @@ class PostUninstallImpl:
# clean local node environment variable
cmd = "(if [ -s '%s' ]; then " % PROFILE_FILE
cmd += "sed -i -e '/^export GPHOME=%s$/d' %s " % (
self.clusterToolPath.replace('/', '\/'), PROFILE_FILE)
cmd += \
"-e '/^export PATH=\$GPHOME\/pssh-2.3.1\/bin:" \
"\$GPHOME\/script:\$PATH$/d' %s " % PROFILE_FILE
cmd += \
"-e '/^export PATH=\$GPHOME\/script\/gspylib\/pssh\/bin:" \
"\$GPHOME\/script:\$PATH$/d' %s " % PROFILE_FILE
cmd += \
"-e '/^export LD_LIBRARY_PATH=\$GPHOME\/script" \
"\/gspylib\/clib:\$LD_LIBRARY_PATH$/d' %s " % PROFILE_FILE
cmd += \
"-e '/^export LD_LIBRARY_PATH=\$GPHOME\/lib:" \
"\$LD_LIBRARY_PATH$/d' %s " % PROFILE_FILE
cmd += \
"-e '/^export PATH=\/root\/gauss_om\/%s\/script:" \
"\$PATH$/d' %s " % (self.user, PROFILE_FILE)
cmd += \
"-e '/^export PYTHONPATH=\$GPHOME\/lib$/d' %s; fi) " \
% PROFILE_FILE
cmd += "sed -i -e '/^export PATH=\/root\/gauss_om\/%s\/script:" \
"\$PATH$/d' %s; fi)" % (self.user, PROFILE_FILE)
self.logger.debug(
"Command for deleting environment variable: %s" % cmd)
(status, output) = subprocess.getstatusoutput(cmd)
if (status != 0):
self.logger.logExit(
ErrorCode.GAUSS_502["GAUSS_50207"]
% "environment variables of the local node"
+ " Error: \n%s" % output)
self.logger.logExit(ErrorCode.GAUSS_502["GAUSS_50207"] %
"environment variables of the local node"
+ " Error: \n%s" % output)
# check if user profile exist
userProfile = ""
if (self.mpprcFile is not None and self.mpprcFile != ""):
@ -780,6 +774,7 @@ class PostUninstallImpl:
self.cleanLocalLog()
self.cleanMpprcFile()
self.cleanScript()
self.setOrCleanGphomeEnv(setGphomeenv=False)
self.logger.log("Successfully cleaned environment.")
except Exception as e:
self.logger.logExit(str(e))

View File

@ -72,6 +72,8 @@ ACTION_CHECK_ENVFILE = "check_envfile"
ACTION_CHECK_DIR_OWNER = "check_dir_owner"
# check os software
ACTION_CHECK_OS_SOFTWARE = "check_os_software"
# change tool env
ACTION_CHANGE_TOOL_ENV = "change_tool_env"
#############################################################################
# Global variables
# self.context.logger: globle logger
@ -899,6 +901,30 @@ class PreinstallImpl:
self.context.logger.log(
"Successfully installed the tools in the cluster.", "constant")
def changeToolEnv(self):
"""
function:
change software tool env path
input:NA
output:NA
"""
try:
# Change software tool env path
cmd = "%s -t %s -u %s -l %s -X '%s' -Q %s" % (
OMCommand.getLocalScript("Local_PreInstall"),
ACTION_CHANGE_TOOL_ENV,
self.context.user,
self.context.localLog,
self.context.xmlFile,
self.context.clusterToolPath)
if self.context.mpprcFile == "":
DefaultValue.execCommandWithMode(
cmd,
"change software tool env path",
self.context.sshTool)
except Exception as e:
raise Exception(str(e))
def checkMappingForHostName(self):
"""
function: check mpping for hostname
@ -1856,6 +1882,8 @@ class PreinstallImpl:
self.checkMappingForHostName()
# exchage user key for common user
self.createTrustForCommonUser()
# change tool env path
self.changeToolEnv()
# delete tmp file
self.deleteStepTmpFile()
# the end of functions which do not use in in local mode

View File

@ -48,7 +48,7 @@ class UninstallImpl:
clusterPath = []
try:
# get tool path
clusterPath.append(DefaultValue.getClusterToolPath())
clusterPath.append(DefaultValue.getClusterToolPath(self.user))
# get tmp path
tmpDir = DefaultValue.getTmpDirFromEnv()
clusterPath.append(tmpDir)
@ -179,7 +179,7 @@ class UninstallImpl:
self.mpprcFile)
# clean upgrade temp backup path
upgrade_bak_dir = DefaultValue.getBackupDir("upgrade")
upgrade_bak_dir = DefaultValue.getBackupDir(self.user, "upgrade")
cmd = g_file.SHELL_CMD_DICT["cleanDir"] % (
upgrade_bak_dir, upgrade_bak_dir, upgrade_bak_dir)
DefaultValue.execCommandWithMode(cmd,

View File

@ -4246,14 +4246,16 @@ class UpgradeImpl:
"clean other tool package files.", "addStep")
try:
commonPart = DefaultValue.get_package_back_name().rsplit("_", 1)[0]
gphomePath = os.listdir(DefaultValue.getClusterToolPath())
gphomePath = \
os.listdir(DefaultValue.getClusterToolPath(self.context.user))
commitId = self.newCommitId
if action == Const.ACTION_AUTO_ROLLBACK:
commitId = self.oldCommitId
for filePath in gphomePath:
if commonPart in filePath and commitId not in filePath:
toDeleteFilePath = os.path.join(
DefaultValue.getClusterToolPath(), filePath)
DefaultValue.getClusterToolPath(self.context.user),
filePath)
deleteCmd = "(if [ -f '%s' ]; then rm -rf '%s'; fi) " % \
(toDeleteFilePath, toDeleteFilePath)
DefaultValue.execCommandWithMode(
@ -4281,11 +4283,11 @@ class UpgradeImpl:
"""
try:
cmd = "(if [ ! -d '%s' ]; then mkdir -p '%s'; fi)" % \
(DefaultValue.getClusterToolPath(),
DefaultValue.getClusterToolPath())
(DefaultValue.getClusterToolPath(self.context.user),
DefaultValue.getClusterToolPath(self.context.user))
cmd += " && (chmod %d -R %s)" % \
(DefaultValue.KEY_DIRECTORY_MODE,
DefaultValue.getClusterToolPath())
DefaultValue.getClusterToolPath(self.context.user))
self.context.logger.debug(
"Command for creating directory: %s" % cmd)
DefaultValue.execCommandWithMode(cmd,
@ -4295,8 +4297,8 @@ class UpgradeImpl:
self.context.mpprcFile)
oldPackName = "%s-Package-bak_%s.tar.gz" % \
(VersionInfo.PRODUCT_NAME_PACKAGE, self.oldCommitId)
packFilePath = "%s/%s" % (DefaultValue.getClusterToolPath(),
oldPackName)
packFilePath = "%s/%s" % (DefaultValue.getClusterToolPath(
self.context.user), oldPackName)
copyNode = ""
cmd = "if [ -f '%s' ]; then echo 'GetFile'; " \
"else echo 'NoThisFile'; fi" % packFilePath
@ -4319,7 +4321,8 @@ class UpgradeImpl:
if 'NoThisFile' in outputMap[node]:
cmd = g_Platform.getRemoteCopyCmd(
packFilePath,
DefaultValue.getClusterToolPath(),
DefaultValue.getClusterToolPath(
self.context.user),
str(copyNode), False, 'directory', node)
self.context.logger.debug(
"Command for copying directory: %s" % cmd)

View File

@ -23,6 +23,7 @@ import os
import sys
import platform
import math
import pwd
sys.path.append(sys.path[0] + "/../")
from gspylib.common.GaussLog import GaussLog
@ -576,7 +577,8 @@ class CheckInstall(LocalBaseOM):
raise Exception(
ErrorCode.GAUSS_502["GAUSS_50201"] % userProfile)
else:
userProfile = "/etc/profile"
userpath = pwd.getpwnam(self.user).pw_dir
userProfile = os.path.join(userpath, ".bashrc")
reEnvList = g_file.readFile(userProfile)
checkList = [
"export PATH=$GPHOME/script/gspylib/pssh/bin:$GPHOME/script"

View File

@ -724,8 +724,8 @@ def setLocalReservedPort():
portList.append(etcd.haPort)
if 20050 not in portList:
portList.append(20050)
sorted(portList)
for port in portList:
sortedPortList = sorted(portList)
for port in sortedPortList:
localPortList = []
nport = port
while nport <= port + 7:

View File

@ -65,6 +65,7 @@ ACTION_CHECK_DISK_SPACE = "check_disk_space"
ACTION_SET_WHITELIST = "set_white_list"
ACTION_CHECK_OS_SOFTWARE = "check_os_software"
ACTION_FIX_SERVER_PACKAGE_OWNER = "fix_server_package_owner"
ACTION_CHANGE_TOOL_ENV = "change_tool_env"
g_nodeInfo = None
envConfig = {}
@ -261,7 +262,8 @@ Common options:
ACTION_CHECK_ENVFILE, ACTION_CHECK_OS_SOFTWARE, \
ACTION_SET_ARM_OPTIMIZATION,
ACTION_CHECK_DISK_SPACE, ACTION_SET_WHITELIST,
ACTION_FIX_SERVER_PACKAGE_OWNER]
ACTION_FIX_SERVER_PACKAGE_OWNER,
ACTION_CHANGE_TOOL_ENV]
if self.action == "":
GaussLog.exitWithError(
ErrorCode.GAUSS_500["GAUSS_50001"] % 't' + ".")
@ -2708,7 +2710,7 @@ Common options:
DefaultValue.execCommandLocally(cmd)
root_scripts = ["gs_postuninstall", "gs_preinstall",
"gs_checkos"]
common_scripts = ["gs_sshexkey", "killall"]
common_scripts = ["gs_sshexkey", "killall", "gs_checkperf"]
# the script files are not stored in the env path
not_in_env_scripts = ["gs_expansion"]
root_save_files = root_scripts + common_scripts
@ -2810,6 +2812,67 @@ Common options:
self.fix_owner_and_permission()
self.separate_root_scripts()
def changeToolEnv(self):
"""
function: change software tool env path
:return:
"""
osProfile = "/etc/profile"
self.clean_tool_env(osProfile)
userpath = pwd.getpwnam(self.user).pw_dir
userProfile = os.path.join(userpath, ".bashrc")
if not os.path.exists(userProfile):
self.logger.logExit(ErrorCode.GAUSS_502[
"GAUSS_50201"] % 'user profile'
+ " Please create %s." % userProfile)
self.clean_tool_env(userProfile)
# set GPHOME
g_file.writeFile(userProfile,
["export GPHOME=%s" % self.clusterToolPath])
# set PATH
g_file.writeFile(userProfile, [
"export PATH=$GPHOME/script/gspylib/pssh/bin:"
"$GPHOME/script:$PATH"])
# set LD_LIBRARY_PATH
g_file.writeFile(userProfile, [
"export LD_LIBRARY_PATH="
"$GPHOME/script/gspylib/clib:$LD_LIBRARY_PATH"])
g_file.writeFile(userProfile, [
"export LD_LIBRARY_PATH=$GPHOME/lib:$LD_LIBRARY_PATH"])
# set PYTHONPATH
g_file.writeFile(userProfile, ["export PYTHONPATH=$GPHOME/lib"])
def clean_tool_env(self, userProfile):
# clean GPHOME
g_file.deleteLine(userProfile, "^\\s*export\\s*GPHOME=.*$")
self.logger.debug(
"Deleting crash GPHOME in user environment variables.")
# clean LD_LIBRARY_PATH
g_file.deleteLine(userProfile,
"^\\s*export\\s*LD_LIBRARY_PATH=\\$GPHOME\\/script"
"\\/gspylib\\/clib:\\$LD_LIBRARY_PATH$")
g_file.deleteLine(userProfile,
"^\\s*export\\s*LD_LIBRARY_PATH=\\$GPHOME\\/lib:"
"\\$LD_LIBRARY_PATH$")
self.logger.debug(
"Deleting crash LD_LIBRARY_PATH in user environment variables.")
# clean PATH
g_file.deleteLine(userProfile,
"^\\s*export\\s*PATH=\\$GPHOME\\/pssh-2.3.1\\/bin:"
"\\$GPHOME\\/script:\\$PATH$")
g_file.deleteLine(userProfile,
"^\\s*export\\s*PATH=\\$GPHOME\\/script\\/gspylib\\"
"/pssh\\/bin:\\$GPHOME\\/script:\\$PATH$")
self.logger.debug("Deleting crash PATH in user environment variables.")
# clean PYTHONPATH
g_file.deleteLine(userProfile,
"^\\s*export\\s*PYTHONPATH=\\$GPHOME\\/lib")
self.logger.debug(
"Deleting crash PYTHONPATH in user environment variables.")
def run(self):
"""
function: run method
@ -2896,6 +2959,8 @@ Common options:
self.checkOSSoftware()
elif self.action == ACTION_FIX_SERVER_PACKAGE_OWNER:
self.fix_server_pkg_permission()
elif self.action == ACTION_CHANGE_TOOL_ENV:
self.changeToolEnv()
else:
self.logger.logExit(ErrorCode.GAUSS_500["GAUSS_50000"]
% self.action)

View File

@ -117,7 +117,8 @@ class Postuninstall(LocalBaseOM):
elif self.action != ACTION_CLEAN_DEPENDENCY:
try:
self.clusterToolPath = DefaultValue.getClusterToolPath()
self.clusterToolPath = DefaultValue.getClusterToolPath(
self.user)
except Exception as e:
self.logger.logExit(
ErrorCode.GAUSS_502["GAUSS_50219"] %