Beispiel #1
0
def _gen_repofile(rfile, data=None):
    if data is None:
        data = [
            _gen_repo("{}-{}".format(rfile.split("/")[-1], i))
            for i in range(3)
        ]
    return RepositoryFile(file=rfile, data=data)
def _get_repositories():
    def asbool(x):
        return x == '1'

    @aslist
    def _parse(r):
        with open(r, mode='r') as fp:
            cp = configparser.ConfigParser()
            cp.readfp(fp)
            for section in cp.sections():
                prepared = {'repoid': section, 'additional_fields': {}}
                data = dict(cp.items(section))
                for key in data.keys():
                    if key in RepositoryData.fields:
                        if isinstance(RepositoryData.fields[key],
                                      fields.Boolean):
                            data[key] = asbool(data[key])
                        prepared[key] = data[key]
                    else:
                        prepared['additional_fields'][key] = data[key]
                prepared['additional_fields'] = json.dumps(
                    prepared['additional_fields'])
                yield RepositoryData(**prepared)

    repos = run(['find', '/etc/yum.repos.d/', '-type', 'f', '-name', '*.repo'],
                split=True)['stdout']
    for repo in repos:
        yield RepositoryFile(file=repo, data=_parse(repo))
def test_repos_mapping(current_actor_context):
    repos_data = [
        RepositoryData(repoid='rhel-7-server-rpms', name='RHEL 7 Server')
    ]
    repos_files = [
        RepositoryFile(file='/etc/yum.repos.d/redhat.repo', data=repos_data)
    ]
    facts = RepositoriesFacts(repositories=repos_files)

    mapping = [
        RepositoryMap(from_id='rhel-7-server-rpms',
                      to_id='rhel-8-for-x86_64-baseos-htb-rpms',
                      from_minor_version='all',
                      to_minor_version='all',
                      arch='x86_64',
                      repo_type='rpm'),
        RepositoryMap(from_id='rhel-7-server-rpms',
                      to_id='rhel-8-for-x86_64-appstream-htb-rpms',
                      from_minor_version='all',
                      to_minor_version='all',
                      arch='x86_64',
                      repo_type='rpm')
    ]
    repos_map = RepositoriesMap(repositories=mapping)

    current_actor_context.feed(facts)
    current_actor_context.feed(repos_map)
    current_actor_context.run()
    assert current_actor_context.consume(TargetRepositories)
    assert len(
        current_actor_context.consume(TargetRepositories)[0].rhel_repos) == 2
Beispiel #4
0
def get_repo_files(repoids, enabled=True):
    files = []
    for i, repo in enumerate(repoids):
        files.append(
            RepositoryFile(file='/etc/yum.d/sample{}.repo'.format(i),
                           data=get_repo_data([repo])))
    return files
def test_all_target_optionals_blacklisted_when_no_optional_on_source(
        monkeypatch, repomap_opts_only):
    """
    Tests whether every target optional repository gets blacklisted
    if no optional repositories are used on the source system.
    """

    repos_data = [
        RepositoryData(
            repoid="rhel-7-server-rpms",
            name="RHEL 7 Server",
            enabled=True,
        )
    ]
    repos_files = [
        RepositoryFile(file="/etc/yum.repos.d/redhat.repo", data=repos_data)
    ]
    repo_facts = RepositoriesFacts(repositories=repos_files)

    monkeypatch.setattr(
        api, 'current_actor',
        CurrentActorMocked(msgs=[repo_facts, repomap_opts_only]))
    monkeypatch.setattr(api, 'produce', produce_mocked())
    monkeypatch.setattr(reporting, 'create_report', produce_mocked())

    repositoriesblacklist.process()

    assert api.produce.called
    assert 'codeready-builder-for-rhel-8-x86_64-rpms' in api.produce.model_instances[
        0].repoids
 def repositories_mock(*model):
     repos_data = [
         RepositoryData(repoid='rhel-7-optional-rpms', name='RHEL 7 Server')
     ]
     repos_files = [
         RepositoryFile(file='/etc/yum.repos.d/redhat.repo',
                        data=repos_data)
     ]
     yield RepositoriesFacts(repositories=repos_files)
Beispiel #7
0
def get_repo_facts(repoids, enabled=True, multiple_files=False):
    if multiple_files:
        repos = get_repo_files(repoids, enabled=enabled)
    else:
        repos = [
            RepositoryFile(file='/etc/yum.d/sample.repo',
                           data=get_repo_data(repoids, enabled))
        ]
    return RepositoriesFacts(repositories=repos)
def test_repos_mapping(current_actor_context):
    repos_data = [
        RepositoryData(repoid='rhel-7-server-rpms', name='RHEL 7 Server'),
        RepositoryData(repoid='rhel-7-blacklisted-rpms',
                       name='RHEL 7 Blacklisted')
    ]
    repos_files = [
        RepositoryFile(file='/etc/yum.repos.d/redhat.repo', data=repos_data)
    ]
    facts = RepositoriesFacts(repositories=repos_files)
    arch = stdlib.run(['uname', '-m'])['stdout'].strip()

    mapping = [
        RepositoryMap(from_repoid='rhel-7-server-rpms',
                      to_repoid='rhel-8-for-{}-baseos-htb-rpms'.format(arch),
                      to_pes_repo='rhel8-baseos',
                      from_minor_version='all',
                      to_minor_version='all',
                      arch=arch,
                      repo_type='rpm'),
        RepositoryMap(
            from_repoid='rhel-7-server-rpms',
            to_repoid='rhel-8-for-{}-appstream-htb-rpms'.format(arch),
            to_pes_repo='rhel8-appstream',
            from_minor_version='all',
            to_minor_version='all',
            arch=arch,
            repo_type='rpm'),
        RepositoryMap(from_repoid='rhel-7-blacklist-rpms',
                      to_repoid='rhel-8-blacklist-rpms',
                      to_pes_repo='rhel8-blacklist',
                      from_minor_version='all',
                      to_minor_version='all',
                      arch=arch,
                      repo_type='rpm')
    ]
    repos_map = RepositoriesMap(repositories=mapping)

    repos_blacklisted = RepositoriesBlacklisted(
        repoids=['rhel-8-blacklisted-rpms'])

    current_actor_context.feed(facts)
    current_actor_context.feed(repos_map)
    current_actor_context.feed(repos_blacklisted)
    current_actor_context.run()
    assert current_actor_context.consume(TargetRepositories)

    rhel_repos = current_actor_context.consume(
        TargetRepositories)[0].rhel_repos
    assert len(rhel_repos) == 2
    assert {repo.repoid
            for repo in rhel_repos} == {
                'rhel-8-for-x86_64-baseos-htb-rpms',
                'rhel-8-for-x86_64-appstream-htb-rpms'
            }
def repofacts_opts_disabled():
    repos_data = [
        RepositoryData(
            repoid="rhel-7-server-optional-rpms",
            name="RHEL 7 Server",
            enabled=False,
        )
    ]
    repos_files = [
        RepositoryFile(file="/etc/yum.repos.d/redhat.repo", data=repos_data)
    ]
    return RepositoriesFacts(repositories=repos_files)
Beispiel #10
0
def parse_repofile(repofile):
    """
    Parse the given repo file.

    :param repofile: Path to the repo file
    :type repofile: str
    :rtype: RepositoryFile
    """
    data = []
    with open(repofile, mode='r') as fp:
        cp = utils.parse_config(fp, strict=False)
        for repoid in cp.sections():
            data.append(_parse_repository(repoid, dict(cp.items(repoid))))
    return RepositoryFile(file=repofile, data=data)
def test_unit_localreposinhibit(current_actor_context, baseurl, mirrorlist, metalink, exp_msgs_len):
    """Ensure the Report is generated when local path is used as a baseurl.

    :type current_actor_context: ActorContext
    """
    with pytest.deprecated_call():
        current_actor_context.feed(
            TMPTargetRepositoriesFacts(
                repositories=[
                    RepositoryFile(
                        file="the/path/to/some/file",
                        data=[
                            RepositoryData(
                                name="BASEOS",
                                baseurl=(
                                    "http://example.com/path/to/repo/BaseOS/x86_64/os/"
                                ),
                                repoid="BASEOS",
                            ),
                            RepositoryData(
                                name="APPSTREAM",
                                baseurl=(
                                    "http://example.com/path/to/repo/AppStream/x86_64/os/"
                                ),
                                repoid="APPSTREAM",
                            ),
                            RepositoryData(
                                name="CRB", repoid="CRB", baseurl=baseurl,
                                mirrorlist=mirrorlist, metalink=metalink
                            ),
                        ],
                    )
                ]
            )
        )
    current_actor_context.feed(
        UsedTargetRepositories(
            repos=[
                UsedTargetRepository(repoid="BASEOS"),
                UsedTargetRepository(repoid="CRB"),
            ]
        )
    )
    current_actor_context.run()
    assert len(current_actor_context.messages()) == exp_msgs_len
def test_enablerepo_option(monkeypatch, enabled_repo, exp_report_title, message_produced):
    repos_data = [
        RepositoryData(
            repoid="rhel-7-server-optional-rpms",
            name="RHEL 7 Server",
            enabled=False,
        )
    ]
    repos_files = [
        RepositoryFile(file="/etc/yum.repos.d/redhat.repo", data=repos_data)
    ]
    msgs_to_feed = [
            RepositoriesMap(
                repositories=(
                    [
                        RepositoryMap(
                            to_pes_repo="rhel-7-server-optional-rpms",
                            from_repoid="rhel-7-server-optional-rpms",
                            to_repoid="codeready-builder-for-rhel-8-x86_64-rpms",
                            from_minor_version="all",
                            to_minor_version="all",
                            arch="x86_64",
                            repo_type="rpm",
                        ),
                    ]
                )
            ),
            RepositoriesFacts(repositories=repos_files),
    ]

    if enabled_repo:
        msgs_to_feed.append(CustomTargetRepository(repoid=enabled_repo))
    monkeypatch.setattr(api, 'current_actor', CurrentActorMocked(msgs=msgs_to_feed))
    monkeypatch.setattr(api, 'produce', produce_mocked())
    monkeypatch.setattr(reporting, 'create_report', create_report_mocked())
    repositoriesblacklist.process()
    assert reporting.create_report.report_fields["title"] == exp_report_title
    if message_produced:
        assert isinstance(api.produce.model_instances[0], RepositoriesBlacklisted)
    else:
        assert not api.produce.model_instances
def get_sample_repository(repoid, name):
    return RepositoryFile(
        file='/etc/yum.d/sample.repo',
        data=[RepositoryData(repoid=repoid, name=name, enabled=True)])
def test_repos_mapping(monkeypatch):
    """
    Tests whether actor correctly determines what repositories should be enabled on target based
    on the information about what repositories are enabled on the source system using
    the RepositoriesMapping information.
    """
    repos_data = [
        RepositoryData(repoid='rhel-7-server-rpms', name='RHEL 7 Server'),
        RepositoryData(repoid='rhel-7-blacklisted-rpms',
                       name='RHEL 7 Blacklisted')
    ]

    repos_files = [
        RepositoryFile(file='/etc/yum.repos.d/redhat.repo', data=repos_data)
    ]
    facts = RepositoriesFacts(repositories=repos_files)

    repomap = RepositoriesMapping(
        mapping=[
            RepoMapEntry(
                source='rhel7-base',
                target=['rhel8-baseos', 'rhel8-appstream', 'rhel8-blacklist'])
        ],
        repositories=[
            PESIDRepositoryEntry(pesid='rhel7-base',
                                 repoid='rhel-7-server-rpms',
                                 major_version='7',
                                 arch='x86_64',
                                 repo_type='rpm',
                                 channel='ga',
                                 rhui=''),
            PESIDRepositoryEntry(pesid='rhel8-baseos',
                                 repoid='rhel-8-for-x86_64-baseos-htb-rpms',
                                 major_version='8',
                                 arch='x86_64',
                                 repo_type='rpm',
                                 channel='ga',
                                 rhui=''),
            PESIDRepositoryEntry(pesid='rhel8-appstream',
                                 repoid='rhel-8-for-x86_64-appstream-htb-rpms',
                                 major_version='8',
                                 arch='x86_64',
                                 repo_type='rpm',
                                 channel='ga',
                                 rhui=''),
            PESIDRepositoryEntry(pesid='rhel8-blacklist',
                                 repoid='rhel-8-blacklisted-rpms',
                                 major_version='8',
                                 arch='x86_64',
                                 repo_type='rpm',
                                 channel='ga',
                                 rhui=''),
        ])

    repos_blacklisted = RepositoriesBlacklisted(
        repoids=['rhel-8-blacklisted-rpms'])

    msgs = [facts, repomap, repos_blacklisted]

    monkeypatch.setattr(api, 'current_actor', CurrentActorMocked(msgs=msgs))
    monkeypatch.setattr(api, 'produce', produce_mocked())

    setuptargetrepos.process()
    assert api.produce.called

    rhel_repos = api.produce.model_instances[0].rhel_repos
    assert len(rhel_repos) == 2

    produced_rhel_repoids = {repo.repoid for repo in rhel_repos}
    expected_rhel_repoids = {
        'rhel-8-for-x86_64-baseos-htb-rpms',
        'rhel-8-for-x86_64-appstream-htb-rpms'
    }
    assert produced_rhel_repoids == expected_rhel_repoids
 def _mocked_parse_repofile(fpath):
     return RepositoryFile(file=fpath, data=[])