Skip to content

Commit f48da07

Browse files
committed
filetree: add failpoint when doing exchange
Inspired by coreos#669 (comment)
1 parent 03157ee commit f48da07

File tree

8 files changed

+105
-5
lines changed

8 files changed

+105
-5
lines changed

Cargo.lock

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

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+
}

src/efi.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl Efi {
141141
log::debug!("Not booted via EFI, skipping firmware update");
142142
return Ok(());
143143
}
144-
let sysroot = Dir::open_ambient_dir(&Path::new("/"), cap_std::ambient_authority())?;
144+
let sysroot = Dir::open_ambient_dir("/", cap_std::ambient_authority())?;
145145
let product_name = get_product_name(&sysroot)?;
146146
log::debug!("Get product name: {product_name}");
147147
assert!(product_name.len() > 0);

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+
}

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
}

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
}

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

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)