예제 #1
0
def check_bash_bug(rpms):
    bug_version = InstalledRpm.from_package('bash-4.4.14-1.any')
    fix_version = InstalledRpm.from_package('bash-4.4.18-1.any')
    current_version = rpms.get_max('bash')
    if bug_version <= current_version < fix_version:
        return make_fail(ERROR_KEY_BASH_BUG_PRESENT, bash=current_version.nvr)
    else:
        return make_pass(ERROR_KEY_BASH_BUG_NOT_PRESENT,
                         bash=current_version.nvr)
예제 #2
0
def test_release_compare():
    rpm1 = InstalledRpm.from_package('kernel-rt-debug-3.10.0-327.rt56.204.el7_2.1')
    rpm2 = InstalledRpm.from_package('kernel-rt-debug-3.10.0-327.rt56.204.el7_2.2')
    rpm3 = InstalledRpm.from_package('kernel-3.10.0-327.10.1.el7')
    rpm4 = InstalledRpm.from_package('kernel-3.10.0-327.el7')
    rpm5 = InstalledRpm.from_package('kernel-3.10.0-327.el7_1')
    rpm6 = InstalledRpm.from_package('kernel-3.10.0-327')
    rpm7 = InstalledRpm.from_package('kernel-3.10.0-327.1')
    rpm8 = InstalledRpm.from_package('kernel-3.10.0-327.x86_64')
    rpm9 = InstalledRpm.from_package('kernel-3.10.0-327.1.x86_64')
    with pytest.raises(ValueError) as ve:
        rpm1 > rpm7
    assert "differing names" in str(ve)
    with pytest.raises(ValueError) as ve:
        rpm1 <= rpm7
    assert "differing names" in str(ve)
    with pytest.raises(ValueError) as ve:
        rpm1 != rpm7
    assert "differing names" in str(ve)

    assert rpm1 < rpm2
    assert rpm1 != rpm2
    assert rpm3 > rpm4
    assert rpm5 > rpm4
    assert rpm5 >= rpm4
    assert not (rpm5 <= rpm4)
    assert rpm6 < rpm7
    assert rpm8 < rpm9
    assert rpm6 < rpm9
    assert rpm6 <= rpm9
    assert rpm6 == rpm8
    assert rpm6 <= rpm8
    assert rpm6 >= rpm8
    assert not (rpm7 != rpm9)
def is_affected_systemd_version(rpms):
    installed_systemd = rpms.newest('systemd')
    systemd760 = InstalledRpm.from_package('systemd-219-62.el7')
    systemd770 = InstalledRpm.from_package('systemd-219-67.el7')
    fixed_systemd76z = InstalledRpm.from_package('systemd-219-62.el7_6.9')
    fixed_systemd7 = InstalledRpm.from_package('systemd-219-67.el7')
    if (installed_systemd >= systemd760 and installed_systemd < systemd770):
        if (installed_systemd < fixed_systemd76z):
            return [installed_systemd.package, 'systemd-219-62.el7_6.9']
    elif (installed_systemd < fixed_systemd7):
        return [installed_systemd.package, 'systemd-219-67.el7']
def affected_tuned_package(rpms):
    installed_tuned = rpms.newest('tuned')
    affected_tuned = InstalledRpm.from_package('tuned-2.11.0-5.el7.noarch')
    affected_tuned_fdp = InstalledRpm.from_package(
        'tuned-2.11.0-5.el7fdp.noarch')
    fixed_tuned = InstalledRpm.from_package('tuned-2.11.0-5.el7_7.1.noarch')
    if (installed_tuned >= affected_tuned
            or installed_tuned >= affected_tuned_fdp):
        if (installed_tuned < fixed_tuned):
            return installed_tuned.package
    return []
예제 #5
0
def test_from_package():
    rpms = InstalledRpms(context_wrap(RPMS_PACKAGE))
    assert not rpms.is_hypervisor
    pkg_rpm = rpms.packages['openssh-server'][0]
    rpm = InstalledRpm.from_package(pkg_rpm.package)
    assert rpm.package == 'openssh-server-5.3p1-104.el6'
    assert pkg_rpm.package == 'openssh-server-5.3p1-104.el6'
    assert rpm == pkg_rpm
    assert rpm.epoch == '0'

    rpm = InstalledRpm.from_package('bash-1:4.1.2-12.el7.x86_64')
    assert rpm.epoch == '1'
예제 #6
0
def test_rpm_object_hashing():
    # Class InstalledRpm implements for hashing function __hash__().
    # This allows to use objects InstalledRpm in set() and dict().

    # just NVR
    rpm_yum1 = InstalledRpm.from_package('yum-3.4.3-132.el7')
    assert rpm_yum1.arch is None
    rpm_yum2 = InstalledRpm.from_package('yum-3.4.3-132.el7')
    assert rpm_yum2.arch is None
    rpm_kernel = InstalledRpm.from_package('kernel-3.10.0-327')
    assert rpm_kernel.arch is None
    assert rpm_yum1.__hash__() == rpm_yum2.__hash__()
    assert rpm_yum1.__hash__() != rpm_kernel.__hash__()
    assert rpm_yum2.__hash__() != rpm_kernel.__hash__()

    # NVRA
    rpm1 = InstalledRpm.from_package('yum-3.4.3-132.el7.i686')
    assert rpm1.arch == 'i686'
    rpm2 = InstalledRpm.from_package('yum-3.4.3-132.el7.i686')
    assert rpm2.arch == 'i686'
    rpm3 = InstalledRpm.from_package('kernel-3.10.0-327.x86_64')
    assert rpm3.arch == 'x86_64'
    assert rpm1.__hash__() == rpm2.__hash__()
    assert rpm1.__hash__() != rpm3.__hash__()
    assert rpm2.__hash__() != rpm3.__hash__()

    # NVR and NVRA
    rpm1 = InstalledRpm.from_package('yum-3.4.3-132.el7')
    assert rpm1.arch is None
    rpm2 = InstalledRpm.from_package('yum-3.4.3-132.el7.ppc64le')
    assert rpm2.arch == 'ppc64le'
    assert rpm1.__hash__() != rpm2.__hash__()
예제 #7
0
def check_bash_bug(rpms):
    bug_version = InstalledRpm.from_package('bash-4.4.14-1.any')
    fix_version = InstalledRpm.from_package('bash-4.4.18-1.any')
    current_version = rpms.get_max('bash')
    if bug_version <= current_version < fix_version:
        found = "Bash bug found! Version: "
        return make_fail(ERROR_KEY_BASH_BUG,
                         bash=current_version.nvr,
                         found=found)
    else:
        not_found = "Bash bug not found: "
        return make_pass(ERROR_KEY_BASH_BUG,
                         bash=current_version.nvr,
                         found=not_found)
예제 #8
0
def _get_name_vra_from_string(rpm_string):
    """
    small helper to pull name + version/release/arch from string

    This supports two styles: ENVRA and NEVRA. The latter is preferred.
    """
    try:
        if re.match("^[0-9]+:", rpm_string):
            _, remainder = rpm_string.split(":", maxsplit=1)
            rpm = InstalledRpm.from_package(remainder)
        else:
            rpm = InstalledRpm.from_package(rpm_string)
    except TypeError:
        raise UnparsableNEVRAError("unable to parse %s into nevra" %
                                   rpm_string)

    vra = rpm.version if rpm.version else ""
    if rpm.release:
        vra = vra + "-" + rpm.release
    if rpm.arch:
        vra = vra + "." + rpm.arch

    return rpm.name, vra
예제 #9
0
def test_different_arch_sep():
    rpm1 = InstalledRpm.from_package('yum-3.4.3-132.el7.noarch')
    rpm2 = InstalledRpm.from_package('yum-3.4.3-132.el7-noarch')
    assert rpm1 == rpm2
    assert rpm1.arch == rpm2.arch
    assert rpm1['arch'] == rpm2.arch
예제 #10
0
def test_exceptions():
    rpm1 = InstalledRpm.from_package('kernel-3.10.0-327.el7.x86_64')
    rpm2 = InstalledRpm.from_package('plevel-3.10.0-327.el7.x86_64')
    with pytest.raises(ValueError):
        assert rpm1 > rpm2
예제 #11
0
def test_formatting():
    rpm = InstalledRpm.from_package('kernel-3.10.0-327.el7.x86_64')
    assert str(rpm) == '0:kernel-3.10.0-327.el7'
    assert repr(rpm) == '0:kernel-3.10.0-327.el7'
예제 #12
0
#!/usr/bin/env python

from insights import rule, make_response, run
from insights.parsers.installed_rpms import InstalledRpm, InstalledRpms


@rule(InstalledRpms)
def bash_installed(rpms):
    rpm = rpms.get_max("bash")
    if rpm:
        return make_response("BASH_INSTALLED", version=rpm.nvr)
    return make_response("BASH_NOT_INSTALLED")


LOWER = InstalledRpm.from_package("bash-4.4.16-1.el7")
UPPER = InstalledRpm.from_package("bash-4.4.22-1.el7")


@rule(InstalledRpms)
def bash_affected(rpms):
    rpm = rpms.get_max("bash")
    if rpm and rpm >= LOWER and rpm < UPPER:
        return make_response("BASH_AFFECTED", version=rpm.nvr)
    elif rpm:
        return make_response("BASH_UNAFFECTED", version=rpm.nvr)
    else:
        return make_response("NO_BASH")


if __name__ == "__main__":
    from sys import argv
If 1&2&3:
return Error_Key

* Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1739418
* KCS: https://access.redhat.com/solutions/4395931
"""

from insights.core.plugins import make_fail, rule, condition
from insights.combiners.redhat_release import RedHatRelease
from insights.parsers.installed_rpms import InstalledRpms, InstalledRpm
from insights.parsers.sysctl import Sysctl
from mycomponents.rules.plugins.shift import is_shift_node_service_running

ERROR_KEY = "OCP_TUNED_REGRESSION"
AFFECTED_VERSION = [
    InstalledRpm.from_package('tuned-2.11.0-5.el7').nvr,
    InstalledRpm.from_package('tuned-2.11.0-5.el7fdp').nvr
]


@condition(InstalledRpms)
def is_affected_tuned_version(installed_rpms):
    tuned_rpm = installed_rpms.get_max('tuned')
    openshift_node_rpm = installed_rpms.get_max('atomic-openshift-node')
    if tuned_rpm and openshift_node_rpm and tuned_rpm.nvr in AFFECTED_VERSION:
        return tuned_rpm.nvr


@condition(Sysctl)
def check_tuned_sysctl(sysctlcommand):
    if "net.ipv4.neigh.default.gc_thresh1" in sysctlcommand and sysctlcommand[
예제 #14
0
def test_get_stale_packages(rpms):
    stale = _get_stale_packages(rpms)
    assert InstalledRpm.from_package("libnl-0:1.1.4-2.el6.x86_64") in stale
    assert len(stale) == 1