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
(cherry picked from commit d984b2b)
  • Loading branch information
rmynar authored and web-flow committed Jan 11, 2024
1 parent 25793b9 commit ed5a535
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 @@ -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'
Expand Down

0 comments on commit ed5a535

Please sign in to comment.