File tree 8 files changed +105
-5
lines changed
8 files changed +105
-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<()> {
396
396
}
397
397
398
398
pub ( crate ) fn client_run_update ( ) -> Result < ( ) > {
399
+ crate :: try_fail_point!( "update" ) ;
399
400
let status: Status = status ( ) ?;
400
401
if status. components . is_empty ( ) && status. adoptable . is_empty ( ) {
401
402
println ! ( "No components installed." ) ;
@@ -489,3 +490,17 @@ pub(crate) fn client_run_validate() -> Result<()> {
489
490
}
490
491
Ok ( ( ) )
491
492
}
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 {
141
141
log:: debug!( "Not booted via EFI, skipping firmware update" ) ;
142
142
return Ok ( ( ) ) ;
143
143
}
144
- let sysroot = Dir :: open_ambient_dir ( & Path :: new ( "/" ) , cap_std:: ambient_authority ( ) ) ?;
144
+ let sysroot = Dir :: open_ambient_dir ( "/" , cap_std:: ambient_authority ( ) ) ?;
145
145
let product_name = get_product_name ( & sysroot) ?;
146
146
log:: debug!( "Get product name: {product_name}" ) ;
147
147
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(
395
395
. local_rename ( tmp, dst)
396
396
. with_context ( || format ! ( "rename for {} and {:?}" , tmp, dst) ) ?;
397
397
}
398
+ crate :: try_fail_point!( "update::exchange" ) ;
398
399
}
399
400
// Ensure all of the updates & changes are written persistently to disk
400
401
if !opts. skip_sync {
@@ -705,7 +706,6 @@ mod tests {
705
706
let b_btime_foo_new = fs:: metadata ( pb. join ( foo) ) ?. created ( ) ?;
706
707
assert_eq ! ( b_btime_foo_new, b_btime_foo) ;
707
708
}
708
-
709
709
Ok ( ( ) )
710
710
}
711
711
}
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ mod component;
24
24
mod coreos;
25
25
#[ cfg( any( target_arch = "x86_64" , target_arch = "aarch64" ) ) ]
26
26
mod efi;
27
+ mod failpoints;
27
28
mod filesystem;
28
29
mod filetree;
29
30
#[ cfg( any(
@@ -43,6 +44,7 @@ use clap::crate_name;
43
44
44
45
/// Binary entrypoint, for both daemon and client logic.
45
46
fn main ( ) {
47
+ let _scenario = fail:: FailScenario :: setup ( ) ;
46
48
let exit_code = run_cli ( ) ;
47
49
std:: process:: exit ( exit_code) ;
48
50
}
Original file line number Diff line number Diff line change @@ -67,7 +67,12 @@ tmpefimount=$(mount_tmp_efi)
67
67
68
68
assert_not_has_file ${tmpefimount} /EFI/fedora/test-bootupd.efi
69
69
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
71
76
assert_file_has_content out.txt " Previous EFI: .*"
72
77
assert_file_has_content out.txt " Updated EFI: ${TARGET_GRUB_PKG} .*,test-bootupd-payload-1.0"
73
78
Original file line number Diff line number Diff line change @@ -24,10 +24,14 @@ export test_tmpdir=${testtmp}
24
24
25
25
# This is new content for our update
26
26
test_bootupd_payload_file=/boot/efi/EFI/fedora/test-bootupd.efi
27
+ test_bootupd_payload_file1=/boot/efi/EFI/BOOT/test-bootupd1.efi
27
28
build_rpm test-bootupd-payload \
28
- files ${test_bootupd_payload_file} \
29
+ files " ${test_bootupd_payload_file}
30
+ ${test_bootupd_payload_file1} " \
29
31
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} "
31
35
32
36
# Start in cosa dir
33
37
cd ${COSA_DIR}
You can’t perform that action at this time.
0 commit comments