aboutsummaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/runtime/systemd.py
blob: 31007df424f20e77579de773549b09b0c0d3de6c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import unittest
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 SystemdBasicTest(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.")

    @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)

    @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_systemd_version')
    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)