ansible-collection-prometheus/roles/prometheus/molecule/latest/tests/test_alternative.py
gardar 083ff4ef36
skip_changelog: make testinfra tests capture logs on service failure
Signed-off-by: gardar <gardar@users.noreply.github.com>
2023-08-18 15:47:32 +00:00

38 lines
1 KiB
Python

from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import os
import testinfra.utils.ansible_runner
import pytest
testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
@pytest.mark.parametrize("files", [
"/etc/systemd/system/prometheus.service",
"/usr/local/bin/prometheus",
"/usr/local/bin/promtool"
])
def test_files(host, files):
f = host.file(files)
assert f.exists
assert f.is_file
def test_service(host):
s = host.service("prometheus")
try:
assert s.is_running
except AssertionError:
# Capture service logs
journal_output = host.run('journalctl -u prometheus --since "1 hour ago"')
print("\n==== journalctl -u prometheus Output ====\n")
print(journal_output)
print("\n============================================\n")
raise # Re-raise the original assertion error
def test_socket(host):
s = host.socket("tcp://0.0.0.0:9090")
assert s.is_listening