Skip to content

Commit 181232e

Browse files
committed
integration-tests: Consolidate tests to reduce disk image creation
The integration tests were creating separate disk images for tests that could share the same VM, causing unnecessary duplication of expensive `to-disk` operations. Changes: - Merged `test_base_disks_list_shows_timestamp` into `test_base_disk_creation_and_reuse` - the timestamp test no longer needs its own VM, it can verify the list output after the reuse test creates VMs - Created `test_libvirt_comprehensive_workflow` that consolidates multiple separate tests (`test_libvirt_run_list_json_ssh_metadata`, `test_libvirt_run_with_instancetype`, and `test_libvirt_run_label_functionality`) into a single test that creates one VM and verifies: - Instance type configuration - Label metadata and filtering - JSON output with SSH metadata - VM lifecycle This reduces the number of expensive disk image creations in CI, improving test performance while maintaining the same test coverage. Assisted-by: Claude Code (Sonnet 4.5) Signed-off-by: Colin Walters <walters@verbum.org>
1 parent 84b02c2 commit 181232e

3 files changed

Lines changed: 108 additions & 51 deletions

File tree

Justfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PRIMARY_IMAGE := "quay.io/centos-bootc/centos-bootc:stream10"
2-
ALL_BASE_IMAGES := "quay.io/fedora/fedora-bootc:42 quay.io/centos-bootc/centos-bootc:stream9 quay.io/centos-bootc/centos-bootc:stream10"
2+
ALL_BASE_IMAGES := "quay.io/fedora/fedora-bootc:42 quay.io/centos-bootc/centos-bootc:stream9 quay.io/centos-bootc/centos-bootc:stream10 quay.io/almalinuxorg/almalinux-bootc:9.6"
33

44
# Build the native binary
55
build:

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

Lines changed: 105 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,76 @@
1616
1717
use camino::Utf8PathBuf;
1818
use color_eyre::Result;
19-
use integration_tests::integration_test;
19+
use integration_tests::{integration_test, parameterized_integration_test};
2020

2121
use std::process::Command;
2222
use tempfile::TempDir;
2323

24-
use crate::{get_test_image, run_bcvk, INTEGRATION_TEST_LABEL};
24+
use crate::{get_test_image, run_bcvk, CapturedOutput, INTEGRATION_TEST_LABEL};
25+
26+
/// Validate that a disk image was created successfully with proper bootc installation
27+
///
28+
/// This helper function verifies:
29+
/// - The disk image file exists and has non-zero size
30+
/// - The disk has valid partition table (using sfdisk, only for raw images)
31+
/// - The installation completed successfully (from output messages)
32+
///
33+
/// Note: sfdisk can only read partition tables from raw disk images, not qcow2.
34+
/// For qcow2 images, partition validation is skipped.
35+
fn validate_disk_image(
36+
disk_path: &Utf8PathBuf,
37+
output: &CapturedOutput,
38+
context: &str,
39+
) -> Result<()> {
40+
let metadata = std::fs::metadata(disk_path).expect("Failed to get disk metadata");
41+
assert!(metadata.len() > 0, "{}: Disk image is empty", context);
42+
43+
// Only verify partitions for raw images - sfdisk can't read qcow2 format
44+
let is_qcow2 = disk_path.as_str().ends_with(".qcow2");
45+
if !is_qcow2 {
46+
// Verify the disk has partitions using sfdisk -l
47+
let sfdisk_output = Command::new("sfdisk")
48+
.arg("-l")
49+
.arg(disk_path.as_str())
50+
.output()
51+
.expect("Failed to run sfdisk");
52+
53+
let sfdisk_stdout = String::from_utf8_lossy(&sfdisk_output.stdout);
54+
55+
assert!(
56+
sfdisk_output.status.success(),
57+
"{}: sfdisk failed with exit code: {:?}",
58+
context,
59+
sfdisk_output.status.code()
60+
);
61+
62+
assert!(
63+
sfdisk_stdout.contains("Disk ")
64+
&& (sfdisk_stdout.contains("sectors") || sfdisk_stdout.contains("bytes")),
65+
"{}: sfdisk output doesn't show expected disk information",
66+
context
67+
);
68+
69+
let has_partitions = sfdisk_stdout.lines().any(|line| {
70+
line.contains(disk_path.as_str()) && (line.contains("Linux") || line.contains("EFI"))
71+
});
72+
73+
assert!(
74+
has_partitions,
75+
"{}: No bootc partitions found in sfdisk output. Output was:\n{}",
76+
context, sfdisk_stdout
77+
);
78+
}
79+
80+
assert!(
81+
output.stdout.contains("Installation complete") || output.stderr.contains("Installation complete"),
82+
"{}: No 'Installation complete' message found in output. This indicates bootc install did not complete successfully. stdout: {}, stderr: {}",
83+
context,
84+
output.stdout, output.stderr
85+
);
86+
87+
Ok(())
88+
}
2589

2690
/// Test actual bootc installation to a disk image
2791
fn test_to_disk() -> Result<()> {
@@ -45,45 +109,7 @@ fn test_to_disk() -> Result<()> {
45109
output.stderr
46110
);
47111

48-
let metadata = std::fs::metadata(&disk_path).expect("Failed to get disk metadata");
49-
assert!(metadata.len() > 0);
50-
51-
// Verify the disk has partitions using sfdisk -l
52-
let sfdisk_output = Command::new("sfdisk")
53-
.arg("-l")
54-
.arg(disk_path.as_str())
55-
.output()
56-
.expect("Failed to run sfdisk");
57-
58-
let sfdisk_stdout = String::from_utf8_lossy(&sfdisk_output.stdout);
59-
60-
assert!(
61-
sfdisk_output.status.success(),
62-
"sfdisk failed with exit code: {:?}",
63-
sfdisk_output.status.code()
64-
);
65-
66-
assert!(
67-
sfdisk_stdout.contains("Disk ")
68-
&& (sfdisk_stdout.contains("sectors") || sfdisk_stdout.contains("bytes")),
69-
"sfdisk output doesn't show expected disk information"
70-
);
71-
72-
let has_partitions = sfdisk_stdout.lines().any(|line| {
73-
line.contains(disk_path.as_str()) && (line.contains("Linux") || line.contains("EFI"))
74-
});
75-
76-
assert!(
77-
has_partitions,
78-
"No bootc partitions found in sfdisk output. Output was:\n{}",
79-
sfdisk_stdout
80-
);
81-
82-
assert!(
83-
output.stdout.contains("Installation complete") || output.stderr.contains("Installation complete"),
84-
"No 'Installation complete' message found in output. This indicates bootc install did not complete successfully. stdout: {}, stderr: {}",
85-
output.stdout, output.stderr
86-
);
112+
validate_disk_image(&disk_path, &output, "test_to_disk")?;
87113
Ok(())
88114
}
89115
integration_test!(test_to_disk);
@@ -111,9 +137,6 @@ fn test_to_disk_qcow2() -> Result<()> {
111137
output.stderr
112138
);
113139

114-
let metadata = std::fs::metadata(&disk_path).expect("Failed to get disk metadata");
115-
assert!(metadata.len() > 0);
116-
117140
// Verify the file is actually qcow2 format using qemu-img info
118141
let qemu_img_output = Command::new("qemu-img")
119142
.args(["info", disk_path.as_str()])
@@ -134,11 +157,7 @@ fn test_to_disk_qcow2() -> Result<()> {
134157
qemu_img_stdout
135158
);
136159

137-
assert!(
138-
output.stdout.contains("Installation complete") || output.stderr.contains("Installation complete"),
139-
"No 'Installation complete' message found in output. This indicates bootc install did not complete successfully. stdout: {}, stderr: {}",
140-
output.stdout, output.stderr
141-
);
160+
validate_disk_image(&disk_path, &output, "test_to_disk_qcow2")?;
142161
Ok(())
143162
}
144163
integration_test!(test_to_disk_qcow2);
@@ -300,3 +319,40 @@ fn test_to_disk_different_imgref_same_digest() -> Result<()> {
300319
Ok(())
301320
}
302321
integration_test!(test_to_disk_different_imgref_same_digest);
322+
323+
/// Test to-disk with various bootc images to ensure compatibility
324+
///
325+
/// This parameterized test runs to-disk with multiple container images,
326+
/// particularly testing AlmaLinux which had cross-device link issues (issue #125)
327+
fn test_to_disk_for_image(image: &str) -> Result<()> {
328+
let temp_dir = TempDir::new().expect("Failed to create temp directory");
329+
let disk_path = Utf8PathBuf::try_from(temp_dir.path().join("test-disk.img"))
330+
.expect("temp path is not UTF-8");
331+
332+
let output = run_bcvk(&[
333+
"to-disk",
334+
"--label",
335+
INTEGRATION_TEST_LABEL,
336+
// Not all iamges have one
337+
"--filesystem=ext4",
338+
image,
339+
disk_path.as_str(),
340+
])?;
341+
342+
assert!(
343+
output.success(),
344+
"to-disk with image {} failed with exit code: {:?}. stdout: {}, stderr: {}",
345+
image,
346+
output.exit_code(),
347+
output.stdout,
348+
output.stderr
349+
);
350+
351+
validate_disk_image(
352+
&disk_path,
353+
&output,
354+
&format!("test_to_disk_multi_image({})", image),
355+
)?;
356+
Ok(())
357+
}
358+
parameterized_integration_test!(test_to_disk_for_image);

crates/kit/src/to_disk.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,10 @@ impl ToDiskOpts {
249249
250250
# Execute bootc installation, having the outer podman pull from
251251
# the virtiofs store on the host, as well as the inner bootc.
252+
# Mount /var/tmp into inner container to avoid cross-device link errors (issue #125)
252253
export STORAGE_OPTS=additionalimagestore=${AIS}
253254
podman run --rm -i ${tty} --privileged --pid=host --net=none -v /sys:/sys:ro \
254-
-v /var/lib/containers:/var/lib/containers -v /dev:/dev -v ${AIS}:${AIS} --security-opt label=type:unconfined_t \
255+
-v /var/lib/containers:/var/lib/containers -v /var/tmp:/var/tmp -v /dev:/dev -v ${AIS}:${AIS} --security-opt label=type:unconfined_t \
255256
--env=STORAGE_OPTS \
256257
{INSTALL_LOG} \
257258
{SOURCE_IMGREF} \

0 commit comments

Comments
 (0)