Пример #1
0
    def checkLogFilePath(self):
        """
        function: Check log file path
        input : NA
        output: NA
        """
        clusterPath = []
        try:
            # get tool path
            clusterPath.append(DefaultValue.getClusterToolPath(self.user))
            # get tmp path
            tmpDir = DefaultValue.getTmpDirFromEnv()
            clusterPath.append(tmpDir)
            # get cluster path
            hostName = DefaultValue.GetHostIpOrName()
            dirs = self.clusterInfo.getClusterDirectorys(hostName, False)
            # loop all cluster path
            for checkdir in dirs.values():
                clusterPath.extend(checkdir)
            self.logger.debug("Cluster paths %s." % clusterPath)

            # check directory
            g_file.checkIsInDirectory(self.logFile, clusterPath)
        except Exception as e:
            self.logger.logExit(str(e))
Пример #2
0
    def checkLogFilePath(self):
        """
        function: Check log file path
        input : NA
        output: NA
        """
        clusterPath = []

        try:
            self.logger.log("Check log file path.", "addStep")
            # get tool path
            clusterPath.append(DefaultValue.getClusterToolPath())

            # get tmp path
            tmpDir = DefaultValue.getTmpDir(self.user, self.xmlFile)
            clusterPath.append(tmpDir)

            # get cluster  path
            hostName = DefaultValue.GetHostIpOrName()
            dirs = self.clusterInfo.getClusterDirectorys(hostName, False)
            for checkdir in dirs.values():
                clusterPath.extend(checkdir)

            self.logger.debug("Cluster paths %s." % clusterPath)
            # check directory
            g_file.checkIsInDirectory(self.logFile, clusterPath)
            self.logger.log("Successfully checked log file path.", "constant")
        except Exception as e:
            self.logger.logExit(str(e))
Пример #3
0
    def cleanOtherNodesLog(self):
        """
        function: clean other nodes log
        input : NA
        output: NA
        """
        # check if local mode
        if self.localMode:
            return
        self.logger.log("Deleting logs of other nodes.")
        try:
            # get other nodes
            hostName = DefaultValue.GetHostIpOrName()
            otherNodes = self.clusterInfo.getClusterNodeNames()
            for otherNode in otherNodes:
                if (otherNode == hostName):
                    otherNodes.remove(otherNode)

            # clean log
            cmd = "rm -rf '%s/%s'; rm -rf /tmp/gauss_*;" % (
                self.clusterInfo.logPath, self.user)
            cmd += "rm -rf '%s/Python-2.7.9'" \
                   % DefaultValue.getClusterToolPath()
            self.logger.debug("Command for deleting logs of other nodes: %s" %
                              cmd)
            DefaultValue.execCommandWithMode(cmd, "delete user log directory",
                                             self.sshTool, self.localMode,
                                             self.mpprcFile, otherNodes)
            self.logger.debug("Successfully deleted logs of the nodes: %s." %
                              otherNodes)
        except Exception as e:
            self.logger.logExit(ErrorCode.GAUSS_502["GAUSS_50207"] %
                                "other nodes log" + " Error: \n%s." % str(e))
        self.logger.log("Successfully deleted logs of other nodes.")
Пример #4
0
    def initGlobals(self):
        """
        init global variables
        input : NA
        output: NA
        """
        global g_nodeInfo
        self.logger = GaussLog(self.logFile, self.action)

        if self.clusterConfig != "":
            if os.path.isfile(self.clusterConfig):
                self.clusterToolPath = DefaultValue.getPreClusterToolPath(
                    self.user, self.clusterConfig)
                self.readConfigInfoByXML()
                hostName = DefaultValue.GetHostIpOrName()
                g_nodeInfo = self.clusterInfo.getDbNodeByName(hostName)
                if (g_nodeInfo is None):
                    self.logger.logExit(
                        ErrorCode.GAUSS_516["GAUSS_51620"] % "local" +
                        " There is no host named %s!" % hostName)
            else:
                self.logger.logExit(ErrorCode.GAUSS_502["GAUSS_50210"] %
                                    ("config file [%s]" % self.clusterConfig))

        elif self.action != ACTION_CLEAN_DEPENDENCY:
            try:
                self.clusterToolPath = DefaultValue.getClusterToolPath(
                    self.user)
            except Exception as e:
                self.logger.logExit(ErrorCode.GAUSS_502["GAUSS_50219"] %
                                    "the cluster tool path" +
                                    " Error: \n%s" % str(e))

        if not self.clusterToolPath:
            self.logger.logExit(ErrorCode.GAUSS_502["GAUSS_50219"] %
                                "cluster tool path")

        # 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):
            self.userProfile = mppenvFile
        else:
            self.userProfile = "/home/%s/.bashrc" % self.user
Пример #5
0
    def cleanLocalNodeEnvSoftware(self):
        """
        function: clean local node environment software and variable
        input : NA
        output: NA
        in this function, Gauss-MPPDB* & sctp_patch is came from R5 upgrade R7
        """
        self.logger.log("Deleting software packages "
                        "and environmental variables of the local node.")
        try:
            self.clusterToolPath = DefaultValue.getClusterToolPath()

            # clean local node environment software
            path = "%s/%s" % (self.clusterToolPath, PSSHDIR)
            g_file.removeDirectory(path)
            path = "%s/upgrade.sh" % self.clusterToolPath
            g_file.removeFile(path)
            path = "%s/version.cfg" % self.clusterToolPath
            g_file.removeFile(path)
            path = "%s/GaussDB.py" % self.clusterToolPath
            g_file.removeFile(path)
            path = "%s/libcgroup" % self.clusterToolPath
            g_file.removeDirectory(path)
            path = "%s/unixodbc" % self.clusterToolPath
            g_file.removeDirectory(path)
            path = "%s/server.key.cipher" % self.clusterToolPath
            g_file.removeFile(path)
            path = "%s/server.key.rand" % self.clusterToolPath
            g_file.removeFile(path)
            path = "%s/%s*" % (self.clusterToolPath, VersionInfo.PRODUCT_NAME)
            g_file.removeDirectory(path)
            path = "%s/server.key.rand" % self.clusterToolPath
            g_file.removeFile(path)
            path = "%s/Gauss*" % (self.clusterToolPath)
            g_file.removeDirectory(path)
            path = "%s/sctp_patch" % (self.clusterToolPath)
            g_file.removeDirectory(path)
            self.logger.debug(
                "Deleting environmental software of local nodes.")

            # clean local node environment variable
            cmd = "(if [ -s '%s' ]; then " % PROFILE_FILE
            cmd += "sed -i -e '/^export GPHOME=%s$/d' %s " % (
                self.clusterToolPath.replace('/', '\/'), PROFILE_FILE)
            cmd += \
                "-e '/^export PATH=\$GPHOME\/pssh-2.3.1\/bin:" \
                "\$GPHOME\/script:\$PATH$/d' %s " % PROFILE_FILE
            cmd += \
                "-e '/^export PATH=\$GPHOME\/script\/gspylib\/pssh\/bin:" \
                "\$GPHOME\/script:\$PATH$/d' %s " % PROFILE_FILE
            cmd += \
                "-e '/^export LD_LIBRARY_PATH=\$GPHOME\/script" \
                "\/gspylib\/clib:\$LD_LIBRARY_PATH$/d' %s " % PROFILE_FILE
            cmd += \
                "-e '/^export LD_LIBRARY_PATH=\$GPHOME\/lib:" \
                "\$LD_LIBRARY_PATH$/d' %s " % PROFILE_FILE
            cmd += \
                "-e '/^export PATH=\/root\/gauss_om\/%s\/script:" \
                "\$PATH$/d' %s " % (self.user, PROFILE_FILE)
            cmd += \
                "-e '/^export PYTHONPATH=\$GPHOME\/lib$/d' %s; fi) " \
                % PROFILE_FILE
            self.logger.debug("Command for deleting environment variable: %s" %
                              cmd)
            (status, output) = subprocess.getstatusoutput(cmd)
            if (status != 0):
                self.logger.logExit(ErrorCode.GAUSS_502["GAUSS_50207"] %
                                    "environment variables of the local node" +
                                    " Error: \n%s" % output)

            # check if user profile exist
            userProfile = ""
            if (self.mpprcFile is not None and self.mpprcFile != ""):
                userProfile = self.mpprcFile
            else:
                userProfile = "/home/%s/.bashrc" % self.user
            if (not os.path.exists(userProfile)):
                self.logger.debug("The %s does not exist. "
                                  "Please skip to clean $GAUSS_ENV." %
                                  userProfile)
                return
            # clean user's environmental variable
            DefaultValue.cleanUserEnvVariable(userProfile,
                                              cleanGAUSS_WARNING_TYPE=True)

            # clean $GAUSS_ENV
            if (not self.deleteUser):
                envContent = "^\\s*export\\s*GAUSS_ENV=.*$"
                g_file.deleteLine(userProfile, envContent)
                self.logger.debug("Command for deleting $GAUSS_ENV: %s" % cmd,
                                  "constant")

        except Exception as e:
            self.logger.logExit(str(e))
        self.logger.log("Successfully deleted software packages "
                        "and environmental variables of the local nodes.")