Skip to content

Commit 0a1ff3b

Browse files
committed
filetree: add failpoint when doing exchange
Inspired by #669 (comment)
1 parent 246a5c9 commit 0a1ff3b

File tree

8 files changed

+178
-4
lines changed

8 files changed

+178
-4
lines changed

Diff for: Cargo.lock

+124
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,12 @@ path = "src/main.rs"
2121
[dependencies]
2222
anyhow = "1.0"
2323
bincode = "1.3.2"
24+
cap-std-ext = "4.0.0"
2425
camino = "1.1.7"
2526
chrono = { version = "0.4.38", features = ["serde"] }
2627
clap = { version = "3.2", default-features = false, features = ["cargo", "derive", "std", "suggestions"] }
2728
env_logger = "0.10"
29+
fail = { version = "0.5", features = ["failpoints"] }
2830
fn-error-context = "0.2.1"
2931
fs2 = "0.4.3"
3032
hex = "0.4.3"
@@ -35,6 +37,7 @@ openat = "0.1.20"
3537
openat-ext = ">= 0.2.2, < 0.3.0"
3638
openssl = "^0.10"
3739
os-release = "0.1.0"
40+
regex = "1.10.4"
3841
rustix = { version = "0.38.34", features = ["process", "fs"] }
3942
serde = { version = "^1.0", features = ["derive"] }
4043
serde_json = "^1.0"

Diff for: src/bootupd.rs

+15
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ pub(crate) fn print_status(status: &Status) -> Result<()> {
396396
}
397397

398398
pub(crate) fn client_run_update() -> Result<()> {
399+
crate::try_fail_point!("update");
399400
let status: Status = status()?;
400401
if status.components.is_empty() && status.adoptable.is_empty() {
401402
println!("No components installed.");
@@ -489,3 +490,17 @@ pub(crate) fn client_run_validate() -> Result<()> {
489490
}
490491
Ok(())
491492
}
493+
494+
#[cfg(test)]
495+
mod tests {
496+
use super::*;
497+
498+
#[test]
499+
fn test_failpoint_update() {
500+
let guard = fail::FailScenario::setup();
501+
fail::cfg("update", "return").unwrap();
502+
let r = client_run_update();
503+
assert_eq!(r.is_err(), true);
504+
guard.teardown();
505+
}
506+
}

Diff for: src/failpoints.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//! Wrappers and utilities on top of the `fail` crate.
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
/// TODO: Use https://github.com/tikv/fail-rs/pull/68 once it merges
5+
/// copy from https://github.com/coreos/rpm-ostree/commit/aa8d7fb0ceaabfaf10252180e2ddee049d07aae3#diff-adcc419e139605fae34d17b31418dbaf515af2fe9fb766fcbdb2eaad862b3daa
6+
#[macro_export]
7+
macro_rules! try_fail_point {
8+
($name:expr) => {{
9+
if let Some(e) = fail::eval($name, |msg| {
10+
let msg = msg.unwrap_or_else(|| "synthetic failpoint".to_string());
11+
anyhow::Error::msg(msg)
12+
}) {
13+
return Err(From::from(e));
14+
}
15+
}};
16+
($name:expr, $cond:expr) => {{
17+
if $cond {
18+
$crate::try_fail_point!($name);
19+
}
20+
}};
21+
}

Diff for: src/filetree.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ pub(crate) fn apply_diff(
395395
.local_rename(tmp, dst)
396396
.with_context(|| format!("rename for {} and {:?}", tmp, dst))?;
397397
}
398+
crate::try_fail_point!("update::exchange");
398399
}
399400
// Ensure all of the updates & changes are written persistently to disk
400401
if !opts.skip_sync {
@@ -705,7 +706,6 @@ mod tests {
705706
let b_btime_foo_new = fs::metadata(pb.join(foo))?.created()?;
706707
assert_eq!(b_btime_foo_new, b_btime_foo);
707708
}
708-
709709
Ok(())
710710
}
711711
}

Diff for: src/main.rs

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ mod component;
2424
mod coreos;
2525
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
2626
mod efi;
27+
mod failpoints;
2728
mod filesystem;
2829
mod filetree;
2930
#[cfg(any(
@@ -43,6 +44,7 @@ use clap::crate_name;
4344

4445
/// Binary entrypoint, for both daemon and client logic.
4546
fn main() {
47+
let _scenario = fail::FailScenario::setup();
4648
let exit_code = run_cli();
4749
std::process::exit(exit_code);
4850
}

Diff for: tests/e2e-update/e2e-update-in-vm.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,12 @@ tmpefimount=$(mount_tmp_efi)
6767

6868
assert_not_has_file ${tmpefimount}/EFI/fedora/test-bootupd.efi
6969

70-
bootupctl update | tee out.txt
70+
if env FAILPOINTS='update::exchange=return' bootupctl update -vvv 2>err.txt; then
71+
fatal "should have errored"
72+
fi
73+
assert_file_has_content err.txt "error: .*synthetic failpoint"
74+
75+
bootupctl update -vvv | tee out.txt
7176
assert_file_has_content out.txt "Previous EFI: .*"
7277
assert_file_has_content out.txt "Updated EFI: ${TARGET_GRUB_PKG}.*,test-bootupd-payload-1.0"
7378

Diff for: tests/e2e-update/e2e-update.sh

+6-2
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@ export test_tmpdir=${testtmp}
2424

2525
# This is new content for our update
2626
test_bootupd_payload_file=/boot/efi/EFI/fedora/test-bootupd.efi
27+
test_bootupd_payload_file1=/boot/efi/EFI/BOOT/test-bootupd1.efi
2728
build_rpm test-bootupd-payload \
28-
files ${test_bootupd_payload_file} \
29+
files "${test_bootupd_payload_file}
30+
${test_bootupd_payload_file1}" \
2931
install "mkdir -p %{buildroot}/$(dirname ${test_bootupd_payload_file})
30-
echo test-payload > %{buildroot}/${test_bootupd_payload_file}"
32+
echo test-payload > %{buildroot}/${test_bootupd_payload_file}
33+
mkdir -p %{buildroot}/$(dirname ${test_bootupd_payload_file1})
34+
echo test-payload1 > %{buildroot}/${test_bootupd_payload_file1}"
3135

3236
# Start in cosa dir
3337
cd ${COSA_DIR}

0 commit comments

Comments
 (0)