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 test_repositoriesblacklist_empty(monkeypatch):
    monkeypatch.setattr(repositoriesblacklist, "_get_repos_to_exclude", lambda: set())  # pylint:disable=W0108
    monkeypatch.setattr(api, 'current_actor', CurrentActorMocked())
    monkeypatch.setattr(api, "produce", produce_mocked())

    repositoriesblacklist.process()
    assert api.produce.called == 0
def test_repositoriesblacklist_empty(monkeypatch):
    monkeypatch.setattr(repositoriesblacklist, "_get_disabled_optional_repo", lambda: [])
    monkeypatch.setattr(api, 'current_actor', CurrentActorMocked())
    monkeypatch.setattr(api, "produce", produce_mocked())

    repositoriesblacklist.process()
    assert api.produce.called == 0
def test_repositoriesblacklist_not_empty(monkeypatch):
    name = 'test'
    monkeypatch.setattr(repositoriesblacklist, "_get_disabled_optional_repo", lambda: [name])
    monkeypatch.setattr(api, "produce", produce_mocked())
    monkeypatch.setattr(reporting, "create_report", produce_mocked())

    repositoriesblacklist.process()
    assert api.produce.called == 1
    assert isinstance(api.produce.model_instances[0], RepositoriesBlacklisted)
    assert api.produce.model_instances[0].repoids[0] == name
    assert reporting.create_report.called == 1
def test_repositoriesblacklist_not_empty(monkeypatch):
    name = 'test'
    monkeypatch.setattr(repositoriesblacklist, "_get_repos_to_exclude", lambda: {name})
    monkeypatch.setattr(api, 'current_actor', CurrentActorMocked())
    monkeypatch.setattr(api, "produce", produce_mocked())
    monkeypatch.setattr(reporting, "create_report", produce_mocked())

    repositoriesblacklist.process()
    assert api.produce.called == 1
    assert isinstance(api.produce.model_instances[0], RepositoriesBlacklisted)
    assert api.produce.model_instances[0].repoids[0] == name
    assert reporting.create_report.called == 1
def test_with_no_mapping_for_optional_repos(monkeypatch, repomap_opts_only,
                                            repofacts_opts_disabled):
    """
    Tests whether nothing gets produced if no valid target is found for an optional repository in mapping data.
    """

    repomap_opts_only.repositories[1].pesid = 'test_pesid'

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

    repositoriesblacklist.process()

    assert not api.produce.called
def test_repositoriesblacklist_empty(monkeypatch, repofacts_opts_disabled,
                                     repomap_opts_only):
    """
    Tests whether nothing is produced if there are some disabled optional repos, but an empty blacklist is determined
    from the repo mapping data.
    """

    msgs_to_feed = [repofacts_opts_disabled, repomap_opts_only]

    monkeypatch.setattr(api, 'current_actor',
                        CurrentActorMocked(msgs=msgs_to_feed))
    monkeypatch.setattr(repositoriesblacklist, "_get_repoids_to_exclude",
                        lambda dummy_mapping: set())  # pylint:disable=W0108
    monkeypatch.setattr(api, "produce", produce_mocked())

    repositoriesblacklist.process()
    assert api.produce.called == 0
def test_no_blacklist_produced_when_optional_repo_enabled(
        monkeypatch, repofacts_opts_disabled, repomap_opts_only):
    """
    Tests whether nothing is produced when an optional repository is enabled.

    Data are set up in such a fashion so that the determined blacklist would not be empty.
    """

    repofacts_opts_disabled.repositories[0].data[0].enabled = True

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

    repositoriesblacklist.process()

    assert not api.produce.called
def test_repositoriesblacklist_not_empty(monkeypatch, repofacts_opts_disabled,
                                         repomap_opts_only):
    """
    Tests whether a message containing correct packages from the determined blacklist is produced.
    """

    blacklisted_repoid = 'test'
    monkeypatch.setattr(repositoriesblacklist, "_get_repoids_to_exclude",
                        lambda dummy_mapping: {blacklisted_repoid})
    monkeypatch.setattr(
        api, 'current_actor',
        CurrentActorMocked(msgs=[repofacts_opts_disabled, repomap_opts_only]))
    monkeypatch.setattr(api, "produce", produce_mocked())
    monkeypatch.setattr(reporting, "create_report", produce_mocked())

    repositoriesblacklist.process()
    assert api.produce.called == 1
    assert isinstance(api.produce.model_instances[0], RepositoriesBlacklisted)
    assert api.produce.model_instances[0].repoids[0] == blacklisted_repoid
    assert reporting.create_report.called == 1
def test_blacklist_produced_when_optional_repo_disabled(
        monkeypatch, repofacts_opts_disabled, repomap_opts_only):
    """
    Tests whether a correct blacklist is generated when there is disabled optional repo on the system.
    """

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

    repositoriesblacklist.process()

    assert api.produce.model_instances, 'A blacklist should get generated.'

    expected_blacklisted_repoid = 'codeready-builder-for-rhel-8-x86_64-rpms'
    err_msg = 'Blacklist does not contain expected repoid.'
    assert expected_blacklisted_repoid in api.produce.model_instances[
        0].repoids, err_msg
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 test_enablerepo_option(monkeypatch, repofacts_opts_disabled,
                           repomap_opts_only, enabled_repo, exp_report_title,
                           message_produced):
    """
    Tests whether the actor respects CustomTargetRepository messages when constructing the blacklist.
    """

    msgs_to_feed = [repomap_opts_only, repofacts_opts_disabled]

    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
Beispiel #13
0
 def process(self):
     process()
Beispiel #14
0
 def process(self):
     repositoriesblacklist.process()