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
+ } ;
3
5
4
6
use anyhow:: Result ;
5
7
use camino:: Utf8Path ;
@@ -23,18 +25,24 @@ pub(crate) const BASE_ARGS: &[&str] = &[
23
25
"label=disable" ,
24
26
] ;
25
27
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 ( ) {
30
32
return Ok ( ( ) ) ;
31
33
}
34
+
35
+ // Without /boot ostree will not delete anything
36
+ let mounts = & [ "-v" , "/ostree:/ostree" , "-v" , "/boot:/boot" ] ;
37
+
32
38
cmd ! (
33
39
sh,
34
- "sudo /bin/sh -c 'chattr -i / ostree/deploy/default/deploy/*' "
40
+ "sudo {BASE_ARGS...} {mounts...} {image} bootc state wipe- ostree"
35
41
)
36
42
. 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 ( ) ?;
38
46
Ok ( ( ) )
39
47
}
40
48
@@ -76,7 +84,7 @@ pub(crate) fn run_alongside(image: &str, mut testargs: libtest_mimic::Arguments)
76
84
let tests = [
77
85
Trial :: test ( "loopback install" , move || {
78
86
let sh = & xshell:: Shell :: new ( ) ?;
79
- reset_root ( sh) ?;
87
+ reset_root ( sh, image ) ?;
80
88
let size = 10 * 1000 * 1000 * 1000 ;
81
89
let mut tmpdisk = tempfile:: NamedTempFile :: new_in ( "/var/tmp" ) ?;
82
90
tmpdisk. as_file_mut ( ) . set_len ( size) ?;
@@ -89,7 +97,7 @@ pub(crate) fn run_alongside(image: &str, mut testargs: libtest_mimic::Arguments)
89
97
"replace=alongside with ssh keys and a karg, and SELinux disabled" ,
90
98
move || {
91
99
let sh = & xshell:: Shell :: new ( ) ?;
92
- reset_root ( sh) ?;
100
+ reset_root ( sh, image ) ?;
93
101
let tmpd = & sh. create_temp_dir ( ) ?;
94
102
let tmp_keys = tmpd. path ( ) . join ( "test_authorized_keys" ) ;
95
103
let tmp_keys = tmp_keys. to_str ( ) . unwrap ( ) ;
@@ -128,7 +136,7 @@ pub(crate) fn run_alongside(image: &str, mut testargs: libtest_mimic::Arguments)
128
136
) ,
129
137
Trial :: test ( "Install and verify selinux state" , move || {
130
138
let sh = & xshell:: Shell :: new ( ) ?;
131
- reset_root ( sh) ?;
139
+ reset_root ( sh, image ) ?;
132
140
cmd ! ( sh, "sudo {BASE_ARGS...} {target_args...} {image} bootc install to-existing-root --acknowledge-destructive {generic_inst_args...}" ) . run ( ) ?;
133
141
generic_post_install_verification ( ) ?;
134
142
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)
138
146
} ) ,
139
147
Trial :: test ( "without an install config" , move || {
140
148
let sh = & xshell:: Shell :: new ( ) ?;
141
- reset_root ( sh) ?;
149
+ reset_root ( sh, image ) ?;
142
150
let empty = sh. create_temp_dir ( ) ?;
143
151
let empty = empty. path ( ) . to_str ( ) . unwrap ( ) ;
144
152
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