Exemplo n.º 1
0
    def installKits(self, dbm):
        self._logger.info('Installing kits')

        self.out('\n' + _('Installing kits') + '...\n')

        kitApi = KitApi()

        # Iterate over the glob of 'kits-*.tar.bz2'
        kitFileGlob = '%s/kits/kit-*.tar.bz2' % (self._cm.getRoot())

        # Split comma-separated list of kits to skip installing. Sorry, you
        # cannot skip installing the base kit.
        val = self._settings['skip_kits'] \
            if 'skip_kits' in self._settings else ''

        skip_kits = set([
            item for item in val.split(',') if item != 'base']) \
            if val else set()

        for kitPackage in glob.glob(kitFileGlob):
            try:
                kit = get_metadata_from_archive(kitPackage)
            except KitNotFound:
                msg = 'Kit [%s] is malformed/invalid. Skipping.' % (
                    os.path.basename(kitPackage))

                self._logger.error(msg)

                self.out('   %s\n' % (msg))

                continue

            if kit['name'] in skip_kits:
                msg = 'Kit [%s] installation skipped.' % (kit['name'])

                self.out('   %s\n' % (msg))

                self._logger.info(msg)

                continue

            try:
                kitApi.installKitPackage(dbm, kitPackage)
            except EulaAcceptanceRequired:
                msg = 'Kit [%s] requires EULA acceptance. Skipping.' % (
                    kitPackage)

                self.out('   %s\n' % (msg))

                self._logger.info(msg)

                continue

            self.out('   - %s installed.\n' % (kit['name']))

            self._logger.info('Kit [%s] installed' % (kit['name']))

        self._logger.info('Done installing kits')

        load_kits()
Exemplo n.º 2
0
    def _prepare_installer(self, kit_pkg_url):
        """
        Extracts a kit archive and prepares the kit installer for the
        installation process.

        :param kit_pkg_url: the URL to the kit package archive

        :return: the KitInstaller instance

        """
        #
        # Download/copy kit archive.
        #
        kit_src_path = os.path.basename(kit_pkg_url)
        kit_pkg_path = utils.retrieve(
            kit_src_path, kit_pkg_url, self._kits_root)

        #
        # Make sure the kit version is compatible
        #
        kit_meta = utils.get_metadata_from_archive(kit_pkg_path)
        kit_spec = (kit_meta['name'], kit_meta['version'],
                    kit_meta['iteration'])
        requires_core = kit_meta.get('requires_core', VERSION)
        if not version_is_compatible(requires_core):
            errmsg = 'The {} kit requires tortuga core >= {}'.format(
                kit_meta['name'], requires_core)

            raise OperationFailed(errmsg)

        #
        # Unpack the archive
        #
        kit_dir = utils.unpack_kit_archive(kit_pkg_path, self._kits_root)

        #
        # Load and initialize kit installer
        #
        load_kits()
        try:
            installer = get_kit_installer(kit_spec)()
            assert installer.is_installable()

        except Exception as ex:
            if os.path.exists(kit_dir):
                self._logger.debug(
                    'Removing kit installation directory: {}'.format(kit_dir))
                osUtility.removeDir(kit_dir)
            self._logger.warning(
                'Kit is not installable: {}'.format(kit_spec))
            return

        return installer
Exemplo n.º 3
0
    def installKitPackage(self, db_manager, kit_pkg_url, key=None):
        """
        Install kit from the given kit url (url might be a local file). Kit
        will be installed for all operating systems that:

            1) have repo configured on the local machine
            2) are specified in the kit.xml file

        :raisesKitAlreadyExists:
        :raisesEulaAcceptanceRequired:

        """
        self.getLogger().debug('Installing kit package: {}'.format(kit_pkg_url))

        #
        # Download/copy kit archive.
        #
        kit_src_path = os.path.basename(kit_pkg_url)
        kit_pkg_path = utils.retrieve(
            kit_src_path, kit_pkg_url, self._kits_root)

        #
        # Make sure the kit version is compatible
        #
        kit_meta = utils.get_metadata_from_archive(kit_pkg_path)
        requires_core = kit_meta.get('requires_core', VERSION)
        if not version_is_compatible(requires_core):
            errmsg = 'The {} kit requires tortuga core >= {}'.format(
                kit_meta['name'],requires_core)

            raise OperationFailed(errmsg)

        #
        # Unpack the archive
        #
        kit_spec = utils.unpack_archive(kit_pkg_path, self._kits_root)

        #
        # Load and initialize kit installer
        #
        load_kits()
        installer = get_kit_installer(kit_spec)()

        if not installer.is_installable():
            self.getLogger().warning(
                'Kit is not installable: {}'.format(kit_spec))
            return

        with db_manager.session() as session:
            installer.session = session

            kit = installer.get_kit()

            #
            # This method will throw KitAlreadyExists, if it does...
            #
            self._check_if_kit_exists(session, kit)

            #
            # Validate eula
            #
            eula = installer.get_eula()
            if not eula:
                self.getLogger().debug('No EULA acceptance required')
            else:
                if not self._eula_validator.validate_eula(eula):
                    raise EulaAcceptanceRequired(
                        'You must accept the EULA to install this kit')

            #
            # Runs the kit pre install method
            #
            installer.run_action('pre_install')

            #
            # Get list of operating systems supported by this installer
            #
            os_info_list = [
                repo.getOsInfo() for repo in repoManager.getRepoList()
            ]

            #
            # Install operating system specific packages
            #
            self._install_os_packages(kit, os_info_list)

            #
            # Initialize any DB tables provided by the kit
            #
            # db_manager = DbManager()
            db_manager.init_database()

            #
            # Add the kit to the database
            #
            self._kit_db_api.addKit(session, kit)

            #
            # Clean up the kit archive directory
            #
            self._clean_kit_achiv_dir(kit, installer.install_path)

            #
            # Install puppet modules
            #
            installer.run_action('install_puppet_modules')

            #
            # Run post install
            #
            try:
                installer.run_action('post_install')
            except Exception as e:
                self._uninstall_kit(session, kit, True)
                raise KitInstallError(
                    'Kit installation failed during post_install: {}'.format(e))

            if eula:
                ActionManager().logAction(
                    'Kit [{}] installed and EULA accepted at [{}]'
                    ' local machine time.'.format(
                        installer.spec, time.ctime())
                )
            else:
                ActionManager().logAction(
                    'Kit [{}] installed at [{}] local machine time.'.format(
                        installer.spec, time.ctime())
                )

            return kit
Exemplo n.º 4
0
def test_get_metadata_from_archive(test_kit_archive):
    #
    # Make sure there are no exceptions in this process
    #
    get_metadata_from_archive(test_kit_archive)