diff options
author | Stefan Stanacar <stefanx.stanacar@intel.com> | 2013-12-18 21:02:05 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-12-20 12:26:29 +0000 |
commit | b24f2172a5e1ac93ea1c378b6989f8f573ccd154 (patch) | |
tree | 0adb463d13f2c3a74b280c7301d11599dd871459 /meta/lib/oeqa/runtime | |
parent | 7c1c3d1c6e4a042e5b20ce006d42757ffbba40f9 (diff) | |
download | poky-b24f2172a5e1ac93ea1c378b6989f8f573ccd154.tar.gz |
lib/oeqa/runtime: rewrite the systemd test module
They are basically the same tests but:
- they look cleaner, using one single method / assert
- output from unittest will be cleaner (and includes a verbose status when needed)
- they are better grouped and use a real, active, enabled service
(machineid will be dropped and hostnamed was a static service)
(From OE-Core rev: 0aa5b97f9e0d8941ce342e9f162dd3b19d4b49bb)
Signed-off-by: Stefan Stanacar <stefanx.stanacar@intel.com>
Signed-off-by: Saul Wold <sgw@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa/runtime')
-rw-r--r-- | meta/lib/oeqa/runtime/systemd.py | 93 |
1 files changed, 45 insertions, 48 deletions
diff --git a/meta/lib/oeqa/runtime/systemd.py b/meta/lib/oeqa/runtime/systemd.py index 31007df424..eed29d3952 100644 --- a/meta/lib/oeqa/runtime/systemd.py +++ b/meta/lib/oeqa/runtime/systemd.py | |||
@@ -1,4 +1,5 @@ | |||
1 | import unittest | 1 | import unittest |
2 | import re | ||
2 | from oeqa.oetest import oeRuntimeTest, skipModule | 3 | from oeqa.oetest import oeRuntimeTest, skipModule |
3 | from oeqa.utils.decorators import * | 4 | from oeqa.utils.decorators import * |
4 | 5 | ||
@@ -9,57 +10,53 @@ def setUpModule(): | |||
9 | skipModule("systemd is not the init manager for this image") | 10 | skipModule("systemd is not the init manager for this image") |
10 | 11 | ||
11 | 12 | ||
12 | class SystemdBasicTest(oeRuntimeTest): | 13 | class SystemdTest(oeRuntimeTest): |
13 | 14 | ||
14 | @skipUnlessPassed('test_ssh') | 15 | def systemctl(self, action = '', target = '', expected = 0, verbose = False): |
15 | def test_systemd_version(self): | 16 | command = 'systemctl %s %s' % (action, target) |
16 | (status, output) = self.target.run('systemctl --version') | 17 | status, output = self.target.run(command) |
17 | self.assertEqual(status, 0, msg="status and output: %s and %s" % (status,output)) | 18 | message = '\n'.join([command, output]) |
18 | 19 | if status != expected and verbose: | |
19 | class SystemdTests(oeRuntimeTest): | 20 | message += self.target.run('systemctl status --full %s' % target)[1] |
20 | 21 | self.assertEqual(status, expected, message) | |
21 | @skipUnlessPassed('test_systemd_version') | 22 | return output |
22 | def test_systemd_failed(self): | ||
23 | (status, output) = self.target.run('systemctl --failed | grep "0 loaded units listed"') | ||
24 | if status != 0: | ||
25 | print self.target.run('systemctl status --failed -l')[1] | ||
26 | self.fail("Some systemd units failed.") | ||
27 | |||
28 | @skipUnlessPassed('test_systemd_version') | ||
29 | def test_systemd_service(self): | ||
30 | (status, output) = self.target.run('systemctl list-unit-files | grep "systemd-hostnamed.service"') | ||
31 | self.assertEqual(status, 0, msg="systemd-hostnamed.service service is not available.") | ||
32 | 23 | ||
33 | @skipUnlessPassed('test_systemd_service') | ||
34 | def test_systemd_stop(self): | ||
35 | self.target.run('systemctl stop systemd-hostnamed.service') | ||
36 | (status, output) = self.target.run('systemctl show systemd-hostnamed.service | grep "ActiveState" | grep "=inactive"') | ||
37 | if status != 0: | ||
38 | (status, output) = self.target.run('systemctl status -l systemd-hostnamed.service') | ||
39 | self.fail(msg="systemd-hostnamed.service service could not be stopped. Status:\n" + output) | ||
40 | 24 | ||
41 | @skipUnlessPassed('test_systemd_stop') | 25 | class SystemdBasicTests(SystemdTest): |
42 | @skipUnlessPassed('test_systemd_version') | ||
43 | def test_systemd_start(self): | ||
44 | self.target.run('systemctl start systemd-hostnamed.service') | ||
45 | (status, output) = self.target.run('systemctl is-active systemd-hostnamed.service') | ||
46 | if status != 0: | ||
47 | (status, output) = self.target.run('systemctl status -l systemd-hostnamed.service') | ||
48 | self.fail(msg="systemd-hostnamed.service service could not be started. Status:\n" + output) | ||
49 | 26 | ||
50 | @skipUnlessPassed('test_systemd_version') | 27 | @skipUnlessPassed('test_ssh') |
51 | def test_systemd_enable(self): | 28 | def test_systemd_basic(self): |
52 | self.target.run('systemctl enable machineid.service') | 29 | self.systemctl('--version') |
53 | (status, output) = self.target.run('systemctl is-enabled machineid.service') | ||
54 | self.assertEqual(output, 'enabled', msg="machineid.service service could not be enabled. Status and output: %s and %s" % (status, output)) | ||
55 | |||
56 | @skipUnlessPassed('test_systemd_enable') | ||
57 | def test_systemd_disable(self): | ||
58 | self.target.run('systemctl disable machineid.service') | ||
59 | (status, output) = self.target.run('systemctl is-enabled machineid.service') | ||
60 | self.assertEqual(output, 'disabled', msg="machineid.service service could not be disabled. Status and output: %s and %s" % (status, output)) | ||
61 | 30 | ||
62 | @skipUnlessPassed('test_systemd_version') | 31 | @skipUnlessPassed('test_system_basic') |
63 | def test_systemd_list(self): | 32 | def test_systemd_list(self): |
64 | (status, output) = self.target.run('systemctl list-unit-files') | 33 | self.systemctl('list-unit-files') |
65 | self.assertEqual(status, 0, msg="systemctl list-unit-files command failed. Status: %s" % status) | 34 | |
35 | @skipUnlessPassed('test_systemd_basic') | ||
36 | def test_systemd_failed(self): | ||
37 | output = self.systemctl('list-units', '--failed') | ||
38 | match = re.search("0 loaded units listed", output) | ||
39 | if not match: | ||
40 | output += self.systemctl('status --full --failed') | ||
41 | self.assertTrue(match, msg="Some systemd units failed:\n%s" % output) | ||
42 | |||
43 | |||
44 | class SystemdServiceTests(SystemdTest): | ||
45 | |||
46 | @skipUnlessPassed('test_systemd_basic') | ||
47 | def test_systemd_status(self): | ||
48 | self.systemctl('status --full', 'avahi-daemon.service') | ||
49 | |||
50 | @skipUnlessPassed('test_systemd_status') | ||
51 | def test_systemd_stop_start(self): | ||
52 | self.systemctl('stop', 'avahi-daemon.service') | ||
53 | self.systemctl('is-active', 'avahi-daemon.service', expected=3, verbose=True) | ||
54 | self.systemctl('start','avahi-daemon.service') | ||
55 | self.systemctl('is-active', 'avahi-daemon.service', verbose=True) | ||
56 | |||
57 | @skipUnlessPassed('test_systemd_basic') | ||
58 | def test_systemd_disable_enable(self): | ||
59 | self.systemctl('disable', 'avahi-daemon.service') | ||
60 | self.systemctl('is-enabled', 'avahi-daemon.service', expected=1) | ||
61 | self.systemctl('enable', 'avahi-daemon.service') | ||
62 | self.systemctl('is-enabled', 'avahi-daemon.service') | ||