def getClusterUser():
    """
    function: Check user information
    input : NA
    output: str
    """
    # get user and group
    gphome = getGphome(g_opts.confFile)
    if not gphome or not os.path.exists(gphome):
        user = "******"
        return user
    user = g_OSlib.getPathOwner(gphome)[0]
    return user
Example #2
0
 def getUserInfo(self):
     """
     Get user and group
     """
     if os.path.islink(self.clusterInfo.appPath):
         appPath = os.path.realpath(self.clusterInfo.appPath)
     elif os.path.exists(self.clusterInfo.appPath):
         appPath = self.clusterInfo.appPath
     else:
         commitid = VersionInfo.getCommitid()
         appPath = self.clusterInfo.appPath + "_" + commitid
     self.logger.debug("Get the install path %s user info." % appPath)
     (self.user, self.group) = g_OSlib.getPathOwner(appPath)
     if (self.user == "" or self.group == ""):
         self.logger.logExit(ErrorCode.GAUSS_503["GAUSS_50308"])
    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))