tests: Add test combining memory and vCPU hotplug

Test resizing with both optional parameters set in the VmResize API
works.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2020-01-13 16:28:43 +00:00 committed by Samuel Ortiz
parent 2073007214
commit d2d1248342

View File

@ -4573,4 +4573,78 @@ mod tests {
Ok(())
});
}
// Test both vCPU and memory resizing together
#[cfg_attr(not(feature = "mmio"), test)]
fn test_resize() {
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 kernel_path = workload_path;
kernel_path.push("vmlinux");
let mut child = Command::new("target/release/cloud-hypervisor")
.args(&["--cpus", "boot=2,max=4"])
.args(&["--memory", "size=512M,hotplug_size=8192M"])
.args(&["--kernel", kernel_path.to_str().unwrap()])
.args(&["--cmdline", "root=PARTUUID=8d93774b-e12c-4ac5-aa35-77bfa7168767 console=tty0 console=ttyS0,115200n8 console=hvc0 quiet init=/usr/lib/systemd/systemd-bootchart initcall_debug tsc=reliable no_timer_check noreplace-smp cryptomgr.notests rootfstype=ext4,btrfs,xfs kvm-intel.nested=1 rw"])
.args(&[
"--disk",
format!(
"path={}",
guest.disk_config.disk(DiskType::OperatingSystem).unwrap()
)
.as_str(),
format!(
"path={}",
guest.disk_config.disk(DiskType::CloudInit).unwrap()
)
.as_str(),
])
.args(&["--net", guest.default_net_string().as_str()])
.args(&["--api-socket", &api_socket])
.spawn()
.unwrap();
thread::sleep(std::time::Duration::new(20, 0));
aver_eq!(tb, guest.get_cpu_count().unwrap_or_default(), 2);
aver!(tb, guest.get_total_memory().unwrap_or_default() > 491_000);
guest
.ssh_command("echo online | sudo tee /sys/devices/system/memory/auto_online_blocks")
.unwrap_or_default();
// Resize the VM
let desired_vcpus = 4;
let desired_ram = 1024 << 20;
let http_body = guest.api_resize_body(Some(desired_vcpus), Some(desired_ram));
curl_command(
&api_socket,
"PUT",
"http://localhost/api/v1/vm.resize",
Some(&http_body),
);
guest.ssh_command("echo 1 | sudo tee /sys/bus/cpu/devices/cpu2/online")?;
guest.ssh_command("echo 1 | sudo tee /sys/bus/cpu/devices/cpu3/online")?;
thread::sleep(std::time::Duration::new(10, 0));
aver_eq!(
tb,
guest.get_cpu_count().unwrap_or_default(),
u32::from(desired_vcpus)
);
aver!(tb, guest.get_total_memory().unwrap_or_default() > 982_000);
guest.ssh_command("sudo shutdown -h now")?;
thread::sleep(std::time::Duration::new(10, 0));
let _ = child.kill();
let _ = child.wait();
Ok(())
});
}
}