tests: add integration tests for vm.add-fs route

Adds integration tests with and without dax for the new vm.add-fs route.

Signed-off-by: Dean Sheather <dean@coder.com>
This commit is contained in:
Dean Sheather 2020-04-15 18:16:17 +10:00 committed by Sebastien Boeuf
parent 18f7789a81
commit f68b08bfdb

View File

@ -1912,6 +1912,122 @@ mod tests {
});
}
fn test_virtio_fs_hotplug(
dax: bool,
cache_size: Option<u64>,
virtiofsd_cache: &str,
prepare_daemon: &dyn Fn(&TempDir, &str, &str) -> (std::process::Child, String),
) {
test_block!(tb, "", {
let mut clear = ClearDiskConfig::new();
let guest = Guest::new(&mut clear);
let api_socket = temp_api_path(&guest.tmp_dir);
let mut workload_path = dirs::home_dir().unwrap();
workload_path.push("workloads");
let mut shared_dir = workload_path.clone();
shared_dir.push("shared_dir");
let mut kernel_path = workload_path;
kernel_path.push("vmlinux");
let (dax_vmm_param, dax_mount_param) = if dax { ("on", "-o dax") } else { ("off", "") };
let cache_size_vmm_param = if let Some(cache) = cache_size {
format!(",cache_size={}", cache)
} else {
"".to_string()
};
let (mut daemon_child, virtiofsd_socket_path) = prepare_daemon(
&guest.tmp_dir,
shared_dir.to_str().unwrap(),
virtiofsd_cache,
);
// Spawn without fs, since we'll add it later via API
let mut child = GuestCommand::new(&guest)
.args(&["--cpus", "boot=1"])
.args(&["--memory", "size=512M,file=/dev/shm"])
.args(&["--kernel", kernel_path.to_str().unwrap()])
.default_disks()
.default_net()
.args(&["--cmdline", CLEAR_KERNEL_CMDLINE])
.args(&["--api-socket", &api_socket])
.spawn()
.unwrap();
thread::sleep(std::time::Duration::new(20, 0));
// Add fs to the VM
aver!(
tb,
remote_command(
&api_socket,
"add-fs",
Some(&format!(
"tag=myfs,sock={},num_queues=1,queue_size=1024,dax={}{}",
virtiofsd_socket_path, dax_vmm_param, cache_size_vmm_param
)),
)
);
thread::sleep(std::time::Duration::new(10, 0));
// Mount shared directory through virtio_fs filesystem
let mount_cmd = format!(
"mkdir -p mount_dir && \
sudo mount -t virtiofs {} myfs mount_dir/ 2>&1 && \
echo ok",
dax_mount_param
);
aver_eq!(
tb,
guest.ssh_command(&mount_cmd).unwrap_or_default().trim(),
"ok"
);
// Check the cache size is the expected one.
// With virtio-mmio the cache doesn't appear in /proc/iomem
#[cfg(not(feature = "mmio"))]
aver_eq!(
tb,
guest
.valid_virtio_fs_cache_size(dax, cache_size)
.unwrap_or_default(),
true
);
// Check file1 exists and its content is "foo"
aver_eq!(
tb,
guest
.ssh_command("cat mount_dir/file1")
.unwrap_or_default()
.trim(),
"foo"
);
// Ensure the VM successfully reboots. The virtio-fs will not be
// automatically recreated since virtiofsd exits on disconnect.
guest.ssh_command("sudo reboot").unwrap_or_default();
thread::sleep(std::time::Duration::new(20, 0));
let reboot_count = guest
.ssh_command("sudo journalctl | grep -c -- \"-- Reboot --\"")
.unwrap_or_default()
.trim()
.parse::<u32>()
.unwrap_or_default();
aver_eq!(tb, reboot_count, 1);
let _ = child.kill();
let _ = daemon_child.kill();
let _ = child.wait();
let _ = daemon_child.wait();
Ok(())
});
}
#[test]
fn test_virtio_fs_dax_on_default_cache_size() {
test_virtio_fs(true, None, "none", &prepare_virtiofsd)
@ -1947,6 +2063,26 @@ mod tests {
test_virtio_fs(false, None, "none", &prepare_vhost_user_fs_daemon)
}
#[cfg_attr(not(feature = "mmio"), test)]
fn test_virtio_fs_hotplug_dax_on() {
test_virtio_fs_hotplug(true, None, "none", &prepare_virtiofsd)
}
#[cfg_attr(not(feature = "mmio"), test)]
fn test_virtio_fs_hotplug_dax_off() {
test_virtio_fs_hotplug(false, None, "none", &prepare_virtiofsd)
}
#[cfg_attr(not(feature = "mmio"), test)]
fn test_virtio_fs_hotplug_dax_on_w_vhost_user_fs_daemon() {
test_virtio_fs_hotplug(true, None, "none", &prepare_vhost_user_fs_daemon)
}
#[cfg_attr(not(feature = "mmio"), test)]
fn test_virtio_fs_hotplug_dax_off_w_vhost_user_fs_daemon() {
test_virtio_fs_hotplug(false, None, "none", &prepare_vhost_user_fs_daemon)
}
#[cfg_attr(not(feature = "mmio"), test)]
fn test_virtio_pmem_persist_writes() {
test_virtio_pmem(false)