def test_custom_repos(current_actor_context):
    custom = CustomTargetRepository(
        repoid='rhel-8-server-rpms',
        name='RHEL 8 Server (RPMs)',
        baseurl='https://.../dist/rhel/server/8/os',
        enabled=True)

    blacklisted = CustomTargetRepository(
        repoid='rhel-8-blacklisted-rpms',
        name='RHEL 8 Blacklisted (RPMs)',
        baseurl='https://.../dist/rhel/blacklisted/8/os',
        enabled=True)

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

    current_actor_context.feed(custom)
    current_actor_context.feed(blacklisted)
    current_actor_context.feed(repos_blacklisted)
    current_actor_context.run()

    assert current_actor_context.consume(TargetRepositories)

    custom_repos = current_actor_context.consume(
        TargetRepositories)[0].custom_repos
    assert len(custom_repos) == 1
    assert custom_repos[0].repoid == 'rhel-8-server-rpms'
def test_custom_repos(monkeypatch):
    """
    Tests whether the CustomRepos provided to the actor are propagated to the TargetRepositories after
    blacklist filtering is applied on them.
    """
    custom = CustomTargetRepository(
        repoid='rhel-8-server-rpms',
        name='RHEL 8 Server (RPMs)',
        baseurl='https://.../dist/rhel/server/8/os',
        enabled=True)

    blacklisted = CustomTargetRepository(
        repoid='rhel-8-blacklisted-rpms',
        name='RHEL 8 Blacklisted (RPMs)',
        baseurl='https://.../dist/rhel/blacklisted/8/os',
        enabled=True)

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

    repositories_mapping = RepositoriesMapping(mapping=[], repositories=[])

    msgs = [custom, blacklisted, repos_blacklisted, repositories_mapping]

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

    setuptargetrepos.process()

    assert api.produce.called

    custom_repos = api.produce.model_instances[0].custom_repos
    assert len(custom_repos) == 1
    assert custom_repos[0].repoid == 'rhel-8-server-rpms'
def process():
    """
    Produce CustomTargetRepository msgs for the custom repo file if the file
    exists.

    The CustomTargetRepository msg is produced for every repository inside
    the <CUSTOM_REPO_PATH> file.
    """
    if not os.path.isfile(CUSTOM_REPO_PATH):
        api.current_logger().debug(
            "The {} file doesn't exist. Nothing to do.".format(
                CUSTOM_REPO_PATH))
        return
    api.current_logger().info("The {} file exists.".format(CUSTOM_REPO_PATH))
    repofile = repofileutils.parse_repofile(CUSTOM_REPO_PATH)
    if not repofile.data:
        return
    api.produce(CustomTargetRepositoryFile(file=CUSTOM_REPO_PATH))
    for repo in repofile.data:
        api.produce(
            CustomTargetRepository(
                repoid=repo.repoid,
                name=repo.name,
                baseurl=repo.baseurl,
                enabled=repo.enabled,
            ))
示例#4
0
def test_custom_repos(current_actor_context):
    custom = CustomTargetRepository(uid='rhel-8-server-rpms',
                                    name='RHEL 8 Server (RPMs)',
                                    baseurl='https://.../dist/rhel/server/8/os',
                                    enabled=True)
    
    current_actor_context.feed(custom)
    current_actor_context.run()
    assert current_actor_context.consume(TargetRepositories)
    assert len(current_actor_context.consume(TargetRepositories)[0].custom_repos) == 1
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
        return self


def test_no_enabledrepos(monkeypatch):
    monkeypatch.setattr(api, 'produce', produce_mocked())
    monkeypatch.setattr(api, 'current_logger', LoggerMocked())
    monkeypatch.setattr(api, 'current_actor', CurrentActorMocked())
    scanclienablerepo.process()
    assert not api.current_logger.infomsg
    assert not api.produce.called


@pytest.mark.parametrize('envars,result', [
    ({
        'LEAPP_ENABLE_REPOS': 'repo1'
    }, [CustomTargetRepository(repoid='repo1')]),
    ({
        'LEAPP_ENABLE_REPOS': 'repo1,repo2'
    }, [
        CustomTargetRepository(repoid='repo1'),
        CustomTargetRepository(repoid='repo2')
    ]),
])
def test_enabledrepos(monkeypatch, envars, result):
    monkeypatch.setattr(api, 'produce', produce_mocked())
    monkeypatch.setattr(api, 'current_logger', LoggerMocked())
    monkeypatch.setattr(api, 'current_actor',
                        CurrentActorMocked(envars=envars))
    scanclienablerepo.process()
    assert api.current_logger.infomsg
    assert api.produce.called == len(result)
示例#8
0
                self._msgs.append(arg)

    def __call__(self, model):
        return iter([msg for msg in self._msgs if isinstance(msg, model)])


_RHEL_REPOS = [
    RHELTargetRepository(repoid='repo1'),
    RHELTargetRepository(repoid='repo2'),
    RHELTargetRepository(repoid='repo3'),
    RHELTargetRepository(repoid='repo4'),
]

_CUSTOM_REPOS = [
    CustomTargetRepository(repoid='repo1',
                           name='repo1name',
                           baseurl='repo1url',
                           enabled=True),
    CustomTargetRepository(repoid='repo2',
                           name='repo2name',
                           baseurl='repo2url',
                           enabled=False),
    CustomTargetRepository(repoid='repo3',
                           name='repo3name',
                           baseurl=None,
                           enabled=True),
    CustomTargetRepository(repoid='repo4',
                           name='repo4name',
                           baseurl=None,
                           enabled=True),
]
                   baseurl="repo1url",
                   enabled=True),
    RepositoryData(repoid="repo2",
                   name="repo2name",
                   baseurl="repo2url",
                   enabled=False),
    RepositoryData(repoid="repo3", name="repo3name", enabled=True),
    RepositoryData(repoid="repo4",
                   name="repo4name",
                   mirrorlist="mirror4list",
                   enabled=True),
]

_CUSTOM_REPOS = [
    CustomTargetRepository(repoid="repo1",
                           name="repo1name",
                           baseurl="repo1url",
                           enabled=True),
    CustomTargetRepository(repoid="repo2",
                           name="repo2name",
                           baseurl="repo2url",
                           enabled=False),
    CustomTargetRepository(repoid="repo3",
                           name="repo3name",
                           baseurl=None,
                           enabled=True),
    CustomTargetRepository(repoid="repo4",
                           name="repo4name",
                           baseurl=None,
                           enabled=True),
]
示例#10
0
def process():
    if not config.get_env('LEAPP_ENABLE_REPOS'):
        return
    api.current_logger().info('The --enablerepo option has been used,')
    for repoid in config.get_env('LEAPP_ENABLE_REPOS').split(','):
        api.produce(CustomTargetRepository(repoid=repoid))