diff options
Diffstat (limited to 'meta/lib/oeqa/runtime/systemd.py')
-rw-r--r-- | meta/lib/oeqa/runtime/systemd.py | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/meta/lib/oeqa/runtime/systemd.py b/meta/lib/oeqa/runtime/systemd.py new file mode 100644 index 0000000000..1451698bb3 --- /dev/null +++ b/meta/lib/oeqa/runtime/systemd.py | |||
@@ -0,0 +1,88 @@ | |||
1 | import unittest | ||
2 | import re | ||
3 | from oeqa.oetest import oeRuntimeTest, skipModule | ||
4 | from oeqa.utils.decorators import * | ||
5 | |||
6 | def 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 | |||
13 | class 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 | |||
25 | class SystemdBasicTests(SystemdTest): | ||
26 | |||
27 | @skipUnlessPassed('test_ssh') | ||
28 | def test_systemd_basic(self): | ||
29 | self.systemctl('--version') | ||
30 | |||
31 | @testcase(551) | ||
32 | @skipUnlessPassed('test_system_basic') | ||
33 | def test_systemd_list(self): | ||
34 | self.systemctl('list-unit-files') | ||
35 | |||
36 | def settle(self): | ||
37 | """ | ||
38 | Block until systemd has finished activating any units being activated, | ||
39 | or until two minutes has elapsed. | ||
40 | |||
41 | Returns a tuple, either (True, '') if all units have finished | ||
42 | activating, or (False, message string) if there are still units | ||
43 | activating (generally, failing units that restart). | ||
44 | """ | ||
45 | import time | ||
46 | endtime = time.time() + (60 * 2) | ||
47 | while True: | ||
48 | status, output = self.target.run('systemctl --state=activating') | ||
49 | if "0 loaded units listed" in output: | ||
50 | return (True, '') | ||
51 | if time.time() >= endtime: | ||
52 | return (False, output) | ||
53 | time.sleep(10) | ||
54 | |||
55 | @testcase(550) | ||
56 | @skipUnlessPassed('test_systemd_basic') | ||
57 | def test_systemd_failed(self): | ||
58 | settled, output = self.settle() | ||
59 | self.assertTrue(settled, msg="Timed out waiting for systemd to settle:\n" + output) | ||
60 | |||
61 | output = self.systemctl('list-units', '--failed') | ||
62 | match = re.search("0 loaded units listed", output) | ||
63 | if not match: | ||
64 | output += self.systemctl('status --full --failed') | ||
65 | self.assertTrue(match, msg="Some systemd units failed:\n%s" % output) | ||
66 | |||
67 | |||
68 | class SystemdServiceTests(SystemdTest): | ||
69 | |||
70 | @skipUnlessPassed('test_systemd_basic') | ||
71 | def test_systemd_status(self): | ||
72 | self.systemctl('status --full', 'avahi-daemon.service') | ||
73 | |||
74 | @testcase(695) | ||
75 | @skipUnlessPassed('test_systemd_status') | ||
76 | def test_systemd_stop_start(self): | ||
77 | self.systemctl('stop', 'avahi-daemon.service') | ||
78 | self.systemctl('is-active', 'avahi-daemon.service', expected=3, verbose=True) | ||
79 | self.systemctl('start','avahi-daemon.service') | ||
80 | self.systemctl('is-active', 'avahi-daemon.service', verbose=True) | ||
81 | |||
82 | @testcase(696) | ||
83 | @skipUnlessPassed('test_systemd_basic') | ||
84 | def test_systemd_disable_enable(self): | ||
85 | self.systemctl('disable', 'avahi-daemon.service') | ||
86 | self.systemctl('is-enabled', 'avahi-daemon.service', expected=1) | ||
87 | self.systemctl('enable', 'avahi-daemon.service') | ||
88 | self.systemctl('is-enabled', 'avahi-daemon.service') | ||