1- use std:: path:: Path ;
2- use std:: { os:: fd:: AsRawFd , path:: PathBuf } ;
1+ use std:: {
2+ os:: fd:: AsRawFd ,
3+ path:: { Path , PathBuf } ,
4+ } ;
35
46use anyhow:: Result ;
57use camino:: Utf8Path ;
@@ -23,18 +25,24 @@ pub(crate) const BASE_ARGS: &[&str] = &[
2325 "label=disable" ,
2426] ;
2527
26- // Clear out and delete any ostree roots
27- fn reset_root ( sh : & Shell ) -> Result < ( ) > {
28- // TODO fix https://github.com/containers/bootc/pull/137
29- if !Path :: new ( "/ostree/deploy/default " ) . exists ( ) {
28+ /// Clear out and delete any ostree roots, leverage bootc hidden wipe-ostree command to get rid of
29+ /// otherwise hard to delete deployment files
30+ fn reset_root ( sh : & Shell , image : & str ) -> Result < ( ) > {
31+ if !Path :: new ( "/ostree/deploy/" ) . exists ( ) {
3032 return Ok ( ( ) ) ;
3133 }
34+
35+ // Without /boot ostree will not delete anything
36+ let mounts = & [ "-v" , "/ostree:/ostree" , "-v" , "/boot:/boot" ] ;
37+
3238 cmd ! (
3339 sh,
34- "sudo /bin/sh -c 'chattr -i / ostree/deploy/default/deploy/*' "
40+ "sudo {BASE_ARGS...} {mounts...} {image} bootc state wipe- ostree"
3541 )
3642 . run ( ) ?;
37- cmd ! ( sh, "sudo rm /ostree/deploy/default -rf" ) . run ( ) ?;
43+
44+ // Now that the hard to delete files are gone, we can just rm -rf the rest
45+ cmd ! ( sh, "sudo /bin/sh -c 'rm -rf /ostree/deploy/*'" ) . run ( ) ?;
3846 Ok ( ( ) )
3947}
4048
@@ -76,7 +84,7 @@ pub(crate) fn run_alongside(image: &str, mut testargs: libtest_mimic::Arguments)
7684 let tests = [
7785 Trial :: test ( "loopback install" , move || {
7886 let sh = & xshell:: Shell :: new ( ) ?;
79- reset_root ( sh) ?;
87+ reset_root ( sh, image ) ?;
8088 let size = 10 * 1000 * 1000 * 1000 ;
8189 let mut tmpdisk = tempfile:: NamedTempFile :: new_in ( "/var/tmp" ) ?;
8290 tmpdisk. as_file_mut ( ) . set_len ( size) ?;
@@ -89,7 +97,7 @@ pub(crate) fn run_alongside(image: &str, mut testargs: libtest_mimic::Arguments)
8997 "replace=alongside with ssh keys and a karg, and SELinux disabled" ,
9098 move || {
9199 let sh = & xshell:: Shell :: new ( ) ?;
92- reset_root ( sh) ?;
100+ reset_root ( sh, image ) ?;
93101 let tmpd = & sh. create_temp_dir ( ) ?;
94102 let tmp_keys = tmpd. path ( ) . join ( "test_authorized_keys" ) ;
95103 let tmp_keys = tmp_keys. to_str ( ) . unwrap ( ) ;
@@ -128,7 +136,7 @@ pub(crate) fn run_alongside(image: &str, mut testargs: libtest_mimic::Arguments)
128136 ) ,
129137 Trial :: test ( "Install and verify selinux state" , move || {
130138 let sh = & xshell:: Shell :: new ( ) ?;
131- reset_root ( sh) ?;
139+ reset_root ( sh, image ) ?;
132140 cmd ! ( sh, "sudo {BASE_ARGS...} {target_args...} {image} bootc install to-existing-root --acknowledge-destructive {generic_inst_args...}" ) . run ( ) ?;
133141 generic_post_install_verification ( ) ?;
134142 let root = & Dir :: open_ambient_dir ( "/ostree" , cap_std:: ambient_authority ( ) ) . unwrap ( ) ;
@@ -138,7 +146,7 @@ pub(crate) fn run_alongside(image: &str, mut testargs: libtest_mimic::Arguments)
138146 } ) ,
139147 Trial :: test ( "without an install config" , move || {
140148 let sh = & xshell:: Shell :: new ( ) ?;
141- reset_root ( sh) ?;
149+ reset_root ( sh, image ) ?;
142150 let empty = sh. create_temp_dir ( ) ?;
143151 let empty = empty. path ( ) . to_str ( ) . unwrap ( ) ;
144152 cmd ! ( sh, "sudo {BASE_ARGS...} {target_args...} -v {empty}:/usr/lib/bootc/install {image} bootc install to-existing-root {generic_inst_args...}" ) . run ( ) ?;
0 commit comments