예제 #1
0
 def __checkSHA256(self):
     '''
     function: Check the sha256 of new version
     input: NA
     output: NA
     '''
     try:
         DefaultValue.checkPackageOS()
     except Exception as e:
         g_logger.logExit(str(e))
예제 #2
0
def checkSHA256():
    """
    function: Check the sha256 number for database install binary file.
    input : NA
    output: NA
    """
    g_opts.logger.log("Checking SHA256.")
    try:
        DefaultValue.checkPackageOS()
    except Exception as e:
        g_opts.logger.logExit(str(e))
    g_opts.logger.log("Successfully checked SHA256.")
    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")