Example #1
0
    def __changeuserEnv(self):
        """
        function: Change user GAUSS_ENV
        input : NA
        output: NA
        """
        # clean os user environment variable
        self.logger.log("Modifying user's environmental variable $GAUSS_ENV.")
        userProfile = self.mpprcFile
        DefaultValue.updateUserEnvVariable(userProfile, "GAUSS_ENV", "1")
        if "HOST_IP" in os.environ.keys():
            g_file.deleteLine(userProfile, "^\\s*export\\s*WHITELIST_ENV=.*$")
        self.logger.log("Successfully modified user's environmental"
                        " variable GAUSS_ENV.")

        self.logger.debug("Deleting symbolic link to $GAUSSHOME if exists.")
        gaussHome = DefaultValue.getInstallDir(self.user)
        if gaussHome == "":
            raise Exception(ErrorCode.GAUSS_518["GAUSS_51800"] % "$GAUSSHOME")
        if os.path.islink(gaussHome):
            self.installPath = os.path.realpath(gaussHome)
            os.remove(gaussHome)
        else:
            self.logger.debug("symbolic link does not exists.")
        self.logger.debug("Deleting bin file in installation path.")
        g_file.removeDirectory("%s/bin" % self.installPath)
        self.logger.debug("Successfully deleting bin file in"
                          " installation path.")
Example #2
0
    def __cleanMonitor(self):
        """
        function: clean om_monitor process and delete cron
        input : NA
        output: NA
        """
        self.logger.log("Deleting monitor.")
        try:
            # get all content by crontab command
            (status, output) = g_OSlib.getAllCrontab()
            # overwrit crontabFile, make it empty.
            crontabFile = "%s/gauss_crontab_file_%d" \
                          % (DefaultValue.getTmpDirFromEnv(), os.getpid())
            g_file.createFile(crontabFile, True)
            content_CronTabFile = [output]
            g_file.writeFile(crontabFile, content_CronTabFile)
            g_file.deleteLine(crontabFile, "\/bin\/om_monitor")
            g_OSlib.execCrontab(crontabFile)
            g_file.removeFile(crontabFile)

            # clean om_monitor,cm_agent,cm_server process
            for progname in ["om_monitor", "cm_agent", "cm_server"]:
                g_OSlib.killallProcess(self.user, progname, '9')
        except Exception as e:
            if os.path.exists(crontabFile):
                g_file.removeFile(crontabFile)
            raise Exception(str(e))
        self.logger.log("Successfully deleted OMMonitor.")
Example #3
0
    def cleanGaussEnv(self):
        """
        function: clean $GAUSS_ENV
        input : NA
        output: NA
        """
        self.logger.debug("Cleaning $GAUSS_ENV.")

        # check if user profile exist
        if (self.userProfile is not None and self.userProfile != ""):
            userProfile = self.userProfile
        else:
            userProfile = "/home/%s/.bashrc" % self.user

        if (not os.path.exists(userProfile)):
            self.logger.debug("The %s does not exist." % userProfile +
                              " Please skip to clean $GAUSS_ENV.")
            return
        # clean user's environmental variable
        DefaultValue.cleanUserEnvVariable(userProfile,
                                          cleanGAUSS_WARNING_TYPE=True)

        # clean $GAUSS_ENV
        envContent = "^\\s*export\\s*GAUSS_ENV=.*$"
        g_file.deleteLine(userProfile, envContent)

        self.logger.debug("Cleaned $GAUSS_ENV.")
 def setOrCleanGphomeEnv(self, setGphomeenv=True):
     osProfile = "/etc/profile"
     if setGphomeenv:
         GphomePath = DefaultValue.getPreClusterToolPath(
             self.user, self.xmlFile)
         # set GPHOME
         g_file.writeFile(osProfile, ["export GPHOME=%s" % GphomePath])
     else:
         g_file.deleteLine(osProfile, "^\\s*export\\s*GPHOME=.*$")
         self.logger.debug(
             "Deleting crash GPHOME in user environment variables.")
Example #5
0
    def cleanEnv(self):
        """
        function: clean envriment variable
        """
        self.logger.debug("Begin clean envrionment variable")
        if not self.userProfile:
            self.logger.logExit("Clean Env failed: can not get user profile.")
        for comp in self.clusterComponent:
            comp.cleanEnv(self.userProfile)

        # clean user's environment variable
        self.logger.debug("Clean user environment variable.")
        DefaultValue.cleanUserEnvVariable(self.userProfile,
                                          cleanGAUSS_WARNING_TYPE=True)
        # clean GAUSS_ENV
        self.logger.debug("Clean GAUSS_ENV.")
        g_file.deleteLine(self.userProfile, "^\\s*export\\s*GAUSS_ENV=.*$")
        self.logger.debug("Clean envrionment variable successfully.")
Example #6
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.")