Skip to content

Commit

Permalink
test: Added tests for rhc status
Browse files Browse the repository at this point in the history
  • Loading branch information
archana-redhat committed Jul 1, 2024
1 parent 888aac9 commit 3b6efb6
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
96 changes: 96 additions & 0 deletions integration-tests/test_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
"""
This Python module contains integration tests for rhc. It uses pytest-client-tools Python module.
More information about this module could be found: https://github.com/ptoscano/pytest-client-tools/
"""

import contextlib

import sh
from utils import yggdrasil_service_is_active, show_yggdrasil_service_status


def test_status_connected(external_candlepin, rhc, test_config):
"""
Test RHC Status command when the host is connected and disconnected
test_steps:
1- rhc connect
2- rhc status
expected_output:
1- Validate following strings in status command output
"Connected to Red Hat Subscription Management"
"Connected to Red Hat Insights"
"The yggdrasil service is active"
"""
rhc.connect(
username=test_config.get("candlepin.username"),
password=test_config.get("candlepin.password"),
)
assert yggdrasil_service_is_active()
status_result = rhc.run("status", check=False)
assert status_result.returncode == 0
assert "Connected to Red Hat Subscription Management" in status_result.stdout
assert "Connected to Red Hat Insights" in status_result.stdout
assert "The yggdrasil service is active" in status_result.stdout


def test_status_disconnected(rhc):
"""
Test RHC Status command when the host is connected and disconnected
test_steps:
1- rhc disconnect
2- rhc status
expected_output:
1- Validate following strings in status command output
"Not connected to Red Hat Subscription Management"
"Not connected to Red Hat Insights"
"The yggdrasil service is inactive"
"""
rhc.run("disconnect", check=False)
status_result = rhc.run("status", check=False)
assert status_result.returncode == 0
assert "Not connected to Red Hat Subscription Management" in status_result.stdout
assert "Not connected to Red Hat Insights" in status_result.stdout
assert "The yggdrasil service is inactive" in status_result.stdout


def test_rhcd_started_after_reboot(external_candlepin, rhc, test_config):
"""
Test RHCD service is started automatically after reboot.
Note:
currently it is not possible to actually reboot a
system due to infra limitations so we will try to
restart service vis systemd instead
test_steps:
1- disconnect the system
2- restart yggdrasil service via systemctl
expected_results:
1- Yggdrasil service should be restarted successfully and set in active state
"""
with contextlib.suppress(Exception):
rhc.disconnect()

# reboot the test system, but currently it is not possible to actually reboot a
# system, so we will try to restart service vis systemd instead
# reboot_commands = ["tmt-reboot", "rhts-reboot", "reboot"] ### Change-Me
try:
cmd = sh.systemctl("restart yggdrasil".split(), _return_cmd=True)
cmd.wait(timeout=60)
assert yggdrasil_service_is_active()
except AssertionError as exc:
show_yggdrasil_service_status()
raise exc

# test yggdrasil service restart on a connected system
rhc.connect(
username=test_config.get("candlepin.username"),
password=test_config.get("candlepin.password"),
)
assert rhc.is_registered
try:
cmd = sh.systemctl("restart yggdrasil".split(), _return_cmd=True)
cmd.wait(timeout=60)
assert yggdrasil_service_is_active()
except AssertionError as exc:
show_yggdrasil_service_status()
raise exc
5 changes: 5 additions & 0 deletions integration-tests/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ def yggdrasil_service_is_active():
return False


def show_yggdrasil_service_status():
status = sh.systemctl("status yggdrasil".split()).strip()
return status


def check_yggdrasil_journalctl(
str_to_check, since_datetime=None, must_exist_in_log=True
):
Expand Down

0 comments on commit 3b6efb6

Please sign in to comment.