Exemplo n.º 1
0
 def publishMetadata(self, metadataDir):
     """
     Publishing step after successful install
     """
     # Currently it simply removes .DAR directory,
     # in future is could update a simple database of dar installations
     cmd = 'rm -rf '+ metadataDir        
     (status, out)=commands.getstatusoutput(cmd)
     if status != 0: # did not succeed            
         DARInternalError("In publishMetadata: " +
                          "doing command" + cmd +
                          "\ncommand output :\n" + out)
Exemplo n.º 2
0
    def saveAndQuit(self, darFile = 'useDefault'):
        """
        Creates the final DARball and returns.
        This is called when the user is satisfied with the result,
        or when the criteria are satisfied (if in non-interactive mode).
        If successful, it will return the name of the final darball that
        was created, otherwise it will return 'None'.
        """

        if darFile == 'useDefault':
            darFile = self.blddir + "/" +\
                      self.darMeta.getVersionTag() +\
                      "." + self.currentRequest.getArchitecture() +\
                      self.darballSuffix
        else:
            darFile = self.blddir + "/" +\
                      self.currentRequest.getDarName() +\
                      self.darballSuffix

        tarCmd = string.join ( [
            'tar -cz -f', darFile,
            '-C',
            os.path.join(self.blddir, self.dar.getTopInstDir()),
            getDarDirName(),
            '-C', self.blddir, self.darMeta.getVersionTag()
            ])
        infoOut("Creating DAR distribution in " +
                self.blddir + "using tar command:")
        infoOut(tarCmd)

        (status, out) = commands.getstatusoutput(tarCmd)
        if status == 0: # successfull 
            infoOut( "Created " + darFile)
            self.timingLog('Created darball: ' + darFile)
            return darFile
        else:
            infoOut( "Creation of dar file failed!\n " + out)
            return None
Exemplo n.º 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.")