Skip to content

Commit 8940445

Browse files
committed
fix: Fix nushell syntax in loader-entries test
The multi-line `or` expression with trailing `or` at end of line is not valid nushell syntax. Collapse the filter predicate to a single line. Assisted-by: OpenCode (Claude claude-opus-4-6)
1 parent 53cf2ff commit 8940445

File tree

3 files changed

+49
-16
lines changed

3 files changed

+49
-16
lines changed

Justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ buildargs := base_buildargs \
7474

7575
# Build container image from current sources (default target)
7676
[group('core')]
77-
build: package _build-ostree-rpms _keygen && _pull-lbi-images
77+
build: _build-ostree-rpms package _keygen && _pull-lbi-images
7878
#!/bin/bash
7979
set -xeuo pipefail
8080
test -d target/packages

crates/lib/src/loader_entries.rs

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,15 @@ fn compute_merged_options(
8888
merged
8989
}
9090

91-
/// Read the BLS entry file content for a deployment by scanning /boot/loader/entries/.
92-
/// We find the entry that matches the deployment's bootconfig options.
91+
/// Read the BLS entry file content for a deployment from /boot/loader/entries/.
92+
///
93+
/// The BLS entry filename pattern changed in ostree 2024.5:
94+
/// - New: ostree-<index>.conf
95+
/// - Old: ostree-<index>-<stateroot>.conf
96+
///
97+
/// Since we can't easily reconstruct the index, we read all ostree-*.conf
98+
/// entries and match by checking the `options` line for the deployment's
99+
/// ostree path (which includes the stateroot and deploy serial).
93100
fn read_bls_entry_for_deployment(
94101
sysroot: &ostree::Sysroot,
95102
deployment: &ostree::Deployment,
@@ -103,27 +110,43 @@ fn read_bls_entry_for_deployment(
103110
.path()
104111
.ok_or_else(|| anyhow::anyhow!("Failed to get boot/loader/entries path"))?;
105112

106-
// The BLS entry filename follows the pattern: ostree-$stateroot-$deployserial.conf
113+
// Build the expected ostree= value from the deployment to match against.
114+
// The ostree= karg format is: /ostree/boot.N/$stateroot/$bootcsum/$bootserial
115+
// where bootcsum is the boot checksum and bootserial is the serial among
116+
// deployments sharing the same bootcsum (NOT the deployserial).
107117
let stateroot = deployment.stateroot();
108-
let deployserial = deployment.deployserial();
118+
let bootserial = deployment.bootserial();
109119
let bootcsum = deployment.bootcsum();
110-
let expected_suffix = format!("{stateroot}-{bootcsum}-{deployserial}.conf");
120+
let ostree_match = format!("/{stateroot}/{bootcsum}/{bootserial}");
111121

122+
let mut found_entries = Vec::new();
112123
for entry in std::fs::read_dir(&entries_dir)
113124
.with_context(|| format!("Reading {}", entries_dir.display()))?
114125
{
115126
let entry = entry?;
116127
let name = entry.file_name();
117128
let name = name.to_string_lossy();
118-
if name.ends_with(&expected_suffix) {
119-
return std::fs::read_to_string(entry.path())
120-
.with_context(|| format!("Reading BLS entry {}", entry.path().display()));
129+
if !name.starts_with("ostree-") || !name.ends_with(".conf") {
130+
continue;
131+
}
132+
found_entries.push(name.to_string());
133+
let content = std::fs::read_to_string(entry.path())
134+
.with_context(|| format!("Reading BLS entry {}", entry.path().display()))?;
135+
// Check if this entry's options line contains our deployment's ostree path
136+
if content
137+
.lines()
138+
.any(|line| line.starts_with("options ") && line.contains(&ostree_match))
139+
{
140+
return Ok(content);
121141
}
122142
}
123143

124144
anyhow::bail!(
125-
"No BLS entry found matching deployment {stateroot} serial {deployserial} in {}",
126-
entries_dir.display()
145+
"No BLS entry found matching deployment {stateroot}/{bootcsum}/{bootserial} in {}. \
146+
Looking for '{}' in options line. Found entries: {:?}",
147+
entries_dir.display(),
148+
ostree_match,
149+
found_entries,
127150
)
128151
}
129152

tmt/tests/booted/test-loader-entries-source.nu

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,17 @@ def read_bls_source_keys [] {
4242
def save_system_kargs [] {
4343
let cmdline = parse_cmdline
4444
# Filter to well-known system kargs that must never be lost
45+
# Note: ostree= is excluded because its value changes between deployments
46+
# (boot version counter, bootcsum). It's managed by ostree's
47+
# install_deployment_kernel() and always regenerated during finalization.
4548
let system_kargs = $cmdline | where { |k|
46-
($k starts-with "root=") or
47-
($k starts-with "ostree=") or
48-
($k == "rw") or
49-
($k starts-with "console=")
49+
(($k starts-with "root=") or ($k == "rw") or ($k starts-with "console="))
5050
}
5151
$system_kargs | to json | save -f /var/bootc-test-system-kargs.json
5252
}
5353

5454
def load_system_kargs [] {
55-
open /var/bootc-test-system-kargs.json | from json
55+
open /var/bootc-test-system-kargs.json
5656
}
5757

5858
def first_boot [] {
@@ -77,10 +77,20 @@ def first_boot [] {
7777

7878
# Valid name with underscores/dashes
7979
let r = do -i { bootc loader-entries set-options-for-source --source "my_custom-src" --options "testvalid=1" } | complete
80+
if $r.exit_code != 0 {
81+
print $"FAILED: valid source name returned exit code ($r.exit_code)"
82+
print $"stdout: ($r.stdout)"
83+
print $"stderr: ($r.stderr)"
84+
}
8085
assert ($r.exit_code == 0) "valid source name should succeed"
8186

8287
# Clear it immediately (no --options = remove source)
8388
let r = do -i { bootc loader-entries set-options-for-source --source "my_custom-src" } | complete
89+
if $r.exit_code != 0 {
90+
print $"FAILED: clearing source returned exit code ($r.exit_code)"
91+
print $"stdout: ($r.stdout)"
92+
print $"stderr: ($r.stderr)"
93+
}
8494
assert ($r.exit_code == 0) "clearing source should succeed"
8595

8696
# -- Add source kargs --

0 commit comments

Comments
 (0)