From 2bd90d9263b0ee512006ef75c110b23b3ea81ac5 Mon Sep 17 00:00:00 2001 From: Sergio Lopez Date: Tue, 21 Jan 2020 12:27:16 +0100 Subject: [PATCH] ci: Add integration test for virtio-blk with 'readonly=on' Previous commit added 'readonly' support for virtio-blk to be able to configure read-only devices, so add an integration test for this new feature. Signed-off-by: Sergio Lopez --- src/main.rs | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index b83395b69..bdde6a1a7 100755 --- a/src/main.rs +++ b/src/main.rs @@ -119,7 +119,7 @@ fn create_app<'a, 'b>( .long("disk") .help( "Disk parameters \"path=,\ - iommu=on|off\"", + readonly=on|off,iommu=on|off\"", ) .takes_value(true) .min_values(1) @@ -2509,6 +2509,72 @@ mod tests { }); } + #[cfg_attr(not(feature = "mmio"), test)] + fn test_virtio_blk_readonly() { + test_block!(tb, "", { + let mut clear = ClearDiskConfig::new(); + let guest = Guest::new(&mut clear); + let mut blk_file_path = dirs::home_dir().unwrap(); + blk_file_path.push("workloads"); + blk_file_path.push("blk.img"); + + let mut cloud_child = Command::new("target/release/cloud-hypervisor") + .args(&["--cpus", "boot=1"]) + .args(&["--memory", "size=512M,file=/dev/shm"]) + .args(&["--kernel", guest.fw_path.as_str()]) + .args(&[ + "--disk", + format!( + "path={}", + guest.disk_config.disk(DiskType::OperatingSystem).unwrap() + ) + .as_str(), + format!( + "path={}", + guest.disk_config.disk(DiskType::CloudInit).unwrap() + ) + .as_str(), + format!("path={},readonly=on", blk_file_path.to_str().unwrap()).as_str(), + ]) + .args(&["--net", guest.default_net_string().as_str()]) + .spawn() + .unwrap(); + + thread::sleep(std::time::Duration::new(20, 0)); + + // Check both if /dev/vdc exists and if the block size is 16M. + aver_eq!( + tb, + guest + .ssh_command("lsblk | grep vdc | grep -c 16M") + .unwrap_or_default() + .trim() + .parse::() + .unwrap_or_default(), + 1 + ); + + // Check both if /dev/vdc exists and if this block is RO. + aver_eq!( + tb, + guest + .ssh_command("lsblk | grep vdc | awk '{print $5}'") + .unwrap_or_default() + .trim() + .parse::() + .unwrap_or_default(), + 1 + ); + + guest.ssh_command("sudo shutdown -h now")?; + thread::sleep(std::time::Duration::new(5, 0)); + let _ = cloud_child.kill(); + let _ = cloud_child.wait(); + + Ok(()) + }); + } + #[cfg_attr(not(feature = "mmio"), test)] fn test_vhost_user_net() { test_block!(tb, "", {