Beispiel #1
0
 def teardown_hotfix_check():
     if float(product()) >= 6.6:
         teardown = ansible_module.command(Packages.unlock())
         for result in teardown.values():
             logger.info(result["stdout"])
             assert "FAIL" not in result["stdout"]
             assert result["rc"] == 0
     if pkgs_locked == 0:
         ansible_module.command(Packages.unlock())
     teardown = ansible_module.command("yum -y reinstall tfm-rubygem-fog-vsphere")
     for result in teardown.values():
         assert result["rc"] == 0
     if float(product()) >= 6.6:
         teardown = ansible_module.command(Packages.lock())
         for result in teardown.values():
             logger.info(result["stdout"])
             assert "FAIL" not in result["stdout"]
             assert result["rc"] == 0
     teardown = ansible_module.file(path="/etc/yum.repos.d/hotfix_repo.repo", state="absent")
     assert teardown.values()[0]["changed"] == 1
     teardown = ansible_module.yum(name=["hotfix-package"], state="absent")
     for result in teardown.values():
         assert result["rc"] == 0
     if pkgs_locked == 0:
         ansible_module.command(Packages.lock())
     ansible_module.command("yum clean all")
Beispiel #2
0
def setup_hotfix_check(request, ansible_module):
    """This fixture is used for installing hofix package and modifying foreman file.
    This fixture is used in test_positive_check_hotfix_installed_with_hotfix of test_health.py
    """
    file = ansible_module.find(
        paths="/opt/theforeman/tfm/root/usr/share/gems/gems/",
        patterns="fog-vsphere-*",
        file_type="directory",
    )
    dpath = file.values()[0]["files"][0]["path"]
    fpath = dpath + "/lib/fog/vsphere/requests/compute/list_clusters.rb"
    ansible_module.lineinfile(dest=fpath,
                              insertafter="EOF",
                              line="#modifying_file")

    ansible_module.yum_repository(
        name="hotfix_repo",
        description="hotfix_repo",
        file="hotfix_repo",
        baseurl=HOTFIX_URL,
        enabled="yes",
        gpgcheck="no",
    )
    setup = ansible_module.file(path="/etc/yum.repos.d/hotfix_repo.repo",
                                state="present")
    assert setup.values()[0]["changed"] == 0
    pkgs_locked = ansible_module.command(
        Packages.is_locked()).values()[0]["rc"]
    if pkgs_locked == 0:
        ansible_module.command(Packages.unlock())
    setup = ansible_module.yum(name="hotfix-package", state="present")
    for result in setup.values():
        assert result["rc"] == 0
    if pkgs_locked == 0:
        ansible_module.command(Packages.lock())

    def teardown_hotfix_check():
        pkgs_locked = ansible_module.command(
            Packages.is_locked()).values()[0]["rc"]
        if pkgs_locked == 0:
            ansible_module.command(Packages.unlock())
        teardown = ansible_module.command(
            "yum -y reinstall tfm-rubygem-fog-vsphere")
        for result in teardown.values():
            assert result["rc"] == 0

        teardown = ansible_module.file(
            path="/etc/yum.repos.d/hotfix_repo.repo", state="absent")
        assert teardown.values()[0]["changed"] == 1
        teardown = ansible_module.yum(name=["hotfix-package"], state="absent")
        for result in teardown.values():
            assert result["rc"] == 0
        if pkgs_locked == 0:
            ansible_module.command(Packages.lock())
        ansible_module.command("yum clean all")

    request.addfinalizer(teardown_hotfix_check)
    return fpath
Beispiel #3
0
def setup_packages_update(request, ansible_module):
    """This fixture is used to downgrade a package for test test_positive_fm_packages_update"""
    ansible_module.yum_repository(
        name="custom_repo",
        description="custom_repo",
        file="custom_repo",
        baseurl=FAKE_YUM0_REPO,
        enabled="yes",
        gpgcheck="no",
    )
    setup = ansible_module.raw(Packages.install(["--assumeyes", "walrus"]))
    for result in setup.values():
        assert result["rc"] == 0
    contacted = ansible_module.yum(
        name="walrus-0.71-1",
        allow_downgrade=True,
        disable_plugin="foreman-protector",
        state="present",
    )
    for result in contacted.values():
        assert result["rc"] == 0

    def teardown_packages_update():
        contacted = ansible_module.yum(name="walrus", state="absent")
        for result in contacted.values():
            assert result["rc"] == 0

    request.addfinalizer(teardown_packages_update)
Beispiel #4
0
def setup_install_pkgs(ansible_module):
    """This fixture installs necessary packages required by Testfm testcases to run properly.
    This fixture is used in test_positive_check_hotfix_installed_with_hotfix and
    test_positive_check_hotfix_installed_without_hotfix of test_health.py
    """
    setup = ansible_module.yum(name="fio", state="present")
    for result in setup.values():
        assert result["rc"] == 0
    setup = ansible_module.command(Packages.unlock())
    for result in setup.values():
        assert result["rc"] == 0
    setup = ansible_module.yum(name=["python-kitchen", "yum-utils"], state="present")
    for result in setup.values():
        assert result["rc"] == 0
    teardown = ansible_module.command(Packages.lock())
    for result in teardown.values():
        assert result["rc"] == 0
Beispiel #5
0
def setup_packages_lock_tests(request, ansible_module,
                              setup_subscribe_to_cdn_dogfood):
    """Setup/Teardown for Packages lock tests"""
    # Test whether packages are locked or not
    contacted = ansible_module.command(
        "satellite-installer --lock-package-versions")
    for result in contacted.values():
        logger.info(result["stdout"])
        assert result["rc"] == 0
    contacted = ansible_module.command(Packages.status())
    for result in contacted.values():
        logger.info(result["stdout"])
        assert "Packages are locked." in result["stdout"]
        assert "Automatic locking of package versions is enabled in installer." in result[
            "stdout"]
        assert "FAIL" not in result["stdout"]
        assert result["rc"] == 0
    contacted = ansible_module.command(Packages.is_locked())
    for result in contacted.values():
        logger.info(result["stdout"])
        assert "Packages are locked" in result["stdout"]
        assert result["rc"] == 0
    contacted = ansible_module.yum(name="zsh", state="absent")
    for result in contacted.values():
        assert result["rc"] == 0
    contacted = ansible_module.yum(name="elinks", state="absent")
    for result in contacted.values():
        assert result["rc"] == 0

    def teardown_packages_lock_tests():
        contacted = ansible_module.yum(name="zsh", state="absent")
        for result in contacted.values():
            assert result["rc"] == 0
        contacted = ansible_module.yum(name="elinks", state="absent")
        for result in contacted.values():
            assert result["rc"] == 0
        # lock packages
        teardown = ansible_module.command(
            "satellite-installer --lock-package-versions")
        for result in teardown.values():
            logger.info(result["stdout"])
            assert result["rc"] == 0

    request.addfinalizer(teardown_packages_lock_tests)
Beispiel #6
0
    def teardown_hotfix_check():
        pkgs_locked = ansible_module.command(
            Packages.is_locked()).values()[0]["rc"]
        if pkgs_locked == 0:
            ansible_module.command(Packages.unlock())
        teardown = ansible_module.command(
            "yum -y reinstall tfm-rubygem-fog-vsphere")
        for result in teardown.values():
            assert result["rc"] == 0

        teardown = ansible_module.file(
            path="/etc/yum.repos.d/hotfix_repo.repo", state="absent")
        assert teardown.values()[0]["changed"] == 1
        teardown = ansible_module.yum(name=["hotfix-package"], state="absent")
        for result in teardown.values():
            assert result["rc"] == 0
        if pkgs_locked == 0:
            ansible_module.command(Packages.lock())
        ansible_module.command("yum clean all")
Beispiel #7
0
def test_positive_fm_packages_update(ansible_module, setup_packages_update):
    """Verify whether packages check-update and update work as expected.

    :id: 354d9940-10f1-4244-9079-fdbd24be49b3

    :setup:
        1. foreman-maintain should be installed.

    :steps:
        1. Run foreman-maintain packages check-update
        2. Run foreman-maintain packages update to update the walrus package.
        3. Verify walrus package is updated.

    :BZ: 1803975

    :expectedresults: foreman-maintain packages check-update should list walrus package for update
                      and foreman-maintain packages update should update the walrus package.

    :CaseImportance: Critical
    """
    # Run foreman-maintain packages check update and verify walrus package is available for update.
    contacted = ansible_module.command(Packages.check_update())
    for result in contacted.values():
        logger.info(result["stdout"])
        assert "FAIL" not in result["stdout"]
        assert result["rc"] == 0
        assert "walrus" in result["stdout"]
    # Run foreman-maintain packages update
    contacted = ansible_module.raw(Packages.update(["--assumeyes", "walrus"]))
    for result in contacted.values():
        logger.info(result["stdout"])
        assert "FAIL" not in result["stdout"]
        assert result["rc"] == 0
    # Verify walrus package is updated.
    contacted = ansible_module.command("rpm -qa walrus")
    for result in contacted.values():
        logger.info(result["stdout"])
        assert result["rc"] == 0
        assert "walrus-5.21-1" in result["stdout"]
Beispiel #8
0
def setup_custom_package(request, ansible_module):
    """Setup/Teardown cusom yum repo/package for non-rh-packages check."""
    ansible_module.yum_repository(
        name="custom_repo",
        description="custom repo",
        file="custom_repo",
        baseurl=f"{FAKE_YUM0_REPO}",
        enabled="yes",
        gpgcheck="no",
    )
    setup = ansible_module.file(path="/etc/yum.repos.d/custom_repo.repo",
                                state="present")
    assert setup.values()[0]["changed"] == 0

    pkgs_locked = ansible_module.command(
        Packages.is_locked()).values()[0]["rc"]
    if pkgs_locked == 0:
        ansible_module.command(Packages.unlock())

    contacted = ansible_module.yum(name="walrus", state="present")
    for result in contacted.values():
        assert result["rc"] == 0

    if pkgs_locked == 0:
        ansible_module.command(Packages.lock())

    def teardown_custom_package():
        teardown = ansible_module.yum(name="walrus", state="absent")
        for result in contacted.values():
            assert result["rc"] == 0

        teardown = ansible_module.file(
            path="/etc/yum.repos.d/custom_repo.repo", state="absent")
        assert teardown.values()[0]["changed"] == 1

    request.addfinalizer(teardown_custom_package)
Beispiel #9
0
def test_positive_fm_packages_lock(ansible_module):
    """Verify whether satellite related packages get locked

    :id: d387d8be-10ad-4a62-aeff-3bc6a82e6bae

    :setup:
        1. foreman-maintain should be installed.

    :steps:
        1. Run foreman-maintain packages lock
        2. Run foreman-maintain packages status
        3. Run foreman-maintain packages is-locked
        4. check 'satellite' is mentioned in /etc/yum/pluginconf.d/versionlock.list
        5. Run foreman-maintain packages unlock
        6. Run foreman-maintain packages status
        7. Run foreman-maintain packages is-locked
        8. check 'satellite' is not mentioned in /etc/yum/pluginconf.d/versionlock.list

    :expectedresults: expected packages get locked and unlocked.

    :CaseImportance: Critical
    """
    # Test Package lock command
    contacted = ansible_module.command(Packages.lock(["--assumeyes"]))
    for result in contacted.values():
        logger.info(result["stdout"])
        assert "FAIL" not in result["stdout"]
        assert result["rc"] == 0
    contacted = ansible_module.command(Packages.status())
    for result in contacted.values():
        logger.info(result["stdout"])
        assert "Packages are locked." in result["stdout"]
        assert "Automatic locking of package versions is enabled in installer." in result[
            "stdout"]
        assert "FAIL" not in result["stdout"]
        assert result["rc"] == 0
    contacted = ansible_module.command(Packages.is_locked())
    for result in contacted.values():
        logger.info(result["stdout"])
        assert "Packages are locked" in result["stdout"]
        assert result["rc"] == 0
    # Test package unlock command
    contacted = ansible_module.command(Packages.unlock())
    for result in contacted.values():
        logger.info(result["stdout"])
        assert "FAIL" not in result["stdout"]
        assert result["rc"] == 0
    contacted = ansible_module.command(Packages.status())
    for result in contacted.values():
        logger.info(result["stdout"])
        assert "FAIL" not in result["stdout"]
        assert "Packages are not locked." in result["stdout"]
        assert "Automatic locking of package versions is enabled in installer." in result[
            "stdout"]
        assert result["rc"] == 0
    contacted = ansible_module.command(Packages.is_locked())
    for result in contacted.values():
        logger.info(result["stdout"])
        assert "Packages are not locked" in result["stdout"]
        assert result["rc"] == 1
    # lock packages
    teardown = ansible_module.command(Packages.lock())
    for result in teardown.values():
        logger.info(result["stdout"])
        assert "FAIL" not in result["stdout"]
        assert result["rc"] == 0
Beispiel #10
0
def test_positive_lock_package_versions(ansible_module):
    """Verify whether satellite related packages get locked

    :id: 9218a718-038c-48bb-b4a4-d4cb74859ddb

    :setup:
        1. foreman-maintain should be installed.

    :steps:
        1. Run satellite-installer --lock-package-versions
        2. Run foreman-maintain packages status
        3. Run foreman-maintain packages is-locked
        4. Run satellite-installer --no-lock-package-versions
        5. Run foreman-maintain packages status
        6. Run foreman-maintain packages is-locked
        7. Teardown (Run satellite-installer --lock-package-versions)

    :expectedresults: expected packages get locked and unlocked.

    :CaseImportance: Critical
    """
    # Test whether packages are locked or not
    contacted = ansible_module.command(
        "satellite-installer --lock-package-versions")
    for result in contacted.values():
        logger.info(result["stdout"])
        assert result["rc"] == 0
    contacted = ansible_module.command(Packages.status())
    for result in contacted.values():
        logger.info(result["stdout"])
        assert "Packages are locked." in result["stdout"]
        assert "Automatic locking of package versions is enabled in installer." in result[
            "stdout"]
        assert "FAIL" not in result["stdout"]
        assert result["rc"] == 0
    contacted = ansible_module.command(Packages.is_locked())
    for result in contacted.values():
        logger.info(result["stdout"])
        assert "Packages are locked" in result["stdout"]
        assert result["rc"] == 0
    # Test whether packages are unlocked or not
    contacted = ansible_module.command(
        "satellite-installer --no-lock-package-versions")
    for result in contacted.values():
        logger.info(result["stdout"])
        assert result["rc"] == 0
    contacted = ansible_module.command(Packages.status())
    for result in contacted.values():
        logger.info(result["stdout"])
        assert "FAIL" not in result["stdout"]
        assert "Packages are not locked." in result["stdout"]
        assert "Automatic locking of package versions is disabled in installer." in result[
            "stdout"]
        assert result["rc"] == 0
    contacted = ansible_module.command(Packages.is_locked())
    for result in contacted.values():
        logger.info(result["stdout"])
        assert "Packages are not locked" in result["stdout"]
        assert result["rc"] == 1
    # lock packages
    teardown = ansible_module.command(
        "satellite-installer --lock-package-versions")
    for result in teardown.values():
        logger.info(result["stdout"])
        assert result["rc"] == 0
Beispiel #11
0
def test_positive_fm_packages_install(ansible_module,
                                      setup_packages_lock_tests):
    """Verify whether packages install/update work as expected.

    :id: 645a3d84-34cb-469c-8b79-105b889aac78

    :setup:
        1. foreman-maintain should be installed.

    :steps:
        1. Run satellite-installer --lock-package-versions
        2. Run foreman-maintain packages status
        3. Run foreman-maintain packages is-locked
        4. Try to install/update package using FM packages install/update command.
        5. Run satellite-installer --no-lock-package-versions
        6. Run foreman-maintain packages status
        7. Run foreman-maintain packages is-locked
        8. Try to install package in unlocked state.
        9. Teardown (Run satellite-installer --lock-package-versions)


    :expectedresults: expected packages get locked and unlocked.

    :CaseImportance: Critical
    """
    contacted = ansible_module.command("yum install -y zsh")
    for result in contacted.values():
        assert result["rc"] == 1
        assert "Use foreman-maintain packages install/update <package>" in result[
            "stdout"]
    # Test whether FM packages install/ update command works as expected.
    contacted = ansible_module.raw(
        Packages.install(["--assumeyes", "zsh-5.0.2-31.el7.x86_64 elinks"]))
    for result in contacted.values():
        logger.info(result["stdout"])
        assert "FAIL" not in result["stdout"]
        assert "Nothing to do" not in result["stdout"]
        assert "Packages are locked." in result["stdout"]
        assert "Automatic locking of package versions is enabled in installer." in result[
            "stdout"]
    contacted = ansible_module.raw(Packages.update(["--assumeyes", "zsh"]))
    for result in contacted.values():
        logger.info(result["stdout"])
        assert "FAIL" not in result["stdout"]
        assert "Nothing to do" not in result["stdout"]
        assert "Packages are locked." in result["stdout"]
        assert "Automatic locking of package versions is enabled in installer." in result[
            "stdout"]
    # Test whether packages are unlocked or not
    contacted = ansible_module.command(
        "satellite-installer --no-lock-package-versions")
    for result in contacted.values():
        logger.info(result["stdout"])
        assert result["rc"] == 0
    contacted = ansible_module.command(Packages.status())
    for result in contacted.values():
        logger.info(result["stdout"])
        assert "FAIL" not in result["stdout"]
        assert "Packages are not locked." in result["stdout"]
        assert "Automatic locking of package versions is disabled in installer." in result[
            "stdout"]
        assert result["rc"] == 0
    contacted = ansible_module.command(Packages.is_locked())
    for result in contacted.values():
        logger.info(result["stdout"])
        assert "Packages are not locked" in result["stdout"]
        assert result["rc"] == 1
    contacted = ansible_module.yum(name="zsh", state="absent")
    for result in contacted.values():
        assert result["rc"] == 0
    contacted = ansible_module.command("yum install -y zsh")
    for result in contacted.values():
        assert result["rc"] == 0
        assert "Use foreman-maintain packages install/update <package>" not in result[
            "stdout"]