-
Notifications
You must be signed in to change notification settings - Fork 1
/
dockertests.py
52 lines (39 loc) · 1.51 KB
/
dockertests.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
import unittest
import re
from .testutils import system
class TestBase(unittest.TestCase):
def test_selinux(self):
"Tests the SELinux"
out, err, eid = system('sudo getenforce')
out = out.strip()
out = out.decode('utf-8')
self.assertEqual(out, 'Enforcing')
def test_logging(self):
"Tests journald logging"
out, err, eid = system('sudo journalctl -a --no-pager -r --since=$(date +%Y-%m-%d) -n1')
out = out.decode('utf-8')
self.assertGreater(len(out.split()), 3, "journalctl output is missing.")
def test_services(self):
"No service should fail in the startup."
out, err, eid = system('systemctl --all --failed')
out = out.decode('utf-8')
self.assertIn('0 loaded units listed', out)
class TestDocker(unittest.TestCase):
def test_docker_enabled(self):
out, err, eid = system('sudo systemctl is-enabled docker')
out = out.strip()
out = out.decode('utf-8')
self.assertEqual('enabled', out)
def test_docker_running(self):
out, err, eid = system('sudo systemctl is-active docker')
out = out.strip()
out = out.decode('utf-8')
self.assertEqual('active', out)
def test_docker_pull(self):
out, err, eid = system('docker pull alpine')
self.assertEqual(0, eid)
def test_docker_run(self):
out, err, eid = system('docker run --rm docker.io/alpine ls')
self.assertEqual(0, eid)
if __name__ == '__main__':
unittest.main()