Skip to content

Commit

Permalink
refactor and simplify ping test after cache status was added
Browse files Browse the repository at this point in the history
  • Loading branch information
rmynar committed Dec 19, 2023
1 parent e17e37b commit 812a49d
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions tests/foreman/cli/test_ping.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,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):
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'
Expand Down

0 comments on commit 812a49d

Please sign in to comment.