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:25:23 +0000 |
commit | 0aa5b97f9e0d8941ce342e9f162dd3b19d4b49bb (patch) | |
tree | f5fbee2d77f8153924b3edba93167d9893e92d4e /meta/lib | |
parent | 0e462295d9db0201fb1ba2b6247ecb05fa7fcee1 (diff) | |
download | openembedded-core-0aa5b97f9e0d8941ce342e9f162dd3b19d4b49bb.tar.gz openembedded-core-0aa5b97f9e0d8941ce342e9f162dd3b19d4b49bb.tar.bz2 openembedded-core-0aa5b97f9e0d8941ce342e9f162dd3b19d4b49bb.zip |
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)
Signed-off-by: Stefan Stanacar <stefanx.stanacar@intel.com>
Signed-off-by: Saul Wold <sgw@linux.intel.com>
Diffstat (limited to 'meta/lib')
-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 @@ import unittest +import re from oeqa.oetest import oeRuntimeTest, skipModule from oeqa.utils.decorators import * @@ -9,57 +10,53 @@ def setUpModule(): skipModule("systemd is not the init manager for this image") -class SystemdBasicTest(oeRuntimeTest): +class SystemdTest(oeRuntimeTest): - @skipUnlessPassed('test_ssh') - def test_systemd_version(self): - (status, output) = self.target.run('systemctl --version') - self.assertEqual(status, 0, msg="status and output: %s and %s" % (status,output)) - -class SystemdTests(oeRuntimeTest): - - @skipUnlessPassed('test_systemd_version') - def test_systemd_failed(self): - (status, output) = self.target.run('systemctl --failed | grep "0 loaded units listed"') - if status != 0: - print self.target.run('systemctl status --failed -l')[1] - self.fail("Some systemd units failed.") - - @skipUnlessPassed('test_systemd_version') - def test_systemd_service(self): - (status, output) = self.target.run('systemctl list-unit-files | grep "systemd-hostnamed.service"') - self.assertEqual(status, 0, msg="systemd-hostnamed.service service is not available.") + def systemctl(self, action = '', target = '', expected = 0, verbose = False): + command = 'systemctl %s %s' % (action, target) + status, output = self.target.run(command) + message = '\n'.join([command, output]) + if status != expected and verbose: + message += self.target.run('systemctl status --full %s' % target)[1] + self.assertEqual(status, expected, message) + return output - @skipUnlessPassed('test_systemd_service') - def test_systemd_stop(self): - self.target.run('systemctl stop systemd-hostnamed.service') - (status, output) = self.target.run('systemctl show systemd-hostnamed.service | grep "ActiveState" | grep "=inactive"') - if status != 0: - (status, output) = self.target.run('systemctl status -l systemd-hostnamed.service') - self.fail(msg="systemd-hostnamed.service service could not be stopped. Status:\n" + output) - @skipUnlessPassed('test_systemd_stop') - @skipUnlessPassed('test_systemd_version') - def test_systemd_start(self): - self.target.run('systemctl start systemd-hostnamed.service') - (status, output) = self.target.run('systemctl is-active systemd-hostnamed.service') - if status != 0: - (status, output) = self.target.run('systemctl status -l systemd-hostnamed.service') - self.fail(msg="systemd-hostnamed.service service could not be started. Status:\n" + output) +class SystemdBasicTests(SystemdTest): - @skipUnlessPassed('test_systemd_version') - def test_systemd_enable(self): - self.target.run('systemctl enable machineid.service') - (status, output) = self.target.run('systemctl is-enabled machineid.service') - self.assertEqual(output, 'enabled', msg="machineid.service service could not be enabled. Status and output: %s and %s" % (status, output)) - - @skipUnlessPassed('test_systemd_enable') - def test_systemd_disable(self): - self.target.run('systemctl disable machineid.service') - (status, output) = self.target.run('systemctl is-enabled machineid.service') - self.assertEqual(output, 'disabled', msg="machineid.service service could not be disabled. Status and output: %s and %s" % (status, output)) + @skipUnlessPassed('test_ssh') + def test_systemd_basic(self): + self.systemctl('--version') - @skipUnlessPassed('test_systemd_version') + @skipUnlessPassed('test_system_basic') def test_systemd_list(self): - (status, output) = self.target.run('systemctl list-unit-files') - self.assertEqual(status, 0, msg="systemctl list-unit-files command failed. Status: %s" % status) + self.systemctl('list-unit-files') + + @skipUnlessPassed('test_systemd_basic') + def test_systemd_failed(self): + output = self.systemctl('list-units', '--failed') + match = re.search("0 loaded units listed", output) + if not match: + output += self.systemctl('status --full --failed') + self.assertTrue(match, msg="Some systemd units failed:\n%s" % output) + + +class SystemdServiceTests(SystemdTest): + + @skipUnlessPassed('test_systemd_basic') + def test_systemd_status(self): + self.systemctl('status --full', 'avahi-daemon.service') + + @skipUnlessPassed('test_systemd_status') + def test_systemd_stop_start(self): + self.systemctl('stop', 'avahi-daemon.service') + self.systemctl('is-active', 'avahi-daemon.service', expected=3, verbose=True) + self.systemctl('start','avahi-daemon.service') + self.systemctl('is-active', 'avahi-daemon.service', verbose=True) + + @skipUnlessPassed('test_systemd_basic') + def test_systemd_disable_enable(self): + self.systemctl('disable', 'avahi-daemon.service') + self.systemctl('is-enabled', 'avahi-daemon.service', expected=1) + self.systemctl('enable', 'avahi-daemon.service') + self.systemctl('is-enabled', 'avahi-daemon.service') |