Debian Codegraph @

ansible_collections/community/mongodb/roles/mongodb_linux/molecule/default/tests/test_default.py

raw
1 import os
2
3 import testinfra.utils.ansible_runner
4
5 testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
6 os.environ['MOLECULE_INVENTORY_FILE']
7 ).get_hosts('all')
8
9
10 def test_ntp_package(host):
11 ntp = host.package("ntp")
12 chrony = host.package("chrony")
13 ntpsec = host.package("ntpsec")
14 timesyncd = host.package("systemd-timesyncd")
15 assert ntp.is_installed or chrony.is_installed or ntpsec.is_installed or timesyncd.is_installed
16
17
18 def test_ntpd_service(host):
19 ntpd = host.service("ntpd")
20
21 if ntpd.is_running:
22 assert ntpd.is_enabled
23 else:
24 ntp = host.service("ntp")
25 if ntp.is_running:
26 assert ntp.is_enabled
27 else:
28 chronyd = host.service("chronyd")
29 if chronyd.is_running:
30 assert chronyd.is_enabled
31 else:
32 timesyncd = host.service("systemd-timesyncd")
33 assert timesyncd.is_running
34 assert timesyncd.is_enabled
35
36
37 def test_swappiness_value(host):
38 cmd = host.run("cat /proc/sys/vm/swappiness")
39
40 assert cmd.rc == 0
41 assert cmd.stdout.strip() == "1"
42
43
44 def test_thp_service_file(host):
45 f = host.file("/etc/systemd/system/manage-transparent-huge-pages.service")
46
47 assert f.exists
48 assert f.user == "root"
49 assert f.group == "root"
50
51
52 def test_thp_service(host):
53 '''
54 Validates the service actually works
55 '''
56 switches = ["/sys/kernel/mm/transparent_hugepage/enabled",
57 "/sys/kernel/mm/transparent_hugepage/defrag"]
58
59 facts = host.ansible("setup")["ansible_facts"]
60 virt_types = facts.get("ansible_virtualization_tech_guest", [facts["ansible_virtualization_type"]])
61 in_docker = "container" in virt_types or "docker" in virt_types
62 # in_docker is false on GHA here since they use custom parent cgroup (actions_job)
63 if not in_docker and facts["ansible_virtualization_role"] == "guest":
64 # inspecting cgroups is iffy on GHA, so use the /.dockerenv file
65 in_docker = host.file("/.dockerenv").exists
66
67 for d in switches:
68 cmd = host.run("cat {0}".format(d))
69
70 assert cmd.rc == 0
71 assert "[never]" in cmd.stdout
72
73
74 def test_limit_file(host):
75 f = host.file("/etc/security/limits.conf")
76
77 assert f.exists
78 assert f.user == "root"
79 assert f.group == "root"
80
81 assert f.contains("mongodb hard nproc 64000")
82 assert f.contains("mongodb hard nofile 64000")
83 assert f.contains("mongodb soft nproc 64000")
84 assert f.contains("mongodb soft nofile 64000")
85 assert f.contains("mongodb hard memlock 1024")
86 assert f.contains("mongodb soft memlock 1024")