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))
Exemple #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.")
Exemple #3
0
 def setOutFile(self):
     """
     function: set out file
     input  : NA
     output : NA
     """
     # get directory component of a pathname
     dirName = os.path.dirname(self.opts.outFile)
     # judge if directory
     if not os.path.isdir(dirName):
         g_file.createDirectory(dirName, True,
                                DefaultValue.KEY_DIRECTORY_MODE)
     # create output file and modify permission
     g_file.createFile(self.opts.outFile, True, DefaultValue.KEY_FILE_MODE)
     g_file.changeOwner(self.opts.user, self.opts.outFile)
     self.logger.log("Performing performance check. "
                     "Output the checking result to the file %s." %
                     self.opts.outFile)
     # write file
     self.opts.outFile_tmp = os.path.join(
         DefaultValue.getTmpDirFromEnv(self.opts.user),
         (os.path.split(self.opts.outFile)[1] + "_tmp_%s" % os.getpid()))
     if not os.path.isfile(self.opts.outFile_tmp):
         g_file.createFile(self.opts.outFile_tmp, True,
                           DefaultValue.KEY_FILE_MODE)
     g_file.changeOwner(self.opts.user, self.opts.outFile_tmp)
     fp = open(self.opts.outFile_tmp, "w")
     outputInfo = fp
     return outputInfo
Exemple #4
0
def createFile(fileName, path, permission=FILE_MODE, user=""):
    # file path
    fileName = os.path.join(path, fileName)
    # Create a file
    g_file.createFile(fileName, True, permission)
    # change owner
    if (user):
        g_file.changeOwner(user, fileName)
    return fileName
Exemple #5
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])
Exemple #6
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])
Exemple #8
0
 def doCheck(self):
     tmpFile = os.path.join(self.tmpPath, "gauss_cluster_status.dat")
     tmpFileName = os.path.join(self.tmpPath, "abnormal_node_status.dat")
     try:
         self.result.val = ""
         self.result.raw = ""
         # Check the cluster status with cm_ctl
         cmd = ClusterCommand.getQueryStatusCmd(self.user, "", tmpFile)
         output = SharedFuncs.runShellCmd(cmd, self.user, self.mpprcFile)
         self.result.raw += output
         # Check whether the cluster needs to be balanced
         # Check whether redistribution is required
         # Initialize cluster status information for temporary file
         clusterStatus = DbClusterStatus()
         clusterStatus.initFromFile(tmpFile)
         # Get the status of cluster
         statusInfo = clusterStatus.getClusterStauts(self.user)
         self.result.val = statusInfo
         if clusterStatus.isAllHealthy():
             self.result.rst = ResultStatus.OK
             if os.path.exists(tmpFile):
                 os.remove(tmpFile)
             return
         # If the abnormal node is present, create a temporary file
         # and print out the details
         g_file.createFile(tmpFileName, True, KEY_FILE_MODE)
         with open(tmpFileName, "w+") as tmpFileFp:
             for dbNode in clusterStatus.dbNodes:
                 if not dbNode.isNodeHealthy():
                     dbNode.outputNodeStatus(tmpFileFp, self.user, True)
             tmpFileFp.flush()
             tmpFileFp.seek(0)
             self.result.raw = tmpFileFp.read()
         if self.result.raw == "":
             self.result.raw = "Failed to obtain the cluster status."
         self.result.rst = ResultStatus.NG
         # Delete the temporary file
         if os.path.exists(tmpFileName):
             os.remove(tmpFileName)
         if os.path.exists(tmpFile):
             os.remove(tmpFile)
     except Exception as e:
         if os.path.exists(tmpFile):
             os.remove(tmpFile)
         if os.path.exists(tmpFileName):
             os.remove(tmpFileName)
         raise Exception(str(e))