@@ -154,6 +154,71 @@ impl Podman {
154
154
self . stopped = true ;
155
155
}
156
156
157
+ pub fn rm ( & mut self ) {
158
+ let mut command = std:: process:: Command :: new ( "podman" ) ;
159
+ command. arg ( "rm" ) ;
160
+ command. arg ( & self . name ) ;
161
+ let output = command. output ( ) . unwrap ( ) ;
162
+ logging:: log:: debug!(
163
+ "Podman rm command args: {:?}" ,
164
+ command. get_args( ) . map( |s| s. to_string_lossy( ) ) . collect:: <Vec <_>>( ) . join( " " )
165
+ ) ;
166
+ assert ! (
167
+ output. status. success( ) ,
168
+ "Failed to run podman command: {:?}\n {}" ,
169
+ command,
170
+ String :: from_utf8_lossy( & output. stderr)
171
+ ) ;
172
+ }
173
+
174
+ /// Uses the command `podman logs` to print the logs of the container.
175
+ pub fn print_logs ( & mut self ) {
176
+ let mut command = std:: process:: Command :: new ( "podman" ) ;
177
+ command. arg ( "logs" ) ;
178
+ command. arg ( & self . name ) ;
179
+ let output = command. output ( ) . unwrap ( ) ;
180
+ logging:: log:: debug!(
181
+ "Podman logs command args: {:?}" ,
182
+ command. get_args( ) . map( |s| s. to_string_lossy( ) ) . collect:: <Vec <_>>( ) . join( " " )
183
+ ) ;
184
+ assert ! (
185
+ output. status. success( ) ,
186
+ "Failed to run podman command: {:?}\n {}" ,
187
+ command,
188
+ String :: from_utf8_lossy( & output. stderr)
189
+ ) ;
190
+
191
+ {
192
+ let mut logs = String :: new ( ) ;
193
+ logs. push_str ( "==================================================================\n " ) ;
194
+ logs. push_str ( "==================================================================\n " ) ;
195
+ logs. push_str ( "==================================================================\n " ) ;
196
+ logs. push_str ( & format ! ( "Logs for container '{}' (stdout):\n " , self . name) ) ;
197
+ logs. push_str ( "==================================================================\n " ) ;
198
+ logs. push_str ( & String :: from_utf8_lossy ( & output. stdout ) ) ;
199
+ logs. push_str ( "==================================================================\n " ) ;
200
+ logs. push_str ( "==================================================================\n " ) ;
201
+ logs. push_str ( "==================================================================\n " ) ;
202
+ logs. push_str ( & format ! ( "Logs for container '{}' (stderr):\n " , self . name) ) ;
203
+ logs. push_str ( "==================================================================\n " ) ;
204
+ logs. push_str ( & String :: from_utf8_lossy ( & output. stderr ) ) ;
205
+ logs. push_str ( "\n \n " ) ;
206
+ logs. push_str ( "==================================================================\n " ) ;
207
+ logs. push_str ( "==================================================================\n " ) ;
208
+ logs. push_str ( "==================================================================\n " ) ;
209
+
210
+ println ! ( "{}" , logs) ;
211
+ }
212
+ }
213
+
214
+ fn destructor ( & mut self ) {
215
+ if !self . stopped {
216
+ self . stop ( ) ;
217
+ }
218
+ self . print_logs ( ) ;
219
+ self . rm ( ) ;
220
+ }
221
+
157
222
#[ allow( dead_code) ]
158
223
pub fn name ( & self ) -> & str {
159
224
& self . name
@@ -162,8 +227,6 @@ impl Podman {
162
227
163
228
impl Drop for Podman {
164
229
fn drop ( & mut self ) {
165
- if !self . stopped {
166
- self . stop ( ) ;
167
- }
230
+ self . destructor ( )
168
231
}
169
232
}
0 commit comments