summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/runtime/systemd.py
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/oeqa/runtime/systemd.py')
-rw-r--r--meta/lib/oeqa/runtime/systemd.py84
1 files changed, 84 insertions, 0 deletions
diff --git a/meta/lib/oeqa/runtime/systemd.py b/meta/lib/oeqa/runtime/systemd.py
new file mode 100644
index 0000000..6de84f8
--- /dev/null
+++ b/meta/lib/oeqa/runtime/systemd.py
@@ -0,0 +1,84 @@
1import unittest
2import re
3from oeqa.oetest import oeRuntimeTest, skipModule
4from oeqa.utils.decorators import *
5
6def setUpModule():
7 if not oeRuntimeTest.hasFeature("systemd"):
8 skipModule("target doesn't have systemd in DISTRO_FEATURES")
9 if "systemd" != oeRuntimeTest.tc.d.getVar("VIRTUAL-RUNTIME_init_manager", True):
10 skipModule("systemd is not the init manager for this image")
11
12
13class SystemdTest(oeRuntimeTest):
14
15 def systemctl(self, action = '', target = '', expected = 0, verbose = False):
16 command = 'systemctl %s %s' % (action, target)
17 status, output = self.target.run(command)
18 message = '\n'.join([command, output])
19 if status != expected and verbose:
20 message += self.target.run('systemctl status --full %s' % target)[1]
21 self.assertEqual(status, expected, message)
22 return output
23
24
25class SystemdBasicTests(SystemdTest):
26
27 @skipUnlessPassed('test_ssh')
28 def test_systemd_basic(self):
29 self.systemctl('--version')
30
31 @skipUnlessPassed('test_system_basic')
32 def test_systemd_list(self):
33 self.systemctl('list-unit-files')
34
35 def settle(self):
36 """
37 Block until systemd has finished activating any units being activated,
38 or until two minutes has elapsed.
39
40 Returns a tuple, either (True, '') if all units have finished
41 activating, or (False, message string) if there are still units
42 activating (generally, failing units that restart).
43 """
44 import time
45 endtime = time.time() + (60 * 2)
46 while True:
47 status, output = self.target.run('systemctl --state=activating')
48 if "0 loaded units listed" in output:
49 return (True, '')
50 if time.time() >= endtime:
51 return (False, output)
52 time.sleep(10)
53
54 @skipUnlessPassed('test_systemd_basic')
55 def test_systemd_failed(self):
56 settled, output = self.settle()
57 self.assertTrue(settled, msg="Timed out waiting for systemd to settle:\n" + output)
58
59 output = self.systemctl('list-units', '--failed')
60 match = re.search("0 loaded units listed", output)
61 if not match:
62 output += self.systemctl('status --full --failed')
63 self.assertTrue(match, msg="Some systemd units failed:\n%s" % output)
64
65
66class SystemdServiceTests(SystemdTest):
67
68 @skipUnlessPassed('test_systemd_basic')
69 def test_systemd_status(self):
70 self.systemctl('status --full', 'avahi-daemon.service')
71
72 @skipUnlessPassed('test_systemd_status')
73 def test_systemd_stop_start(self):
74 self.systemctl('stop', 'avahi-daemon.service')
75 self.systemctl('is-active', 'avahi-daemon.service', expected=3, verbose=True)
76 self.systemctl('start','avahi-daemon.service')
77 self.systemctl('is-active', 'avahi-daemon.service', verbose=True)
78
79 @skipUnlessPassed('test_systemd_basic')
80 def test_systemd_disable_enable(self):
81 self.systemctl('disable', 'avahi-daemon.service')
82 self.systemctl('is-enabled', 'avahi-daemon.service', expected=1)
83 self.systemctl('enable', 'avahi-daemon.service')
84 self.systemctl('is-enabled', 'avahi-daemon.service')