mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-01-22 12:35:19 +00:00
tests: Add integration test for hotplugging vCPUs
Resize the VM to increase the number of vCPUs. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
66a31c19e8
commit
e0830640b7
69
src/main.rs
69
src/main.rs
@ -934,6 +934,10 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
fn api_resize_body(&self, desired_vcpus: u8) -> String {
|
||||
format!("{{\"desired_vcpus\":{}}}", desired_vcpus)
|
||||
}
|
||||
|
||||
fn get_cpu_count(&self) -> Result<u32, Error> {
|
||||
Ok(self
|
||||
.ssh_command("grep -c processor /proc/cpuinfo")?
|
||||
@ -3209,4 +3213,69 @@ mod tests {
|
||||
fn test_memory_mergeable_off() {
|
||||
test_memory_mergeable(false)
|
||||
}
|
||||
|
||||
#[cfg_attr(not(feature = "mmio"), test)]
|
||||
fn test_cpu_hotplug() {
|
||||
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.clone();
|
||||
kernel_path.push("vmlinux");
|
||||
|
||||
let mut child = Command::new("target/release/cloud-hypervisor")
|
||||
.args(&["--cpus", "boot=2,max=4"])
|
||||
.args(&["--memory", "size=512M"])
|
||||
.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);
|
||||
|
||||
// Resize the VM
|
||||
let desired_vcpus = 4;
|
||||
let http_body = guest.api_resize_body(desired_vcpus);
|
||||
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)
|
||||
);
|
||||
|
||||
guest.ssh_command("sudo shutdown -h now")?;
|
||||
thread::sleep(std::time::Duration::new(10, 0));
|
||||
let _ = child.kill();
|
||||
let _ = child.wait();
|
||||
Ok(())
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user