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
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)
예제 #4
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)
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
예제 #8
0
def get_repositories_status():
    ''' Get a basic information about YUM repositories installed in the system '''
    return RepositoriesFacts(repositories=_get_repositories())
예제 #9
0
def get_repositories_status():
    ''' Get a basic information about YUM repositories installed in the system '''
    return RepositoriesFacts(repositories=repofileutils.get_parsed_repofiles())
def get_sample_repositories(repos):
    return RepositoriesFacts(
        repositories=[get_sample_repository(*r) for r in repos])
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