Beispiel #1
0
def get_os_release(path):
    """Retrieve data about System OS release from provided file."""
    try:
        with open(path) as f:
            data = dict(l.strip().split('=', 1) for l in f.readlines()
                        if '=' in l)
            return OSRelease(release_id=data.get('ID', '').strip('"'),
                             name=data.get('NAME', '').strip('"'),
                             pretty_name=data.get('PRETTY_NAME',
                                                  '').strip('"'),
                             version=data.get('VERSION', '').strip('"'),
                             version_id=data.get('VERSION_ID', '').strip('"'),
                             variant=data.get('VARIANT', '').strip('"')
                             or None,
                             variant_id=data.get('VARIANT_ID', '').strip('"')
                             or None)
    except IOError as e:
        reporting.create_report([
            reporting.Title('Error while collecting system OS facts'),
            reporting.Summary(str(e)),
            reporting.Severity(reporting.Severity.HIGH),
            reporting.Tags([reporting.Tags.OS_FACTS, reporting.Tags.SANITY]),
            reporting.Flags([reporting.Flags.INHIBITOR]),
            reporting.RelatedResource('file', path)
        ])
        return None
def _get_os_release(version='7.9', codename='Maipo'):
    release = OSRelease(release_id='rhel',
                        name='Red Hat Enterprise Linux Server',
                        pretty_name='Red Hat Enterprise Linux',
                        version='{} ({})'.format(version, codename),
                        version_id='{}'.format(version),
                        variant='Server',
                        variant_id='server')
    return release
def test_get_os_release_info(monkeypatch):
    expected = OSRelease(release_id='rhel',
                         name='Red Hat Enterprise Linux Server',
                         pretty_name='Red Hat Enterprise Linux',
                         version='7.6 (Maipo)',
                         version_id='7.6',
                         variant='Server',
                         variant_id='server')
    assert expected == library.get_os_release('tests/files/os-release')

    with pytest.raises(StopActorExecutionError):
        library.get_os_release('tests/files/non-existent-file')
def test_get_os_release_info(monkeypatch):
    expected = OSRelease(release_id='rhel',
                         name='Red Hat Enterprise Linux Server',
                         pretty_name='Red Hat Enterprise Linux',
                         version='7.6 (Maipo)',
                         version_id='7.6',
                         variant='Server',
                         variant_id='server')
    assert expected == ipuworkflowconfig.get_os_release(
        os.path.join(CUR_DIR, 'files/os-release'))

    with pytest.raises(StopActorExecutionError):
        ipuworkflowconfig.get_os_release(
            os.path.join(CUR_DIR, 'files/non-existent-file'))
Beispiel #5
0
def test_get_os_release_info(monkeypatch):
    monkeypatch.setattr('leapp.libraries.stdlib.api.produce', produce_mocked())
    monkeypatch.setattr(reporting, 'report_generic', report_generic_mocked())

    expected = OSRelease(
        release_id='rhel',
        name='Red Hat Enterprise Linux Server',
        pretty_name='Red Hat Enterprise Linux',
        version='7.6 (Maipo)',
        version_id='7.6',
        variant='Server',
        variant_id='server')
    assert expected == library.get_os_release('tests/files/os-release')

    assert not library.get_os_release('tests/files/non-existent-file')
    assert reporting.report_generic.called == 1
    assert 'inhibitor' in reporting.report_generic.report_fields['flags']
def get_os_release(path):
    """Retrieve data about System OS release from provided file."""
    try:
        with open(path) as f:
            data = dict(l.strip().split('=', 1) for l in f.readlines() if '=' in l)
            return OSRelease(
                release_id=data.get('ID', '').strip('"'),
                name=data.get('NAME', '').strip('"'),
                pretty_name=data.get('PRETTY_NAME', '').strip('"'),
                version=data.get('VERSION', '').strip('"'),
                version_id=data.get('VERSION_ID', '').strip('"'),
                variant=data.get('VARIANT', '').strip('"') or None,
                variant_id=data.get('VARIANT_ID', '').strip('"') or None
            )
    except IOError as e:
        raise StopActorExecutionError(
            message='Cannot collect the system OS facts.',
            details={'details': str(e)}
        )
Beispiel #7
0
def get_os_release(path):
    """Retrieve data about System OS release from provided file."""
    try:
        with open(path) as f:
            data = dict(l.strip().split('=', 1) for l in f.readlines()
                        if '=' in l)
            return OSRelease(release_id=data.get('ID', '').strip('"'),
                             name=data.get('NAME', '').strip('"'),
                             pretty_name=data.get('PRETTY_NAME',
                                                  '').strip('"'),
                             version=data.get('VERSION', '').strip('"'),
                             version_id=data.get('VERSION_ID', '').strip('"'),
                             variant=data.get('VARIANT', '').strip('"')
                             or None,
                             variant_id=data.get('VARIANT_ID', '').strip('"')
                             or None)
    except IOError as e:
        reporting.report_generic(
            title='Error while collecting system OS facts',
            summary=str(e),
            severity='high',
            flags=['inhibitor'])
        return None
Beispiel #8
0
"""
This is not regular library.

The library is supposed to be used only for testing purposes. Import of the
library is expected only inside test files.
"""

from leapp.models import IPUConfig, EnvVar, OSRelease, Version

CONFIG = IPUConfig(
    leapp_env_vars=[EnvVar(name='LEAPP_DEVEL', value='0')],
    os_release=OSRelease(release_id='rhel',
                         name='Red Hat Enterprise Linux Server',
                         pretty_name='RHEL',
                         version='7.6 (Maipo)',
                         version_id='7.6'),
    version=Version(source='7.6', target='8.0'),
    architecture='x86_64',
    kernel='3.10.0-957.43.1.el7.x86_64',
)

CONFIG_ALL_SIGNED = IPUConfig(
    leapp_env_vars=[EnvVar(name='LEAPP_DEVEL_RPMS_ALL_SIGNED', value='1')],
    os_release=OSRelease(release_id='rhel',
                         name='Red Hat Enterprise Linux Server',
                         pretty_name='RHEL',
                         version='7.6 (Maipo)',
                         version_id='7.6'),
    version=Version(source='7.6', target='8.0'),
    architecture='x86_64',
    kernel='3.10.0-957.43.1.el7.x86_64',