Skip to content

Commit

Permalink
Podman now deletes the container on exit and prints the logs to stdout
Browse files Browse the repository at this point in the history
  • Loading branch information
TheQuantumPhysicist committed Sep 26, 2023
1 parent 648d378 commit 4ce9b83
Showing 1 changed file with 66 additions and 3 deletions.
69 changes: 66 additions & 3 deletions api-server/storage-test-suite/tests/containers/podman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,71 @@ impl Podman {
self.stopped = true;
}

pub fn rm(&mut self) {
let mut command = std::process::Command::new("podman");
command.arg("rm");
command.arg(&self.name);
let output = command.output().unwrap();
logging::log::debug!(
"Podman rm command args: {:?}",
command.get_args().map(|s| s.to_string_lossy()).collect::<Vec<_>>().join(" ")
);
assert!(
output.status.success(),
"Failed to run podman command: {:?}\n{}",
command,
String::from_utf8_lossy(&output.stderr)
);
}

/// Uses the command `podman logs` to print the logs of the container.
pub fn print_logs(&mut self) {
let mut command = std::process::Command::new("podman");
command.arg("logs");
command.arg(&self.name);
let output = command.output().unwrap();
logging::log::debug!(
"Podman logs command args: {:?}",
command.get_args().map(|s| s.to_string_lossy()).collect::<Vec<_>>().join(" ")
);
assert!(
output.status.success(),
"Failed to run podman command: {:?}\n{}",
command,
String::from_utf8_lossy(&output.stderr)
);

{
let mut logs = String::new();
logs.push_str("==================================================================\n");
logs.push_str("==================================================================\n");
logs.push_str("==================================================================\n");
logs.push_str(&format!("Logs for container '{}' (stdout):\n", self.name));
logs.push_str("==================================================================\n");
logs.push_str(&String::from_utf8_lossy(&output.stdout));
logs.push_str("==================================================================\n");
logs.push_str("==================================================================\n");
logs.push_str("==================================================================\n");
logs.push_str(&format!("Logs for container '{}' (stderr):\n", self.name));
logs.push_str("==================================================================\n");
logs.push_str(&String::from_utf8_lossy(&output.stderr));
logs.push_str("\n\n");
logs.push_str("==================================================================\n");
logs.push_str("==================================================================\n");
logs.push_str("==================================================================\n");

println!("{}", logs);
}
}

fn destructor(&mut self) {
if !self.stopped {
self.stop();
}
self.print_logs();
self.rm();
}

#[allow(dead_code)]
pub fn name(&self) -> &str {
&self.name
Expand All @@ -162,8 +227,6 @@ impl Podman {

impl Drop for Podman {
fn drop(&mut self) {
if !self.stopped {
self.stop();
}
self.destructor()
}
}

0 comments on commit 4ce9b83

Please sign in to comment.