forked from osism/ansible-collection-services
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenstack_health_monitor.py
74 lines (63 loc) · 2.63 KB
/
openstack_health_monitor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from .util.util import get_ansible, get_variable
testinfra_runner, testinfra_hosts = get_ansible()
def test_required_directories(host):
directories = [
get_variable(host, "openstack_health_monitor_configuration_directory"),
get_variable(host, "openstack_health_monitor_crontabs_directory"),
get_variable(host, "openstack_health_monitor_docker_compose_directory"),
]
for directory in directories:
dir = host.file(directory)
assert dir.exists
assert dir.is_directory
assert dir.user == get_variable(host, "operator_user")
assert dir.group == get_variable(host, "operator_group")
assert dir.mode == 0o750
def test_configuration_files(host):
files = [
{
"path": "openstack_health_monitor_configuration_directory",
"file": "openstack_health_monitor.env",
},
{
"path": "openstack_health_monitor_configuration_directory",
"file": "clouds.yml",
},
{
"path": "openstack_health_monitor_configuration_directory",
"file": "secure.yml",
},
]
for item in files:
file_path = f"{get_variable(host, item['path'])}/{item['file']}"
file = host.file(file_path)
assert file.exists
assert not file.is_directory
assert file.user == get_variable(host, "operator_user")
assert file.group == get_variable(host, "operator_group")
assert file.mode == 0o640
def test_docker_compose_file(host):
docker_compose_file_path = (
f"{get_variable(host, 'openstack_health_monitor_docker_compose_directory')}/"
f"docker-compose.yml"
)
docker_compose_file = host.file(docker_compose_file_path)
assert docker_compose_file.exists
assert not docker_compose_file.is_directory
assert docker_compose_file.user == get_variable(host, "operator_user")
assert docker_compose_file.group == get_variable(host, "operator_group")
assert docker_compose_file.mode == 0o640
def test_openstack_health_monitor_service(host):
service = host.service(get_variable(host, "openstack_health_monitor_service_name"))
assert service.is_running
assert service.is_enabled
def test_cronjob_setup(host):
cronjob_enabled = get_variable(host, "openstack_health_monitor_cronjob")
if cronjob_enabled:
cron_file_path = (
f"{get_variable(host, 'openstack_health_monitor_crontabs_directory')}/main"
)
cron_file = host.file(cron_file_path)
assert cron_file.exists
assert cron_file.user == get_variable(host, "operator_user")
assert "*/10" in cron_file.content_string