mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
tests: Check disk consistency after use
We've encountered issues that Cloud Hypervisor corrupts disk images after use. Those issues may not be immediately obvious until the corrupted images are used again. Run consistency checks over the disk images in the test cases to catch issues as early as possible. Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
@@ -3489,24 +3489,59 @@ mod common_parallel {
|
||||
_test_virtio_block(FOCAL_IMAGE_NAME, true, true);
|
||||
}
|
||||
|
||||
/// Uses `qemu-img check` to verify disk image consistency.
|
||||
///
|
||||
/// Supported formats are `qcow2` (compressed and uncompressed),
|
||||
/// `vhdx`, `qed`, `parallels`, `vmdk`, and `vdi`. See man page
|
||||
/// for more details.
|
||||
///
|
||||
/// It takes either a full path to the image or just the name of
|
||||
/// the image located in the `workloads` directory.
|
||||
fn disk_check_consistency(path_or_image_name: impl AsRef<std::path::Path>) {
|
||||
let path = if path_or_image_name.as_ref().exists() {
|
||||
// A full path is provided
|
||||
path_or_image_name.as_ref().to_path_buf()
|
||||
} else {
|
||||
// An image name is provided
|
||||
let mut workload_path = dirs::home_dir().unwrap();
|
||||
workload_path.push("workloads");
|
||||
workload_path.as_path().join(path_or_image_name.as_ref())
|
||||
};
|
||||
|
||||
let output = std::process::Command::new("qemu-img")
|
||||
.args(["check", path.to_str().unwrap()])
|
||||
.output()
|
||||
.expect("should spawn and run command successfully");
|
||||
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"qemu-img check failed: {}",
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_virtio_block_qcow2() {
|
||||
_test_virtio_block(JAMMY_IMAGE_NAME_QCOW2, false, false);
|
||||
disk_check_consistency(JAMMY_IMAGE_NAME_QCOW2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_virtio_block_qcow2_zlib() {
|
||||
_test_virtio_block(JAMMY_IMAGE_NAME_QCOW2_ZLIB, false, false);
|
||||
disk_check_consistency(JAMMY_IMAGE_NAME_QCOW2_ZLIB);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_virtio_block_qcow2_zstd() {
|
||||
_test_virtio_block(JAMMY_IMAGE_NAME_QCOW2_ZSTD, false, false);
|
||||
disk_check_consistency(JAMMY_IMAGE_NAME_QCOW2_ZSTD);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_virtio_block_qcow2_backing_file() {
|
||||
_test_virtio_block(JAMMY_IMAGE_NAME_QCOW2_BACKING_FILE, false, false);
|
||||
disk_check_consistency(JAMMY_IMAGE_NAME_QCOW2_BACKING_FILE);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -3556,6 +3591,7 @@ mod common_parallel {
|
||||
.expect("Expect generating dynamic VHDx image from RAW image");
|
||||
|
||||
_test_virtio_block(FOCAL_IMAGE_NAME_VHDX, false, false);
|
||||
disk_check_consistency(FOCAL_IMAGE_NAME_VHDX);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -3635,6 +3671,8 @@ mod common_parallel {
|
||||
let output = cloud_child.wait_with_output().unwrap();
|
||||
|
||||
handle_child_output(r, &output);
|
||||
|
||||
disk_check_consistency(vhdx_path);
|
||||
}
|
||||
|
||||
fn vhdx_image_size(disk_name: &str) -> u64 {
|
||||
|
||||
Reference in New Issue
Block a user