61 lines
1.9 KiB
Python

import os
import testinfra.utils.ansible_runner
test_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']
).get_hosts('all')
def test_user_and_group_exist(host):
"""
Проверяем, что пользователь и группа node_exporter существуют.
"""
user = host.user("node_exporter")
assert user.exists
assert user.group == "node_exporter"
def test_binary_and_symlink(host):
"""
Проверяем, что бинарник node_exporter установлен и имеет права на исполнение.
"""
binary = host.file("/opt/node_exporter/node_exporter")
symlink = host.file("/usr/local/bin/node_exporter")
assert binary.exists
assert binary.mode & 0o111
assert binary.user == "node_exporter"
assert binary.group == "node_exporter"
assert symlink.exists
assert symlink.is_symlink
assert symlink.linked_to == "/opt/node_exporter/node_exporter"
def test_service_unit_file(host):
"""
Проверяем, что systemd unit-файл для node_exporter существует и содержит правильную команду запуска.
"""
unit = host.file("/etc/systemd/system/node_exporter.service")
assert unit.exists
assert unit.user == "root"
assert unit.group == "root"
assert unit.mode == 0o644
assert unit.contains("ExecStart=/usr/local/bin/node_exporter")
def test_service_running_and_enabled(host):
"""
Проверяем, что сервис node_exporter запущен и включён в автозагрузку.
"""
svc = host.service("node_exporter")
assert svc.is_enabled
assert svc.is_running
def test_listen_port(host):
"""
Проверяем, что node_exporter слушает порт 9100.
"""
socket = host.socket("tcp://0.0.0.0:9100")
assert socket.is_listening