Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

Commit

Permalink
Add check for BZ-1830355
Browse files Browse the repository at this point in the history
Signed-off-by: Gaurav Talreja <gtalreja@redhat.com>
  • Loading branch information
Gauravtalreja1 committed Oct 31, 2021
1 parent 1bfe83b commit 11d73bc
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 39 deletions.
44 changes: 33 additions & 11 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,22 +61,13 @@ def setup_hotfix_check(request, ansible_module):
ansible_module.command(Packages.lock())

def teardown_hotfix_check():
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
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
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")
Expand Down Expand Up @@ -565,3 +556,34 @@ def teardown_custom_package():
assert teardown.values()[0]["changed"] == 1

request.addfinalizer(teardown_custom_package)


@pytest.fixture(scope="function")
def change_admin_passwd(request, setup_install_pexpect, ansible_module):
"""Setup/Teardown for test_advanced.test_positive_foreman_maintain_hammer_setup"""
setup = ansible_module.command(
"hammer -u admin -p changeme user update --login admin --password admin"
)
for result in setup.values():
logger.info(result)
assert result["rc"] == 0

def default_admin_passwd():
teardown = ansible_module.command(
"hammer -u admin -p admin user update --login admin --password 'changeme'"
)
for result in teardown.values():
logger.info(result)
assert result["rc"] == 0
# Make default admin creds available in foreman_maintain_yml
output = ansible_module.command(Advanced.run_hammer_setup())
for result in output.values():
logger.info(result)
assert result["rc"] == 0
# Make sure default password available in foreman_maintain_yml
output = ansible_module.command(f"grep -i ':password: changeme' {foreman_maintain_yml}")
for result in output.values():
assert result["rc"] == 0
assert "changeme" in result["stdout"]

request.addfinalizer(default_admin_passwd)
62 changes: 34 additions & 28 deletions tests/test_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from testfm.advanced_by_tag import AdvancedByTag
from testfm.constants import cap_beta_repo
from testfm.constants import cap_repos
from testfm.constants import foreman_maintain_yml
from testfm.constants import sat_beta_repo
from testfm.constants import sat_repos
from testfm.decorators import stubbed
Expand Down Expand Up @@ -33,7 +34,7 @@ def test_positive_foreman_maintain_service_restart(ansible_module):
assert "FAIL" not in result["stdout"]


def test_positive_foreman_maintain_hammer_setup(setup_install_pexpect, ansible_module):
def test_positive_foreman_maintain_hammer_setup(change_admin_passwd, ansible_module):
"""Hammer setup using advanced procedure
:id: 236171c0-5185-465e-9eec-e15dfefb41c3
Expand All @@ -49,34 +50,39 @@ def test_positive_foreman_maintain_hammer_setup(setup_install_pexpect, ansible_m
:expectedresults: Hammer setup should successful.
:CaseImportance: Critical
:BZ: 1830355
"""
try:
setup = ansible_module.command(
"hammer -u admin -p changeme"
" user update"
" --login admin "
"--password 'JMNBzJ*a-4;XH!C~'"
)
for result in setup.values():
logger.info(result)
assert result["rc"] == 0
output = ansible_module.expect(
command=Advanced.run_hammer_setup(),
responses={"Hammer admin password: ": "JMNBzJ*a-4;XH!C~"},
)
for result in output.values():
logger.info(result)
assert result["rc"] == 0
finally:
teardown = ansible_module.command(
"hammer -u admin "
"-p 'JMNBzJ*a-4;XH!C~'"
" user update --login admin"
" --password 'changeme'"
)
for result in teardown.values():
logger.info(result)
assert result["rc"] == 0
# try with incorrect password
output = ansible_module.expect(
command=Advanced.run_hammer_setup(),
responses={"Hammer admin password: ": "wrong_password"},
)
for result in output.values():
logger.info(result)
assert "Incorrect credential for admin user" in result["stdout"]
assert result["rc"] == 1

# Verify wrong_password isn't updated in foreman_maintain_yml
output = ansible_module.command(f"grep -i ':password: wrong_password' {foreman_maintain_yml}")
for result in output.values():
assert result["rc"] == 1
assert "wrong_password" not in result["stdout"]

# try with correct password
output = ansible_module.expect(
command=Advanced.run_hammer_setup(),
responses={"Hammer admin password: ": "admin"},
)
for result in output.values():
logger.info(result)
assert result["rc"] == 0

# Verify new password updated in foreman_maintain_yml
output = ansible_module.command(f"grep -i ':password: admin' {foreman_maintain_yml}")
for result in output.values():
assert result["rc"] == 0
assert "admin" in result["stdout"]


@stubbed
Expand Down

0 comments on commit 11d73bc

Please sign in to comment.