File: test_mark.py

package info (click to toggle)
rauc 1.15-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,336 kB
  • sloc: ansic: 36,989; python: 3,354; sh: 1,391; xml: 53; makefile: 41
file content (248 lines) | stat: -rw-r--r-- 7,890 bytes parent folder | download
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
import json
import os

from conftest import have_grub, have_qemu, no_service
from helper import run
from helper import slot_data_from_json


@no_service
@have_grub
def test_status_mark_good_internally(rauc_no_service):
    out, err, exitcode = run(f"{rauc_no_service} --override-boot-slot=A status mark-good")

    assert exitcode == 0


@no_service
@have_grub
def test_status_mark_bad_internally(rauc_no_service):
    out, err, exitcode = run(f"{rauc_no_service} --override-boot-slot=A status mark-bad")

    assert exitcode == 0


@no_service
@have_grub
def test_status_mark_active_internally(rauc_no_service):
    out, err, exitcode = run(f"{rauc_no_service} --override-boot-slot=A status mark-active")

    assert exitcode == 0


@no_service
@have_grub
def test_status_mark_good_booted(rauc_no_service):
    out, err, exitcode = run(f"{rauc_no_service} --override-boot-slot=A status mark-good booted")

    assert exitcode == 0


@no_service
@have_grub
def test_status_mark_good_other(rauc_no_service):
    out, err, exitcode = run(f"{rauc_no_service} --override-boot-slot=A status mark-good other")

    assert exitcode == 0


@no_service
@have_grub
def test_status_mark_good_any_bootslot(rauc_no_service):
    out, err, exitcode = run(f"{rauc_no_service} --override-boot-slot=A status mark-good rescue.0")

    assert exitcode == 0


@no_service
@have_grub
def test_status_mark_good_non_bootslot(rauc_no_service):
    out, err, exitcode = run(f"{rauc_no_service} --override-boot-slot=A status mark-good bootloader.0")

    assert exitcode == 1


@have_grub
def test_status_mark_bad_other(rauc_dbus_service_with_system_abc):
    out, err, exitcode = run("rauc status --output-format=json")
    assert exitcode == 0
    status = json.loads(out)

    for slotname, property in status["slots"][0].items():
        if property["state"] != "booted" and property["class"] == "rootfs":
            assert property["boot_status"] == "good"

    out, err, exitcode = run("rauc status mark-bad other")
    assert exitcode == 0

    out, err, exitcode = run("rauc status --output-format=json")
    assert exitcode == 0
    status = json.loads(out)

    for slotname, property in status["slots"][0].items():
        if property["state"] != "booted" and property["class"] == "rootfs":
            assert property["boot_status"] == "bad"


@have_grub
def test_status_mark_prevent_late_fallback(tmp_path, create_system_files, system):
    system.prepare_abc_config()
    system.config["system"]["prevent-late-fallback"] = "true"
    system.write_config()
    with system.running_service("A"):
        out, err, exitcode = run("rauc status --output-format=json")
        assert exitcode == 0
        status = json.loads(out)

        for slotname, property in status["slots"][0].items():
            if property["state"] != "booted" and property["class"] == "rootfs":
                assert property["boot_status"] == "good"

        out, err, exitcode = run("rauc status mark-good")
        assert exitcode == 0

        out, err, exitcode = run("rauc status --output-format=json")
        assert exitcode == 0
        status = json.loads(out)

        for slotname, property in status["slots"][0].items():
            if property["state"] != "booted" and property["class"] == "rootfs":
                assert property["boot_status"] == "bad"


@have_grub
def test_status_mark_good_dbus(rauc_dbus_service_with_system):
    out, err, exitcode = run("rauc status --output-format=json-pretty")
    assert exitcode == 0
    status_data = json.loads(out)

    assert slot_data_from_json(status_data, "rootfs.0")["boot_status"] == "good"
    assert slot_data_from_json(status_data, "rootfs.1")["boot_status"] == "bad"

    out, err, exitcode = run("rauc status mark-good")

    assert exitcode == 0
    assert "marked slot(s) rootfs.0 as good" in out

    out, err, exitcode = run("rauc status --output-format=json-pretty")
    assert exitcode == 0
    status_data = json.loads(out)

    assert slot_data_from_json(status_data, "rootfs.0")["boot_status"] == "good"
    assert slot_data_from_json(status_data, "rootfs.1")["boot_status"] == "bad"


@have_grub
def test_status_mark_bad_dbus(rauc_dbus_service_with_system):
    # check pre-condition
    out, err, exitcode = run("rauc status --output-format=json-pretty")
    assert exitcode == 0
    status_data = json.loads(out)

    assert slot_data_from_json(status_data, "rootfs.0")["boot_status"] == "good"
    assert slot_data_from_json(status_data, "rootfs.1")["boot_status"] == "bad"

    # mark bad
    out, err, exitcode = run("rauc status mark-bad")

    assert exitcode == 0
    assert "marked slot(s) rootfs.0 as bad" in out

    # check post-condition
    out, err, exitcode = run("rauc status --output-format=json-pretty")
    assert exitcode == 0
    status_data = json.loads(out)

    assert slot_data_from_json(status_data, "rootfs.0")["boot_status"] == "bad"
    assert slot_data_from_json(status_data, "rootfs.1")["boot_status"] == "bad"


@have_grub
def test_status_mark_active_dbus(rauc_dbus_service_with_system):
    # check pre-condition
    out, err, exitcode = run("rauc status --output-format=json-pretty")
    assert exitcode == 0
    status_data = json.loads(out)

    assert slot_data_from_json(status_data, "rootfs.0")["boot_status"] == "good"
    assert slot_data_from_json(status_data, "rootfs.1")["boot_status"] == "bad"
    assert status_data["boot_primary"] == "rootfs.0"

    # mark active other
    out, err, exitcode = run("rauc status mark-active other")

    assert exitcode == 0
    assert "rootfs.1 as active" in out

    # check post-condition
    out, err, exitcode = run("rauc status --output-format=json-pretty")
    assert exitcode == 0
    status_data = json.loads(out)

    assert slot_data_from_json(status_data, "rootfs.0")["boot_status"] == "good"
    assert slot_data_from_json(status_data, "rootfs.1")["boot_status"] == "good"
    assert status_data["boot_primary"] == "rootfs.1"


@have_qemu
def test_status_mark_bad_barebox(tmp_path, create_system_files, system):
    """
    Tests that 'mark-bad' call for barebox alters the barebox state
    variables appropriately.

    Leverages the 'barebox-state' dummy with variables pre-set from env.
    """

    system.prepare_minimal_config()
    system.config["system"]["bootloader"] = "barebox"
    del system.config["system"]["grubenv"]
    system.write_config()
    os.environ["BAREBOX_STATE_VARS_PRE"] = """
bootstate.A.priority=20
bootstate.B.priority=21
bootstate.A.remaining_attempts=3
bootstate.B.remaining_attempts=3
"""
    os.environ["BAREBOX_STATE_VARS_POST"] = """
bootstate.A.priority=20
bootstate.B.priority=0
bootstate.A.remaining_attempts=3
bootstate.B.remaining_attempts=0
"""
    with system.running_service("A"):
        # mark rootfs.1 (B) bad
        out, err, exitcode = run("rauc status mark-bad rootfs.1")
        assert not err
        assert exitcode == 0


@have_qemu
def test_status_mark_active_barebox(tmp_path, create_system_files, system):
    """
    Tests that 'mark-primary' call for barebox alters the barebox state
    variables appropriately.

    Leverages the 'barebox-state' dummy with variables pre-set from env.
    """

    system.prepare_minimal_config()
    system.config["system"]["bootloader"] = "barebox"
    del system.config["system"]["grubenv"]
    system.write_config()
    os.environ["BAREBOX_STATE_VARS_PRE"] = """
bootstate.A.priority=21
bootstate.B.priority=20
bootstate.A.remaining_attempts=3
bootstate.B.remaining_attempts=0
"""
    os.environ["BAREBOX_STATE_VARS_POST"] = """
bootstate.A.priority=10
bootstate.B.priority=20
bootstate.A.remaining_attempts=3
bootstate.B.remaining_attempts=3
"""
    with system.running_service("A"):
        # mark rootfs.1 (B) active/primary
        out, err, exitcode = run("rauc status mark-active rootfs.1")
        assert not err
        assert exitcode == 0