Ejemplo n.º 1
0
    def __writeHostFiles(self):
        """
        function: Write all hostname to a file
        input : NA
        output: NA
        """
        try:
            g_file.createFileInSafeMode(self.__hostsFile)
            with open(self.__hostsFile, "w") as fp:
                for host in self.hostNames:
                    fp.write("%s\n" % host)
                fp.flush()
            subprocess.getstatusoutput(
                "chmod %s '%s'" % (DefaultValue.FILE_MODE, self.__hostsFile))
        except Exception as e:
            g_file.removeFile(self.__hostsFile)
            raise Exception(ErrorCode.GAUSS_502["GAUSS_50205"] % "host file" +
                            " Error: \n%s" % str(e))

        # change the mode
        # if it created by root user,and permission is 640, then
        # install user will have no permission to read it, so we should set
        # its permission 644.
        g_file.changeMode(DefaultValue.KEY_HOSTS_FILE, self.__hostsFile, False,
                          "python")
Ejemplo n.º 2
0
 def createServerCa(self, hostList=None):
     """
     function: create grpc ca file
     input : NA
     output: NA
     """
     self.logger.debug("Generating CA files.")
     if hostList is None:
         hostList = []
     appPath = DefaultValue.getInstallDir(self.user)
     caPath = os.path.join(appPath, "share/sslcert/om")
     self.logger.debug("The ca file dir is: %s." % caPath)
     if (len(hostList) == 0):
         for dbNode in self.clusterInfo.dbNodes:
             hostList.append(dbNode.name)
     # Create CA dir and prepare files for using.
     self.logger.debug("Create CA file directory.")
     try:
         DefaultValue.createCADir(self.sshTool, caPath, hostList)
         self.logger.debug("Add hostname to config file.")
         DefaultValue.createServerCA(DefaultValue.SERVER_CA, caPath,
                                     self.logger)
         # Clean useless files, and change permission of ca file to 600.
         DefaultValue.cleanServerCaDir(caPath)
         self.logger.debug("Scp CA files to all nodes.")
     except Exception as e:
         certFile = caPath + "/demoCA/cacert.pem"
         if os.path.exists(certFile):
             g_file.removeFile(certFile)
         DefaultValue.cleanServerCaDir(caPath)
         raise Exception(str(e))
     for certFile in DefaultValue.SERVER_CERT_LIST:
         scpFile = os.path.join(caPath, "%s" % certFile)
         self.sshTool.scpFiles(scpFile, caPath, hostList)
     self.logger.debug("Successfully generated server CA files.")
Ejemplo n.º 3
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.")
Ejemplo n.º 4
0
    def __decompressBinPackage(self):
        """
        function: Install database binary file.
        input : NA
        output: NA
        """
        if self.dws_mode:
            self.logger.log("Copying bin file.")
            bin_image_path = DefaultValue.DWS_APP_PAHT
            srcPath = "'%s'/*" % bin_image_path
            destPath = "'%s'/" % self.installPath
            cmd = g_file.SHELL_CMD_DICT["copyFile"] % (srcPath, destPath)
            self.logger.debug("Copy command: " + cmd)
            status, output = subprocess.getstatusoutput(cmd)
            if status != 0:
                self.logger.logExit(ErrorCode.GAUSS_502["GAUSS_50214"] %
                                    srcPath + " Error: " + output)
        else:
            self.logger.log("Decompressing bin file.")
            tarFile = g_OSlib.getBz2FilePath()
            # let bin executable
            g_file.changeMode(DefaultValue.KEY_DIRECTORY_MODE, tarFile)

            cmd = "export LD_LIBRARY_PATH=$GPHOME/script/gspylib/clib:" \
                  "$LD_LIBRARY_PATH && "
            # decompress tar file.
            strCmd = cmd + "tar -xpf \"" + tarFile + "\" -C \"" + \
                     self.installPath + "\""
            self.logger.log("Decompress command: " + strCmd)
            status, output = subprocess.getstatusoutput(strCmd)
            if status != 0:
                self.logger.logExit(ErrorCode.GAUSS_502["GAUSS_50217"] %
                                    tarFile + " Error: \n%s" % str(output))

            # mv $GPHOME/script/transfer.py to $GAUSSHOME/bin/
            dirName = os.path.dirname(os.path.realpath(__file__))
            transferFile = dirName + "/../../script/transfer.py"
            if os.path.exists(transferFile):
                g_file.cpFile(transferFile, self.installPath + "/bin/")
                g_file.removeFile(transferFile)
            # cp $GPHOME/script to $GAUSSHOME/bin/
            g_file.cpFile(dirName + "/../../script",
                          self.installPath + "/bin/")

            # cp $GAUSSHOME/bin/script/gspylib/etc/sql/pmk to /share/postgresql
            destPath = self.installPath + "/share/postgresql/"
            pmkPath = self.installPath + "/bin/script/gspylib/etc/sql/"
            pmkFile = pmkPath + "pmk_schema.sql"
            if os.path.exists(pmkFile):
                g_file.cpFile(pmkFile, destPath)

            pmkSingeInstFile = pmkPath + "pmk_schema_single_inst.sql"
            if os.path.exists(pmkSingeInstFile):
                g_file.cpFile(pmkSingeInstFile, destPath)

            # change owner for tar file.
            g_file.changeOwner(self.user, self.installPath, True)
        self.logger.log("Successfully decompressed bin file.")
Ejemplo n.º 5
0
    def __init__(self,
                 hostNames,
                 logFile=None,
                 timeout=DefaultValue.TIMEOUT_PSSH_COMMON,
                 key=""):
        '''
        Constructor
        '''
        self.hostNames = hostNames
        self.__logFile = logFile
        self.__pid = os.getpid()
        self.__timeout = timeout + 10
        self._finalizer = weakref.finalize(self, self.clenSshResultFiles)

        currentTime = str(datetime.datetime.now()).replace(" ", "_").replace(
            ".", "_")
        randomnum = ''.join(sample('0123456789', 3))
        # can tmp path always access?
        if key == "":
            self.__hostsFile = "/tmp/gauss_hosts_file_%d_%s_%s" % (
                self.__pid, currentTime, randomnum)
            self.__resultFile = "/tmp/gauss_result_%d_%s_%s.log" % (
                self.__pid, currentTime, randomnum)
            self.__outputPath = "/tmp/gauss_output_files_%d_%s_%s" % (
                self.__pid, currentTime, randomnum)
            self.__errorPath = "/tmp/gauss_error_files_%d_%s_%s" % (
                self.__pid, currentTime, randomnum)
        else:
            self.__hostsFile = "/tmp/gauss_hosts_file_%d_%s_%s_%s" % (
                self.__pid, key, currentTime, randomnum)
            self.__resultFile = "/tmp/gauss_result_%d_%s_%s_%s.log" % (
                self.__pid, key, currentTime, randomnum)
            self.__outputPath = "/tmp/gauss_output_files_%d_%s_%s_%s" % (
                self.__pid, key, currentTime, randomnum)
            self.__errorPath = "/tmp/gauss_error_files_%d_%s_%s_%s" % (
                self.__pid, key, currentTime, randomnum)

        self.__resultStatus = {}
        if logFile is None:
            self.__logFile = "/dev/null"

        # before using, clean the old ones
        g_file.removeFile(self.__hostsFile)
        g_file.removeFile(self.__resultFile)

        if os.path.exists(self.__outputPath):
            g_file.removeDirectory(self.__outputPath)

        if os.path.exists(self.__errorPath):
            g_file.removeDirectory(self.__errorPath)

        self.__writeHostFiles()
Ejemplo n.º 6
0
 def cleanTempFile(self):
     """
     function: clean temp file
     input: NA
     output: NA
     """
     filename = "/tmp/temp.%s" % self.user
     try:
         if os.path.isfile(filename):
             g_file.removeFile(filename)
     except Exception as e:
         raise Exception(ErrorCode.GAUSS_502["GAUSS_50207"]
                         % ("file [%s]" % filename))
Ejemplo n.º 7
0
    def clenSshResultFiles(self):
        """
        function: Delete file
        input : NA
        output: NA
        """
        if os.path.exists(self.__hostsFile):
            g_file.removeFile(self.__hostsFile)

        if os.path.exists(self.__resultFile):
            g_file.removeFile(self.__resultFile)

        if os.path.exists(self.__outputPath):
            g_file.removeDirectory(self.__outputPath)

        if os.path.exists(self.__errorPath):
            g_file.removeDirectory(self.__errorPath)
Ejemplo n.º 8
0
    def run(self):
        """
        function: the real interface that execute the check method
        input : NA
        output: NA
        """
        try:
            outputInfo = None
            # check output file
            if self.opts.outFile != "":
                self.opts.outFile_tmp = os.path.join(
                    DefaultValue.getTmpDirFromEnv(self.opts.user),
                    (os.path.split(self.opts.outFile)[1] +
                     "_tmp_%s" % os.getpid()))
                outputInfo = self.setOutFile()
            else:
                outputInfo = sys.stdout
            # check check item
            for key in self.opts.checkItem:
                if key == "PMK":
                    # check PMK
                    self.CheckPMKPerf(outputInfo)
                elif key == "SSD":
                    # check SSD
                    self.CheckSSDPerf(outputInfo)

            # Follow-up
            self.closeFile(outputInfo)
        except Exception as e:
            # close file handle if outputInfo is out file
            if self.opts.outFile and outputInfo:
                outputInfo.flush()
                outputInfo.close()
            if os.path.isfile(self.opts.outFile_tmp):
                g_file.removeFile(self.opts.outFile_tmp)
            # modify the log file's owner
            g_file.changeOwner(self.opts.user, self.logger.logFile)
            self.logger.error(str(e))
            sys.exit(1)
Ejemplo n.º 9
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))
Ejemplo n.º 10
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.")
Ejemplo n.º 11
0
    def createTrust(self,
                    user,
                    pwd,
                    ips=None,
                    mpprcFile="",
                    skipHostnameSet=False,
                    preMode=False):
        """
        function: create trust for specified user with both ip and hostname,
                  when using N9000 tool create trust failed
                  do not support using a normal user to create trust for
                  another user.
        input : user, pwd, ips, mpprcFile, skipHostnameSet
        output: NA
        """
        tmp_hosts = "/tmp/tmp_hosts_%d" % self.__pid
        cnt = 0
        status = 0
        output = ""
        if ips is None:
            ips = []
        try:
            g_file.removeFile(tmp_hosts)
            # 1.prepare hosts file
            for ip in ips:
                cmd = "echo %s >> %s 2>/dev/null" % (ip, tmp_hosts)
                (status, output) = subprocess.getstatusoutput(cmd)
                if status != 0:
                    raise Exception(ErrorCode.GAUSS_502["GAUSS_50201"] %
                                    tmp_hosts + " Error:\n%s." % output +
                                    "The cmd is %s" % cmd)
            g_file.changeMode(DefaultValue.KEY_HOSTS_FILE, tmp_hosts, False,
                              "python")

            # 2.call createtrust script
            create_trust_file = "gs_sshexkey"
            if pwd is None or len(str(pwd)) == 0:
                GaussLog.printMessage("Please enter password for current"
                                      " user[%s]." % user)
                pwd = getpass.getpass()

            if (mpprcFile != ""
                    and g_file.checkFilePermission(mpprcFile, True)
                    and self.checkMpprcfile(user, mpprcFile)):
                cmd = "source %s; %s -f %s -l '%s'" % (
                    mpprcFile, create_trust_file, tmp_hosts, self.__logFile)
            elif (mpprcFile == ""
                  and g_file.checkFilePermission('/etc/profile', True)):
                cmd = "source /etc/profile;" \
                      " %s -f %s -l '%s'" % (create_trust_file,
                                             tmp_hosts, self.__logFile)

            if skipHostnameSet:
                cmd += " --skip-hostname-set"
            cmd += " 2>&1"

            tempcmd = ["su", "-", user, "-c"]
            tempcmd.append(cmd)
            cmd = tempcmd

            p = subprocess.Popen(cmd,
                                 stdin=subprocess.PIPE,
                                 stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
            if os.getuid() != 0:
                time.sleep(5)
                p.stdin.write((pwd + "\n").encode(encoding="utf-8"))
            time.sleep(10)
            p.stdin.write((pwd + "\n").encode(encoding="utf-8"))
            (output, err) = p.communicate()
            # 3.delete hosts file
            g_file.removeFile(tmp_hosts)
            if output is not None:
                output = str(output, encoding='utf-8')
                if re.search("\[GAUSS\-", output):
                    if re.search("Please enter password", output):
                        GaussLog.printMessage(
                            ErrorCode.GAUSS_503["GAUSS_50306"] % user)
                    else:
                        GaussLog.printMessage(output.strip())
                    sys.exit(1)
                else:
                    GaussLog.printMessage(output.strip())
            else:
                sys.exit(1)
        except Exception as e:
            g_file.removeFile(tmp_hosts)
            raise Exception(str(e))
    def installToolsPhase1(self):
        """
        function: install tools to local machine
        input: NA
        output: NA
        """
        self.context.logger.log("Installing the tools on the local node.",
                                "addStep")
        try:
            # Determine if the old version of the distribution package
            # is in the current directory
            oldPackName = "%s-Package-bak.tar.gz" \
                          % VersionInfo.PRODUCT_NAME_PACKAGE
            oldPackPath = os.path.join(self.context.clusterToolPath,
                                       oldPackName)
            if os.path.exists(self.context.clusterToolPath):
                versionFile = os.path.join(self.context.clusterToolPath,
                                           "version.cfg")
                if os.path.isfile(versionFile):
                    version, number, commitid = VersionInfo.get_version_info(
                        versionFile)
                    newPackName = "%s-Package-bak_%s.tar.gz" % (
                        VersionInfo.PRODUCT_NAME_PACKAGE, commitid)
                    newPackPath = os.path.join(self.context.clusterToolPath,
                                               newPackName)
                    if os.path.isfile(oldPackPath):
                        cmd = "(if [ -f '%s' ];then mv -f '%s' '%s';fi)" % (
                            oldPackPath, oldPackPath, newPackPath)
                        self.context.logger.debug(
                            "Command for rename bak-package: %s." % cmd)
                        DefaultValue.execCommandWithMode(
                            cmd, "backup bak-package files",
                            self.context.sshTool, self.context.localMode
                            or self.context.isSingle, self.context.mpprcFile)

            if (self.context.mpprcFile != ""):
                # check mpprc file
                self.checkMpprcFile()
            # check the package is not matches the system
            DefaultValue.checkPackageOS()
            # get the package path
            dirName = os.path.dirname(os.path.realpath(__file__))
            packageDir = os.path.join(dirName, "./../../../../")
            packageDir = os.path.normpath(packageDir)

            # change logPath owner
            self.context.logger.debug("Modifying logPath owner")
            dirName = os.path.dirname(self.context.logFile)
            topDirFile = "%s/topDirPath.dat" % dirName
            keylist = []
            if (self.context.localMode):
                if (os.path.exists(topDirFile)):
                    keylist = g_file.readFile(topDirFile)
                    if (keylist != []):
                        for key in keylist:
                            if (os.path.exists(key.strip())):
                                g_file.changeOwner(self.context.user,
                                                   key.strip(), True, "shell")
                            else:
                                self.context.logger.debug(
                                    "Warning: Can not find the "
                                    "path in topDirPath.dat.")

                    g_file.removeFile(topDirFile)
            self.context.logger.debug("Successfully modified logPath owner")

            # Delete the old bak package in GPHOME before copy the new one.
            for bakPack in DefaultValue.PACKAGE_BACK_LIST:
                bakFile = os.path.join(self.context.clusterToolPath, bakPack)
                if (os.path.isfile(bakFile)):
                    self.context.logger.debug("Remove old bak-package: %s." %
                                              bakFile)
                    g_file.removeFile(bakFile)

            DefaultValue.makeCompressedToolPackage(packageDir)

            # check and create tool package dir
            global toolTopPath
            ownerPath = self.context.clusterToolPath
            clusterToolPathExistAlready = True
            # if clusterToolPath exist,
            # set the clusterToolPathExistAlready False
            if (not os.path.exists(ownerPath)):
                clusterToolPathExistAlready = False
                ownerPath = DefaultValue.getTopPathNotExist(ownerPath)
                toolTopPath = ownerPath
            # append clusterToolPath to self.context.needFixOwnerPaths
            # self.context.needFixOwnerPaths will be checked the ownet
            self.context.needFixOwnerPaths.append(ownerPath)

            # if clusterToolPath is not exist, then create it

            if not os.path.exists(self.context.clusterToolPath):
                g_file.createDirectory(self.context.clusterToolPath)
                g_file.changeMode(DefaultValue.MAX_DIRECTORY_MODE,
                                  self.context.clusterToolPath, True, "shell")

            # change the clusterToolPath permission
            if not clusterToolPathExistAlready:
                #check the localMode
                if self.context.localMode:
                    #local mode,change the owner
                    g_file.changeMode(DefaultValue.DIRECTORY_MODE,
                                      ownerPath,
                                      recursive=True,
                                      cmdType="shell")
                    g_file.changeOwner(self.context.user,
                                       ownerPath,
                                       recursive=True,
                                       cmdType="shell")
                #not localMode, only change the permission
                else:
                    g_file.changeMode(DefaultValue.MAX_DIRECTORY_MODE,
                                      ownerPath,
                                      recursive=True,
                                      cmdType="shell")
            else:
                g_file.changeMode(DefaultValue.DIRECTORY_MODE,
                                  ownerPath,
                                  recursive=False,
                                  cmdType="shell")

            # Send compressed package to local host
            if (packageDir != self.context.clusterToolPath):
                # copy the package to clusterToolPath
                g_file.cpFile(
                    os.path.join(packageDir,
                                 DefaultValue.get_package_back_name()),
                    self.context.clusterToolPath)

            # Decompress package on local host
            g_file.decompressFiles(
                os.path.join(self.context.clusterToolPath,
                             DefaultValue.get_package_back_name()),
                self.context.clusterToolPath)

            # change mode of packages
            g_file.changeMode(DefaultValue.DIRECTORY_MODE,
                              self.context.clusterToolPath,
                              recursive=True,
                              cmdType="shell")

            # get the top path of mpprc file need to be created on local node
            # this is used to fix the newly created path owner later
            if self.context.mpprcFile != "":
                ownerPath = self.context.mpprcFile
                if (not os.path.exists(self.context.mpprcFile)):
                    while True:
                        # find the top path to be created
                        (ownerPath, dirName) = os.path.split(ownerPath)
                        if os.path.exists(ownerPath) or dirName == "":
                            ownerPath = os.path.join(ownerPath, dirName)
                            break
                self.context.needFixOwnerPaths.append(ownerPath)

            # check the current storage package path is legal
            Current_Path = os.path.dirname(os.path.realpath(__file__))
            DefaultValue.checkPathVaild(os.path.normpath(Current_Path))
            # set ENV
            cmd = "%s -t %s -u %s -l %s -X '%s' -Q %s" % (
                OMCommand.getLocalScript("Local_PreInstall"),
                ACTION_SET_TOOL_ENV, self.context.user, self.context.localLog,
                self.context.xmlFile, self.context.clusterToolPath)
            if self.context.mpprcFile != "":
                cmd += " -s '%s' " % self.context.mpprcFile
                #check the localmode,if mode is local then modify user group
                if self.context.localMode:
                    cmd += "-g %s" % self.context.group
            (status, output) = subprocess.getstatusoutput(cmd)
            # if cmd failed, then exit
            if status != 0:
                self.context.logger.debug(
                    "Command for setting %s tool environment variables: %s" %
                    (VersionInfo.PRODUCT_NAME, cmd))
                raise Exception(output)

        except Exception as e:
            raise Exception(str(e))

        self.context.logger.log(
            "Successfully installed the tools on the local node.", "constant")
Ejemplo n.º 13
0
    def cleanEnvSoftware(self):
        """
        function: clean environment software and variable
        Gauss-MPPDB* & sctp_patch is came from R5 upgrade R7
        input : NA
        output: NA
        """
        self.logger.debug("Cleaning the environmental software and variable.")
        # clean environment software
        path = "%s/%s" % (self.clusterToolPath, PSSHDIR)
        g_file.removeDirectory(path)
        path = "%s/lib" % self.clusterToolPath
        g_file.removeDirectory(path)
        path = "%s/script" % self.clusterToolPath
        g_file.removeDirectory(path)
        path = "%s/sudo" % self.clusterToolPath
        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/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/Gauss*" % (self.clusterToolPath)
        g_file.removeDirectory(path)
        path = "%s/sctp_patch" % (self.clusterToolPath)
        g_file.removeDirectory(path)
        path = "%s/unixodbc" % self.clusterToolPath
        g_file.removeDirectory(path)
        path = "%s/%s" % (self.clusterToolPath, Const.UPGRADE_SQL_FILE)
        g_file.removeFile(path)
        path = "%s/%s" % (self.clusterToolPath, Const.UPGRADE_SQL_SHA)
        g_file.removeFile(path)
        self.logger.debug(
            "Successfully cleaned the environmental software and variable.")

        self.logger.debug("Cleaning environmental software.")
        # clean 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\/lib:" \
            "\$LD_LIBRARY_PATH$/d' %s " % PROFILE_FILE
        cmd += \
            "-e '/^export PYTHONPATH=\$GPHOME\/lib$/d' %s; fi) " % PROFILE_FILE
        self.logger.debug("Command for cleaning environment variable: %s." %
                          cmd)
        (status, output) = subprocess.getstatusoutput(cmd)
        if (status != 0):
            self.logger.logExit(ErrorCode.GAUSS_514["GAUSS_51400"] % cmd +
                                " Error:\n%s" % output)

        self.logger.debug(
            "Successfully cleaned environmental software and variable.")
Ejemplo n.º 14
0
    def cleanDir(self, instDir):
        """
        function: Clean the dirs
        input : instDir
        output: NA
        """
        if (not os.path.exists(instDir)):
            return

        dataDir = []
        dataDir = os.listdir(instDir)
        if (os.getuid() == 0):
            pglDir = '%s/pg_location' % instDir
            isPglDirEmpty = False
            if (os.path.exists(pglDir) and len(os.listdir(pglDir)) == 0):
                isPglDirEmpty = True
            if (len(dataDir) == 0 or isPglDirEmpty):
                g_file.cleanDirectoryContent(instDir)
        else:
            for info in dataDir:
                if (str(info) == "pg_location"):
                    resultMount = []
                    resultFile = []
                    resultDir = []
                    pglDir = '%s/pg_location' % instDir

                    # delete all files in the mount point
                    cmd = "%s | %s '%s' | %s '{printf $3}'" % \
                          (g_Platform.getMountCmd(), g_Platform.getGrepCmd(),
                           pglDir, g_Platform.getAwkCmd())
                    (status, outputMount) = subprocess.getstatusoutput(cmd)
                    if (status != 0):
                        raise Exception(ErrorCode.GAUSS_502["GAUSS_50207"] %
                                        instDir +
                                        " Error:\n%s." % str(outputMount) +
                                        "The cmd is %s" % cmd)
                    else:
                        if (len(outputMount) > 0):
                            resultMount = str(outputMount).split()
                            for infoMount in resultMount:
                                g_file.cleanDirectoryContent(infoMount)
                        else:
                            g_file.cleanDirectoryContent(instDir)
                            continue

                    # delete file in the pg_location directory
                    if (not os.path.exists(pglDir)):
                        continue
                    cmd = "cd '%s'" % pglDir
                    (status, output) = subprocess.getstatusoutput(cmd)
                    if (status != 0):
                        raise Exception(ErrorCode.GAUSS_514["GAUSS_51400"] %
                                        cmd + " Error: \n%s " % output)

                    outputFile = g_file.findFile(".", "f", "type")
                    if (len(outputFile) > 0):
                        for infoFile in outputFile:
                            tmpinfoFile = pglDir + infoFile[1:]
                            for infoMount in resultMount:
                                if (tmpinfoFile.find(infoMount) < 0
                                        and infoMount.find(tmpinfoFile) < 0):
                                    realFile = "'%s/%s'" % (pglDir, infoFile)
                                    g_file.removeFile(realFile, "shell")

                    # delete directory in the pg_location directory
                    cmd = "if [ -d '%s' ]; then cd '%s' && find -type d; fi" \
                          % \
                          (pglDir, pglDir)
                    (status, outputDir) = subprocess.getstatusoutput(cmd)
                    if (status != 0):
                        raise Exception(ErrorCode.GAUSS_502["GAUSS_50207"] %
                                        instDir +
                                        " Error:\n%s." % str(outputDir) +
                                        "The cmd is %s" % cmd)
                    else:
                        resultDir = g_file.findFile(".", "d", "type")
                        resultDir.remove(".")
                        if (len(resultDir) > 0):
                            for infoDir in resultDir:
                                tmpinfoDir = pglDir + infoDir[1:]
                                for infoMount in resultMount:
                                    if (tmpinfoDir.find(infoMount) < 0 and
                                            infoMount.find(tmpinfoDir) < 0):
                                        realPath = "'%s/%s'" % (pglDir,
                                                                infoDir)
                                        g_file.removeDirectory(realPath)
            cmd = "if [ -d '%s' ];then cd '%s' && find . ! -name " \
                  "'pg_location' " \
                  "! -name '..' ! -name '.' -print0 |xargs -r -0 -n100 rm " \
                  "-rf; " \
                  "fi" % (instDir, instDir)
            (status, output) = subprocess.getstatusoutput(cmd)
            if (status != 0):
                raise Exception(ErrorCode.GAUSS_502["GAUSS_50207"] % instDir +
                                " Error:\n%s." % str(output) +
                                "The cmd is %s" % cmd)
Ejemplo n.º 15
0
 def removeSocketFile(self, fileName):
     """
     """
     g_file.removeFile(fileName, "shell")