Ejemplo n.º 1
0
    def modifyStaticConf(self):
        """
        Modify the cluster static conf and save it
        """
        self.logger.log(
            "[gs_dropnode]Start to modify the cluster static conf.")
        staticConfigPath = "%s/bin/cluster_static_config" % self.appPath
        # first backup, only need to be done on primary node
        tmpDir = DefaultValue.getEnvironmentParameterValue(
            "PGHOST", self.user, self.userProfile)
        cmd = "cp %s %s/%s_BACKUP" % (staticConfigPath, tmpDir,
                                      'cluster_static_config')
        (status, output) = subprocess.getstatusoutput(cmd)
        if status:
            self.logger.debug(
                "[gs_dropnode]Backup cluster_static_config failed" + output)
        backIpDict = self.context.backIpNameMap
        backIpDict_values = list(backIpDict.values())
        backIpDict_keys = list(backIpDict.keys())
        for ipLoop in self.context.hostIpListForDel:
            nameLoop = backIpDict_keys[backIpDict_values.index(ipLoop)]
            dnLoop = self.context.clusterInfo.getDbNodeByName(nameLoop)
            self.context.clusterInfo.dbNodes.remove(dnLoop)
        for dbNode in self.context.clusterInfo.dbNodes:
            if dbNode.name == self.localhostname:
                self.context.clusterInfo.saveToStaticConfig(
                    staticConfigPath, dbNode.id)
                continue
            staticConfigPath_dn = "%s/cluster_static_config_%s" % (tmpDir,
                                                                   dbNode.name)
            self.context.clusterInfo.saveToStaticConfig(
                staticConfigPath_dn, dbNode.id)
        self.logger.debug(
            "[gs_dropnode]Start to scp the cluster static conf to any other node."
        )

        if not self.context.flagOnlyPrimary:
            sshtool = SshTool(self.context.clusterInfo.getClusterNodeNames())
            cmd = "%s/script/gs_om -t refreshconf" % self.gphomepath
            (status, output) = subprocess.getstatusoutput(cmd)
            self.logger.debug(
                "[gs_dropnode]Output of refresh dynamic conf :%s." % output)
            for hostName in self.context.hostMapForExist.keys():
                hostSsh = SshTool([hostName])
                if hostName != self.localhostname:
                    staticConfigPath_name = "%s/cluster_static_config_%s" % (
                        tmpDir, hostName)
                    hostSsh.scpFiles(staticConfigPath_name, staticConfigPath,
                                     [hostName], self.envFile)
                    try:
                        os.unlink(staticConfigPath_name)
                    except FileNotFoundError:
                        pass
                self.cleanSshToolFile(hostSsh)

        self.logger.log("[gs_dropnode]End of modify the cluster static conf.")
Ejemplo n.º 2
0
def checkOldInstallStatus():
    """
    function: Check old database install.
              If this user have old install, report error and exit.
    input : NA
    output: NA
    """
    g_opts.logger.log("Checking old installation.")
    # Check $GAUSS_ENV.
    try:
        gauss_ENV = DefaultValue.getEnvironmentParameterValue(
            "GAUSS_ENV", g_opts.user)
        if (str(gauss_ENV) == str(INSTALL_FLAG)):
            g_opts.logger.logExit(ErrorCode.GAUSS_518["GAUSS_51806"])
    except Exception as ex:
        g_opts.logger.logExit(str(ex))
    g_opts.logger.log("Successfully checked old installation.")
Ejemplo n.º 3
0
    def __checkAppVersion(self):
        """
        function: Check version
        input: NA
        output: NA
        """
        # grey upgrade no need do this check
        curVer = DefaultValue.getAppVersion(self.appPath)
        if (curVer == ""):
            g_logger.logExit(ErrorCode.GAUSS_516["GAUSS_51623"])

        gaussHome = DefaultValue.getEnvironmentParameterValue(
            "GAUSSHOME", g_opts.user)
        if not gaussHome:
            g_logger.logExit(ErrorCode.GAUSS_518["GAUSS_51800"] % "$GAUSSHOME")

        gaussdbFile = "%s/bin/gaussdb" % gaussHome
        cmd = "%s --version 2>/dev/null" % (gaussdbFile)
        (status, output) = subprocess.getstatusoutput(cmd)
        if (status != 0):
            g_logger.logExit(ErrorCode.GAUSS_514["GAUSS_51400"] % cmd +
                             "Error:\n %s" % output)