Skip to content

Commit

Permalink
filetree: add failpoint when doing exchange
Browse files Browse the repository at this point in the history
  • Loading branch information
HuijingHei committed Jul 11, 2024
1 parent 20987eb commit d33fb72
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 1 deletion.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ camino = "1.1.7"
chrono = { version = "0.4.38", features = ["serde"] }
clap = { version = "3.2", default-features = false, features = ["cargo", "derive", "std", "suggestions"] }
env_logger = "0.10"
fail = { version = "0.5", features = ["failpoints"] }
fn-error-context = "0.2.1"
fs2 = "0.4.3"
hex = "0.4.3"
Expand Down
21 changes: 21 additions & 0 deletions src/failpoints.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! Wrappers and utilities on top of the `fail` crate.
// SPDX-License-Identifier: Apache-2.0 OR MIT

/// TODO: Use https://github.com/tikv/fail-rs/pull/68 once it merges
/// copy from https://github.com/coreos/rpm-ostree/commit/aa8d7fb0ceaabfaf10252180e2ddee049d07aae3#diff-adcc419e139605fae34d17b31418dbaf515af2fe9fb766fcbdb2eaad862b3daa
#[macro_export]
macro_rules! try_fail_point {
($name:expr) => {{
if let Some(e) = fail::eval($name, |msg| {
let msg = msg.unwrap_or_else(|| "synthetic failpoint".to_string());
anyhow::Error::msg(msg)
}) {
return Err(From::from(e));
}
}};
($name:expr, $cond:expr) => {{
if $cond {
$crate::try_fail_point!($name);
}
}};
}
4 changes: 3 additions & 1 deletion src/filetree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ pub(crate) fn apply_diff(
diff: &FileTreeDiff,
opts: Option<&ApplyUpdateOptions>,
) -> Result<()> {
println!("{diff:?}");
let default_opts = ApplyUpdateOptions {
..Default::default()
};
Expand Down Expand Up @@ -382,6 +383,7 @@ pub(crate) fn apply_diff(
.with_context(|| format!("copying {:?} to {:?}", path, path_tmp))?;
}

println!("{updates:?}");
// do local exchange or rename
for (dst, tmp) in updates.iter() {
let dst = dst.as_std_path();
Expand All @@ -395,6 +397,7 @@ pub(crate) fn apply_diff(
.local_rename(tmp, dst)
.with_context(|| format!("rename for {} and {:?}", tmp, dst))?;
}
crate::try_fail_point!("exchange");
}
// Ensure all of the updates & changes are written persistently to disk
if !opts.skip_sync {
Expand Down Expand Up @@ -705,7 +708,6 @@ mod tests {
let b_btime_foo_new = fs::metadata(pb.join(foo))?.created()?;
assert_eq!(b_btime_foo_new, b_btime_foo);
}

Ok(())
}
}
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ mod component;
mod coreos;
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
mod efi;
mod failpoints;
mod filesystem;
mod filetree;
#[cfg(any(
Expand Down
5 changes: 5 additions & 0 deletions tests/e2e-update/e2e-update-in-vm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ tmpefimount=$(mount_tmp_efi)

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

if env FAILPOINTS='exchange=return' bootupctl update -vvv 2>err.txt; then
fatal "should have errored"
fi
assert_file_has_content_literal err.txt "error: synthetic failpoint"

bootupctl update | tee out.txt
assert_file_has_content out.txt "Previous EFI: .*"
assert_file_has_content out.txt "Updated EFI: ${TARGET_GRUB_PKG}.*,test-bootupd-payload-1.0"
Expand Down

0 comments on commit d33fb72

Please sign in to comment.