Skip to content

Commit 1d30aa7

Browse files
committed
tests: consolidate libvirt karg testing to reduce base disk creation
Remove the dedicated test_libvirt_run_ssh_full_workflow test and fold kernel argument testing into test_libvirt_run_bind_mounts instead. The separate test was creating a unique base disk just to validate --karg functionality, taking 8-10 minutes in CI. In a fresh CI environment, each test with different parameters (image, filesystem, or kernel args) triggers a separate base disk creation via bootc install. The removed test used --karg bcvk.test-install-karg=1, which created a unique cache key and prevented sharing with other tests. By consolidating karg validation into an existing test that already boots a VM and uses SSH, we eliminate one redundant base disk creation while maintaining the same test coverage. This change reduces the libvirt_verb test suite from 7 to 6 VM-creating tests, with 5 tests now sharing a single base disk (fedora-bootc:42 + ext4 + no kargs) and only the bind_mounts test requiring its own base disk due to the test karg. Assisted-by: Claude Code (Sonnet 4.5) Signed-off-by: Colin Walters <[email protected]>
1 parent 4c385b8 commit 1d30aa7

File tree

1 file changed

+24
-93
lines changed

1 file changed

+24
-93
lines changed

crates/integration-tests/src/tests/libvirt_verb.rs

Lines changed: 24 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -363,95 +363,6 @@ fn test_libvirt_ssh_integration() -> Result<()> {
363363
Ok(())
364364
}
365365

366-
#[distributed_slice(INTEGRATION_TESTS)]
367-
static TEST_LIBVIRT_RUN_SSH_FULL_WORKFLOW: IntegrationTest = IntegrationTest::new(
368-
"test_libvirt_run_ssh_full_workflow",
369-
test_libvirt_run_ssh_full_workflow,
370-
);
371-
372-
/// Test full libvirt run + SSH workflow like run_ephemeral SSH tests
373-
fn test_libvirt_run_ssh_full_workflow() -> Result<()> {
374-
let test_image = get_test_image();
375-
376-
// Generate unique domain name for this test
377-
let domain_name = format!(
378-
"test-ssh-{}",
379-
std::time::SystemTime::now()
380-
.duration_since(std::time::UNIX_EPOCH)
381-
.unwrap()
382-
.as_secs()
383-
);
384-
385-
println!(
386-
"Testing full libvirt run + SSH workflow with domain: {}",
387-
domain_name
388-
);
389-
390-
// Cleanup any existing domain with this name
391-
cleanup_domain(&domain_name);
392-
393-
// Create domain with SSH key generation
394-
println!("Creating libvirt domain with SSH key injection...");
395-
let create_output = run_bcvk(&[
396-
"libvirt",
397-
"run",
398-
"--name",
399-
&domain_name,
400-
"--label",
401-
LIBVIRT_INTEGRATION_TEST_LABEL,
402-
"--filesystem",
403-
"ext4",
404-
"--karg",
405-
"bcvk.test-install-karg=1",
406-
&test_image,
407-
])
408-
.expect("Failed to run libvirt run with SSH");
409-
410-
println!("Create stdout: {}", create_output.stdout);
411-
println!("Create stderr: {}", create_output.stderr);
412-
413-
if !create_output.success() {
414-
cleanup_domain(&domain_name);
415-
416-
panic!("Failed to create domain with SSH: {}", create_output.stderr);
417-
}
418-
419-
println!("Successfully created domain: {}", domain_name);
420-
421-
// Wait for VM to boot and SSH to become available
422-
println!("Waiting for VM to boot and SSH to become available...");
423-
std::thread::sleep(std::time::Duration::from_secs(30));
424-
425-
// Test SSH connection and read kernel command line
426-
println!("Testing SSH connection and validating karg");
427-
let ssh_output = run_bcvk(&["libvirt", "ssh", &domain_name, "--", "cat", "/proc/cmdline"])
428-
.expect("Failed to run libvirt ssh command");
429-
430-
println!("SSH stdout: {}", ssh_output.stdout);
431-
println!("SSH stderr: {}", ssh_output.stderr);
432-
433-
// Cleanup domain before checking results
434-
cleanup_domain(&domain_name);
435-
436-
// Check SSH results
437-
if !ssh_output.success() {
438-
panic!(
439-
"SSH connection failed: {}\nkernel cmdline: {}",
440-
ssh_output.stderr, ssh_output.stdout
441-
);
442-
}
443-
444-
// Verify we got the expected karg in /proc/cmdline
445-
assert!(
446-
ssh_output.stdout.contains("bcvk.test-install-karg=1"),
447-
"Expected bcvk.test-install-karg=1 in kernel cmdline.\nActual cmdline: {}",
448-
ssh_output.stdout
449-
);
450-
451-
println!("✓ Full libvirt run + SSH workflow test passed");
452-
Ok(())
453-
}
454-
455366
/// Helper function to cleanup domain
456367
fn cleanup_domain(domain_name: &str) {
457368
println!("Cleaning up domain: {}", domain_name);
@@ -1164,6 +1075,7 @@ static TEST_LIBVIRT_RUN_BIND_MOUNTS: IntegrationTest =
11641075
IntegrationTest::new("test_libvirt_run_bind_mounts", test_libvirt_run_bind_mounts);
11651076

11661077
/// Test automatic bind mount functionality with systemd mount units
1078+
/// Also validates kernel argument (--karg) functionality
11671079
fn test_libvirt_run_bind_mounts() -> Result<()> {
11681080
use camino::Utf8Path;
11691081
use std::fs;
@@ -1185,7 +1097,7 @@ fn test_libvirt_run_bind_mounts() -> Result<()> {
11851097
.as_secs()
11861098
);
11871099

1188-
println!("Testing bind mounts with domain: {}", domain_name);
1100+
println!("Testing bind mounts and kargs with domain: {}", domain_name);
11891101

11901102
// Create temporary directories for testing bind mounts
11911103
let rw_dir = TempDir::new().expect("Failed to create read-write temp directory");
@@ -1204,8 +1116,8 @@ fn test_libvirt_run_bind_mounts() -> Result<()> {
12041116
// Cleanup any existing domain with this name
12051117
cleanup_domain(&domain_name);
12061118

1207-
// Create domain with bind mounts
1208-
println!("Creating libvirt domain with bind mounts...");
1119+
// Create domain with bind mounts and test karg
1120+
println!("Creating libvirt domain with bind mounts and karg...");
12091121
let create_output = run_bcvk(&[
12101122
"libvirt",
12111123
"run",
@@ -1215,6 +1127,8 @@ fn test_libvirt_run_bind_mounts() -> Result<()> {
12151127
LIBVIRT_INTEGRATION_TEST_LABEL,
12161128
"--filesystem",
12171129
"ext4",
1130+
"--karg",
1131+
"bcvk.test-install-karg=1",
12181132
"--bind",
12191133
&format!("{}:/var/mnt/test-rw", rw_dir_path),
12201134
"--bind-ro",
@@ -1404,9 +1318,26 @@ fn test_libvirt_run_bind_mounts() -> Result<()> {
14041318
);
14051319
println!("✓ RO bind mount correctly rejects writes");
14061320

1321+
// Test kernel argument was applied
1322+
println!("Validating kernel argument...");
1323+
let cmdline_output = run_bcvk(&["libvirt", "ssh", &domain_name, "--", "cat", "/proc/cmdline"])
1324+
.expect("Failed to read kernel cmdline");
1325+
1326+
assert!(
1327+
cmdline_output.success(),
1328+
"Failed to read /proc/cmdline. stderr: {}",
1329+
cmdline_output.stderr
1330+
);
1331+
assert!(
1332+
cmdline_output.stdout.contains("bcvk.test-install-karg=1"),
1333+
"Expected bcvk.test-install-karg=1 in kernel cmdline.\nActual: {}",
1334+
cmdline_output.stdout
1335+
);
1336+
println!("✓ Kernel argument validated");
1337+
14071338
// Cleanup domain
14081339
cleanup_domain(&domain_name);
14091340

1410-
println!("✓ Bind mounts test passed");
1341+
println!("✓ Bind mounts and karg test passed");
14111342
Ok(())
14121343
}

0 commit comments

Comments
 (0)