def changeObsLogSetting(self): """ function: change the obs log setting file distribute package input : NA output: NA """ obspathNum = self.clusterInfo.appPath.count("/") """ obs path is the relative path between log path and app path. if app path is /test/app and log path is /test/log then the relative path from app to log is '..'+'/..'*(num-1)+logpath the relative path from obs to log is '../../..'+'/..'*(num-1)+logpath """ username = DefaultValue.getEnv("LOGNAME") DefaultValue.checkPathVaild(username) obspath = "LogPath=../.." + "/.." * obspathNum + "%s/" \ % self.clusterInfo.logPath + "%s" % username + "/bin/gs_obs" cmd = "mkdir -p '%s/%s/bin/gs_obs' -m %s" \ % (self.clusterInfo.logPath, username, DefaultValue.KEY_DIRECTORY_MODE) (status, output) = subprocess.getstatusoutput(cmd) if (status != 0): self.logger.debug("The cmd is %s " % cmd) raise Exception(ErrorCode.GAUSS_502["GAUSS_50208"] % "obs log" + " Error: \n%s " % output) obsLogName = "gs_obs" obsinifile = "%s/lib/OBS.ini" % self.clusterInfo.appPath if not os.path.exists(obsinifile): self.logger.logExit(ErrorCode.GAUSS_502["GAUSS_50201"] % obsinifile) try: with open(obsinifile, 'r') as fp: lines = fp.readlines() flen = len(lines) - 1 for i in range(flen): if "sdkname=eSDK-OBS-API-Linux-C" in lines[i]: lines[i] = lines[i].replace("sdkname=eSDK-OBS-API-Linux-C", "sdkname=gs_obs") if "LogPath=../logs" in lines[i]: lines[i] = lines[i].replace("LogPath=../logs", obspath) with open(obsinifile, 'w') as fpw: fpw.writelines(lines) except Exception as e: self.logger.logExit(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")