Esempio n. 1
0
    def test_convert_repo_origin(self):
        """Test the conversion of the repo origin."""
        ks_repo = RepoData()
        ks_repo.name = "repo-name"

        # Test the system origin.
        repo_data = convert_ks_repo_to_repo_data(ks_repo)
        assert repo_data.origin == REPO_ORIGIN_SYSTEM

        ks_repo = convert_repo_data_to_ks_repo(repo_data)
        assert ks_repo.treeinfo_origin is False

        # Test the user origin.
        ks_repo.baseurl = "http://url"

        repo_data = convert_ks_repo_to_repo_data(ks_repo)
        assert repo_data.origin == REPO_ORIGIN_USER

        ks_repo = convert_repo_data_to_ks_repo(repo_data)
        assert ks_repo.treeinfo_origin is False

        # Test the treeinfo origin.
        ks_repo.treeinfo_origin = True

        repo_data = convert_ks_repo_to_repo_data(ks_repo)
        assert repo_data.origin == REPO_ORIGIN_TREEINFO

        ks_repo = convert_repo_data_to_ks_repo(repo_data)
        assert ks_repo.treeinfo_origin is True
Esempio n. 2
0
    def test_convert_repo_enabled(self):
        """Test the conversion of the enabled attribute."""
        ks_repo = RepoData()
        repo_data = convert_ks_repo_to_repo_data(ks_repo)
        assert repo_data.enabled is True

        ks_repo = convert_repo_data_to_ks_repo(repo_data)
        assert ks_repo.enabled is True

        ks_repo.enabled = False
        repo_data = convert_ks_repo_to_repo_data(ks_repo)
        assert repo_data.enabled is False

        ks_repo = convert_repo_data_to_ks_repo(repo_data)
        assert ks_repo.enabled is False
Esempio n. 3
0
    def _load_treeinfo_repositories(self, base_repo_url, repo_names_to_disable,
                                    data):
        """Load new repositories from treeinfo file.

        :param base_repo_url: base repository url. This is not saved anywhere when the function
                              is called. It will be add to the existing urls if not None.
        :param repo_names_to_disable: list of repository names which should be disabled after load
        :type repo_names_to_disable: [str]
        :param data: repo configuration data
        """
        if self._install_tree_metadata:
            existing_urls = []

            if base_repo_url is not None:
                existing_urls.append(base_repo_url)

            for ks_repo in self.data.repo.dataList():
                baseurl = ks_repo.baseurl
                existing_urls.append(baseurl)

            enabled_repositories_from_treeinfo = conf.payload.enabled_repositories_from_treeinfo

            for repo_md in self._install_tree_metadata.get_metadata_repos():
                if repo_md.path not in existing_urls:
                    repo_treeinfo = self._install_tree_metadata.get_treeinfo_for(
                        repo_md.name)

                    # disable repositories disabled by user manually before
                    if repo_md.name in repo_names_to_disable:
                        repo_enabled = False
                    else:
                        repo_enabled = repo_treeinfo.type in enabled_repositories_from_treeinfo

                    repo = RepoData(
                        name=repo_md.name,
                        baseurl=repo_md.path,
                        noverifyssl=not data.ssl_verification_enabled,
                        proxy=data.proxy,
                        sslcacert=data.ssl_configuration.ca_cert_path,
                        sslclientcert=data.ssl_configuration.client_cert_path,
                        sslclientkey=data.ssl_configuration.client_key_path,
                        install=False,
                        enabled=repo_enabled)
                    repo.treeinfo_origin = True
                    log.debug("Adding new treeinfo repository: %s enabled: %s",
                              repo_md.name, repo_enabled)

                    self._add_repo_to_dnf_and_ks(repo)
Esempio n. 4
0
    def add_additional_repositories_to_ksdata(self):
        from pyanaconda.kickstart import RepoData

        for add_repo in self.additional_repos:
            name, repo_url = self._get_additional_repo_name(add_repo)
            try:
                source = SourceFactory.parse_repo_cmdline_string(repo_url)
            except PayloadSourceTypeUnrecognized:
                log.error(
                    "Type for additional repository %s is not recognized!",
                    add_repo)
                return

            repo = RepoData(name=name, baseurl=repo_url, install=False)

            if source.is_nfs or source.is_http or source.is_https or source.is_ftp \
                    or source.is_file:
                repo.enabled = True
            elif source.is_harddrive:
                repo.enabled = True
                repo.partition = source.partition
                repo.iso_path = source.path
                repo.baseurl = "file://"
            else:
                log.error(
                    "Source type %s for additional repository %s is not supported!",
                    source.source_type.value, add_repo)
                continue

            self._check_repo_name_uniqueness(repo)
            self.ksdata.repo.dataList().append(repo)
Esempio n. 5
0
    def add_additional_repositories_to_ksdata(self):
        from pyanaconda.kickstart import RepoData

        for add_repo in self.additional_repos:
            name, repo_url = self._get_additional_repo_name(add_repo)
            try:
                source = SourceFactory.parse_repo_cmdline_string(repo_url)
            except PayloadSourceTypeUnrecognized:
                log.error("Type for additional repository %s is not recognized!", add_repo)
                return

            repo = RepoData(name=name, baseurl=repo_url, install=False)

            if source.is_nfs or source.is_http or source.is_https or source.is_ftp \
                    or source.is_file:
                repo.enabled = True
            elif source.is_harddrive:
                repo.enabled = True
                repo.partition = source.partition
                repo.iso_path = source.path
                repo.baseurl = "file://"
            else:
                log.error("Source type %s for additional repository %s is not supported!",
                          source.source_type.value, add_repo)
                continue

            self._check_repo_name_uniqueness(repo)
            self.ksdata.repo.dataList().append(repo)
Esempio n. 6
0
    def configurePayload(self, payload):  # pylint: disable=line-too-long
        '''
            Load SL specific payload repos
        '''
        if isinstance(payload, PackagePayload):
            major_version = productVersion.replace('rolling', '').split('.')[0]

            # A number of users like EPEL, seed it disabled
            payload.addDisabledRepo(
                RepoData(
                    name='epel',
                    metalink=
                    "https://mirrors.fedoraproject.org/metalink?repo=epel-" +
                    major_version + "&arch=" + productArch))
            # ELRepo provides handy hardware drivers, seed it disabled
            payload.addDisabledRepo(
                RepoData(
                    name='elrepo',
                    mirrorlist="http://mirrors.elrepo.org/mirrors-elrepo.el" +
                    major_version))

        super().configurePayload(payload)
Esempio n. 7
0
def convert_repo_data_to_ks_repo(repo_data):
    """Convert the repo configuration into a kickstart command.

    :param RepoConfigurationData repo_data: a repo configuration
    :return RepoData: a kickstart data
    """
    if not isinstance(repo_data, RepoConfigurationData):
        raise ValueError("Unexpected data: {}".format(type(repo_data)))

    ks_data = RepoData()
    ks_data.name = repo_data.name
    ks_data.enabled = repo_data.enabled

    if repo_data.type == URL_TYPE_BASEURL:
        ks_data.baseurl = repo_data.url
    elif repo_data.type == URL_TYPE_MIRRORLIST:
        ks_data.mirrorlist = repo_data.url
    elif repo_data.type == URL_TYPE_METALINK:
        ks_data.metalink = repo_data.url

    ks_data.proxy = repo_data.proxy
    ks_data.noverifyssl = not repo_data.ssl_verification_enabled
    ks_data.sslcacert = repo_data.ssl_configuration.ca_cert_path
    ks_data.sslclientcert = repo_data.ssl_configuration.client_cert_path
    ks_data.sslclientkey = repo_data.ssl_configuration.client_key_path

    if repo_data.cost != DNF_DEFAULT_REPO_COST:
        ks_data.cost = repo_data.cost

    ks_data.includepkgs = repo_data.included_packages
    ks_data.excludepkgs = repo_data.excluded_packages
    ks_data.install = repo_data.installation_enabled

    return ks_data