diff options
author | Adrian Dudau <adrian.dudau@enea.com> | 2014-06-26 14:36:22 +0200 |
---|---|---|
committer | Adrian Dudau <adrian.dudau@enea.com> | 2014-06-26 15:32:53 +0200 |
commit | f4cf9fe05bb3f32fabea4e54dd92d368967a80da (patch) | |
tree | 487180fa9866985ea7b28e625651765d86f515c3 /meta/lib/oeqa/runtime/systemd.py | |
download | poky-f4cf9fe05bb3f32fabea4e54dd92d368967a80da.tar.gz |
initial commit for Enea Linux 4.0
Migrated from the internal git server on the daisy-enea branch
Signed-off-by: Adrian Dudau <adrian.dudau@enea.com>
Diffstat (limited to 'meta/lib/oeqa/runtime/systemd.py')
-rw-r--r-- | meta/lib/oeqa/runtime/systemd.py | 84 |
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 0000000000..6de84f891b --- /dev/null +++ b/meta/lib/oeqa/runtime/systemd.py | |||
@@ -0,0 +1,84 @@ | |||
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 | @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 | |||
66 | class 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') | ||