Ejemplo n.º 1
0
def process_events(events):
    """ Process PES Events and generate Leapp messages """
    to_install = {}
    to_remove = {}

    for event in events:
        to_install.update(event.out_pkgs)

        if event.action not in ('Present', 'Deprecated',
                                'Moved') and event.in_pkgs:
            to_remove.update(event.in_pkgs)

    filter_by_repositories(to_install)
    map_repositories(to_install)

    to_install_pkgs = set(to_install.keys())
    to_remove_pkgs = set(to_remove.keys())

    common = to_install_pkgs.intersection(to_remove_pkgs)
    to_install_pkgs.difference_update(common)
    to_remove_pkgs.difference_update(common)

    if to_install_pkgs or to_remove_pkgs:
        api.produce(
            RpmTransactionTasks(to_install=list(to_install_pkgs),
                                to_remove=list(to_remove_pkgs)))

    to_enable_repos = set(to_install.values())

    if to_enable_repos:
        api.produce(RepositoriesSetupTasks(to_enable=list(to_enable_repos)))
Ejemplo n.º 2
0
def produce_messages(tasks):
    # Type casting to list to be Py2&Py3 compatible as on Py3 keys() returns dict_keys(), not a list
    to_install_pkgs = sorted(tasks[Task.INSTALL].keys())
    to_remove_pkgs = sorted(tasks[Task.REMOVE].keys())
    to_enable_repos = sorted(
        set(tasks[Task.INSTALL].values()) | set(tasks[Task.KEEP].values()))

    if to_install_pkgs or to_remove_pkgs:
        enabled_modules = _get_enabled_modules()
        modules_to_enable = [
            Module(name=p[1][0], stream=p[1][1]) for p in to_install_pkgs
            if p[1]
        ]
        modules_to_reset = enabled_modules
        to_install_pkg_names = [p[0] for p in to_install_pkgs]
        to_remove_pkg_names = [p[0] for p in to_remove_pkgs]

        api.produce(
            PESRpmTransactionTasks(to_install=to_install_pkg_names,
                                   to_remove=to_remove_pkg_names,
                                   modules_to_enable=modules_to_enable,
                                   modules_to_reset=modules_to_reset))

    if to_enable_repos:
        api.produce(RepositoriesSetupTasks(to_enable=to_enable_repos))
def test_repositories_setup_tasks(current_actor_context):
    repositories_setup_tasks = RepositoriesSetupTasks(
        to_enable=['rhel-8-server-rpms'])
    current_actor_context.feed(repositories_setup_tasks)
    current_actor_context.run()
    assert current_actor_context.consume(TargetRepositories)
    assert len(
        current_actor_context.consume(TargetRepositories)[0].rhel_repos) == 1
Ejemplo n.º 4
0
def produce_messages(tasks):
    # Type casting to list to be Py2&Py3 compatible as on Py3 keys() returns dict_keys(), not a list
    to_install_pkgs = sorted(tasks['to_install'].keys())
    to_remove_pkgs = sorted(tasks['to_remove'].keys())
    to_enable_repos = sorted(set(tasks['to_install'].values() + tasks['to_keep'].values()))

    if to_install_pkgs or to_remove_pkgs:
        api.produce(PESRpmTransactionTasks(to_install=to_install_pkgs,
                                           to_remove=to_remove_pkgs))

    if to_enable_repos:
        api.produce(RepositoriesSetupTasks(to_enable=to_enable_repos))
Ejemplo n.º 5
0
def produce_messages(to_install, to_remove):
    to_install_pkgs = set(to_install.keys())
    to_remove_pkgs = set(to_remove.keys())
    to_enable_repos = set(to_install.values())

    if to_install_pkgs or to_remove_pkgs:
        api.produce(
            PESRpmTransactionTasks(to_install=list(to_install_pkgs),
                                   to_remove=list(to_remove_pkgs)))

    if to_enable_repos:
        api.produce(RepositoriesSetupTasks(to_enable=list(to_enable_repos)))
def test_repositories_setup_tasks(current_actor_context):
    repositories_setup_tasks = RepositoriesSetupTasks(
        to_enable=['rhel-8-server-rpms', 'rhel-8-blacklisted-rpms'])

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

    current_actor_context.feed(repositories_setup_tasks)
    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) == 1
    assert rhel_repos[0].repoid == 'rhel-8-server-rpms'
def test_repositories_setup_tasks(monkeypatch):
    """
    Tests whether the actor propagates repositories received via a RepositoriesSetupTasks message
    to the resulting TargetRepositories (and blacklist filtering is applied to them).
    """
    repositories_setup_tasks = RepositoriesSetupTasks(
        to_enable=['rhel-8-server-rpms', 'rhel-8-blacklisted-rpms'])
    repos_blacklisted = RepositoriesBlacklisted(
        repoids=['rhel-8-blacklisted-rpms'])
    repositories_mapping = RepositoriesMapping(mapping=[], repositories=[])
    msgs = [repositories_setup_tasks, repos_blacklisted, repositories_mapping]

    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) == 1
    assert rhel_repos[0].repoid == 'rhel-8-server-rpms'