summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/selftest/cases/bbclasses.py
blob: 10545ebe658ecba762095bca24a35ea0ab65dd3b (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#
# Copyright OpenEmbedded Contributors
#
# SPDX-License-Identifier: MIT
#

from oeqa.selftest.case import OESelftestTestCase
from oeqa.utils.commands import get_bb_vars, bitbake

class Systemd(OESelftestTestCase):
    """
    Tests related to the systemd bbclass.
    """

    def getVars(self, recipe):
        self.bb_vars = get_bb_vars(
            [
                'BPN',
                'D',
                'INIT_D_DIR',
                'prefix',
                'systemd_system_unitdir',
                'sysconfdir',
            ],
            recipe,
        )

    def fileExists(self, filename):
        self.assertExists(filename.format(**self.bb_vars))

    def fileNotExists(self, filename):
        self.assertNotExists(filename.format(**self.bb_vars))

    def test_systemd_in_distro(self):
        """
        Summary:    Verify that no sysvinit files are installed when the
                    systemd distro feature is enabled, but sysvinit is not.
        Expected:   Systemd service file exists, but /etc does not.
        Product:    OE-Core
        Author:     Peter Kjellerstedt <peter.kjellerstedt@axis.com>
        """

        self.write_config("""
DISTRO_FEATURES:append = " systemd usrmerge"
DISTRO_FEATURES:remove = "sysvinit"
VIRTUAL-RUNTIME_init_manager = "systemd"
""")
        bitbake("systemd-only systemd-and-sysvinit -c install")

        self.getVars("systemd-only")
        self.fileExists("{D}{systemd_system_unitdir}/{BPN}.service")

        self.getVars("systemd-and-sysvinit")
        self.fileExists("{D}{systemd_system_unitdir}/{BPN}.service")
        self.fileNotExists("{D}{sysconfdir}")

    def test_systemd_and_sysvinit_in_distro(self):
        """
        Summary:    Verify that both systemd and sysvinit files are installed
                    when both the systemd and sysvinit distro features are
                    enabled.
        Expected:   Systemd service file and sysvinit initscript exist.
        Product:    OE-Core
        Author:     Peter Kjellerstedt <peter.kjellerstedt@axis.com>
        """

        self.write_config("""
DISTRO_FEATURES:append = " systemd sysvinit usrmerge"
VIRTUAL-RUNTIME_init_manager = "systemd"
""")
        bitbake("systemd-only systemd-and-sysvinit -c install")

        self.getVars("systemd-only")
        self.fileExists("{D}{systemd_system_unitdir}/{BPN}.service")

        self.getVars("systemd-and-sysvinit")
        self.fileExists("{D}{systemd_system_unitdir}/{BPN}.service")
        self.fileExists("{D}{INIT_D_DIR}/{BPN}")

    def test_sysvinit_in_distro(self):
        """
        Summary:    Verify that no systemd service files are installed when the
                    sysvinit distro feature is enabled, but systemd is not.
        Expected:   The systemd  service file does not exist, nor does /usr.
                    The sysvinit initscript exists.
        Product:    OE-Core
        Author:     Peter Kjellerstedt <peter.kjellerstedt@axis.com>
        """

        self.write_config("""
DISTRO_FEATURES:remove = "systemd"
DISTRO_FEATURES:append = " sysvinit usrmerge"
VIRTUAL-RUNTIME_init_manager = "sysvinit"
""")
        bitbake("systemd-only systemd-and-sysvinit -c install")

        self.getVars("systemd-only")
        self.fileNotExists("{D}{systemd_system_unitdir}/{BPN}.service")
        self.fileNotExists("{D}{prefix}")
        self.fileNotExists("{D}{sysconfdir}")
        self.fileExists("{D}")

        self.getVars("systemd-and-sysvinit")
        self.fileNotExists("{D}{systemd_system_unitdir}/{BPN}.service")
        self.fileNotExists("{D}{prefix}")
        self.fileExists("{D}{INIT_D_DIR}/{BPN}")