mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-10-03 20:15:45 +00:00
tests: Pull common code into a separate method
Yet another small refactoring step for WindowsGuest
after f56471566b
.
For this particular case - there's currently neither overloading nor
default argument support in Rust (except a macro or other tricky stuff),
so keep the timeout and other options default for now.
Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
parent
7ae631e0c1
commit
56b9149325
@ -5309,82 +5309,51 @@ mod tests {
|
|||||||
&self.guest
|
&self.guest
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn ssh_cmd(&self, cmd: &str) -> String {
|
||||||
|
ssh_command_ip_with_auth(
|
||||||
|
cmd,
|
||||||
|
&self.auth,
|
||||||
|
&self.guest.network.guest_ip,
|
||||||
|
DEFAULT_SSH_RETRIES,
|
||||||
|
DEFAULT_SSH_TIMEOUT,
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
fn cpu_count(&self) -> u8 {
|
fn cpu_count(&self) -> u8 {
|
||||||
return ssh_command_ip_with_auth(
|
self.ssh_cmd("powershell -Command \"(Get-CimInstance win32_computersystem).NumberOfLogicalProcessors\"")
|
||||||
"powershell -Command \"(Get-CimInstance win32_computersystem).NumberOfLogicalProcessors\"",
|
.trim()
|
||||||
&self.auth,
|
.parse::<u8>()
|
||||||
&self.guest.network.guest_ip,
|
.unwrap_or(0)
|
||||||
DEFAULT_SSH_RETRIES,
|
|
||||||
DEFAULT_SSH_TIMEOUT,
|
|
||||||
)
|
|
||||||
.unwrap()
|
|
||||||
.trim()
|
|
||||||
.parse::<u8>()
|
|
||||||
.unwrap_or(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn ram_size(&self) -> usize {
|
fn ram_size(&self) -> usize {
|
||||||
return ssh_command_ip_with_auth(
|
self.ssh_cmd("powershell -Command \"(Get-CimInstance win32_computersystem).TotalPhysicalMemory\"")
|
||||||
"powershell -Command \"(Get-CimInstance win32_computersystem).TotalPhysicalMemory\"",
|
.trim()
|
||||||
&self.auth,
|
.parse::<usize>()
|
||||||
&self.guest.network.guest_ip,
|
.unwrap_or(0)
|
||||||
DEFAULT_SSH_RETRIES,
|
|
||||||
DEFAULT_SSH_TIMEOUT,
|
|
||||||
)
|
|
||||||
.unwrap()
|
|
||||||
.trim()
|
|
||||||
.parse::<usize>()
|
|
||||||
.unwrap_or(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn netdev_count(&self) -> u8 {
|
fn netdev_count(&self) -> u8 {
|
||||||
return ssh_command_ip_with_auth(
|
self.ssh_cmd("powershell -Command \"netsh int ipv4 show interfaces | Select-String ethernet | Measure-Object -Line | Format-Table -HideTableHeaders\"")
|
||||||
"powershell -Command \"netsh int ipv4 show interfaces | Select-String ethernet | Measure-Object -Line | Format-Table -HideTableHeaders\"",
|
.trim()
|
||||||
&self.auth,
|
.parse::<u8>()
|
||||||
&self.guest.network.guest_ip,
|
.unwrap_or(0)
|
||||||
DEFAULT_SSH_RETRIES,
|
|
||||||
DEFAULT_SSH_TIMEOUT,
|
|
||||||
)
|
|
||||||
.unwrap()
|
|
||||||
.trim()
|
|
||||||
.parse::<u8>()
|
|
||||||
.unwrap_or(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn disk_count(&self) -> u8 {
|
fn disk_count(&self) -> u8 {
|
||||||
return ssh_command_ip_with_auth(
|
self.ssh_cmd("powershell -Command \"Get-Disk | Measure-Object -Line | Format-Table -HideTableHeaders\"")
|
||||||
"powershell -Command \"Get-Disk | Measure-Object -Line | Format-Table -HideTableHeaders\"",
|
.trim()
|
||||||
&self.auth,
|
.parse::<u8>()
|
||||||
&self.guest.network.guest_ip,
|
.unwrap_or(0)
|
||||||
DEFAULT_SSH_RETRIES,
|
|
||||||
DEFAULT_SSH_TIMEOUT,
|
|
||||||
)
|
|
||||||
.unwrap()
|
|
||||||
.trim()
|
|
||||||
.parse::<u8>()
|
|
||||||
.unwrap_or(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn reboot(&self) {
|
fn reboot(&self) {
|
||||||
ssh_command_ip_with_auth(
|
let _ = self.ssh_cmd("shutdown /r /t 0");
|
||||||
"shutdown /r /t 0",
|
|
||||||
&self.auth,
|
|
||||||
&self.guest.network.guest_ip,
|
|
||||||
DEFAULT_SSH_RETRIES,
|
|
||||||
DEFAULT_SSH_TIMEOUT,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn shutdown(&self) {
|
fn shutdown(&self) {
|
||||||
ssh_command_ip_with_auth(
|
let _ = self.ssh_cmd("shutdown /s /t 0");
|
||||||
"shutdown /s",
|
|
||||||
&self.auth,
|
|
||||||
&self.guest.network.guest_ip,
|
|
||||||
DEFAULT_SSH_RETRIES,
|
|
||||||
DEFAULT_SSH_TIMEOUT,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_dnsmasq(&self) -> std::process::Child {
|
fn run_dnsmasq(&self) -> std::process::Child {
|
||||||
@ -5500,50 +5469,25 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn disks_set_rw(&self) {
|
fn disks_set_rw(&self) {
|
||||||
ssh_command_ip_with_auth(
|
let _ = self.ssh_cmd("powershell -Command \"Get-Disk | Where-Object IsOffline -eq $True | Set-Disk -IsReadOnly $False\"");
|
||||||
"powershell -Command \"Get-Disk | Where-Object IsOffline -eq $True | Set-Disk -IsReadOnly $False\"",
|
|
||||||
&self.auth,
|
|
||||||
&self.guest.network.guest_ip,
|
|
||||||
DEFAULT_SSH_RETRIES,
|
|
||||||
DEFAULT_SSH_TIMEOUT,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn disks_online(&self) {
|
fn disks_online(&self) {
|
||||||
ssh_command_ip_with_auth(
|
let _ = self.ssh_cmd("powershell -Command \"Get-Disk | Where-Object IsOffline -eq $True | Set-Disk -IsOffline $False\"");
|
||||||
"powershell -Command \"Get-Disk | Where-Object IsOffline -eq $True | Set-Disk -IsOffline $False\"",
|
|
||||||
&self.auth,
|
|
||||||
&self.guest.network.guest_ip,
|
|
||||||
DEFAULT_SSH_RETRIES,
|
|
||||||
DEFAULT_SSH_TIMEOUT,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn disk_file_put(&self, fname: &str, data: &str) {
|
fn disk_file_put(&self, fname: &str, data: &str) {
|
||||||
ssh_command_ip_with_auth(
|
let _ = self.ssh_cmd(&format!(
|
||||||
&format!(
|
"powershell -Command \"'{}' | Set-Content -Path {}\"",
|
||||||
"powershell -Command \"'{}' | Set-Content -Path {}\"",
|
data, fname
|
||||||
data, fname
|
));
|
||||||
),
|
|
||||||
&self.auth,
|
|
||||||
&self.guest.network.guest_ip,
|
|
||||||
DEFAULT_SSH_RETRIES,
|
|
||||||
DEFAULT_SSH_TIMEOUT,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn disk_file_read(&self, fname: &str) -> String {
|
fn disk_file_read(&self, fname: &str) -> String {
|
||||||
ssh_command_ip_with_auth(
|
self.ssh_cmd(&format!(
|
||||||
&format!("powershell -Command \"Get-Content -Path {}\"", fname),
|
"powershell -Command \"Get-Content -Path {}\"",
|
||||||
&self.auth,
|
fname
|
||||||
&self.guest.network.guest_ip,
|
))
|
||||||
DEFAULT_SSH_RETRIES,
|
|
||||||
DEFAULT_SSH_TIMEOUT,
|
|
||||||
)
|
|
||||||
.unwrap()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user