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))
def parseCommandLine():
    """
    parse command line
    input : NA
    output: NA
    """
    try:
        opts, args = getopt.getopt(sys.argv[1:], "U:R:C:l:X:", ["help"])
    except getopt.GetoptError as e:
        GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % str(e))
    if (len(args) > 0):
        usage()
        GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] %
                               str(args[0]))

    global g_opts
    g_opts = CmdOptions()

    parameter_map = {
        "-U": g_opts.userInfo,
        "-R": g_opts.installPath,
        "-l": g_opts.logFile,
        "-X": g_opts.clusterConfig
    }
    parameter_keys = parameter_map.keys()
    for key, value in opts:
        if (key == "--help"):
            usage()
            sys.exit(0)
        elif (key in parameter_keys):
            parameter_map[key] = value
        elif (key == "-C"):
            g_opts.confParameters.append(value)
        else:
            GaussLog.exitWithError(ErrorCode.GAUSS_500["GAUSS_50000"] % value)
        Parameter.checkParaVaild(key, value)

    g_opts.userInfo = parameter_map["-U"]
    g_opts.installPath = parameter_map["-R"]
    if os.path.islink(
            g_opts.installPath) or not os.path.exists(g_opts.installPath):
        versionFile = VersionInfo.get_version_file()
        commitid = VersionInfo.get_version_info(versionFile)[2]
        g_opts.installPath = g_opts.installPath + "_" + commitid
    g_opts.logFile = parameter_map["-l"]
    g_opts.clusterConfig = parameter_map["-X"]
Beispiel #3
0
 def deleteSymbolicAppPath(self):
     """
     function: delete symbolic app path
     input  : NA
     output : NA
     """
     self.context.logger.debug("Delete symbolic link $GAUSSHOME.")
     versionFile = VersionInfo.get_version_file()
     commitid = VersionInfo.get_version_info(versionFile)[2]
     cmd = "rm -rf %s" % self.context.clusterInfo.appPath
     self.context.clusterInfo.appPath = \
         self.context.clusterInfo.appPath + "_" + commitid
     DefaultValue.execCommandWithMode(cmd, "Delete symbolic link",
                                      self.context.sshTool,
                                      self.context.isSingle,
                                      self.context.mpprcFile)
     self.context.logger.debug(
         "Successfully delete symbolic link $GAUSSHOME, cmd: %s." % cmd)
Beispiel #4
0
 def getPackageFile(self, fileType="tarFile"):
     """
     function : Get the path of binary file version.
     input : NA
     output : String
     """
     (distName, version) = g_Platform.getCurrentPlatForm()
     return g_Platform.getPackageFile(distName, version,
                                      VersionInfo.getPackageVersion(),
                                      VersionInfo.PRODUCT_NAME_PACKAGE,
                                      fileType)
def createLinkToApp():
    """
    function: create link to app
    input  : NA
    output : NA
    """
    if g_opts.upgrade:
        g_opts.logger.log("Under upgrade process,"
                          " no need to create symbolic link.")
        return
    g_opts.logger.debug("Created symbolic link to $GAUSSHOME with commitid.")
    gaussHome = DefaultValue.getInstallDir(g_opts.user)
    if gaussHome == "":
        raise Exception(ErrorCode.GAUSS_518["GAUSS_51800"] % "$GAUSSHOME")
    versionFile = VersionInfo.get_version_file()
    commitid = VersionInfo.get_version_info(versionFile)[2]
    actualPath = gaussHome + "_" + commitid
    if os.path.exists(gaussHome):
        if not os.path.islink(gaussHome):
            raise Exception(ErrorCode.GAUSS_502["GAUSS_50200"] % gaussHome
                            + " Cannot create symbolic link,"
                              " please rename or delete it.")
        else:
            if os.path.realpath(gaussHome) == actualPath:
                g_opts.logger.log("$GAUSSHOME points to %s, no need to create"
                                  " symbolic link." % actualPath)
                return

    cmd = "ln -snf %s %s" % (actualPath, gaussHome)
    g_opts.logger.log("Command for creating symbolic link: %s." % cmd)
    (status, output) = subprocess.getstatusoutput(cmd)
    if status != 0:
        g_opts.logger.log(output)
        g_opts.logger.logExit(ErrorCode.GAUSS_501["GAUSS_50107"] % "app.")
    g_opts.logger.debug("Successfully created symbolic link to"
                        " $GAUSSHOME with commitid.")
Beispiel #6
0
 def getUserInfo(self):
     """
     Get user and group
     """
     if os.path.islink(self.clusterInfo.appPath):
         appPath = os.path.realpath(self.clusterInfo.appPath)
     elif os.path.exists(self.clusterInfo.appPath):
         appPath = self.clusterInfo.appPath
     else:
         commitid = VersionInfo.getCommitid()
         appPath = self.clusterInfo.appPath + "_" + commitid
     self.logger.debug("Get the install path %s user info." % appPath)
     (self.user, self.group) = g_OSlib.getPathOwner(appPath)
     if (self.user == "" or self.group == ""):
         self.logger.logExit(ErrorCode.GAUSS_503["GAUSS_50308"])
    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")