Example #1
0
def test_doc_examples():
    sat_rpms = InstalledRpms(context_wrap(installed_rpms_62))
    cap_rpms = InstalledRpms(context_wrap(installed_rpms_62_cap))
    env = {
            'sat_ver': SatelliteVersion(sat_rpms, None),
            'cap_ver': CapsuleVersion(cap_rpms, None),
          }
    failed, total = doctest.testmod(satellite_version, globs=env)
    assert failed == 0
Example #2
0
def test_no_sat_installed():
    rpms = InstalledRpms(context_wrap(no_sat))
    with pytest.raises(SkipComponent) as sc:
        SatelliteVersion(rpms, None)
    assert "Not a Satellite machine" in str(sc)

    rpms = InstalledRpms(context_wrap(installed_rpms_611x_confilct))
    with pytest.raises(SkipComponent) as sc:
        SatelliteVersion(rpms, None)
    assert "unable to determine Satellite version" in str(sc)
def test_oracleasmrpms():
    # Oracle RPMs have a weird format - fix that in the read process
    ora_rpms = InstalledRpms(context_wrap(ORACLEASM_RPMS))
    assert ora_rpms is not None
    assert 'oracleasm' in ora_rpms.packages
    assert ora_rpms.get_max('oracleasm').version == '2.6.18-164.el5-2.0.5'
    assert ora_rpms.get_max('oracleasm').release == '1.el5'
    assert 'oracleasmlib' in ora_rpms.packages
    assert ora_rpms.get_max('oracleasmlib').version == '2.0.4'
    assert ora_rpms.get_max('oracleasmlib').release == '1.el5'
    assert 'oracleasm-support' in ora_rpms.packages
    assert ora_rpms.get_max('oracleasm-support').version == '2.1.3'
    assert ora_rpms.get_max('oracleasm-support').release == '1.el5'
Example #4
0
def test_both_pkgs():
    rpms = InstalledRpms(context_wrap(BOTH_CAPSULE_AND_FOREMAN_PKGS_INSTALLED))
    capsule = CapsuleVersion(rpms, None)
    assert capsule is not None
    assert capsule.version == '6.9.0.11'

    both_satellite_and_capsule_rpms = InstalledRpms(context_wrap(BOTH_CAPSULE_AND_SATELLITE_PKGS_INSTALLED))
    satellite = SatelliteVersion(both_satellite_and_capsule_rpms, None)
    assert satellite is not None
    assert satellite.version == '6.9.0.11'

    with pytest.raises(SkipComponent):
        CapsuleVersion(both_satellite_and_capsule_rpms, satellite)
def test_from_line():
    rpms = InstalledRpms(context_wrap(RPMS_LINE))
    assert rpms.get_max("ConsoleKit").arch == 'x86_64'
    assert rpms.get_max("kernel").version == '2.6.32'
    assert rpms.get_max("yum").release == '69.el6'
    assert rpms.get_max("tftp-server").version == '5.2'
    assert rpms.get_max("yum").package == "yum-3.2.29-69.el6"
    assert rpms.get_max("tftp-server").redhat_signed is None
    assert rpms.get_max("yum").redhat_signed
    assert rpms.corrupt is False
def test_rpm_manifest():
    rpms = InstalledRpms(context_wrap(RPM_MANIFEST))
    assert 'gpg-pubkey' in rpms
    assert rpms.packages['vmware-tools'][0].package == \
        'vmware-tools-8.3.19-1310361.el6'
    assert rpms.packages['vmware-tools'][0].installtime == \
        'Sat Aug 29 19:10:11 2015'
def test_no_suffixes():
    # make sure 'in' really means 'has a package that starts with'
    rpms = InstalledRpms(context_wrap(RPMS_PACKAGE))
    assert 'openssh-askpass' in rpms
    assert 'askpass' not in rpms
    assert 'openobex' in rpms
    assert 'penobex' not in rpms
Example #8
0
def test_get_sat60():
    rpms = InstalledRpms(context_wrap(installed_rpms_60))
    expected = ('6.0.8', '6.0.8', None, 6, 0)
    result = SatelliteVersion(rpms, None)
    assert result.major == expected[-2]
    assert result.minor == expected[-1]
    assert result.full == expected[0]
    assert result.release == expected[2]
    assert result.version == expected[1]
Example #9
0
def test_get_sat62_version():
    rpms = InstalledRpms(context_wrap(installed_rpms_62))
    expected = ('satellite-6.2.0.11-1.el7sat', '6.2.0.11', '1.el7sat', 6, 2)
    result = SatelliteVersion(rpms, None)
    assert result.major == expected[-2]
    assert result.minor == expected[-1]
    assert result.full == expected[0]
    assert result.version == expected[1]
    assert result.release == expected[2]
Example #10
0
def test_from_json():
    rpms = InstalledRpms(context_wrap(RPMS_JSON))
    assert isinstance(rpms.get_max("log4j").source, InstalledRpm)
    assert len(rpms.packages) == len(RPMS_JSON.splitlines())
    assert rpms.get_max("log4j").source.name == "log4j"
    assert rpms.get_max("util-linux").epoch == '0'
    assert rpms.get_max("jboss-servlet-3.0-api").redhat_signed

    assert rpms.newest('libnl').vendor == '(none)'
    assert rpms.newest('crash').vendor == 'Red Hat, Inc.'
    assert rpms.newest('log4j').vendor is None
Example #11
0
def test_get_sat61_version_both():
    rpms = InstalledRpms(context_wrap(installed_rpms_61))
    sat = Satellite6Version(context_wrap(satellite_version_rb))
    expected = ('6.1.3', '6.1.3', None, 6, 1)
    result = SatelliteVersion(rpms, sat)
    assert result.major == expected[-2]
    assert result.minor == expected[-1]
    assert result.full == expected[0]
    assert result.release == expected[2]
    assert result.version == expected[1]
Example #12
0
def test_get_sat5_version():
    rpms = InstalledRpms(context_wrap(installed_rpms_5))
    expected = ('satellite-schema-5.6.0.10-1.el6sat',
                '5.6.0.10', '1.el6sat', 5, 6)
    result = SatelliteVersion(rpms, None)
    assert result.major == expected[-2]
    assert result.minor == expected[-1]
    assert result.full == expected[0]
    assert result.release == expected[2]
    assert result.version == expected[1]
def test_ansible_info_auto_controller():
    rpms = InstalledRpms(context_wrap(AUTO_CONTROLLER_RPM))
    comb = AnsibleInfo(rpms)
    assert not comb.is_tower
    assert comb.is_controller
    assert not comb.is_hub
    assert not comb.is_catalog_worker
    assert comb.tower_version is None
    assert comb.controller_version == '1.0.1'
    assert comb.hub_version is None
    assert comb.catalog_worker_version is None
def test_get_grub_cmdlines_none():
    grub1 = Grub1Config(context_wrap(GRUB1_TEMPLATE))
    grub2 = Grub2Config(context_wrap(GRUB2_TEMPLATE))
    cmdline = CmdLine(context_wrap(CMDLINE_V2))
    sys_firmware = LsSysFirmware(context_wrap(SYS_FIRMWARE_DIR_EFI))
    with pytest.raises(ParseException) as pe:
        GrubConf(grub1, grub2, None, None, None, cmdline, sys_firmware)
    assert "No valid grub configuration is found." in str(pe)

    grub1e = Grub1EFIConfig(context_wrap(GRUB1_TEMPLATE))
    grub2e = Grub2EFIConfig(context_wrap(GRUB2_TEMPLATE))
    rpms = InstalledRpms(context_wrap(INSTALLED_RPMS_V2))
    with pytest.raises(ParseException) as pe:
        GrubConf(None, None, grub1e, grub2e, rpms, None, None)
    assert "No valid grub configuration is found." in str(pe)

    grub2e = Grub2EFIConfig(context_wrap(GRUB2_EFI_CFG))
    rpms = InstalledRpms(context_wrap(INSTALLED_RPMS_V2))
    with pytest.raises(ParseException) as pe:
        GrubConf(grub1, None, grub1e, None, rpms, None, None)
    assert "No valid grub configuration is found." in str(pe)
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'
def test_from_json():
    rpms = InstalledRpms(context_wrap(RPMS_JSON))
    assert isinstance(rpms.get_max("log4j").source, InstalledRpm)
    assert len(rpms.packages) == len(RPMS_JSON.splitlines())
    assert rpms.get_max("log4j").source.name == "log4j"
    assert rpms.get_max("util-linux").epoch == '0'
    assert rpms.get_max("jboss-servlet-3.0-api").redhat_signed
Example #17
0
def test_grub2_grubenv():
    grub2 = Grub2Config(context_wrap(GRUB2_TEMPLATE))
    grub2env = Grub2Grubenv(context_wrap(GRUBENV))
    rhel8 = RedhatRelease(context_wrap(RHEL8))
    rhel = RedHatRelease(None, rhel8)
    rpms = InstalledRpms(context_wrap(INSTALLED_RPMS_V2))
    sys_firmware = LsSysFirmware(context_wrap(SYS_FIRMWARE_DIR_NOEFI))
    result = GrubConf(None, grub2, None, None, grub2env, None, rpms, None,
                      sys_firmware, rhel)
    assert len(result.get_grub_cmdlines()) == 1
    assert 'noapic' not in result.get_grub_cmdlines()[0]['cmdline']
    assert result.version == 2
    assert not result.is_efi
def test_max_min_kernel():
    rpms = InstalledRpms(context_wrap(RPMS_MULTIPLE_KERNEL))
    assert rpms.get_min('kernel').package == 'kernel-3.10.0-327.el7'
    assert rpms.get_max('kernel').package == 'kernel-3.10.0-327.36.1.el7'
    assert rpms.get_min(
        'kernel-devel').package == 'kernel-devel-3.10.0-327.el7'
    assert rpms.get_max(
        'kernel-devel').package == 'kernel-devel-3.10.0-327.36.1.el7'
def test_grub2_boot_loader_entries():
    grub2 = Grub2Config(context_wrap(GRUB2_TEMPLATE))
    grub_ble1 = BLE(context_wrap(BOOT_LOADER_ENTRIES_1))
    grub_ble2 = BLE(context_wrap(BOOT_LOADER_ENTRIES_2))
    grub_bles = BootLoaderEntries([grub_ble1, grub_ble2], None, None)
    rhel8 = RedhatRelease(context_wrap(RHEL8))
    rhel = RedHatRelease(None, rhel8)
    rpms = InstalledRpms(context_wrap(INSTALLED_RPMS_V2))
    sys_firmware = LsSysFirmware(context_wrap(SYS_FIRMWARE_DIR_EFI))
    result = GrubConf(None, grub2, None, None, grub_bles, rpms, None,
                      sys_firmware, rhel)
    assert len(result.get_grub_cmdlines()) == 2
    assert 'noapic' in result.get_grub_cmdlines()[0]['cmdline']
    assert result.version == 2
    assert result.is_efi
def test_get_sat61_version():
    rpms = InstalledRpms(context_wrap(installed_rpms_61))
    expected = ('6.1.7', '6.1.7', None, 6, 1)
    result = SatelliteVersion(None, rpms)
    assert result.major == expected[-2]
    assert result.minor == expected[-1]
    assert result.full == expected[0]
    assert result.release == expected[2]
    assert result.version == expected[1]

    sat = Satellite6Version(context_wrap(satellite_version_rb))
    expected = ('6.1.3', '6.1.3', None, 6, 1)
    result = SatelliteVersion(sat, None)
    assert result.major == expected[-2]
    assert result.minor == expected[-1]
    assert result.full == expected[0]
    assert result.release == expected[2]
    assert result.version == expected[1]

    rpms = InstalledRpms(context_wrap(installed_rpms_6110))
    expected = ('6.1.10', '6.1.10', None, 6, 1)
    result = SatelliteVersion(None, rpms)
    assert result.major == expected[-2]
    assert result.minor == expected[-1]
    assert result.full == expected[0]
    assert result.release == expected[2]
    assert result.version == expected[1]

    rpms = InstalledRpms(context_wrap(installed_rpms_6111))
    expected = ('6.1.11', '6.1.11', None, 6, 1)
    result = SatelliteVersion(None, rpms)
    assert result.major == expected[-2]
    assert result.minor == expected[-1]
    assert result.full == expected[0]
    assert result.release == expected[2]
    assert result.version == expected[1]
def test_ansible_info_all():
    rpms = InstalledRpms(context_wrap(ALL_RPMS))
    comb = AnsibleInfo(rpms)
    assert comb is not None
    assert comb.is_tower
    assert comb.tower_version == '1.0.0'
    assert comb[ANSIBLE_TOWER_PKG].nvr == TOWER_RPM
    assert comb[ANSIBLE_AUTOMATION_CONTROLLER_PKG].nvr == AUTO_CONTROLLER_RPM
    assert comb.is_controller
    assert comb.controller_version == '1.0.0'
    assert comb.is_hub
    assert comb.hub_version == '1.0.3'
    assert comb[ANSIBLE_AUTOMATION_HUB_PKG].nvr == HUB_RPM
    assert comb.is_catalog_worker
    assert comb.catalog_worker_version == '1.0.2'
    assert comb[ANSIBLE_CATALOG_WORKER_PKG].nvr == CATALOG_WORKER_RPM
def test_grub2_grubenv_with_kernelopts():
    grub2 = Grub2Config(context_wrap(GRUB2_TEMPLATE))
    grub_ble3 = BLE(context_wrap(BOOT_LOADER_ENTRIES_3))
    grub_bles = BootLoaderEntries([grub_ble3], None, None)
    rhel8 = RedhatRelease(context_wrap(RHEL8))
    rhel = RedHatRelease(None, rhel8)
    rpms = InstalledRpms(context_wrap(INSTALLED_RPMS_V2))
    sys_firmware = LsSysFirmware(context_wrap(SYS_FIRMWARE_DIR_NOEFI))
    result = GrubConf(None, grub2, None, None, grub_bles, rpms, None,
                      sys_firmware, rhel)
    assert len(result.get_grub_cmdlines()) == 1
    assert 'noapic' not in result.get_grub_cmdlines()[0]['cmdline']
    assert 'transparent_hugepages' not in result.get_grub_cmdlines(
    )[0]['cmdline']
    assert result.version == 2
    assert not result.is_efi
Example #23
0
def test_grub2_efi_rpms():
    grub1 = Grub1Config(context_wrap(GRUB1_TEMPLATE))
    grub2 = Grub2Config(context_wrap(GRUB2_TEMPLATE))
    grub1e = Grub1EFIConfig(context_wrap(GRUB1_EFI_CFG))
    grub2e = Grub2EFIConfig(context_wrap(GRUB2_EFI_CFG))
    rpms = InstalledRpms(context_wrap(INSTALLED_RPMS_V2))
    cmdline = CmdLine(context_wrap(CMDLINE_V1))
    sys_firmware = LsSysFirmware(context_wrap(SYS_FIRMWARE_DIR_EFI))
    result = GrubConf(grub1, grub2, grub1e, grub2e, None, None, rpms, cmdline,
                      sys_firmware, None)
    assert result.kernel_initrds['grub_initrds'][
        0] == 'initramfs-3.10.0-514.16.1.el7.x86_64.img'
    assert result.get_grub_cmdlines() == result.get_grub_cmdlines('/vmlinuz')
    assert result.get_grub_cmdlines('rescue')[0].name.startswith(
        "'Red Hat Enterprise Linux Server (0-rescue")
    assert len(result.get_grub_cmdlines()) == 4
    assert result.version == 2
    assert result.is_efi is True
def test_corrupt_db():
    rpms = InstalledRpms(context_wrap(ERROR_DB))
    assert rpms.corrupt is True
    assert "yum-security" in rpms.packages
    assert "yum-security" in rpms

    rpms = InstalledRpms(context_wrap(ERROR_DB_NO_PKG))
    assert rpms.corrupt is True
    assert not rpms.packages
    assert "kernel" not in rpms
    assert "kernel" not in rpms.packages
    assert rpms.newest("kernel") is None
    assert rpms.oldest("kernel") is None
def test_epoch():
    rpms = InstalledRpms(context_wrap(RPMS_PACKAGE))
    # no epoch
    rpm = rpms.get_max('openldap')
    assert rpm.package_with_epoch == 'openldap-0:2.4.23-31.el6'
    assert rpm.nevra == 'openldap-0:2.4.23-31.el6.x86_64'

    rpms = InstalledRpms(context_wrap(RPMS_JSON))
    # epoch 0
    rpm = rpms.get_max('log4j')
    assert rpm.package_with_epoch == 'log4j-0:1.2.17-15.el7'
    assert rpm.nevra == 'log4j-0:1.2.17-15.el7.noarch'
    # epoch (none)
    rpm = rpms.get_max('kbd-misc')
    assert rpm.package_with_epoch == 'kbd-misc-0:1.15.5-11.el7'
    assert rpm.nevra == 'kbd-misc-0:1.15.5-11.el7.noarch'
    # epoch 1
    rpm = rpms.get_max('grub2-tools')
    assert rpm.package_with_epoch == 'grub2-tools-1:2.02-0.34.el7_2'
    assert rpm.nevra == 'grub2-tools-1:2.02-0.34.el7_2.x86_64'
Example #26
0
def test_grub1_efi_rpms():
    grub1 = Grub1Config(context_wrap(GRUB1_TEMPLATE))
    grub2 = Grub2Config(context_wrap(GRUB2_TEMPLATE))
    grub1e = Grub1EFIConfig(context_wrap(GRUB1_EFI_CFG))
    grub2e = Grub2EFIConfig(context_wrap(GRUB2_EFI_CFG))
    rpms = InstalledRpms(context_wrap(INSTALLED_RPMS_V1))
    cmdline = CmdLine(context_wrap(CMDLINE_V2))
    sys_firmware = LsSysFirmware(context_wrap(SYS_FIRMWARE_DIR_EFI))
    result = GrubConf(grub1, grub2, grub1e, grub2e, None, None, rpms, cmdline,
                      sys_firmware, None)
    assert result.kernel_initrds['grub_kernels'][
        0] == 'vmlinuz-2.6.32-71.el6.x86_64'
    assert result.kernel_initrds['grub_initrds'][
        0] == 'initramfs-2.6.32-71.el6.x86_64.img'
    assert result.is_kdump_iommu_enabled is False
    assert result.get_grub_cmdlines() == result.get_grub_cmdlines('/vmlinuz')
    assert len(result.get_grub_cmdlines()) == 1
    assert result.version == 1
    assert result.is_efi is True
def test_grub2_rpms():
    grub1 = Grub1Config(context_wrap(GRUB1_TEMPLATE))
    grub2 = Grub2Config(context_wrap(GRUB2_TEMPLATE))
    grub1e = Grub1EFIConfig(context_wrap(GRUB1_EFI_CFG))
    grub2e = Grub2EFIConfig(context_wrap(GRUB2_EFI_CFG))
    rpms = InstalledRpms(context_wrap(INSTALLED_RPMS_V2))
    cmdline = CmdLine(context_wrap(CMDLINE_V1))
    result = GrubConf(grub1, grub2, grub1e, grub2e, rpms, cmdline, None)
    assert result.kernel_initrds['grub_kernels'][
        0] == 'vmlinuz-3.10.0-327.el7.x86_64'
    assert result.kernel_initrds['grub_initrds'][
        0] == 'initramfs-3.10.0-327.el7.x86_64.img'
    assert result.is_kdump_iommu_enabled is False
    assert result.get_grub_cmdlines(
        '/vmlinuz-3.10.0'
    )[0].name == "'Red Hat Enterprise Linux Server (3.10.0-327.el7.x86_64) 7.2 (Maipo)' --class red --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option 'gnulinux-3.10.0-327.el7.x86_64-advanced-4f80b3d4-90ba-4545-869c-febdecc586ce'"
    assert result.get_grub_cmdlines('test') == []
    assert result.get_grub_cmdlines('') == []
    assert len(result.get_grub_cmdlines()) == 2
    assert result.version == 2
    assert result.is_efi is False
def test_vmaas():
    rpms = InstalledRpms(context_wrap(RPMS_VMAAS))
    rpm = rpms.get_max("compat-libstdc++-296")
    assert isinstance(rpm, InstalledRpm)
    assert rpm.version == "2.96"
    assert rpm.release == "144.el6"

    rpm = rpms.get_max("compat-libstdc++-33")
    assert isinstance(rpm, InstalledRpm)
    assert rpm.version == "3.2.3"
    assert rpm.release == "72.el7"

    rpm = rpms.get_max("flash-plugin")
    assert isinstance(rpm, InstalledRpm)
    assert rpm.version == "32.0.0.171"
    assert rpm.release == "1.el6_10"

    rpm = rpms.get_max("glibc")
    assert isinstance(rpm, InstalledRpm)
    assert rpm.version == "2.12"
    assert rpm.release == "1.149.el6_6.5"

    rpm = rpms.get_max("infinipath-psm")
    assert isinstance(rpm, InstalledRpm)
    assert rpm.version == "3.3"
    assert rpm.release == "19_g67c0807_open.el6"

    rpm = rpms.get_max("kmod-fnic")
    assert isinstance(rpm, InstalledRpm)
    assert rpm.version == "1.6.0.12b"
    assert rpm.release == "rhel6u6.el6"

    rpm = rpms.get_max("krb5-libs")
    assert isinstance(rpm, InstalledRpm)
    assert rpm.version == "1.10.3"
    assert rpm.release == "65.el6"

    rpm = rpms.get_max("libaio-devel")
    assert isinstance(rpm, InstalledRpm)
    assert rpm.version == "0.3.107"
    assert rpm.release == "10.el6"

    rpm = rpms.get_max("mdadm")
    assert isinstance(rpm, InstalledRpm)
    assert rpm.version == "4.1"
    assert rpm.release == "rc1_2.el7"

    rpm = rpms.get_max("nagios-plugins-disk")
    assert isinstance(rpm, InstalledRpm)
    assert rpm.version == "2.2.1"
    assert rpm.release == "16.20180725git3429dad.el7"

    rpm = rpms.get_max("TaniumClient")
    assert isinstance(rpm, InstalledRpm)
    assert rpm.version == "7.2.314.3211"
    assert rpm.release == "1.rhe7"

    rpm = rpms.get_max("xymon")
    assert isinstance(rpm, InstalledRpm)
    assert rpm.version == "4.3.25"
    assert rpm.release == "1.el6"

    rpm = rpms.get_max("xz")
    assert isinstance(rpm, InstalledRpm)
    assert rpm.version == "5.2.2"
    assert rpm.release == "1.el7"

    rpm = rpms.get_max("xz-libs")
    assert isinstance(rpm, InstalledRpm)
    assert rpm.version == "5.2.2"
    assert rpm.release == "1.el7"
def test_gpgkey():
    rpms = InstalledRpms(context_wrap(RPMS_GPG_PUBKEY))
    assert isinstance(rpms.get_max("gpg-pubkey"), InstalledRpm)
    assert len(rpms.packages) == 1
    assert rpms.get_max("gpg-pubkey").name == "gpg-pubkey"
def test_unicode_char_in_rpms():
    rpms = InstalledRpms(context_wrap(RPMS_PACKAGE_WITH_UNICODE))
    assert u"openobex\u018e" in rpms.packages
    rpm = rpms.get_max(u'openobex\u018e')
    assert rpm.package == u'openobex\u018e-1.4-7.el6'