Пример #1
0
    def __init__(self, tmpdir, program):
        """ Makes necessary checks and sets RefDBDAR attributes"""

        #check that CMS environment  is set:
        if not os.environ.has_key('CMS_PATH'):
            message = """CMS_PATH variable is not defined.
Please set CMS environment"""
            sys.exit(message)            
        self.tmpdir = tmpdir
        infoOut( 'temporary directory is '+self.tmpdir)
        if notWritable(self.tmpdir):
            sys.exit(notWritable(self.tmpdir))

        # Collect a list of warnings:
        self.allWarnings = []

        # Start session to execute shell commands
        self.s=Session()

        # Create every time new build directory in tmpdir pool
        # using datestamp :
        self.blddir = self.tmpdir + '/' + str(time.time())
        self.s.run('mkdir -p ' + self.blddir)

        # Define log files (all in one directory):
        self.logdir = self.blddir + '/logfiles/'
        self.s.run('mkdir -p ' + self.logdir)
        self.timingLog = Logger(self.logdir+'session.timing')
        self.sessionStdoutLog = self.logdir+'session.stdout'
        self.sessionHistoryLog = self.logdir+'session.history'

        self.programPath, self.programName=os.path.split(program)
        self.dar = self.programPath+'/dar2'
        infoOut( 'dar executable is '+self.dar)
        (out, stat) = self.s.run(self.dar+' -v ') # display dar version 
        if stat != "0":
            message="""dar executable failed
Please check DAR availability and configuration"""
            self.error(message)

        infoOut("current dar version is: "+out[len(out)-1][:-1])

        self.cvsbase = ':pserver:[email protected]:/cvs_server/repositories/'
        infoOut('cvs server basename is ' + self.cvsbase )

        # Initialize required attributes:
        self.numExe = 0
        self.executables = []
        self.applList = [] # allow zero applications 
        self.geomFilesList = []
        self.geomPathList = []
        self.darHooks = {}
        self.DARRemoveTools = []
        self.DARIgnoreFile = None
        # Log current time
        self.timingLog('RefDBDAR configured')
Пример #2
0
    def __init__(self, darInput, pltf=None, cnf=None):        
        """
        __init__
          Initializes DAR Manager apects common to both create and install mode.
        """        
        Lister.__init__(self)

        # Set defaults:
        self.darballSuffix = '_dar.tar.gz'

        # and initialize variables:
        self.baseBomDict = {}  # need for incremental darball
        self.darpool = None    # 
        self.dar = None # need for creating darball
        
        self.config = cnf
        infoOut('Validating DAR configuration ...')
        if getVerbose():
            print "CONFIGURATION:", self.config
        # Check that dar shared pool is set up, exists and has right permissions:
        # DAR shared pool is to lookup for a base dar distributions and/or
        # installations . 
        if self.config.has_key("dar_shared_pool"):
            self.sharedPool = self.config["dar_shared_pool"]
        else:
            sys.exit("ERROR:dar shared pool is not defined in the configuration")
        if self.config.has_key("dar_dist_pool"):
            self.distPool = self.config["dar_dist_pool"]
        else:
            sys.exit("ERROR: dar dist pool is not defined in the configuration")
        if self.config.has_key("dar_inst_pool"):
            self.instPool = self.config["dar_inst_pool"]
        else:
            sys.exit("ERROR: dar inst pool is not defined in the configuration")

        # Check that dar tmpdir is set, exists, and has right permissions:
        if self.config.has_key("dar_tmp_dir"):
            self.tmpdir = self.config["dar_tmp_dir"]
        else:
            sys.exit("ERROR: dar_tmp_dir is not defined in the configuration")
        if notWritable(self.tmpdir):
            sys.exit(notWritable(self.tmpdir))
            
        # Each time when dar is called, it creates a new build directory
        # in tmpdir pool, using a unique datestamp:
        self.blddir = self.tmpdir+'/'+str(time.time())

        # Start logger and pre-set log files:
        self.logdir = self.blddir + '/logfiles' # one dir for all logfiles
        self.timingLog = Logger(self.logdir+'/session.timing')
        self.sessionStdoutLog = self.logdir+'/session.stdout'
        self.sessionHistoryLog = self.logdir+'/session.history'

        # Create necessary directories and files:
        os.makedirs(self.blddir)
        os.makedirs(self.logdir)
        for logfile in (self.sessionStdoutLog,  self.sessionHistoryLog):
            infoOut('Creating ' + logfile + ' file')
            open(logfile, 'w').close()

        # Get platform info:
        self.platform = pltf

        self.timingLog('Completed configuration and setup ')

        # Create a request 
        self.currentRequest = Request(darInput, self.timingLog)
        self.timingLog('Created request object')

        # Initialize dar metadata
        self.darMeta = Metadata()
        self.darMeta.setDarVersion(getDarVersion())
    
        # Get release/version metadata from request and
        # put them into Metadata container:
        self.darMeta.setDarInput(darInput)
        self.darMeta.setBaseReleaseName(self.currentRequest.getBaseReleaseName())
        self.darMeta.setProjectName(self.currentRequest.getProjectName())
        self.darMeta.setVersionTag(self.currentRequest.getVersionTag())

        # Architecture
        self.darMeta.setArchitecture(self.currentRequest.getArchitecture())
Пример #3
0
    def installApplication(self, installDir, testmode):
        """
        Manager.installApplication
          Installs the application by performing the following steps:
            - checks to see if the installation directory is writable
            - loads metadata
            - checks if enough disk space is available
            - checks to see if this is an incremental installation
              - looks for the base disribution for this release
            - checks for previous installation of this package
              and checks the md5sum <not implemented>
            - unpacks the installation package
            - publishes package metadata
            - sets up the environment scripts and runs setup scripts
            - creates links and checks installation size
        """
        if notWritable(installDir):
            sys.exit(notWritable(installDir))
        # Absolutize path if needed:
        if not os.path.isabs(installDir):
            installDir = os.path.abspath(installDir)
        # Extract metadata from distribution:
        metadata = loadMetadata(getMetaDataFile(),
                                archive = self.currentRequest.getDarFile())

        infoOut('Loaded DAR metadata from '+self.currentRequest.getDarFile())
        # If in test mode, print out users info and exit:
        if testmode:
            print metadata.userInfo()
            return
        # Check  that  there is enough space in the installation directory:
        available = spaceLeft(installDir)
        installSize = float(metadata.getInstallationSize())

        if available < installSize:
            sys.exit('Not enough space on the disk!\n Installation size: ' \
                     + str(installSize) +
                     ' KB\n Available: ' +
                     str(available) + ' KB')

        self.timingLog('Checked space left in '+installDir)
        ##########################################
        #   Handling  incremental DARballs:
        ##########################################
        # Check if darball metadata contain a reference to a base dar:
        baseDar = metadata.getBaseDar()
        if baseDar:
            infoOut("This is  incremental distribution based on "+baseDar)
            # This is an incremental darball, so 
            # we need matching base installation.
            baseInstallation = self.currentRequest.baseDar
            if  not baseInstallation:
                usageError ('Please specify a base .')
                # Lookup for base installation in the installation pool:
                # baseInstallation = self.findBaseInstallation(self.distPool,
                #                                           baseDar)
                # if not baseInstallation:
                #    sys.exit( 'Could not find base installation for ' +
                #                   baseDar + '
                #                   in '+self.sharedPool)
            infoOut("(todo)Verifying base installation "+baseInstallation)
        ##########################################
        #   General actions for all DARballs:
        ##########################################
        # Check if the installation already exists:
        releaseInstTop = os.path.join(installDir,
                                      metadata.getVersionTag(),
                                      metadata.getArchitecture())
        if os.path.exists( releaseInstTop):
            # TODO: validate the installation using  md5sum and
            # tell user the results
            sys.exit("ERROR: You already have installation here: \n   " \
                     +releaseInstTop+"\nExiting ....\n")
        # Unpack darball
        infoOut('Unpacking '+self.currentRequest.getDarFile()+' .... ')
        unpackCommand = 'tar -xz -C ' + \
                        installDir + ' -f ' + \
                        self.currentRequest.getDarFile()

        (status, out) = commands.getstatusoutput(unpackCommand)
        
        # Check that in unpacked into toInstallDir as expected:
        if status: # failed
            if out:
                # save command output in the logfile:
                unpackLogfile = os.path.join(self.logdir, 'dar_unpack.log')
                tarlog = open(unpackLogfile, 'w')
                tarlog.write('Output from unpacking command:\n' + \
                         unpackCommand + '\n' + out )
                tarlog.close()
            sys.exit ('Unpacking failed with exit status ' + status + \
                      '\nOutput can be found in \n' + unpackLogfile )
        elif not os.path.isdir(releaseInstTop):
            sys.exit ('Can not  find  '+releaseInstTop)            
        # Link to a base installation for incremental darballs 
        if baseDar:
            infoOut("Create a link to base installation:\n ln -s "
                     +baseInstallation+'/shared '+releaseInstTop+'/base')
            os.symlink(baseInstallation+'/shared', releaseInstTop+'/base')
        # Set up environment scripts:
        infoOut("Setting up the installation")
        templateStub = os.path.join(releaseInstTop, getSetupScriptBasename())
        newSetupScriptStub = os.path.join(releaseInstTop, 'envSetup')
        helpText = self.updateSetupScripts(\
                   templateStub, \
                   releaseInstTop, \
                   newSetupScriptStub )

        # For compatibility with the old Production tools:
        oldSetupScriptStub = os.path.join(releaseInstTop,
                                          metadata.getVersionTag() + '_env')
        self.updateSetupScripts(\
                   templateStub, \
                   releaseInstTop, \
                   oldSetupScriptStub )

        # Move script templates to the DAR admin directory. 
        #infoOut('Removing setup scripts templates ...')
        cmd = 'mv ' + templateStub + '.*sh' + ' ' \
              + installDir + '/' + getDarDirName()
        (status, out)=commands.getstatusoutput(cmd)
        if status != 0: # did not succeed
            DARInternalError("In installApplication: " +
                             "doing command" + cmd +
                             "\ncommand output :\n" + out)
        
        
        #infoOut("(todo) Do md5sum check of BOM in resulting installation")
        #infoOut("(todo) If successful, " +
        #        "register installation in publishing service ")
        self.publishMetadata(installDir + '/' + getDarDirName())
        # Publish installation metadata:
        self.publishMetadata(installDir + '/' + getDarDirName())

        #Print out runtime environment setup help (and exit):
        infoOut(helpText)
        infoOut("Installation completed.")