|
| 1 | +// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +//! VM-driver-specific assertions for the sandbox root filesystem. |
| 5 | +
|
| 6 | +use std::process::Stdio; |
| 7 | + |
| 8 | +use openshell_e2e::harness::binary::openshell_cmd; |
| 9 | +use openshell_e2e::harness::output::strip_ansi; |
| 10 | +use openshell_e2e::harness::sandbox::SandboxGuard; |
| 11 | + |
| 12 | +#[tokio::test] |
| 13 | +async fn vm_overlay() { |
| 14 | + let mut sandbox = SandboxGuard::create(&["--", "echo", "vm-sandbox-ready"]) |
| 15 | + .await |
| 16 | + .expect("sandbox create should succeed"); |
| 17 | + |
| 18 | + let script = concat!( |
| 19 | + "set -eu; ", |
| 20 | + "test \"$(stat -f -c %T /)\" = \"overlayfs\"; ", |
| 21 | + "printf \"overlay-write\\n\" > /sandbox/overlay-check; ", |
| 22 | + "test \"$(cat /sandbox/overlay-check)\" = \"overlay-write\"; ", |
| 23 | + "if [ -e /opt/openshell/tls/tls.key ]; then ", |
| 24 | + "test \"$(stat -c %a /opt/openshell/tls/tls.key)\" = \"600\"; ", |
| 25 | + "fi; ", |
| 26 | + "echo vm-overlay-ok", |
| 27 | + ); |
| 28 | + |
| 29 | + let mut exec_cmd = openshell_cmd(); |
| 30 | + exec_cmd |
| 31 | + .args(["sandbox", "exec", "--name", &sandbox.name, "--no-tty", "--"]) |
| 32 | + .arg("sh") |
| 33 | + .arg("-lc") |
| 34 | + .arg(script) |
| 35 | + .stdout(Stdio::piped()) |
| 36 | + .stderr(Stdio::piped()); |
| 37 | + |
| 38 | + let output = exec_cmd |
| 39 | + .output() |
| 40 | + .await |
| 41 | + .expect("failed to run VM overlay assertion"); |
| 42 | + let combined = strip_ansi(&format!( |
| 43 | + "{}{}", |
| 44 | + String::from_utf8_lossy(&output.stdout), |
| 45 | + String::from_utf8_lossy(&output.stderr), |
| 46 | + )); |
| 47 | + assert!( |
| 48 | + output.status.success() && combined.contains("vm-overlay-ok"), |
| 49 | + "VM overlay assertion failed (status {:?}):\n{combined}", |
| 50 | + output.status.code(), |
| 51 | + ); |
| 52 | + |
| 53 | + sandbox.cleanup().await; |
| 54 | +} |
0 commit comments