Beispiel #1
0
def test_version_is_compatible():
    #
    # Make sure the exact same version is compatible
    #
    assert version_is_compatible(VERSION)

    #
    # Make sure future version is not compatible
    #
    assert not version_is_compatible('10.0.0')

    #
    # Make sure past verion is compatible
    #
    assert version_is_compatible('0.0.1')
Beispiel #2
0
    def load_meta(cls, meta_dict):
        """
        Loads the meta data for the kit into the class.

        :param meta_dict: A dict containing the metadata, as specified by
                          the KitMetadataSchema class.

        """
        errors = KitMetadataSchema().validate(meta_dict)
        if errors:
            raise Exception(
                'Kit metadata validation error: {}'.format(errors))

        requires_core = meta_dict.get('requires_core', VERSION)
        if not version_is_compatible(requires_core):
            raise Exception(
                'The {} kit requires tortuga core >= {}'.format(
                    meta_dict['name'], requires_core))

        meta_dict = copy.deepcopy(meta_dict)
        cls.name = meta_dict.pop('name')
        cls.version = meta_dict.pop('version')
        cls.iteration = meta_dict.pop('iteration')
        cls.spec = (cls.name, cls.version, cls.iteration)
        cls.meta = meta_dict
Beispiel #3
0
    def get_kit_metadata():
        """
        Gets kit metadata from the KIT_METADATA_FILE, validates it, and
        returns the result as a python dict.

        :return: dict of the loaded metadata

        """
        logger.info('Getting kit metadata...')

        if not os.path.exists(KIT_METADATA_FILE):
            raise KitBuildError(
                'No kit metadata file found: {}'.format(KIT_METADATA_FILE))

        kit_meta_fp = open(KIT_METADATA_FILE)
        kit_meta = json.load(kit_meta_fp)
        errors = KitMetadataSchema().validate(kit_meta)
        if errors:
            raise KitBuildError(
                'Kit metadata validation error: {}'.format(errors))

        requires_core = kit_meta.get('requires_core', VERSION)
        if not version_is_compatible(requires_core):
            raise KitBuildError(
                'The {} kit requires tortuga core >= {}'.format(
                    kit_meta['name'], requires_core))

        return kit_meta
Beispiel #4
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
Beispiel #5
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