Skip to content

Commit 39440da

Browse files
Merge pull request #1236 from mintlayer/fix/podman_print_logs
Podman now deletes the container on exit and prints the logs to stdout
2 parents 648d378 + 4ce9b83 commit 39440da

File tree

1 file changed

+66
-3
lines changed
  • api-server/storage-test-suite/tests/containers

1 file changed

+66
-3
lines changed

api-server/storage-test-suite/tests/containers/podman.rs

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,71 @@ impl Podman {
154154
self.stopped = true;
155155
}
156156

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+
157222
#[allow(dead_code)]
158223
pub fn name(&self) -> &str {
159224
&self.name
@@ -162,8 +227,6 @@ impl Podman {
162227

163228
impl Drop for Podman {
164229
fn drop(&mut self) {
165-
if !self.stopped {
166-
self.stop();
167-
}
230+
self.destructor()
168231
}
169232
}

0 commit comments

Comments
 (0)