From ed5a535402d40dea03a19c26e6f32759da30c0f1 Mon Sep 17 00:00:00 2001 From: Radek Mynar Date: Mon, 18 Dec 2023 16:26:40 +0100 Subject: [PATCH] refactor and simplify ping test after cache status was added (cherry picked from commit d984b2b8438e0b4bb8ccadba2cce77f8d85c6b8c) --- tests/foreman/cli/test_ping.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/tests/foreman/cli/test_ping.py b/tests/foreman/cli/test_ping.py index 0a288143233..1036b3c5fd9 100644 --- a/tests/foreman/cli/test_ping.py +++ b/tests/foreman/cli/test_ping.py @@ -37,21 +37,13 @@ def test_positive_ping(target_sat, switch_user): """ result = target_sat.execute(f"su - {'postgres' if switch_user else 'root'} -c 'hammer ping'") assert result.stderr[1].decode() == '' - assert result.status == 0 - status_count = 0 - ok_count = 0 - # Exclude message from stdout for services candlepin_events and katello_events - result.stdout = [line for line in result.stdout.splitlines() if 'message' not in line] + # Filter lines containing status + statuses = [line for line in result.stdout.splitlines() if 'status:' in line.lower()] - # iterate over the lines grouping every 3 lines - # example [1, 2, 3, 4, 5, 6] will return [(1, 2, 3), (4, 5, 6)] - # only the status line is relevant for this test - for _, status, _ in zip(*[iter(result.stdout)] * 3, strict=False): # should this be strict? - status_count += 1 - - if status.split(':')[1].strip().lower() == 'ok': - ok_count += 1 + # Get count of total status lines and lines containing OK + status_count = len(statuses) + ok_count = len([status for status in statuses if status.split(':')[1].strip().lower() == 'ok']) if status_count == ok_count: assert result.status == 0, 'Return code should be 0 if all services are ok'