-
Notifications
You must be signed in to change notification settings - Fork 767
test(e2e): close Podman driver test coverage gaps #1439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| //! Shared CLI helpers for e2e tests that need to invoke `openshell` commands | ||
| //! and poll for readiness. | ||
|
|
||
| use std::process::Stdio; | ||
| use std::time::{Duration, Instant}; | ||
|
|
||
| use tokio::time::sleep; | ||
|
|
||
| use super::binary::openshell_cmd; | ||
| use super::output::strip_ansi; | ||
|
|
||
| pub async fn run_cli(args: &[&str]) -> (String, i32) { | ||
| let mut cmd = openshell_cmd(); | ||
| cmd.args(args).stdout(Stdio::piped()).stderr(Stdio::piped()); | ||
|
|
||
| let output = cmd.output().await.expect("spawn openshell"); | ||
| let stdout = String::from_utf8_lossy(&output.stdout); | ||
| let stderr = String::from_utf8_lossy(&output.stderr); | ||
| let combined = format!("{stdout}{stderr}"); | ||
| let code = output.status.code().unwrap_or(-1); | ||
| (combined, code) | ||
| } | ||
|
|
||
| pub async fn wait_for_healthy(timeout: Duration) -> Result<(), String> { | ||
| let start = Instant::now(); | ||
| let mut last_output: String; | ||
|
|
||
| loop { | ||
| let (output, code) = run_cli(&["status"]).await; | ||
| let clean = strip_ansi(&output); | ||
| let lower = clean.to_lowercase(); | ||
| if code == 0 | ||
| && (lower.contains("healthy") | ||
| || lower.contains("running") | ||
| || lower.contains("connected")) | ||
| { | ||
| return Ok(()); | ||
| } | ||
| last_output = clean; | ||
|
|
||
| if start.elapsed() > timeout { | ||
| return Err(format!( | ||
| "gateway did not become healthy within {}s. Last output:\n{last_output}", | ||
| timeout.as_secs() | ||
| )); | ||
| } | ||
| sleep(Duration::from_secs(2)).await; | ||
| } | ||
| } | ||
|
|
||
| pub async fn sandbox_names() -> Result<Vec<String>, String> { | ||
| let (output, code) = run_cli(&["sandbox", "list", "--names"]).await; | ||
| let clean = strip_ansi(&output); | ||
| if code != 0 { | ||
| return Err(format!("sandbox list failed (exit {code}):\n{clean}")); | ||
| } | ||
|
|
||
| Ok(clean | ||
| .lines() | ||
| .map(str::trim) | ||
| .filter(|line| !line.is_empty()) | ||
| .map(ToOwned::to_owned) | ||
| .collect()) | ||
| } | ||
|
|
||
| pub async fn wait_for_sandbox_exec_contains( | ||
| sandbox_name: &str, | ||
| command: &[&str], | ||
| expected: &str, | ||
| timeout: Duration, | ||
| ) -> Result<(), String> { | ||
| let start = Instant::now(); | ||
| let mut last_output: String; | ||
|
|
||
| loop { | ||
| let mut cmd = openshell_cmd(); | ||
| cmd.args(["sandbox", "exec", "--name", sandbox_name, "--no-tty", "--"]) | ||
| .args(command) | ||
| .stdout(Stdio::piped()) | ||
| .stderr(Stdio::piped()); | ||
|
|
||
| match cmd.output().await { | ||
| Ok(output) => { | ||
| let stdout = String::from_utf8_lossy(&output.stdout); | ||
| let stderr = String::from_utf8_lossy(&output.stderr); | ||
| last_output = strip_ansi(&format!("{stdout}{stderr}")); | ||
| if output.status.success() && last_output.contains(expected) { | ||
| return Ok(()); | ||
| } | ||
| } | ||
| Err(err) => { | ||
| last_output = format!("failed to spawn openshell sandbox exec: {err}"); | ||
| } | ||
| } | ||
|
|
||
| if start.elapsed() > timeout { | ||
| return Err(format!( | ||
| "sandbox '{sandbox_name}' exec did not produce '{expected}' within {}s. Last output:\n{last_output}", | ||
| timeout.as_secs() | ||
| )); | ||
| } | ||
| sleep(Duration::from_secs(2)).await; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #![cfg(feature = "e2e-podman")] | ||
|
|
||
| //! Podman-specific E2E coverage for resuming sandboxes after a standalone | ||
| //! gateway restart. | ||
| //! | ||
| //! Unlike the Docker driver, Podman does not stop sandbox containers when the | ||
| //! gateway process exits — the containers keep running and the restarted | ||
| //! gateway re-adopts them. This test follows the `vm_gateway_resume.rs` | ||
| //! pattern: verify sandbox survival at the application level without asserting | ||
| //! intermediate container-state transitions. | ||
|
|
||
| use std::time::Duration; | ||
|
|
||
| use openshell_e2e::harness::cli::{sandbox_names, wait_for_healthy, wait_for_sandbox_exec_contains}; | ||
| use openshell_e2e::harness::gateway::ManagedGateway; | ||
| use openshell_e2e::harness::sandbox::SandboxGuard; | ||
|
|
||
| const READY_MARKER: &str = "podman-gateway-resume-ready"; | ||
| const RESUME_FILE: &str = "/sandbox/podman-gateway-resume-state"; | ||
|
|
||
| #[tokio::test] | ||
| async fn podman_gateway_restart_resumes_running_sandbox() { | ||
| if std::env::var("OPENSHELL_E2E_DRIVER").as_deref() != Ok("podman") { | ||
| eprintln!("Skipping Podman gateway resume test: e2e driver is not podman"); | ||
| return; | ||
| } | ||
| let Some(gateway) = ManagedGateway::from_env().expect("load managed e2e gateway metadata") | ||
| else { | ||
| eprintln!( | ||
| "Skipping Podman gateway resume test: e2e gateway is not managed by this test run" | ||
| ); | ||
| return; | ||
| }; | ||
|
|
||
| wait_for_healthy(Duration::from_secs(30)) | ||
| .await | ||
| .expect("gateway should start healthy"); | ||
|
|
||
| let script = format!( | ||
| "echo before-restart > {RESUME_FILE}; echo {READY_MARKER}; while true; do sleep 1; done" | ||
| ); | ||
| let mut sandbox = SandboxGuard::create_keep(&["sh", "-lc", &script], READY_MARKER) | ||
| .await | ||
| .expect("create long-running Podman sandbox"); | ||
|
|
||
| let before_restart = sandbox | ||
| .exec(&["cat", RESUME_FILE]) | ||
| .await | ||
| .expect("read Podman sandbox state before restart"); | ||
| assert!( | ||
| before_restart.contains("before-restart"), | ||
| "sandbox state was not written before restart:\n{before_restart}" | ||
| ); | ||
|
|
||
| gateway.stop().expect("stop e2e gateway"); | ||
| gateway.start().expect("restart e2e gateway"); | ||
| wait_for_healthy(Duration::from_secs(120)) | ||
| .await | ||
| .expect("gateway should become healthy after restart"); | ||
|
|
||
| let names = sandbox_names().await.expect("list sandboxes after restart"); | ||
| assert!( | ||
| names.contains(&sandbox.name), | ||
| "sandbox '{}' should still be listed after gateway restart. Names: {names:?}", | ||
| sandbox.name | ||
| ); | ||
|
|
||
| wait_for_sandbox_exec_contains( | ||
| &sandbox.name, | ||
| &["cat", RESUME_FILE], | ||
| "before-restart", | ||
| Duration::from_secs(240), | ||
| ) | ||
| .await | ||
| .expect("Podman sandbox should become ready again with its state preserved"); | ||
|
|
||
| sandbox.cleanup().await; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.