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

Added more output to test_no_fail_service test case. #268

Merged
merged 1 commit into from
Aug 16, 2023
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
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
Loading