From c527fd1f14c27855a37f2e8ac5346ce8d940ced2 Mon Sep 17 00:00:00 2001 From: Tudor Florea Date: Thu, 16 Oct 2014 03:05:19 +0200 Subject: initial commit for Enea Linux 4.0-140929 Migrated from the internal git server on the daisy-enea-point-release branch Signed-off-by: Tudor Florea --- meta/lib/oeqa/runtime/systemd.py | 84 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 meta/lib/oeqa/runtime/systemd.py (limited to 'meta/lib/oeqa/runtime/systemd.py') 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 @@ +import unittest +import re +from oeqa.oetest import oeRuntimeTest, skipModule +from oeqa.utils.decorators import * + +def setUpModule(): + if not oeRuntimeTest.hasFeature("systemd"): + skipModule("target doesn't have systemd in DISTRO_FEATURES") + if "systemd" != oeRuntimeTest.tc.d.getVar("VIRTUAL-RUNTIME_init_manager", True): + skipModule("systemd is not the init manager for this image") + + +class SystemdTest(oeRuntimeTest): + + 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 + + +class SystemdBasicTests(SystemdTest): + + @skipUnlessPassed('test_ssh') + def test_systemd_basic(self): + self.systemctl('--version') + + @skipUnlessPassed('test_system_basic') + def test_systemd_list(self): + self.systemctl('list-unit-files') + + def settle(self): + """ + Block until systemd has finished activating any units being activated, + or until two minutes has elapsed. + + Returns a tuple, either (True, '') if all units have finished + activating, or (False, message string) if there are still units + activating (generally, failing units that restart). + """ + import time + endtime = time.time() + (60 * 2) + while True: + status, output = self.target.run('systemctl --state=activating') + if "0 loaded units listed" in output: + return (True, '') + if time.time() >= endtime: + return (False, output) + time.sleep(10) + + @skipUnlessPassed('test_systemd_basic') + def test_systemd_failed(self): + settled, output = self.settle() + self.assertTrue(settled, msg="Timed out waiting for systemd to settle:\n" + output) + + 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') -- cgit v1.2.3-54-g00ecf