Example #1
0
    def setup_repositories(self, clear_cache=False, signing_keys=None):
        """
        Set up repositories for software installation and return a
        package manager for performing software installation tasks

        :return: Instance of PackageManager
        :rtype: PackageManager
        """
        repository_options = []
        repository_sections = \
            self.xml_state.get_repository_sections_used_for_build()
        package_manager = self.xml_state.get_package_manager()
        if self.xml_state.get_rpm_check_signatures():
            repository_options.append('check_signatures')
        if self.xml_state.get_rpm_excludedocs():
            repository_options.append('exclude_docs')
        repo = Repository(self.root_bind, package_manager, repository_options)
        if signing_keys:
            repo.import_trusted_keys(signing_keys)
        for xml_repo in repository_sections:
            repo_type = xml_repo.get_type()
            repo_source = xml_repo.get_source().get_path()
            repo_user = xml_repo.get_username()
            repo_secret = xml_repo.get_password()
            repo_alias = xml_repo.get_alias()
            repo_priority = xml_repo.get_priority()
            repo_dist = xml_repo.get_distribution()
            repo_components = xml_repo.get_components()
            repo_repository_gpgcheck = xml_repo.get_repository_gpgcheck()
            repo_package_gpgcheck = xml_repo.get_package_gpgcheck()
            log.info('Setting up repository %s', repo_source)
            log.info('--> Type: %s', repo_type)
            if repo_priority:
                log.info('--> Priority: %s', repo_priority)

            uri = Uri(repo_source, repo_type)
            repo_source_translated = uri.translate()
            log.info('--> Translated: %s', repo_source_translated)
            if not repo_alias:
                repo_alias = uri.alias()
            log.info('--> Alias: %s', repo_alias)

            if not uri.is_remote() and not os.path.exists(
                    repo_source_translated):
                log.warning('repository %s does not exist and will be skipped',
                            repo_source)
                continue

            if not uri.is_remote():
                self.root_bind.mount_shared_directory(repo_source_translated)

            repo.add_repo(repo_alias, repo_source_translated, repo_type,
                          repo_priority, repo_dist, repo_components, repo_user,
                          repo_secret, uri.credentials_file_name(),
                          repo_repository_gpgcheck, repo_package_gpgcheck)
            if clear_cache:
                repo.delete_repo_cache(repo_alias)
            self.uri_list.append(uri)
        repo.cleanup_unused_repos()
        return PackageManager(repo, package_manager)
Example #2
0
    def pinch_system(self, manager=None, force=False):
        """
        Delete packages marked for deletion in the XML description. If force
        param is set to False uninstalls packages marked with
        `type="uninstall"` if any; if force is set to True deletes packages
        marked with `type="delete"` if any.

        :param object manager: instance of :class:`PackageManager`
        :param bool force: Forced deletion True|False

        :raises KiwiPackagesDeletePhaseFailed: if the deletion packages
            process fails
        """
        to_become_deleted_packages = \
            self.xml_state.get_to_become_deleted_packages(force)
        if to_become_deleted_packages:
            log.info('{0} system packages (chroot)'.format(
                'Force deleting' if force else 'Uninstalling'))
            try:
                if manager is None:
                    package_manager = self.xml_state.get_package_manager()
                    manager = PackageManager(
                        Repository(self.root_bind, package_manager),
                        package_manager)
                self.delete_packages(manager, to_become_deleted_packages,
                                     force)
            except Exception as issue:
                raise KiwiPackagesDeletePhaseFailed(
                    self.issue_message.format(
                        headline='System package deletion failed',
                        reason=issue))
Example #3
0
File: prepare.py Project: jfkw/kiwi
 def clean_package_manager_leftovers(self) -> None:
     """
     This methods cleans some package manager artifacts created
     at run time such as macros
     """
     package_manager = self.xml_state.get_package_manager()
     manager = PackageManager.new(
         Repository.new(self.root_bind, package_manager), package_manager)
     manager.clean_leftovers()
Example #4
0
 def import_repositories_marked_as_imageinclude(self):
     """
     Those <repository> sections which are marked with the
     imageinclude attribute should be permanently added to
     the image repository configuration
     """
     repository_sections = \
         self.xml_state.get_repository_sections_used_in_image()
     root = RootInit(
         root_dir=self.root_dir, allow_existing=True
     )
     repo = Repository(
         RootBind(root), self.xml_state.get_package_manager()
     )
     repo.use_default_location()
     for xml_repo in repository_sections:
         repo_type = xml_repo.get_type()
         repo_source = xml_repo.get_source().get_path()
         repo_user = xml_repo.get_username()
         repo_secret = xml_repo.get_password()
         repo_alias = xml_repo.get_alias()
         repo_priority = xml_repo.get_priority()
         repo_dist = xml_repo.get_distribution()
         repo_components = xml_repo.get_components()
         repo_repository_gpgcheck = xml_repo.get_repository_gpgcheck()
         repo_package_gpgcheck = xml_repo.get_package_gpgcheck()
         uri = Uri(repo_source, repo_type)
         repo_source_translated = uri.translate(
             check_build_environment=False
         )
         if not repo_alias:
             repo_alias = uri.alias()
         log.info('Setting up image repository %s', repo_source)
         log.info('--> Type: %s', repo_type)
         log.info('--> Translated: %s', repo_source_translated)
         log.info('--> Alias: %s', repo_alias)
         repo.add_repo(
             repo_alias, repo_source_translated,
             repo_type, repo_priority, repo_dist, repo_components,
             repo_user, repo_secret, uri.credentials_file_name(),
             repo_repository_gpgcheck, repo_package_gpgcheck
         )
Example #5
0
 def import_repositories_marked_as_imageinclude(self):
     """
     Those <repository> sections which are marked with the
     imageinclude attribute should be permanently added to
     the image repository configuration
     """
     repository_sections = \
         self.xml_state.get_repository_sections_used_in_image()
     root = RootInit(root_dir=self.root_dir, allow_existing=True)
     repo = Repository(RootBind(root), self.xml_state.get_package_manager())
     repo.use_default_location()
     for xml_repo in repository_sections:
         repo_type = xml_repo.get_type()
         repo_source = xml_repo.get_source().get_path()
         repo_user = xml_repo.get_username()
         repo_secret = xml_repo.get_password()
         repo_alias = xml_repo.get_alias()
         repo_priority = xml_repo.get_priority()
         repo_dist = xml_repo.get_distribution()
         repo_components = xml_repo.get_components()
         repo_repository_gpgcheck = xml_repo.get_repository_gpgcheck()
         repo_package_gpgcheck = xml_repo.get_package_gpgcheck()
         uri = Uri(repo_source, repo_type)
         repo_source_translated = uri.translate(
             check_build_environment=False)
         if not repo_alias:
             repo_alias = uri.alias()
         log.info('Setting up image repository %s', repo_source)
         log.info('--> Type: %s', repo_type)
         log.info('--> Translated: %s', repo_source_translated)
         log.info('--> Alias: %s', repo_alias)
         repo.add_repo(repo_alias, repo_source_translated, repo_type,
                       repo_priority, repo_dist, repo_components, repo_user,
                       repo_secret, uri.credentials_file_name(),
                       repo_repository_gpgcheck, repo_package_gpgcheck)
Example #6
0
    def setup_repositories(self, clear_cache=False, signing_keys=None):
        """
        Set up repositories for software installation and return a
        package manager for performing software installation tasks

        :param bool clear_cache: flag the clear cache before configure
            anything
        :param list signing_keys: keys imported to the package manager

        :return: instance of :class:`PackageManager`

        :rtype: PackageManager
        """
        repository_options = []
        repository_sections = \
            self.xml_state.get_repository_sections_used_for_build()
        package_manager = self.xml_state.get_package_manager()
        rpm_locale_list = self.xml_state.get_rpm_locale()
        if self.xml_state.get_rpm_check_signatures():
            repository_options.append('check_signatures')
        if self.xml_state.get_rpm_excludedocs():
            repository_options.append('exclude_docs')
        if rpm_locale_list:
            repository_options.append(
                '_install_langs%{0}'.format(':'.join(rpm_locale_list))
            )
        repo = Repository.new(
            self.root_bind, package_manager, repository_options
        )
        repo.setup_package_database_configuration()
        if signing_keys:
            repo.import_trusted_keys(signing_keys)
        for xml_repo in repository_sections:
            repo_type = xml_repo.get_type()
            repo_source = xml_repo.get_source().get_path()
            repo_user = xml_repo.get_username()
            repo_secret = xml_repo.get_password()
            repo_alias = xml_repo.get_alias()
            repo_priority = xml_repo.get_priority()
            repo_dist = xml_repo.get_distribution()
            repo_components = xml_repo.get_components()
            repo_repository_gpgcheck = xml_repo.get_repository_gpgcheck()
            repo_package_gpgcheck = xml_repo.get_package_gpgcheck()
            repo_sourcetype = xml_repo.get_sourcetype()
            repo_use_for_bootstrap = \
                True if xml_repo.get_use_for_bootstrap() else False
            log.info('Setting up repository %s', repo_source)
            log.info('--> Type: {0}'.format(repo_type))
            if repo_sourcetype:
                log.info('--> SourceType: {0}'.format(repo_sourcetype))
            if repo_priority:
                log.info('--> Priority: {0}'.format(repo_priority))

            uri = Uri(repo_source, repo_type)
            repo_source_translated = uri.translate()
            log.info('--> Translated: {0}'.format(repo_source_translated))
            if not repo_alias:
                repo_alias = uri.alias()
            log.info('--> Alias: {0}'.format(repo_alias))

            if not uri.is_remote() and not os.path.exists(
                repo_source_translated
            ):
                log.warning(
                    'repository %s does not exist and will be skipped',
                    repo_source
                )
                continue

            if not uri.is_remote():
                self.root_bind.mount_shared_directory(repo_source_translated)

            repo.add_repo(
                repo_alias, repo_source_translated,
                repo_type, repo_priority, repo_dist, repo_components,
                repo_user, repo_secret, uri.credentials_file_name(),
                repo_repository_gpgcheck, repo_package_gpgcheck,
                repo_sourcetype, repo_use_for_bootstrap
            )
            if clear_cache:
                repo.delete_repo_cache(repo_alias)
            self.uri_list.append(uri)
        repo.cleanup_unused_repos()
        return PackageManager.new(
            repo, package_manager
        )
Example #7
0
 def test_repository_apt(self, mock_manager):
     root_bind = mock.Mock()
     Repository(root_bind, 'apt-get')
     mock_manager.assert_called_once_with(root_bind, None)
Example #8
0
 def test_repository_zypper(self, mock_manager):
     root_bind = mock.Mock()
     Repository(root_bind, 'zypper')
     mock_manager.assert_called_once_with(root_bind, None)
Example #9
0
 def test_repository_manager_not_implemented(self):
     Repository('root_bind', 'ms-manager')
Example #10
0
 def test_repository_manager_not_implemented(self):
     with raises(KiwiRepositorySetupError):
         Repository.new('root_bind', 'ms-manager')
Example #11
0
 def test_repository_pacman(self, mock_manager):
     root_bind = mock.Mock()
     Repository.new(root_bind, 'pacman')
     mock_manager.assert_called_once_with(root_bind, None)
Example #12
0
 def test_repository_microdnf(self, mock_manager):
     root_bind = mock.Mock()
     Repository.new(root_bind, 'microdnf')
     mock_manager.assert_called_once_with(root_bind, None)
Example #13
0
    def setup_repositories(self, clear_cache=False, signing_keys=None):
        """
        Set up repositories for software installation and return a
        package manager for performing software installation tasks

        :param bool clear_cache: flag the clear cache before configure
            anything
        :param list signing_keys: keys imported to the package manager

        :return: instance of :class:`PackageManager`

        :rtype: PackageManager
        """
        repository_options = []
        repository_sections = \
            self.xml_state.get_repository_sections_used_for_build()
        package_manager = self.xml_state.get_package_manager()
        if self.xml_state.get_rpm_check_signatures():
            repository_options.append('check_signatures')
        if self.xml_state.get_rpm_excludedocs():
            repository_options.append('exclude_docs')
        repo = Repository(
            self.root_bind, package_manager, repository_options
        )
        if signing_keys:
            repo.import_trusted_keys(signing_keys)
        for xml_repo in repository_sections:
            repo_type = xml_repo.get_type()
            repo_source = xml_repo.get_source().get_path()
            repo_user = xml_repo.get_username()
            repo_secret = xml_repo.get_password()
            repo_alias = xml_repo.get_alias()
            repo_priority = xml_repo.get_priority()
            repo_dist = xml_repo.get_distribution()
            repo_components = xml_repo.get_components()
            repo_repository_gpgcheck = xml_repo.get_repository_gpgcheck()
            repo_package_gpgcheck = xml_repo.get_package_gpgcheck()
            log.info('Setting up repository %s', repo_source)
            log.info('--> Type: %s', repo_type)
            if repo_priority:
                log.info('--> Priority: %s', repo_priority)

            uri = Uri(repo_source, repo_type)
            repo_source_translated = uri.translate()
            log.info('--> Translated: %s', repo_source_translated)
            if not repo_alias:
                repo_alias = uri.alias()
            log.info('--> Alias: %s', repo_alias)

            if not uri.is_remote() and not os.path.exists(
                repo_source_translated
            ):
                log.warning(
                    'repository %s does not exist and will be skipped',
                    repo_source
                )
                continue

            if not uri.is_remote():
                self.root_bind.mount_shared_directory(repo_source_translated)

            repo.add_repo(
                repo_alias, repo_source_translated,
                repo_type, repo_priority, repo_dist, repo_components,
                repo_user, repo_secret, uri.credentials_file_name(),
                repo_repository_gpgcheck, repo_package_gpgcheck
            )
            if clear_cache:
                repo.delete_repo_cache(repo_alias)
            self.uri_list.append(uri)
        repo.cleanup_unused_repos()
        return PackageManager(
            repo, package_manager
        )