mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-01-03 03:15:20 +00:00
tests: Make a wrapper function for snapshot/restore
Signed-off-by: Muminul Islam <muislam@microsoft.com>
This commit is contained in:
parent
b37e2ed378
commit
58d8795b53
@ -5689,7 +5689,11 @@ mod common_parallel {
|
|||||||
// through each ssh command. There's no need to perform a dedicated test to
|
// through each ssh command. There's no need to perform a dedicated test to
|
||||||
// verify the migration went well for virtio-net.
|
// verify the migration went well for virtio-net.
|
||||||
#[test]
|
#[test]
|
||||||
fn test_snapshot_restore() {
|
fn test_snapshot_restore_hotplug_virtiomem() {
|
||||||
|
_test_snapshot_restore(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn _test_snapshot_restore(use_hotplug: bool) {
|
||||||
let focal = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_string());
|
let focal = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_string());
|
||||||
let guest = Guest::new(Box::new(focal));
|
let guest = Guest::new(Box::new(focal));
|
||||||
let kernel_path = direct_kernel_boot_path();
|
let kernel_path = direct_kernel_boot_path();
|
||||||
@ -5701,6 +5705,11 @@ mod common_parallel {
|
|||||||
"id={},tap=,mac={},ip={},mask=255.255.255.0",
|
"id={},tap=,mac={},ip={},mask=255.255.255.0",
|
||||||
net_id, guest.network.guest_mac, guest.network.host_ip
|
net_id, guest.network.guest_mac, guest.network.host_ip
|
||||||
);
|
);
|
||||||
|
let mut mem_params = "size=4G";
|
||||||
|
|
||||||
|
if use_hotplug {
|
||||||
|
mem_params = "size=4G,hotplug_method=virtio-mem,hotplug_size=32G"
|
||||||
|
}
|
||||||
|
|
||||||
let cloudinit_params = format!(
|
let cloudinit_params = format!(
|
||||||
"path={},iommu=on",
|
"path={},iommu=on",
|
||||||
@ -5714,10 +5723,7 @@ mod common_parallel {
|
|||||||
.args(["--api-socket", &api_socket_source])
|
.args(["--api-socket", &api_socket_source])
|
||||||
.args(["--event-monitor", format!("path={}", event_path).as_str()])
|
.args(["--event-monitor", format!("path={}", event_path).as_str()])
|
||||||
.args(["--cpus", "boot=4"])
|
.args(["--cpus", "boot=4"])
|
||||||
.args([
|
.args(["--memory", mem_params])
|
||||||
"--memory",
|
|
||||||
"size=4G,hotplug_method=virtio-mem,hotplug_size=32G",
|
|
||||||
])
|
|
||||||
.args(["--balloon", "size=0"])
|
.args(["--balloon", "size=0"])
|
||||||
.args(["--kernel", kernel_path.to_str().unwrap()])
|
.args(["--kernel", kernel_path.to_str().unwrap()])
|
||||||
.args([
|
.args([
|
||||||
@ -5747,28 +5753,30 @@ mod common_parallel {
|
|||||||
assert_eq!(guest.get_cpu_count().unwrap_or_default(), 4);
|
assert_eq!(guest.get_cpu_count().unwrap_or_default(), 4);
|
||||||
// Check the guest RAM
|
// Check the guest RAM
|
||||||
assert!(guest.get_total_memory().unwrap_or_default() > 3_840_000);
|
assert!(guest.get_total_memory().unwrap_or_default() > 3_840_000);
|
||||||
// Increase guest RAM with virtio-mem
|
if use_hotplug {
|
||||||
resize_command(
|
// Increase guest RAM with virtio-mem
|
||||||
&api_socket_source,
|
resize_command(
|
||||||
None,
|
&api_socket_source,
|
||||||
Some(6 << 30),
|
None,
|
||||||
None,
|
Some(6 << 30),
|
||||||
Some(&event_path),
|
None,
|
||||||
);
|
Some(&event_path),
|
||||||
thread::sleep(std::time::Duration::new(5, 0));
|
);
|
||||||
assert!(guest.get_total_memory().unwrap_or_default() > 5_760_000);
|
thread::sleep(std::time::Duration::new(5, 0));
|
||||||
// Use balloon to remove RAM from the VM
|
assert!(guest.get_total_memory().unwrap_or_default() > 5_760_000);
|
||||||
resize_command(
|
// Use balloon to remove RAM from the VM
|
||||||
&api_socket_source,
|
resize_command(
|
||||||
None,
|
&api_socket_source,
|
||||||
None,
|
None,
|
||||||
Some(1 << 30),
|
None,
|
||||||
Some(&event_path),
|
Some(1 << 30),
|
||||||
);
|
Some(&event_path),
|
||||||
thread::sleep(std::time::Duration::new(5, 0));
|
);
|
||||||
let total_memory = guest.get_total_memory().unwrap_or_default();
|
thread::sleep(std::time::Duration::new(5, 0));
|
||||||
assert!(total_memory > 4_800_000);
|
let total_memory = guest.get_total_memory().unwrap_or_default();
|
||||||
assert!(total_memory < 5_760_000);
|
assert!(total_memory > 4_800_000);
|
||||||
|
assert!(total_memory < 5_760_000);
|
||||||
|
}
|
||||||
// Check the guest virtio-devices, e.g. block, rng, vsock, console, and net
|
// Check the guest virtio-devices, e.g. block, rng, vsock, console, and net
|
||||||
guest.check_devices_common(Some(&socket), Some(&console_text), None);
|
guest.check_devices_common(Some(&socket), Some(&console_text), None);
|
||||||
|
|
||||||
@ -5921,18 +5929,22 @@ mod common_parallel {
|
|||||||
// Perform same checks to validate VM has been properly restored
|
// Perform same checks to validate VM has been properly restored
|
||||||
assert_eq!(guest.get_cpu_count().unwrap_or_default(), 4);
|
assert_eq!(guest.get_cpu_count().unwrap_or_default(), 4);
|
||||||
let total_memory = guest.get_total_memory().unwrap_or_default();
|
let total_memory = guest.get_total_memory().unwrap_or_default();
|
||||||
assert!(total_memory > 4_800_000);
|
if !use_hotplug {
|
||||||
assert!(total_memory < 5_760_000);
|
assert!(guest.get_total_memory().unwrap_or_default() > 3_840_000);
|
||||||
// Deflate balloon to restore entire RAM to the VM
|
} else {
|
||||||
resize_command(&api_socket_restored, None, None, Some(0), None);
|
assert!(total_memory > 4_800_000);
|
||||||
thread::sleep(std::time::Duration::new(5, 0));
|
assert!(total_memory < 5_760_000);
|
||||||
assert!(guest.get_total_memory().unwrap_or_default() > 5_760_000);
|
// Deflate balloon to restore entire RAM to the VM
|
||||||
// Decrease guest RAM with virtio-mem
|
resize_command(&api_socket_restored, None, None, Some(0), None);
|
||||||
resize_command(&api_socket_restored, None, Some(5 << 30), None, None);
|
thread::sleep(std::time::Duration::new(5, 0));
|
||||||
thread::sleep(std::time::Duration::new(5, 0));
|
assert!(guest.get_total_memory().unwrap_or_default() > 5_760_000);
|
||||||
let total_memory = guest.get_total_memory().unwrap_or_default();
|
// Decrease guest RAM with virtio-mem
|
||||||
assert!(total_memory > 4_800_000);
|
resize_command(&api_socket_restored, None, Some(5 << 30), None, None);
|
||||||
assert!(total_memory < 5_760_000);
|
thread::sleep(std::time::Duration::new(5, 0));
|
||||||
|
let total_memory = guest.get_total_memory().unwrap_or_default();
|
||||||
|
assert!(total_memory > 4_800_000);
|
||||||
|
assert!(total_memory < 5_760_000);
|
||||||
|
}
|
||||||
|
|
||||||
guest.check_devices_common(Some(&socket), Some(&console_text), None);
|
guest.check_devices_common(Some(&socket), Some(&console_text), None);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user