File tree Expand file tree Collapse file tree 8 files changed +107
-5
lines changed Expand file tree Collapse file tree 8 files changed +107
-5
lines changed Original file line number Diff line number Diff line change @@ -396,6 +396,7 @@ pub(crate) fn print_status(status: &Status) -> Result<()> {
396396}
397397
398398pub ( 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+ }
Original file line number Diff line number Diff 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 ) ;
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ mod component;
2424mod coreos;
2525#[ cfg( any( target_arch = "x86_64" , target_arch = "aarch64" ) ) ]
2626mod efi;
27+ mod failpoints;
2728mod filesystem;
2829mod filetree;
2930#[ cfg( any(
@@ -43,6 +44,7 @@ use clap::crate_name;
4344
4445/// Binary entrypoint, for both daemon and client logic.
4546fn main ( ) {
47+ let _scenario = fail:: FailScenario :: setup ( ) ;
4648 let exit_code = run_cli ( ) ;
4749 std:: process:: exit ( exit_code) ;
4850}
Original file line number Diff line number Diff line change @@ -67,7 +67,12 @@ tmpefimount=$(mount_tmp_efi)
6767
6868assert_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
7176assert_file_has_content out.txt " Previous EFI: .*"
7277assert_file_has_content out.txt " Updated EFI: ${TARGET_GRUB_PKG} .*,test-bootupd-payload-1.0"
7378
Original file line number Diff line number Diff line change @@ -24,10 +24,14 @@ export test_tmpdir=${testtmp}
2424
2525# This is new content for our update
2626test_bootupd_payload_file=/boot/efi/EFI/fedora/test-bootupd.efi
27+ test_bootupd_payload_file1=/boot/efi/EFI/BOOT/test-bootupd1.efi
2728build_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
3337cd ${COSA_DIR}
You can’t perform that action at this time.
0 commit comments