Some checks failed
Run Check Script / check (pull_request) Failing after 37s
68 lines
2.4 KiB
Rust
68 lines
2.4 KiB
Rust
//! VM-side smoke test #1 — operator → agent ping over NATS.
|
|
//!
|
|
//! Same `Verb::Ping` round-trip as `tests/ping.rs`, but the agent
|
|
//! runs on a real aarch64 libvirt VM with `runtime_enabled=true`
|
|
//! (real podman socket attached). Proves the agent's command
|
|
//! server arm comes up end-to-end on the production deploy path.
|
|
//!
|
|
//! Gating: skipped unless `HARMONY_FLEET_VM_E2E=1` is set. Brings
|
|
//! up an aarch64 VM, which costs ~10-30 minutes on a typical
|
|
//! x86_64 dev host under TCG.
|
|
|
|
use std::time::Duration;
|
|
|
|
use harmony_fleet_e2e::{VmStackOptions, shared_vm_stack};
|
|
use harmony_fleet_operator::commands::FleetCommandsClient;
|
|
|
|
const ENV_GATE: &str = "HARMONY_FLEET_VM_E2E";
|
|
|
|
fn enabled() -> bool {
|
|
matches!(std::env::var(ENV_GATE).as_deref(), Ok("1" | "true"))
|
|
}
|
|
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
|
|
async fn agent_on_vm_replies_to_ping() -> anyhow::Result<()> {
|
|
if !enabled() {
|
|
eprintln!(
|
|
"skipping {ENV_GATE}-gated VM e2e test (set {ENV_GATE}=1 to run; \
|
|
requires libvirt + qemu + k3d + an aarch64 cross-toolchain on the host)"
|
|
);
|
|
return Ok(());
|
|
}
|
|
|
|
let _ = tracing_subscriber::fmt()
|
|
.with_env_filter(
|
|
tracing_subscriber::EnvFilter::try_from_default_env()
|
|
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info")),
|
|
)
|
|
.try_init();
|
|
|
|
let stack = shared_vm_stack(VmStackOptions::from_env()).await?;
|
|
stack.print_debug_info();
|
|
|
|
// `FleetDeviceSetupScore` returns when the systemd unit is
|
|
// started, not when the agent's NATS subscription is live —
|
|
// a ping right after bring-up gets `NoResponders` immediately.
|
|
// Block until the agent answers ping at least once.
|
|
stack.wait_until_ready(Duration::from_secs(60)).await?;
|
|
|
|
let device = stack.devices.first().expect("at least one VM device");
|
|
let device_id = device.device_id.to_string();
|
|
let client = FleetCommandsClient::new(stack.infra.nats_client.clone());
|
|
|
|
let reply = tokio::time::timeout(Duration::from_secs(15), client.ping(&device_id))
|
|
.await
|
|
.map_err(|_| anyhow::anyhow!("ping outer timeout"))??;
|
|
|
|
assert_eq!(
|
|
reply.device_id.to_string(),
|
|
device_id,
|
|
"agent must echo back its own device_id",
|
|
);
|
|
assert!(
|
|
!reply.agent_version.is_empty(),
|
|
"agent_version must be non-empty (env!(CARGO_PKG_VERSION) at compile time)",
|
|
);
|
|
Ok(())
|
|
}
|