Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(test):Refactoring to replace service name from rhcd to yggdrasil #122

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions integration-tests/test_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import sh

from utils import (
rhcd_service_is_active,
yggdrasil_service_is_active,
prepare_args_for_connect,
check_rhcd_journalctl,
check_yggdrasil_journalctl,
)

logger = logging.getLogger(__name__)
Expand All @@ -23,18 +23,18 @@
@pytest.mark.parametrize("auth", ["basic", "activation-key"])
def test_connect(external_candlepin, rhc, test_config, auth):
"""Test if RHC can connect to CRC using basic auth and activation key,
Also verify that rhcd service is in active state afterward.
Also verify that yggdrasil service is in active state afterward.
"""
with contextlib.suppress(Exception):
rhc.disconnect()
command_args = prepare_args_for_connect(test_config, auth=auth)
command = ["connect"] + command_args
result = rhc.run(*command)
assert rhc.is_registered
assert rhcd_service_is_active()
assert yggdrasil_service_is_active()
assert "Connected to Red Hat Subscription Management" in result.stdout
assert "Connected to Red Hat Insights" in result.stdout
assert "Activated the Remote Host Configuration daemon" in result.stdout
assert "Activated the yggdrasil service" in result.stdout
assert "Successfully connected to Red Hat!" in result.stdout


Expand Down Expand Up @@ -101,7 +101,7 @@ def test_connect_wrong_parameters(
command = ["connect"] + command_args
result = rhc.run(*command, check=False)
assert result.returncode == 1
assert not rhcd_service_is_active()
assert not yggdrasil_service_is_active()


@pytest.mark.parametrize("auth", ["basic", "activation-key"])
Expand All @@ -113,7 +113,7 @@ def test_rhc_worker_playbook_install_after_rhc_connect(
Also log the total time taken to install the package
test_steps:
1- run 'rhc connect'
2- monitor rhcd logs to see when package-manager-worker installs 'rhc-worker-playbook'
2- monitor yggdrasil logs to see when package-manager-worker installs 'rhc-worker-playbook'
3- validate rhc-worker-playbook is installed
"""
with contextlib.suppress(Exception):
Expand All @@ -125,7 +125,7 @@ def test_rhc_worker_playbook_install_after_rhc_connect(

start_date_time = datetime.now().strftime(
"%Y-%m-%d %H:%M:%S"
) # current date and time for observing rhcd logs
) # current date and time for observing yggdrasil logs
command_args = prepare_args_for_connect(test_config, auth=auth)
command = ["connect"] + command_args
rhc.run(*command, check=False)
Expand All @@ -134,7 +134,7 @@ def test_rhc_worker_playbook_install_after_rhc_connect(
# Verifying if rhc-worker-playbook was installed successfully
t_end = time.time() + 60 * 5 # maximum time to wait for installation
while time.time() < t_end:
installed_status = check_rhcd_journalctl(
installed_status = check_yggdrasil_journalctl(
str_to_check=success_message,
since_datetime=start_date_time,
must_exist_in_log=True,
Expand All @@ -151,6 +151,6 @@ def test_rhc_worker_playbook_install_after_rhc_connect(
pkg_version = sh.rpm("-qa", "rhc-worker-playbook")
logger.info(f"successfully installed rhc_worker_playbook package {pkg_version}")
logger.info(
f"time taken to start rhcd service and install "
f"time taken to start yggdrasil service and install "
f"rhc_worker_playbook : {total_runtime} s"
)
22 changes: 12 additions & 10 deletions integration-tests/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
import sh


def rhcd_service_is_active():
"""Method to verify if rhcd is in active/inactive state
:return: True if rhcd in active state else False
def yggdrasil_service_is_active():
"""Method to verify if yggdrasil is in active/inactive state
:return: True if yggdrasil in active state else False
"""
try:
stdout = sh.systemctl("is-active rhcd".split()).strip()
stdout = sh.systemctl("is-active yggdrasil".split()).strip()
return stdout == "active"
except sh.ErrorReturnCode_3:
return False


def check_rhcd_journalctl(str_to_check, since_datetime=None, must_exist_in_log=True):
"""This method helps in verifying strings in rhcd logs
def check_yggdrasil_journalctl(
str_to_check, since_datetime=None, must_exist_in_log=True
):
"""This method helps in verifying strings in yggdrasil logs
:param str_to_check: string to be searched in logs
:param since_datetime: start time for logs
:param must_exist_in_log: True if str_to_check should exist in log else false
:return: True/False
"""
if since_datetime:
rhcd_logs = sh.journalctl("-u", "rhcd", "--since", since_datetime)
yggdrasil_logs = sh.journalctl("-u", "yggdrasil", "--since", since_datetime)
else:
rhcd_logs = sh.journalctl("-u", "rhcd")
yggdrasil_logs = sh.journalctl("-u", "yggdrasil")

if must_exist_in_log:
return str_to_check in rhcd_logs
return str_to_check in yggdrasil_logs
else:
return str_to_check not in rhcd_logs
return str_to_check not in yggdrasil_logs


def prepare_args_for_connect(
Expand Down
Loading