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 57cb445
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 3 deletions.
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);
}
}};
}
2 changes: 1 addition & 1 deletion src/filetree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,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 +706,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
9 changes: 7 additions & 2 deletions tests/e2e-update/e2e-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,16 @@ export test_tmpdir=${testtmp}

# This is new content for our update
test_bootupd_payload_file=/boot/efi/EFI/fedora/test-bootupd.efi
test_bootupd_payload_file1=/boot/efi/EFI/BOOT/test-bootupd1.efi
build_rpm test-bootupd-payload \
files ${test_bootupd_payload_file} \
files "${test_bootupd_payload_file}
${test_bootupd_payload_file1}" \
install "mkdir -p %{buildroot}/$(dirname ${test_bootupd_payload_file})
echo test-payload > %{buildroot}/${test_bootupd_payload_file}"
echo test-payload > %{buildroot}/${test_bootupd_payload_file}
mkdir -p %{buildroot}/$(dirname ${test_bootupd_payload_file1})
echo test-payload1 > %{buildroot}/${test_bootupd_payload_file1}"

exit 0
# Start in cosa dir
cd ${COSA_DIR}
test -d builds
Expand Down

0 comments on commit 57cb445

Please sign in to comment.