コード例 #1
0
def test_get_available_repo_ids_error():
    context_mocked = IsolatedActionsMocked(raise_err=True)

    with pytest.raises(StopActorExecutionError) as err:
        rhsm.get_available_repo_ids(context_mocked)

    assert 'Unable to use yum' in str(err)
コード例 #2
0
def test_get_available_repo_ids_error():
    context_mocked = IsolatedActionsMocked(raise_err=True)

    with pytest.raises(StopActorExecutionError) as err:
        rhsm.get_available_repo_ids(context_mocked)

    assert 'Unable to get list of available yum repositories.' in str(err)
    assert "Command ['yum', 'repoinfo'] failed" in err.value.details['details']
コード例 #3
0
def _get_rhsm_available_repoids(context):
    target_major_version = get_target_major_version()
    # FIXME: check that required repo IDs (baseos, appstream)
    # + or check that all required RHEL repo IDs are available.
    if rhsm.skip_rhsm():
        return set()
    # Get the RHSM repos available in the target RHEL container
    # TODO: very similar thing should happens for all other repofiles in container
    #
    repoids = rhsm.get_available_repo_ids(context)
    if not repoids or len(repoids) < 2:
        raise StopActorExecutionError(
            message='Cannot find required basic RHEL {} repositories.'.format(
                target_major_version),
            details={
                'hint':
                ('It is required to have RHEL repositories on the system'
                 ' provided by the subscription-manager unless the --no-rhsm'
                 ' options is specified. Possibly you'
                 ' are missing a valid SKU for the target system or network'
                 ' connection failed. Check whether your system is attached'
                 ' to a valid SKU providing RHEL {} repositories.'
                 ' In case the Satellite is used, read the upgrade documentation'
                 ' to setup the satellite and the system properly.'.format(
                     target_major_version))
            })
    return set(repoids)
コード例 #4
0
def gather_target_repositories(context):
    """
    Perform basic checks on requirements for RHSM repositories and return the list of target repository ids to use
    during the upgrade.

    :param context: An instance of a mounting.IsolatedActions class
    :type context: mounting.IsolatedActions class
    :return: List of target system repoids
    :rtype: List(string)
    """
    # Get the RHSM repos available in the RHEL 8 container
    available_repos = rhsm.get_available_repo_ids(
        context, releasever=api.current_actor().configuration.version.target)

    # FIXME: check that required repo IDs (baseos, appstream)
    # + or check that all required RHEL repo IDs are available.
    if not rhsm.skip_rhsm():
        if not available_repos or len(available_repos) < 2:
            raise StopActorExecutionError(
                message='Cannot find required basic RHEL 8 repositories.',
                details={
                    'hint':
                    ('It is required to have RHEL repositories on the system'
                     ' provided by the subscription-manager. Possibly you'
                     ' are missing a valid SKU for the target system or network'
                     ' connection failed. Check whether your system is attached'
                     ' to a valid SKU providing RHEL 8 repositories.')
                })

    target_repoids = []
    for target_repo in api.consume(TargetRepositories):
        for rhel_repo in target_repo.rhel_repos:
            if rhel_repo.repoid in available_repos:
                target_repoids.append(rhel_repo.repoid)
            else:
                # TODO: We shall report that the RHEL repos that we deem necessary for the upgrade are not available.
                # The StopActorExecutionError called above might be moved here.
                pass
        for custom_repo in target_repo.custom_repos:
            # TODO: complete processing of custom repositories
            # HINT: now it will work only for custom repos that exist
            # + already on the system in a repo file
            # TODO: should check available_target_repoids + additional custom repos
            # + outside of rhsm..
            # #if custom_repo.repoid in available_target_repoids:
            target_repoids.append(custom_repo.repoid)
    api.current_logger().debug("Gathered target repositories: {}".format(
        ', '.join(target_repoids)))
    if not target_repoids:
        raise StopActorExecutionError(
            message=
            'There are no enabled target repositories for the upgrade process to proceed.',
            details={
                'hint':
                ('Ensure your system is correctly registered with the subscription manager and that'
                 ' your current subscription is entitled to install the requested target version {version}'
                 ).format(
                     version=api.current_actor().configuration.version.target)
            })
    return target_repoids
コード例 #5
0
def test_get_available_repo_ids(monkeypatch, releasever, available_repos):
    context_mocked = IsolatedActionsMocked()
    monkeypatch.setattr(rhsm, '_inhibit_on_duplicate_repos', lambda x: None)
    monkeypatch.setattr(rhsm, '_get_repos', lambda x: iter(available_repos))
    monkeypatch.setattr(api, 'current_logger', LoggerMocked())

    available_repos = rhsm.get_available_repo_ids(context_mocked, releasever)

    if releasever:
        assert context_mocked.commands_called == [['yum', 'repoinfo', '--releasever', '8.2']]
    else:
        assert context_mocked.commands_called == [['yum', 'repoinfo']]
    if available_repos:
        available_repoid = 'repoidX'
        assert available_repos == [available_repoid]
        assert api.current_logger.infomsg == (
            'The following repoids are available through RHSM:{0}{1}'
            .format(LIST_SEPARATOR, available_repoid))
    else:
        assert available_repos == []
        assert api.current_logger.infomsg == 'There are no repos available through RHSM.'
コード例 #6
0
def _get_rhsm_available_repoids(context):
    target_major_version = get_target_major_version()
    # FIXME: check that required repo IDs (baseos, appstream)
    # + or check that all required RHEL repo IDs are available.
    if rhsm.skip_rhsm():
        return set()
    # Get the RHSM repos available in the target RHEL container
    # TODO: very similar thing should happens for all other repofiles in container
    #
    repoids = rhsm.get_available_repo_ids(context)
    if not repoids or len(repoids) < 2:
        reporting.create_report([
            reporting.Title(
                'Cannot find required basic RHEL target repositories.'),
            reporting.Summary(
                'This can happen when a repository ID was entered incorrectly either while using the --enablerepo'
                ' option of leapp or in a third party actor that produces a CustomTargetRepositoryMessage.'
            ),
            reporting.Tags([reporting.Tags.REPOSITORY]),
            reporting.Severity(reporting.Severity.HIGH),
            reporting.Flags([reporting.Flags.INHIBITOR]),
            reporting.Remediation(hint=(
                'It is required to have RHEL repositories on the system'
                ' provided by the subscription-manager unless the --no-rhsm'
                ' option is specified. You might be missing a valid SKU for'
                ' the target system or have a failed network connection.'
                ' Check whether your system is attached to a valid SKU that is'
                ' providing RHEL {} repositories.'
                ' If you are using Red Hat Satellite, read the upgrade documentation'
                ' to set up Satellite and the system properly.'
            ).format(target_major_version)),
            reporting.ExternalLink(
                # TODO: How to handle different documentation links for each version?
                url='https://red.ht/preparing-for-upgrade-to-rhel8',
                title='Preparing for the upgrade')
        ])
        raise StopActorExecution()
    return set(repoids)
コード例 #7
0
def test_get_available_repo_ids(monkeypatch, other_repofiles, rhsm_repofile):
    context_mocked = IsolatedActionsMocked()
    repos = other_repofiles[:]
    if rhsm_repofile:
        repos.append(rhsm_repofile)
    rhsm_repos = [repo.repoid
                  for repo in rhsm_repofile.data] if rhsm_repofile else []

    monkeypatch.setattr(api, 'current_logger', logger_mocked())
    monkeypatch.setattr(rhsm, '_inhibit_on_duplicate_repos', lambda x: None)
    monkeypatch.setattr(repofileutils, 'get_parsed_repofiles', lambda x: repos)

    result = rhsm.get_available_repo_ids(context_mocked)

    rhsm_repos.sort()
    assert context_mocked.commands_called == [['yum', 'clean', 'all']]
    assert result == rhsm_repos
    if result:
        msg = (
            'The following repoids are available through RHSM:{0}{1}'.format(
                LIST_SEPARATOR, LIST_SEPARATOR.join(rhsm_repos)))
        assert msg in api.current_logger.infomsg
    else:
        assert 'There are no repos available through RHSM.' in api.current_logger.infomsg