适配CM组件

Signed-off-by: coolany <kyosang@163.com>

support cgroup

追加合入
This commit is contained in:
coolany
2022-03-03 20:37:33 +08:00
parent 8874d89c6f
commit eae422baf3
229 changed files with 17230 additions and 13148 deletions

View File

@ -28,15 +28,17 @@ sys.path.append(sys.path[0] + "/../")
from gspylib.common.GaussLog import GaussLog
from gspylib.common.Common import DefaultValue
from gspylib.common.ParameterParsecheck import Parameter
from gspylib.common.VersionInfo import VersionInfo
from gspylib.common.ErrorCode import ErrorCode
from gspylib.os.gsfile import g_file
from gspylib.os.gsOSlib import g_OSlib
from gspylib.os.gsnetwork import g_network
from gspylib.os.gsservice import g_service
from os_platform.gsservice import g_service
from gspylib.common.LocalBaseOM import LocalBaseOM
from gspylib.os.gsfile import g_Platform
import impl.upgrade.UpgradeConst as Const
from domain_utils.cluster_file.cluster_dir import ClusterDir
from domain_utils.cluster_file.cluster_log import ClusterLog
from base_utils.os.env_util import EnvUtil
from base_utils.os.file_util import FileUtil
from domain_utils.cluster_file.version_info import VersionInfo
from base_utils.os.net_util import NetUtil
from domain_utils.domain_common.cluster_constants import ClusterConstants
ACTION_CLEAN_SYSLOG_CONFIG = 'clean_syslog_config'
ACTION_CLEAN_TOOL_ENV = 'clean_tool_env'
@ -59,7 +61,6 @@ SCRIPTPATH = "script"
#####################################################
RSYSLOG = "rsyslog"
RSYSLOG_CONFIG_FILE = "/etc/rsyslog.conf"
RSYSLOG_FACILITY_LEVEL = "local3.*"
AP_RSYSLOG_FACILITY_LEVEL = ":msg,contains,\"MPPDB\""
SYSLOG_NG = "syslog-ng"
SYSLOG_NG_CONFIG_FILE = "/etc/syslog-ng/syslog-ng.conf"
@ -102,12 +103,12 @@ class Postuninstall(LocalBaseOM):
if self.clusterConfig != "":
if os.path.isfile(self.clusterConfig):
self.clusterToolPath = DefaultValue.getPreClusterToolPath(
self.user, self.clusterConfig)
self.clusterToolPath = ClusterDir.getPreClusterToolPath(
self.clusterConfig)
self.readConfigInfoByXML()
hostName = DefaultValue.GetHostIpOrName()
hostName = NetUtil.GetHostIpOrName()
g_nodeInfo = self.clusterInfo.getDbNodeByName(hostName)
if (g_nodeInfo is None):
if g_nodeInfo is None:
self.logger.logExit(
ErrorCode.GAUSS_516["GAUSS_51620"] % "local"
+ " There is no host named %s!" % hostName)
@ -117,7 +118,7 @@ class Postuninstall(LocalBaseOM):
elif self.action != ACTION_CLEAN_DEPENDENCY:
try:
self.clusterToolPath = DefaultValue.getClusterToolPath(
self.clusterToolPath = ClusterDir.getClusterToolPath(
self.user)
except Exception as e:
self.logger.logExit(
@ -131,21 +132,22 @@ class Postuninstall(LocalBaseOM):
# make sure if we are using env seperate version,
# and get the right profile
# we can not check mppenvfile exists here
mppenvFile = DefaultValue.getEnv(DefaultValue.MPPRC_FILE_ENV)
if (mppenvFile != "" and mppenvFile is not None):
mppenvFile = EnvUtil.getEnv(DefaultValue.MPPRC_FILE_ENV)
if mppenvFile != "" and mppenvFile is not None:
self.userProfile = mppenvFile
else:
self.userProfile = "/home/%s/.bashrc" % self.user
self.userProfile = ClusterConstants.HOME_USER_BASHRC % self.user
def usage(self):
"""
Usage:
python3 UnPreInstallUtility.py -t action -u user [-X xmlfile] [-l log]
python3 UnPreInstallUtility.py -t action -u user [-X xmlfile] [-l log] [-f tmpfile]
Common options:
-t the type of action
-u the os user of cluster
-X the xml file path
-l the path of log file
-f The file is a temporary file
--help show this help, then exit
"""
print(self.usage.__doc__)
@ -163,23 +165,23 @@ class Postuninstall(LocalBaseOM):
self.usage()
GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(e))
if (len(args) > 0):
if len(args) > 0:
GaussLog.exitWithError(
ErrorCode.GAUSS_500["GAUSS_50000"] % str(args[0]))
for (key, value) in opts:
if (key == "--help"):
if key == "--help":
self.usage()
sys.exit(0)
elif (key == "-t"):
elif key == "-t":
self.action = value
elif (key == "-u"):
elif key == "-u":
self.user = value
elif (key == "-X"):
elif key == "-X":
self.clusterConfig = value
elif (key == "-l"):
elif key == "-l":
self.logFile = os.path.realpath(value)
elif (key == "-f"):
elif key == "-f":
self.tmpFile = value
elif key == "-Q":
self.clusterToolPath = value
@ -202,8 +204,8 @@ class Postuninstall(LocalBaseOM):
ErrorCode.GAUSS_500["GAUSS_50001"] % "t" + ".")
if self.logFile == "":
self.logFile = DefaultValue.getOMLogPath(
DefaultValue.LOCAL_LOG_FILE, self.user, "")
self.logFile = ClusterLog.getOMLogPath(
ClusterConstants.LOCAL_LOG_FILE, self.user, "")
if self.user == "" and self.action != ACTION_CLEAN_DEPENDENCY:
GaussLog.exitWithError(
@ -216,9 +218,9 @@ class Postuninstall(LocalBaseOM):
output: str
"""
self.logger.debug("Judging the syslog type is rsyslog or syslog-ng.")
if (os.path.isfile(RSYSLOG_CONFIG_FILE)):
if os.path.isfile(RSYSLOG_CONFIG_FILE):
return RSYSLOG
elif (os.path.isfile(SYSLOG_NG_CONFIG_FILE)):
elif os.path.isfile(SYSLOG_NG_CONFIG_FILE):
return SYSLOG_NG
else:
self.logger.logExit(
@ -235,9 +237,9 @@ class Postuninstall(LocalBaseOM):
# judge the installed syslog type on the local host is rsyslog
# or syslog-ng
syslogType = self.getSyslogType()
if (syslogType == SYSLOG_NG):
if syslogType == SYSLOG_NG:
self.cleanWarningConfigForSyslogng()
elif (syslogType == RSYSLOG):
elif syslogType == RSYSLOG:
self.cleanWarningConfigForRsyslog()
self.logger.debug("Successfully cleaned system log.")
@ -257,7 +259,7 @@ class Postuninstall(LocalBaseOM):
"destination(d_gaussdb); };$/d' %s;fi;) " % SYSLOG_NG_CONFIG_FILE
self.logger.debug("Command for cleaning client system log: %s" % cmd)
(status, output) = subprocess.getstatusoutput(cmd)
if (status != 0):
if status != 0:
self.logger.logExit(
ErrorCode.GAUSS_514["GAUSS_51400"] % cmd
+ " Error:\n%s" % output)
@ -282,14 +284,14 @@ class Postuninstall(LocalBaseOM):
cmd += "fi) "
self.logger.debug("Command for cleaning server system log: %s" % cmd)
(status, output) = subprocess.getstatusoutput(cmd)
if (status != 0):
if status != 0:
self.logger.logExit(
ErrorCode.GAUSS_514["GAUSS_51400"] % cmd +
" Error:\n%s" % output)
# restart the syslog service
(status, output) = g_service.manageOSService("syslog", "restart")
if (status != 0):
if status != 0:
self.logger.logExit(
ErrorCode.GAUSS_508["GAUSS_50802"] % "restart syslog"
+ " Error: \n%s" % output)
@ -314,14 +316,14 @@ class Postuninstall(LocalBaseOM):
cmd += "fi) "
self.logger.debug("Command for cleaning crash rsyslog: %s." % cmd)
(status, output) = subprocess.getstatusoutput(cmd)
if (status != 0):
if status != 0:
self.logger.logExit(
ErrorCode.GAUSS_502["GAUSS_50207"] % 'crash rsyslog'
+ " Error: \n%s" % output)
# restart the rsyslog service
(status, output) = g_service.manageOSService("rsyslog", "restart")
if (status != 0):
if status != 0:
self.logger.logExit(
ErrorCode.GAUSS_508["GAUSS_50802"] % "restart rsyslog"
+ " Error: \n%s" % output)
@ -336,37 +338,37 @@ class Postuninstall(LocalBaseOM):
self.logger.debug("Cleaning the environmental software and variable.")
# clean environment software
path = "%s/%s" % (self.clusterToolPath, PSSHDIR)
g_file.removeDirectory(path)
FileUtil.removeDirectory(path)
path = "%s/lib" % self.clusterToolPath
g_file.removeDirectory(path)
FileUtil.removeDirectory(path)
path = "%s/script" % self.clusterToolPath
g_file.removeDirectory(path)
FileUtil.removeDirectory(path)
path = "%s/sudo" % self.clusterToolPath
g_file.removeDirectory(path)
FileUtil.removeDirectory(path)
path = "%s/upgrade.sh" % self.clusterToolPath
g_file.removeFile(path)
FileUtil.removeFile(path)
path = "%s/version.cfg" % self.clusterToolPath
g_file.removeFile(path)
FileUtil.removeFile(path)
path = "%s/GaussDB.py" % self.clusterToolPath
g_file.removeFile(path)
FileUtil.removeFile(path)
path = "%s/libcgroup" % self.clusterToolPath
g_file.removeDirectory(path)
FileUtil.removeDirectory(path)
path = "%s/server.key.cipher" % self.clusterToolPath
g_file.removeFile(path)
FileUtil.removeFile(path)
path = "%s/server.key.rand" % self.clusterToolPath
g_file.removeFile(path)
FileUtil.removeFile(path)
path = "%s/%s*" % (self.clusterToolPath, VersionInfo.PRODUCT_NAME)
g_file.removeDirectory(path)
FileUtil.removeDirectory(path)
path = "%s/Gauss*" % (self.clusterToolPath)
g_file.removeDirectory(path)
FileUtil.removeDirectory(path)
path = "%s/sctp_patch" % (self.clusterToolPath)
g_file.removeDirectory(path)
FileUtil.removeDirectory(path)
path = "%s/unixodbc" % self.clusterToolPath
g_file.removeDirectory(path)
FileUtil.removeDirectory(path)
path = "%s/%s" % (self.clusterToolPath, Const.UPGRADE_SQL_FILE)
g_file.removeFile(path)
FileUtil.removeFile(path)
path = "%s/%s" % (self.clusterToolPath, Const.UPGRADE_SQL_SHA)
g_file.removeFile(path)
FileUtil.removeFile(path)
self.logger.debug(
"Successfully cleaned the environmental software and variable.")
@ -389,7 +391,7 @@ class Postuninstall(LocalBaseOM):
self.logger.debug(
"Command for cleaning environment variable: %s." % cmd)
(status, output) = subprocess.getstatusoutput(cmd)
if (status != 0):
if status != 0:
self.logger.logExit(
ErrorCode.GAUSS_514["GAUSS_51400"] % cmd
+ " Error:\n%s" % output)
@ -411,7 +413,7 @@ class Postuninstall(LocalBaseOM):
self.logger.logExit(str(e))
# check if user profile exist
if (not os.path.exists(self.userProfile)):
if not os.path.exists(self.userProfile):
self.logger.debug(
"The %s does not exist." % self.userProfile
+ " Please skip to check UnPreInstall.")
@ -422,12 +424,12 @@ class Postuninstall(LocalBaseOM):
self.user, self.userProfile)
self.logger.debug("Command for getting $GAUSSHOME: %s" % cmd)
(status, output) = subprocess.getstatusoutput(cmd)
if (status != 0):
if status != 0:
self.logger.logExit(
ErrorCode.GAUSS_514["GAUSS_51400"] % cmd
+ " Error:\n%s" % output)
gaussEnv = output.strip()
if (gaussEnv == "2"):
if gaussEnv == "2":
self.logger.logExit(
ErrorCode.GAUSS_525["GAUSS_52501"] % "gs_uninstall")
@ -436,13 +438,13 @@ class Postuninstall(LocalBaseOM):
self.user, self.userProfile)
self.logger.debug("Command for getting $GAUSS_ENV: %s" % cmd)
(status, output) = subprocess.getstatusoutput(cmd)
if (status != 0):
if status != 0:
self.logger.logExit(
ErrorCode.GAUSS_514["GAUSS_51400"] % cmd
+ " Error:\n%s" % output)
gaussEnv = output.strip()
if (str(gaussEnv) != "1"):
if str(gaussEnv) != "1":
self.logger.logExit(
ErrorCode.GAUSS_525["GAUSS_52501"] % "gs_preinstall")
@ -457,12 +459,12 @@ class Postuninstall(LocalBaseOM):
self.logger.debug("Cleaning $GAUSS_ENV.")
# check if user profile exist
if (self.userProfile is not None and self.userProfile != ""):
if self.userProfile is not None and self.userProfile != "":
userProfile = self.userProfile
else:
userProfile = "/home/%s/.bashrc" % self.user
userProfile = ClusterConstants.HOME_USER_BASHRC % self.user
if (not os.path.exists(userProfile)):
if not os.path.exists(userProfile):
self.logger.debug(
"The %s does not exist." % userProfile
+ " Please skip to clean $GAUSS_ENV.")
@ -473,114 +475,10 @@ class Postuninstall(LocalBaseOM):
# clean $GAUSS_ENV
envContent = "^\\s*export\\s*GAUSS_ENV=.*$"
g_file.deleteLine(userProfile, envContent)
FileUtil.deleteLine(userProfile, envContent)
self.logger.debug("Cleaned $GAUSS_ENV.")
def cleanNetworkfile(self, backIpNIC, virtualIp):
"""
function: clean configured IP in Network file
input : NA
output: NA
"""
self.logger.debug("Cleaning network file.")
try:
# read information from networkfile
networkfile = "/etc/sysconfig/network/ifcfg-" + backIpNIC
networkinfo = []
# check if the file is a link
g_OSlib.checkLink(networkfile)
with open(networkfile, "r") as fp:
networkinfo = fp.readlines()
LABEL = self.getLABEL(virtualIp, networkfile)
if (LABEL is not None):
# init linenum for delete
del_1 = 0
del_2 = 0
linenum = 1
for line in networkinfo:
if (line.split("=")[1].strip() == virtualIp):
# find if the netmask exist, if exist, delete this line
cmd_g = "grep -n 'NETMASK_%s=' %s" % (
LABEL, networkfile)
(status, output) = subprocess.getstatusoutput(cmd_g)
if (status == 0):
linenum_net = int(output.split(":")[0])
if (linenum + 1 == linenum_net):
del_1 = linenum_net
# find if the LABEL number exist,
# if exist, delete this line
cmd_g = "grep -n 'LABEL_%s=' %s " % (
LABEL, networkfile)
(status, output) = subprocess.getstatusoutput(cmd_g)
if (status == 0):
linenum_net = int(output.split(":")[0])
if (linenum + 2 == linenum_net):
del_2 = linenum_net
# delete issues which exist
if (del_1 != 0 and del_2 != 0):
cmd = "sed -i '%dd;%dd;%dd' %s" % (
linenum, del_1, del_2, networkfile)
elif (del_1 != 0 and del_2 == 0):
cmd = "sed -i '%dd;%dd' %s" % (
linenum, del_1, networkfile)
elif (del_1 == 0 and del_2 != 0):
cmd = "sed -i '%dd;%dd' %s" % (
linenum, del_2, networkfile)
else:
cmd = "sed -i '%dd' %s" % (linenum, networkfile)
(status, output) = subprocess.getstatusoutput(cmd)
if (status != 0):
raise Exception(
ErrorCode.GAUSS_514["GAUSS_51400"] % cmd
+ "Error:\n%s" % output)
linenum += 1
self.logger.log(
"Successfully clean virtual Ip from network file")
else:
raise Exception(ErrorCode.GAUSS_502["GAUSS_50204"] % (
"the LABEL number of %s " % virtualIp))
self.logger.debug("Successfully cleaned network file.")
except Exception as e:
self.logger.log("Error: Write networkfile failed." + str(e))
def IsSuSE12SP0(self):
"""
function:Check is OS SuSE12.0
input :NA
output :bool
"""
if (os.path.isfile("/etc/SuSE-release")):
cmd = "grep -i 'PATCHLEVEL' /etc/SuSE-release " \
"| awk -F '=' '{print $2}'"
(status, output) = subprocess.getstatusoutput(cmd)
if (status == 0 and output != ""):
if (output.strip().isdigit() and int(output.strip()) == 0):
return True
else:
raise Exception(
ErrorCode.GAUSS_514["GAUSS_51400"] % cmd
+ " Error: \n%s " % output)
return False
def getLABEL(self, virtualIp, networkfile):
"""
function: get LABEL number of virtual ip from network file
input : fp, virtualIp
output: int
"""
# check if the file is a link
g_OSlib.checkLink(networkfile)
with open(networkfile, "r") as fp:
for line in fp:
if line.split("=")[1].strip() == virtualIp:
if line.split("IPADDR_")[1].split("=%s" % virtualIp)[0]:
return line.split("IPADDR_")[1].split(
"=%s" % virtualIp)[0]
else:
return None
return None
def cleanGroup(self):
"""
function: clean group
@ -588,7 +486,7 @@ class Postuninstall(LocalBaseOM):
output: NA
"""
self.logger.debug("Cleaning user group.")
hostName = DefaultValue.GetHostIpOrName()
hostName = NetUtil.GetHostIpOrName()
groupname = self.user
try:
@ -624,29 +522,29 @@ class Postuninstall(LocalBaseOM):
# clean lib
libPath = os.path.join(self.clusterToolPath, LIBPATH)
if os.path.exists(libPath):
g_file.removeDirectory(libPath)
FileUtil.removeDirectory(libPath)
# clean om script
scriptPath = os.path.join(self.clusterToolPath, SCRIPTPATH)
if os.path.exists(scriptPath):
g_file.removeDirectory(scriptPath)
FileUtil.removeDirectory(scriptPath)
# clean root script path
root_script_path = os.path.join(DefaultValue.ROOT_SCRIPTS_PATH,
self.user)
if os.path.exists(root_script_path):
g_file.removeDirectory(root_script_path)
FileUtil.removeDirectory(root_script_path)
# if /root/gauss_om has no files, delete it.
if not os.listdir(DefaultValue.ROOT_SCRIPTS_PATH):
g_file.removeDirectory(DefaultValue.ROOT_SCRIPTS_PATH)
FileUtil.removeDirectory(DefaultValue.ROOT_SCRIPTS_PATH)
# clean others
if os.path.exists(self.clusterToolPath):
g_file.cleanDirectoryContent(self.clusterToolPath)
FileUtil.cleanDirectoryContent(self.clusterToolPath)
if self.userHome != "":
if os.path.exists(self.userHome):
g_file.removeDirectory(self.userHome)
FileUtil.removeDirectory(self.userHome)
def cleanEnv(self):
"""
@ -664,7 +562,7 @@ class Postuninstall(LocalBaseOM):
cleanGAUSS_WARNING_TYPE=True)
# clean GAUSS_ENV
self.logger.debug("Clean GAUSS_ENV.")
g_file.deleteLine(self.userProfile, "^\\s*export\\s*GAUSS_ENV=.*$")
FileUtil.deleteLine(self.userProfile, "^\\s*export\\s*GAUSS_ENV=.*$")
self.logger.debug("Clean envrionment variable successfully.")
def cleanPath(self):
@ -677,14 +575,14 @@ class Postuninstall(LocalBaseOM):
if os.path.exists(self.clusterInfo.appPath):
self.logger.debug("Deleting the install directory.")
cleanPath = os.path.join(self.clusterInfo.appPath, "./*")
g_file.removeDirectory(cleanPath)
FileUtil.removeDirectory(cleanPath)
self.logger.debug("Successfully deleted the install directory.")
for i in self.component:
i.cleanPath()
gsdbHomePath = "/home/%s/gsdb_home" % self.user
if os.path.exists(gsdbHomePath):
self.logger.debug("Deleting the gsdb home path.")
g_file.removeDirectory(gsdbHomePath)
FileUtil.removeDirectory(gsdbHomePath)
self.logger.debug("Successfully deleted the gsdb home path.")
self.logger.debug("Clean Path successfully.")
@ -697,21 +595,21 @@ class Postuninstall(LocalBaseOM):
GaussLog.exitWithError(str(e))
try:
if (self.action == ACTION_CLEAN_SYSLOG_CONFIG):
if self.action == ACTION_CLEAN_SYSLOG_CONFIG:
self.cleanWarningConfig()
elif (self.action == ACTION_CLEAN_TOOL_ENV):
elif self.action == ACTION_CLEAN_TOOL_ENV:
self.cleanEnvSoftware()
elif (self.action == ACTION_CHECK_UNPREINSTALL):
elif self.action == ACTION_CHECK_UNPREINSTALL:
self.checkUnPreInstall()
elif (self.action == ACTION_CLEAN_GAUSS_ENV):
elif self.action == ACTION_CLEAN_GAUSS_ENV:
self.cleanGaussEnv()
elif (self.action == ACTION_DELETE_GROUP):
elif self.action == ACTION_DELETE_GROUP:
self.cleanGroup()
elif (self.action == ACTION_CLEAN_DEPENDENCY):
elif self.action == ACTION_CLEAN_DEPENDENCY:
self.cleanScript()
elif (self.action == ACTION_CLEAN_ENV):
elif self.action == ACTION_CLEAN_ENV:
self.cleanEnv()
elif (self.action == ACTION_CLEAN_INSTANCE_PATHS):
elif self.action == ACTION_CLEAN_INSTANCE_PATHS:
self.cleanPath()
else:
self.logger.logExit(