Ejemplo n.º 1
0
 def __getPreviousCFG( self, oRemoteConfData ):
   remoteExpectedVersion = oRemoteConfData.getVersion()
   backupsList = self.__getCfgBackups( gConfigurationData.getBackupDir(), date = oRemoteConfData.getVersion() )
   if not backupsList:
     return S_ERROR( "Could not AutoMerge. Could not retrieve original commiter's version" )
   prevRemoteConfData = ConfigurationData()
   backFile = backupsList[0]
   if backFile[0] == "/":
     backFile = os.path.join( gConfigurationData.getBackupDir(), backFile[1:] )
   try:
     prevRemoteConfData.loadConfigurationData( backFile )
   except Exception, e:
     return S_ERROR( "Could not load original commiter's version: %s" % str( e ) )
Ejemplo n.º 2
0
 def updateConfiguration(self, sBuffer, commiter="", updateVersionOption=False):
     if not gConfigurationData.isMaster():
         return S_ERROR("Configuration modification is not allowed in this server")
     # Load the data in a ConfigurationData object
     oRemoteConfData = ConfigurationData(False)
     oRemoteConfData.loadRemoteCFGFromCompressedMem(sBuffer)
     if updateVersionOption:
         oRemoteConfData.setVersion(gConfigurationData.getVersion())
     # Test that remote and new versions are the same
     sRemoteVersion = oRemoteConfData.getVersion()
     sLocalVersion = gConfigurationData.getVersion()
     gLogger.info("Checking versions\nremote: %s\nlocal:  %s" % (sRemoteVersion, sLocalVersion))
     if sRemoteVersion != sLocalVersion:
         if not gConfigurationData.mergingEnabled():
             return S_ERROR(
                 "Local and remote versions differ (%s vs %s). Cannot commit." % (sLocalVersion, sRemoteVersion)
             )
         else:
             gLogger.info("AutoMerging new data!")
             if updateVersionOption:
                 return S_ERROR("Cannot AutoMerge! version was overwritten")
             result = self.__mergeIndependentUpdates(oRemoteConfData)
             if not result["OK"]:
                 gLogger.warn("Could not AutoMerge!", result["Message"])
                 return S_ERROR("AutoMerge failed: %s" % result["Message"])
             requestedRemoteCFG = result["Value"]
             gLogger.info("AutoMerge successful!")
             oRemoteConfData.setRemoteCFG(requestedRemoteCFG)
     # Test that configuration names are the same
     sRemoteName = oRemoteConfData.getName()
     sLocalName = gConfigurationData.getName()
     if sRemoteName != sLocalName:
         return S_ERROR("Names differ: Server is %s and remote is %s" % (sLocalName, sRemoteName))
     # Update and generate a new version
     gLogger.info("Committing new data...")
     gConfigurationData.lock()
     gLogger.info("Setting the new CFG")
     gConfigurationData.setRemoteCFG(oRemoteConfData.getRemoteCFG())
     gConfigurationData.unlock()
     gLogger.info("Generating new version")
     gConfigurationData.generateNewVersion()
     # self.__checkSlavesStatus( forceWriteConfiguration = True )
     gLogger.info("Writing new version to disk!")
     retVal = gConfigurationData.writeRemoteConfigurationToDisk(
         "%s@%s" % (commiter, gConfigurationData.getVersion())
     )
     gLogger.info("New version it is!")
     return retVal
Ejemplo n.º 3
0
 def __getPreviousCFG(self, oRemoteConfData):
     remoteExpectedVersion = oRemoteConfData.getVersion()
     backupsList = self.__getCfgBackups(gConfigurationData.getBackupDir(),
                                        date=oRemoteConfData.getVersion())
     if not backupsList:
         return S_ERROR(
             "Could not AutoMerge. Could not retrieve original commiter's version"
         )
     prevRemoteConfData = ConfigurationData()
     backFile = backupsList[0]
     if backFile[0] == "/":
         backFile = os.path.join(gConfigurationData.getBackupDir(),
                                 backFile[1:])
     try:
         prevRemoteConfData.loadConfigurationData(backFile)
     except Exception, e:
         return S_ERROR("Could not load original commiter's version: %s" %
                        str(e))
Ejemplo n.º 4
0
 def __getPreviousCFG(self, oRemoteConfData):
     backupsList = self.__getCfgBackups(gConfigurationData.getBackupDir(), date=oRemoteConfData.getVersion())
     if not backupsList:
         return S_ERROR("Could not AutoMerge. Could not retrieve original committer's version")
     prevRemoteConfData = ConfigurationData()
     backFile = backupsList[0]
     if backFile[0] == "/":
         backFile = os.path.join(gConfigurationData.getBackupDir(), backFile[1:])
     try:
         prevRemoteConfData.loadConfigurationData(backFile)
     except Exception as e:
         return S_ERROR("Could not load original committer's version: %s" % str(e))
     gLogger.info("Loaded client original version %s" % prevRemoteConfData.getVersion())
     return S_OK(prevRemoteConfData.getRemoteCFG())
Ejemplo n.º 5
0
 def updateConfiguration(self,
                         sBuffer,
                         commiterDN="",
                         updateVersionOption=False):
     if not gConfigurationData.isMaster():
         return S_ERROR(
             "Configuration modification is not allowed in this server")
     #Load the data in a ConfigurationData object
     oRemoteConfData = ConfigurationData(False)
     oRemoteConfData.loadRemoteCFGFromCompressedMem(sBuffer)
     if updateVersionOption:
         oRemoteConfData.setVersion(gConfigurationData.getVersion())
     #Test that remote and new versions are the same
     sRemoteVersion = oRemoteConfData.getVersion()
     sLocalVersion = gConfigurationData.getVersion()
     gLogger.info("Checking versions\nremote: %s\nlocal:  %s" %
                  (sRemoteVersion, sLocalVersion))
     if sRemoteVersion != sLocalVersion:
         if not gConfigurationData.mergingEnabled():
             return S_ERROR(
                 "Local and remote versions differ (%s vs %s). Cannot commit."
                 % (sLocalVersion, sRemoteVersion))
         else:
             gLogger.info("AutoMerging new data!")
             if updateVersionOption:
                 return S_ERROR("Cannot AutoMerge! version was overwritten")
             result = self.__mergeIndependentUpdates(oRemoteConfData)
             if not result['OK']:
                 gLogger.warn("Could not AutoMerge!", result['Message'])
                 return S_ERROR("AutoMerge failed: %s" % result['Message'])
             requestedRemoteCFG = result['Value']
             gLogger.info("AutoMerge successful!")
             oRemoteConfData.setRemoteCFG(requestedRemoteCFG)
     #Test that configuration names are the same
     sRemoteName = oRemoteConfData.getName()
     sLocalName = gConfigurationData.getName()
     if sRemoteName != sLocalName:
         return S_ERROR("Names differ: Server is %s and remote is %s" %
                        (sLocalName, sRemoteName))
     #Update and generate a new version
     gLogger.info("Committing new data...")
     gConfigurationData.lock()
     gLogger.info("Setting the new CFG")
     gConfigurationData.setRemoteCFG(oRemoteConfData.getRemoteCFG())
     gConfigurationData.unlock()
     gLogger.info("Generating new version")
     gConfigurationData.generateNewVersion()
     #self.__checkSlavesStatus( forceWriteConfiguration = True )
     gLogger.info("Writing new version to disk!")
     retVal = gConfigurationData.writeRemoteConfigurationToDisk(
         "%s@%s" % (commiterDN, gConfigurationData.getVersion()))
     gLogger.info("New version it is!")
     return retVal
Ejemplo n.º 6
0
    def updateConfiguration(self, sBuffer, committer="", updateVersionOption=False):
        """
        Update the master configuration with the newly received changes

        :param str sBuffer: newly received configuration data
        :param str committer: the user name of the committer
        :param bool updateVersionOption: flag to update the current configuration version
        :return: S_OK/S_ERROR of the write-to-disk of the new configuration
        """
        if not gConfigurationData.isMaster():
            return S_ERROR("Configuration modification is not allowed in this server")
        # Load the data in a ConfigurationData object
        oRemoteConfData = ConfigurationData(False)
        oRemoteConfData.loadRemoteCFGFromCompressedMem(sBuffer)
        if updateVersionOption:
            oRemoteConfData.setVersion(gConfigurationData.getVersion())
        # Test that remote and new versions are the same
        sRemoteVersion = oRemoteConfData.getVersion()
        sLocalVersion = gConfigurationData.getVersion()
        gLogger.info("Checking versions\n", "remote: %s\nlocal:  %s" % (sRemoteVersion, sLocalVersion))
        if sRemoteVersion != sLocalVersion:
            if not gConfigurationData.mergingEnabled():
                return S_ERROR(
                    "Local and remote versions differ (%s vs %s). Cannot commit." % (sLocalVersion, sRemoteVersion)
                )
            else:
                gLogger.info("AutoMerging new data!")
                if updateVersionOption:
                    return S_ERROR("Cannot AutoMerge! version was overwritten")
                result = self.__mergeIndependentUpdates(oRemoteConfData)
                if not result["OK"]:
                    gLogger.warn("Could not AutoMerge!", result["Message"])
                    return S_ERROR("AutoMerge failed: %s" % result["Message"])
                requestedRemoteCFG = result["Value"]
                gLogger.info("AutoMerge successful!")
                oRemoteConfData.setRemoteCFG(requestedRemoteCFG)
        # Test that configuration names are the same
        sRemoteName = oRemoteConfData.getName()
        sLocalName = gConfigurationData.getName()
        if sRemoteName != sLocalName:
            return S_ERROR("Names differ: Server is %s and remote is %s" % (sLocalName, sRemoteName))
        # Update and generate a new version
        gLogger.info("Committing new data...")
        gConfigurationData.lock()
        gLogger.info("Setting the new CFG")
        gConfigurationData.setRemoteCFG(oRemoteConfData.getRemoteCFG())
        gConfigurationData.unlock()
        gLogger.info("Generating new version")
        gConfigurationData.generateNewVersion()
        # self.__checkSlavesStatus( forceWriteConfiguration = True )
        gLogger.info("Writing new version to disk")
        retVal = gConfigurationData.writeRemoteConfigurationToDisk(
            "%s@%s" % (committer, gConfigurationData.getVersion())
        )
        gLogger.info("New version", gConfigurationData.getVersion())

        # Attempt to update the configuration on currently registered slave services
        if gConfigurationData.getAutoSlaveSync():
            self.forceSlavesUpdate()

        return retVal