def setOutFile(self): """ function: set out file input : NA output : NA """ # get directory component of a pathname dirName = os.path.dirname(self.opts.outFile) # judge if directory if not os.path.isdir(dirName): g_file.createDirectory(dirName, True, DefaultValue.KEY_DIRECTORY_MODE) # create output file and modify permission g_file.createFile(self.opts.outFile, True, DefaultValue.KEY_FILE_MODE) g_file.changeOwner(self.opts.user, self.opts.outFile) self.logger.log("Performing performance check. " "Output the checking result to the file %s." % self.opts.outFile) # write file self.opts.outFile_tmp = os.path.join( DefaultValue.getTmpDirFromEnv(self.opts.user), (os.path.split(self.opts.outFile)[1] + "_tmp_%s" % os.getpid())) if not os.path.isfile(self.opts.outFile_tmp): g_file.createFile(self.opts.outFile_tmp, True, DefaultValue.KEY_FILE_MODE) g_file.changeOwner(self.opts.user, self.opts.outFile_tmp) fp = open(self.opts.outFile_tmp, "w") outputInfo = fp return outputInfo
def createFolder(folderName, path, permission=DIRECTORY_MODE, user=""): # Folder path folderName = os.path.join(path, folderName) # Create a folder g_file.createDirectory(folderName, True, permission) # change owner if (user): g_file.changeOwner(user, folderName) return folderName
def __makeDirForDBUser(self, path, desc): """ function: Create a dir for DBUser: 1.create a dir for DB user 2.Check if target directory is writeable for user input : path, desc output: NA """ self.logger.debug("Making %s directory[%s] for database node user." % (desc, path)) g_file.createDirectory(path) g_file.changeMode(DefaultValue.KEY_DIRECTORY_MODE, path) if (not g_file.checkDirWriteable(path)): self.logger.logExit(ErrorCode.GAUSS_501["GAUSS_50102"] % (path, self.user))
def doReplaceSSLCert(self): """ function: replace ssl cert files input: NA output: NA """ try: # Initialize the cluster information according to the xml file self.context.clusterInfo = dbClusterInfo() self.context.clusterInfo.initFromStaticConfig( g_OSlib.getPathOwner(self.context.g_opts.certFile)[0]) self.sshTool = SshTool( self.context.clusterInfo.getClusterNodeNames(), self.logger.logFile) except Exception as e: raise Exception(str(e)) try: self.logger.log("Starting ssl cert files replace.", "addStep") tempDir = os.path.join(DefaultValue.getTmpDirFromEnv(), "tempCertDir") # unzip files to temp directory if (os.path.exists(tempDir)): g_file.removeDirectory(tempDir) g_file.createDirectory(tempDir, True, DefaultValue.KEY_DIRECTORY_MODE) g_file.decompressZipFiles(self.context.g_opts.certFile, tempDir) realCertList = DefaultValue.CERT_FILES_LIST clientCertList = DefaultValue.CLIENT_CERT_LIST # check file exists for clientCert in clientCertList: sslFile = os.path.join(tempDir, clientCert) if (not os.path.isfile(sslFile)): raise Exception( (ErrorCode.GAUSS_502["GAUSS_50201"] % sslFile) + \ "Missing SSL client cert file in ZIP file.") certList = [] dnDict = self.getDnNodeDict() for cert in realCertList: sslFile = os.path.join(tempDir, cert) if (not os.path.isfile(sslFile) and cert != DefaultValue.SSL_CRL_FILE): raise Exception( (ErrorCode.GAUSS_502["GAUSS_50201"] % sslFile) + \ "Missing SSL server cert file in ZIP file.") if (os.path.isfile(sslFile)): certList.append(cert) # distribute cert files to datanodes self.doDNBackup() self.distributeDNCert(certList, dnDict) # clear temp directory g_file.removeDirectory(tempDir) if (not self.context.g_opts.localMode): self.logger.log( "Successfully distributed cert files on all nodes.") except Exception as e: g_file.removeDirectory(tempDir) raise Exception(str(e))
def installToolsPhase1(self): """ function: install tools to local machine input: NA output: NA """ self.context.logger.log("Installing the tools on the local node.", "addStep") try: # Determine if the old version of the distribution package # is in the current directory oldPackName = "%s-Package-bak.tar.gz" \ % VersionInfo.PRODUCT_NAME_PACKAGE oldPackPath = os.path.join(self.context.clusterToolPath, oldPackName) if os.path.exists(self.context.clusterToolPath): versionFile = os.path.join(self.context.clusterToolPath, "version.cfg") if os.path.isfile(versionFile): version, number, commitid = VersionInfo.get_version_info( versionFile) newPackName = "%s-Package-bak_%s.tar.gz" % ( VersionInfo.PRODUCT_NAME_PACKAGE, commitid) newPackPath = os.path.join(self.context.clusterToolPath, newPackName) if os.path.isfile(oldPackPath): cmd = "(if [ -f '%s' ];then mv -f '%s' '%s';fi)" % ( oldPackPath, oldPackPath, newPackPath) self.context.logger.debug( "Command for rename bak-package: %s." % cmd) DefaultValue.execCommandWithMode( cmd, "backup bak-package files", self.context.sshTool, self.context.localMode or self.context.isSingle, self.context.mpprcFile) if (self.context.mpprcFile != ""): # check mpprc file self.checkMpprcFile() # check the package is not matches the system DefaultValue.checkPackageOS() # get the package path dirName = os.path.dirname(os.path.realpath(__file__)) packageDir = os.path.join(dirName, "./../../../../") packageDir = os.path.normpath(packageDir) # change logPath owner self.context.logger.debug("Modifying logPath owner") dirName = os.path.dirname(self.context.logFile) topDirFile = "%s/topDirPath.dat" % dirName keylist = [] if (self.context.localMode): if (os.path.exists(topDirFile)): keylist = g_file.readFile(topDirFile) if (keylist != []): for key in keylist: if (os.path.exists(key.strip())): g_file.changeOwner(self.context.user, key.strip(), True, "shell") else: self.context.logger.debug( "Warning: Can not find the " "path in topDirPath.dat.") g_file.removeFile(topDirFile) self.context.logger.debug("Successfully modified logPath owner") # Delete the old bak package in GPHOME before copy the new one. for bakPack in DefaultValue.PACKAGE_BACK_LIST: bakFile = os.path.join(self.context.clusterToolPath, bakPack) if (os.path.isfile(bakFile)): self.context.logger.debug("Remove old bak-package: %s." % bakFile) g_file.removeFile(bakFile) DefaultValue.makeCompressedToolPackage(packageDir) # check and create tool package dir global toolTopPath ownerPath = self.context.clusterToolPath clusterToolPathExistAlready = True # if clusterToolPath exist, # set the clusterToolPathExistAlready False if (not os.path.exists(ownerPath)): clusterToolPathExistAlready = False ownerPath = DefaultValue.getTopPathNotExist(ownerPath) toolTopPath = ownerPath # append clusterToolPath to self.context.needFixOwnerPaths # self.context.needFixOwnerPaths will be checked the ownet self.context.needFixOwnerPaths.append(ownerPath) # if clusterToolPath is not exist, then create it if not os.path.exists(self.context.clusterToolPath): g_file.createDirectory(self.context.clusterToolPath) g_file.changeMode(DefaultValue.MAX_DIRECTORY_MODE, self.context.clusterToolPath, True, "shell") # change the clusterToolPath permission if not clusterToolPathExistAlready: #check the localMode if self.context.localMode: #local mode,change the owner g_file.changeMode(DefaultValue.DIRECTORY_MODE, ownerPath, recursive=True, cmdType="shell") g_file.changeOwner(self.context.user, ownerPath, recursive=True, cmdType="shell") #not localMode, only change the permission else: g_file.changeMode(DefaultValue.MAX_DIRECTORY_MODE, ownerPath, recursive=True, cmdType="shell") else: g_file.changeMode(DefaultValue.DIRECTORY_MODE, ownerPath, recursive=False, cmdType="shell") # Send compressed package to local host if (packageDir != self.context.clusterToolPath): # copy the package to clusterToolPath g_file.cpFile( os.path.join(packageDir, DefaultValue.get_package_back_name()), self.context.clusterToolPath) # Decompress package on local host g_file.decompressFiles( os.path.join(self.context.clusterToolPath, DefaultValue.get_package_back_name()), self.context.clusterToolPath) # change mode of packages g_file.changeMode(DefaultValue.DIRECTORY_MODE, self.context.clusterToolPath, recursive=True, cmdType="shell") # get the top path of mpprc file need to be created on local node # this is used to fix the newly created path owner later if self.context.mpprcFile != "": ownerPath = self.context.mpprcFile if (not os.path.exists(self.context.mpprcFile)): while True: # find the top path to be created (ownerPath, dirName) = os.path.split(ownerPath) if os.path.exists(ownerPath) or dirName == "": ownerPath = os.path.join(ownerPath, dirName) break self.context.needFixOwnerPaths.append(ownerPath) # 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)) self.context.logger.log( "Successfully installed the tools on the local node.", "constant")