gs_install support non-interactive whit init-passwd

This commit is contained in:
zhang_xubo
2020-12-25 11:33:50 +08:00
parent 2da909eb3f
commit 081713c378
2 changed files with 35 additions and 4 deletions

View File

@ -886,7 +886,7 @@ class ParallelBaseOM(object):
self.sshTool.scpFiles(scpFile, caPath, hostList) self.sshTool.scpFiles(scpFile, caPath, hostList)
self.logger.debug("Successfully generated grpc CA files.") self.logger.debug("Successfully generated grpc CA files.")
def genCipherAndRandFile(self, hostList=None): def genCipherAndRandFile(self, hostList=None, initPwd=None):
self.logger.debug("Encrypting cipher and rand files.") self.logger.debug("Encrypting cipher and rand files.")
if hostList is None: if hostList is None:
hostList = [] hostList = []
@ -894,8 +894,11 @@ class ParallelBaseOM(object):
binPath = os.path.join(appPath, "bin") binPath = os.path.join(appPath, "bin")
retry = 0 retry = 0
while True: while True:
sshpwd = getpass.getpass("Please enter password for database:") if not initPwd:
sshpwd_check = getpass.getpass("Please repeat for database:") sshpwd = getpass.getpass("Please enter password for database:")
sshpwd_check = getpass.getpass("Please repeat for database:")
else:
sshpwd = sshpwd_check = initPwd
if sshpwd_check != sshpwd: if sshpwd_check != sshpwd:
sshpwd = "" sshpwd = ""
sshpwd_check = "" sshpwd_check = ""
@ -910,6 +913,7 @@ class ParallelBaseOM(object):
(status, output) = subprocess.getstatusoutput(cmd) (status, output) = subprocess.getstatusoutput(cmd)
sshpwd = "" sshpwd = ""
sshpwd_check = "" sshpwd_check = ""
initPwd = ""
if status != 0: if status != 0:
self.logger.error( self.logger.error(
ErrorCode.GAUSS_503["GAUSS_50322"] % "database" ErrorCode.GAUSS_503["GAUSS_50322"] % "database"

View File

@ -347,7 +347,8 @@ class InstallImpl:
self.configZenithInst() self.configZenithInst()
self.context.logger.log("encrypt cipher and rand files " self.context.logger.log("encrypt cipher and rand files "
"for database.") "for database.")
self.context.genCipherAndRandFile() initPasswd = self.getPasswdFromInitParam()
self.context.genCipherAndRandFile(None, initPasswd)
self.context.logger.log("begin to create CA cert files") self.context.logger.log("begin to create CA cert files")
self.context.createServerCa() self.context.createServerCa()
if not self.context.localMode: if not self.context.localMode:
@ -360,6 +361,32 @@ class InstallImpl:
self.context.logger.log("Cluster installation is completed.", self.context.logger.log("Cluster installation is completed.",
"constant") "constant")
def getPasswdFromInitParam(self):
"""
function: get passwd from init-parameter
return: passwd
get passwd from --gsinit-parameter. if the passwd has been assigned,
the database will install with non-interactive.
"""
if len(self.context.dbInitParam) == 0:
return None
passwd = None
pwdIndex = -1
for idx,param in enumerate(self.context.dbInitParam):
if param.startswith("--pwpasswd="):
passwd = param[11:]
pwdIndex = idx
break
elif param.startswith("-w="):
passwd = param[3:]
pwdIndex = idx
break
#remove initpasswd from dbInitParam. otherwise it will be printed in log.
if pwdIndex > -1:
self.context.dbInitParam.pop(pwdIndex)
return passwd
def configZenithInst(self): def configZenithInst(self):
""" """
function: config zenith inst function: config zenith inst