示例#1
0
    def __saveUpgradeVerionInfo(self):
        """
        function: save upgrade version info
        input: NA
        output: NA
        """
        if self.dws_mode:
            versionCfgFile = "%s/version.cfg" % DefaultValue.DWS_PACKAGE_PATH
            upgradeVersionFile = "%s/bin/upgrade_version" % self.installPath
        else:
            dirName = os.path.dirname(os.path.realpath(__file__))
            versionCfgFile = "%s/../../version.cfg" % dirName
            upgradeVersionFile = "%s/bin/upgrade_version" % self.installPath

        if not os.path.exists(versionCfgFile):
            self.logger.logExit(ErrorCode.GAUSS_502["GAUSS_50201"]
                                % versionCfgFile)
        if not os.path.isfile(versionCfgFile):
            self.logger.logExit(ErrorCode.GAUSS_502["GAUSS_50210"]
                                % versionCfgFile)

        try:
            # read version info from version.cfg file
            (newClusterVersion, newClusterNumber, commitId) = \
                VersionInfo.get_version_info(versionCfgFile)
            # save version info to upgrade_version file
            if os.path.isfile(upgradeVersionFile):
                os.remove(upgradeVersionFile)

            g_file.createFile(upgradeVersionFile)
            g_file.writeFile(upgradeVersionFile,
                             [newClusterVersion, newClusterNumber, commitId])
            g_file.changeMode(DefaultValue.KEY_FILE_MODE, upgradeVersionFile)
        except Exception as e:
            self.logger.logExit(str(e))
示例#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.")
 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.")
示例#4
0
def writeFile(fileName, content, path, permission=FILE_MODE, user=""):
    """
    function: write file
    input  : NA
    output : NA
    """
    filePath = os.path.join(path, fileName)
    # Create a file
    g_file.createFile(filePath, True, permission)
    # Modify the file permissions
    if (user):
        g_file.changeOwner(user, filePath)
    g_file.writeFile(filePath, [content])
示例#5
0
    def checkSingleSysTable(self, Instance):
        tablelist = [
            "pg_attribute", "pg_class", "pg_constraint", "pg_partition",
            "pgxc_class", "pg_index", "pg_stats"
        ]
        localPath = os.path.dirname(os.path.realpath(__file__))
        resultMap = {}
        try:
            for i in tablelist:
                sqlFile = "%s/sqlFile_%s_%s.sql" % (self.tmpPath, i,
                                                    Instance.instanceId)
                resFile = "%s/resFile_%s_%s.out" % (self.tmpPath, i,
                                                    Instance.instanceId)
                g_file.createFile(sqlFile, True, DefaultValue.SQL_FILE_MODE)
                g_file.createFile(resFile, True, DefaultValue.SQL_FILE_MODE)
                g_file.changeOwner(self.user, sqlFile)
                g_file.changeOwner(self.user, resFile)
                sql = "select * from pg_table_size('%s');" % i
                sql += "select count(*) from %s;" % i
                sql += "select * from pg_column_size('%s');" % i
                g_file.writeFile(sqlFile, [sql])

                cmd = "gsql -d %s -p %s -f %s --output %s -t -A -X" % (
                    self.database, Instance.port, sqlFile, resFile)
                if (self.mpprcFile != "" and self.mpprcFile is not None):
                    cmd = "source '%s' && %s" % (self.mpprcFile, cmd)
                SharedFuncs.runShellCmd(cmd, self.user)

                restule = g_file.readFile(resFile)
                g_file.removeFile(sqlFile)
                g_file.removeFile(resFile)

                size = restule[0].strip()
                line = restule[1].strip()
                width = restule[2].strip()
                Role = ""
                if (Instance.instanceRole == INSTANCE_ROLE_COODINATOR):
                    Role = "CN"
                elif (Instance.instanceRole == INSTANCE_ROLE_DATANODE):
                    Role = "DN"
                instanceName = "%s_%s" % (Role, Instance.instanceId)
                resultMap[i] = [instanceName, size, line, width]
            return resultMap
        except Exception as e:
            if os.path.exists(sqlFile):
                g_file.removeFile(sqlFile)
            if os.path.exists(resFile):
                g_file.removeFile(resFile)
            raise Exception(str(e))
    def genhostfile(self, nodenames):
        """
        Function : generate host file
        """
        iphostInfo = ""
        nodenameFile = "hostfile"
        # the path of script
        recordFile = os.path.join(SHELLPATH, nodenameFile)
        for nodename in nodenames:
            iphostInfo += '%s\n' % nodename

        g_file.createFile(recordFile, True, DefaultValue.KEY_DIRECTORY_MODE)

        # Write IP information to file
        g_file.writeFile(recordFile, [iphostInfo])
示例#7
0
    def __modifyAlarmItemConfFile(self):
        """
        function: modify alarm item conf file
        input: NA
        output: NA
        """
        # modify alarmItem.conf file
        alarmItemConfigFile = "%s/bin/alarmItem.conf" % self.installPath
        if not os.path.exists(alarmItemConfigFile):
            self.logger.log("Alarm's configuration file %s does not exist."
                            % alarmItemConfigFile)
            return

        self.logger.log("Modifying Alarm configuration.")
        g_file.replaceFileLineContent("^.*\(alarm_component.*=.*\)", "#\\1",
                                      alarmItemConfigFile)
        g_file.writeFile(alarmItemConfigFile, ['    '])
        g_file.writeFile(alarmItemConfigFile, ['alarm_component = %s'
                                               % self.alarmComponent])