|
1 |
+ |
//! The one boot with no console has to say so, and every way that regresses is
|
|
2 |
+ |
//! silent.
|
|
3 |
+ |
//!
|
|
4 |
+ |
//! `alloy-layer-components.service` installs the console and terminal and then
|
|
5 |
+ |
//! reboots, so a person sees a boot that draws nothing and restarts itself.
|
|
6 |
+ |
//! That happens after an install and again after adopting a rebuilt image,
|
|
7 |
+ |
//! because `bootc switch` discards the layer and the unit re-fires to install
|
|
8 |
+ |
//! the new image's copy (measured, `build/layertest/README.md`). The second is
|
|
9 |
+ |
//! the common case and the one nobody expects.
|
|
10 |
+ |
//!
|
|
11 |
+ |
//! `usr/bin/alloy-layer-notice` is what breaks the silence, and it sits in
|
|
12 |
+ |
//! front of the only thing that gives the machine a console. So it is asserted
|
|
13 |
+ |
//! on two axes at once: that it still speaks, and that it can never be the
|
|
14 |
+ |
//! reason the components are not installed. The Containerfile checks the script
|
|
15 |
+ |
//! is executable and parses; that needs a build. This runs with `cargo test`,
|
|
16 |
+ |
//! which is where the unit and the script are actually edited.
|
|
17 |
+ |
|
|
18 |
+ |
use std::path::PathBuf;
|
|
19 |
+ |
|
|
20 |
+ |
fn repo(relative: &str) -> String {
|
|
21 |
+ |
let path = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
|
22 |
+ |
.join("../..")
|
|
23 |
+ |
.join(relative);
|
|
24 |
+ |
std::fs::read_to_string(&path)
|
|
25 |
+ |
.unwrap_or_else(|error| panic!("reading {}: {error}", path.display()))
|
|
26 |
+ |
}
|
|
27 |
+ |
|
|
28 |
+ |
fn unit() -> String {
|
|
29 |
+ |
repo("etc/systemd/system/alloy-layer-components.service")
|
|
30 |
+ |
}
|
|
31 |
+ |
|
|
32 |
+ |
fn notice() -> String {
|
|
33 |
+ |
repo("usr/bin/alloy-layer-notice")
|
|
34 |
+ |
}
|
|
35 |
+ |
|
|
36 |
+ |
fn directives(prefix: &str) -> Vec<String> {
|
|
37 |
+ |
unit()
|
|
38 |
+ |
.lines()
|
|
39 |
+ |
.map(str::trim)
|
|
40 |
+ |
.filter(|line| line.starts_with(prefix))
|
|
41 |
+ |
.map(str::to_string)
|
|
42 |
+ |
.collect()
|
|
43 |
+ |
}
|
|
44 |
+ |
|
|
45 |
+ |
#[test]
|
|
46 |
+ |
fn the_notice_is_a_posix_shell_script() {
|
|
47 |
+ |
assert!(notice().starts_with("#!/bin/sh\n"), "{}", notice());
|
|
48 |
+ |
}
|
|
49 |
+ |
|
|
50 |
+ |
// The wiring. Everything else here can hold and the boot still say nothing.
|
|
51 |
+ |
#[test]
|
|
52 |
+ |
fn the_unit_speaks_before_it_installs() {
|
|
53 |
+ |
let pre = directives("ExecStartPre=");
|
|
54 |
+ |
assert!(
|
|
55 |
+ |
pre.iter()
|
|
56 |
+ |
.any(|line| line.contains("alloy-layer-notice start")),
|
|
57 |
+ |
"the unit must announce itself before the install: {pre:?}",
|
|
58 |
+ |
);
|
|
59 |
+ |
}
|
|
60 |
+ |
|
|
61 |
+ |
// On failure the machine is stuck in the state the user cannot fix from the
|
|
62 |
+ |
// session that will not start, which is exactly when a journal line is the
|
|
63 |
+ |
// wrong place to put the explanation.
|
|
64 |
+ |
#[test]
|
|
65 |
+ |
fn the_unit_speaks_again_when_it_fails() {
|
|
66 |
+ |
let post = directives("ExecStopPost=");
|
|
67 |
+ |
assert!(
|
|
68 |
+ |
post.iter()
|
|
69 |
+ |
.any(|line| line.contains("alloy-layer-notice fail")),
|
|
70 |
+ |
"a failure must reach the console, not only the journal: {post:?}",
|
|
71 |
+ |
);
|
|
72 |
+ |
}
|
|
73 |
+ |
|
|
74 |
+ |
// And only on failure. Without the guard the ordinary path prints a failure
|
|
75 |
+ |
// notice on its way to a reboot it is already performing.
|
|
76 |
+ |
#[test]
|
|
77 |
+ |
fn the_failure_notice_is_guarded_on_the_service_result() {
|
|
78 |
+ |
let post = directives("ExecStopPost=");
|
|
79 |
+ |
let line = post
|
|
80 |
+ |
.iter()
|
|
81 |
+ |
.find(|line| line.contains("alloy-layer-notice fail"))
|
|
82 |
+ |
.expect("the unit notices failure");
|
|
83 |
+ |
|
|
84 |
+ |
assert!(line.contains("SERVICE_RESULT"), "{line}");
|
|
85 |
+ |
}
|
|
86 |
+ |
|
|
87 |
+ |
// The `-` prefix makes systemd ignore the exit status. Telling the user is
|
|
88 |
+ |
// worth less than installing the console, and this file exists as much to keep
|
|
89 |
+ |
// the notice harmless as to keep it present.
|
|
90 |
+ |
#[test]
|
|
91 |
+ |
fn no_notice_can_stop_the_components_being_installed() {
|
|
92 |
+ |
for line in directives("ExecStartPre=")
|
|
93 |
+ |
.into_iter()
|
|
94 |
+ |
.chain(directives("ExecStopPost="))
|
|
95 |
+ |
.filter(|line| line.contains("alloy-layer-notice"))
|
|
96 |
+ |
{
|
|
97 |
+ |
let (_, value) = line.split_once('=').expect("a systemd directive");
|
|
98 |
+ |
assert!(
|
|
99 |
+ |
value.trim_start().starts_with('-'),
|
|
100 |
+ |
"a failing notice would fail the unit: {line}",
|
|
101 |
+ |
);
|
|
102 |
+ |
}
|
|
103 |
+ |
}
|
|
104 |
+ |
|
|
105 |
+ |
// Same belt inside the script, for the calls the unit's `-` does not cover:
|
|
106 |
+ |
// nothing here may exit non-zero, and `set -e` would undo every guard at once.
|
|
107 |
+ |
#[test]
|
|
108 |
+ |
fn the_notice_cannot_fail_from_the_inside_either() {
|
|
109 |
+ |
let script = notice();
|
|
110 |
+ |
// Comments excluded, and the header names `set -e` to explain its absence.
|
|
111 |
+ |
// Matching on the whole file would fail on the sentence arguing for the
|
|
112 |
+ |
// rule, which is the noisiest way a test can be wrong.
|
|
113 |
+ |
for line in script
|
|
114 |
+ |
.lines()
|
|
115 |
+ |
.map(str::trim)
|
|
116 |
+ |
.filter(|line| !line.starts_with('#'))
|
|
117 |
+ |
{
|
|
118 |
+ |
assert!(!line.contains("set -e"), "set -e would defeat the guards");
|
|
119 |
+ |
}
|
|
120 |
+ |
|
|
121 |
+ |
for line in script
|
|
122 |
+ |
.lines()
|
|
123 |
+ |
.filter(|line| line.contains("> /dev/console"))
|
|
124 |
+ |
{
|
|
125 |
+ |
assert!(line.contains("|| true"), "an unguarded write: {line}");
|
|
126 |
+ |
}
|
|
127 |
+ |
}
|
|
128 |
+ |
|
|
129 |
+ |
// The journal is precisely what a machine with no console and no terminal
|
|
130 |
+ |
// cannot show anyone, so stdout is not a substitute. `quiet` filters kernel
|
|
131 |
+ |
// printk and leaves a userspace write to the console device alone, which is
|
|
132 |
+ |
// what makes this land on a screen the cmdline has otherwise silenced.
|
|
133 |
+ |
#[test]
|
|
134 |
+ |
fn the_notice_writes_to_the_console_rather_than_the_journal() {
|
|
135 |
+ |
assert!(notice().contains("> /dev/console"), "{}", notice());
|
|
136 |
+ |
}
|
|
137 |
+ |
|
|
138 |
+ |
// The claim the copy makes about adopting a rebuild is only true while the gate
|
|
139 |
+ |
// is read off the filesystem. A stamp file would say "done" after a `bootc
|
|
140 |
+ |
// switch` dropped the layer, so the unit would not re-fire, the machine would
|
|
141 |
+ |
// stay without a console, and the notice would be describing something that no
|
|
142 |
+ |
// longer happens. The unit's own comment argues this; here it is enforceable.
|
|
143 |
+ |
#[test]
|
|
144 |
+ |
fn the_gate_still_reads_the_filesystem_rather_than_a_stamp() {
|
|
145 |
+ |
let unit = unit();
|
|
146 |
+ |
assert!(
|
|
147 |
+ |
unit.contains("ConditionPathExists=!/usr/bin/alloy"),
|
|
148 |
+ |
"the console's absence is what makes the unit re-fire: {unit}",
|
|
149 |
+ |
);
|
|
150 |
+ |
}
|
|
151 |
+ |
|
|
152 |
+ |
// The copy may not promise a security property, name a duration it cannot keep,
|
|
153 |
+ |
// or carry the house's banned marks. The first line is what a person reads off
|
|
154 |
+ |
// a blank screen, so it says what is happening rather than what it is called.
|
|
155 |
+ |
#[test]
|
|
156 |
+ |
fn the_copy_says_what_is_happening_and_promises_nothing_else() {
|
|
157 |
+ |
let script = notice();
|
|
158 |
+ |
let spoken: Vec<&str> = script
|
|
159 |
+ |
.lines()
|
|
160 |
+ |
.filter(|line| line.trim_start().starts_with("say \""))
|
|
161 |
+ |
.collect();
|
|
162 |
+ |
|
|
163 |
+ |
assert!(
|
|
164 |
+ |
spoken
|
|
165 |
+ |
.iter()
|
|
166 |
+ |
.any(|line| line.contains("installing its console")),
|
|
167 |
+ |
"the notice must name what it is doing: {spoken:?}",
|
|
168 |
+ |
);
|
|
169 |
+ |
for line in &spoken {
|
|
170 |
+ |
assert!(!line.contains('—'), "no em dash in shipped copy: {line}");
|
|
171 |
+ |
}
|
|
172 |
+ |
}
|