Skip to content

Commit

Permalink
Added more output to test_no_fail_service test case.
Browse files Browse the repository at this point in the history
  • Loading branch information
narmaku committed Aug 16, 2023
1 parent 2aedf69 commit 0168ef0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
19 changes: 18 additions & 1 deletion lib/test_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import re
import time

from lib import ssh_lib
from lib import ssh_lib, console_lib


def is_rhel_atomic_host(host):
Expand Down Expand Up @@ -192,3 +192,20 @@ def filter_host_log_file_by_keywords(host,
print(result.stderr)

return None


def print_host_command_output(host, command, use_sudo=True):
console_lib.print_divider(command)

if use_sudo:
with host.sudo():
result = host.run(command)
else:
result = host.run(command)

if result.failed:
print(f'Exit code: {result.exit_status}\n')
print(f'Stdout:\n{result.stdout}\n')
print(f'Stderr:\n{result.stderr}\n')
else:
print(result.stdout)
26 changes: 24 additions & 2 deletions test_suite/generic/test_generic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re
import time

import pytest
Expand Down Expand Up @@ -420,8 +421,29 @@ def test_no_fail_service(self, host):

print(result.stdout)

assert result.rc != 0 and result.stdout == '', \
'There are failing services'
failing_services = []

failing_service_regex = r'^● (?P<service>.*).service\s+'

failing_services_lines = result.stdout.split('\n')
for line in failing_services_lines:
regex_match = re.match(failing_service_regex, line)

if regex_match:
failing_service_data = regex_match.groupdict()

service_name = failing_service_data['service']
failing_services.append(service_name)

test_lib.print_host_command_output(host, f'systemctl status {service_name}')

test_lib.print_host_command_output(
host,
f'rpm -qf "$(systemctl show --value --property=FragmentPath {service_name})"'
)

assert len(failing_services) == 0, \
f'There are failing services: {",".join(failing_services)}'


@pytest.mark.pub
Expand Down

0 comments on commit 0168ef0

Please sign in to comment.