mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-08-20 06:51:15 +00:00
tests: Introduce ssh_command_ok()
Adding a new function ssh_command_ok() as a wrapper around the existing ssh_command() function. The goal being to identify if the command returned without any error. This new function allow for a bit of factorization through the codebase. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
1c60591eab
commit
239e2adc68
@ -404,6 +404,13 @@ mod tests {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn ssh_command_ok(&self, command: &str) -> Result<bool, SshCommandError> {
|
||||||
|
Ok(self
|
||||||
|
.ssh_command(&format!("{} && echo ok", command))?
|
||||||
|
.trim()
|
||||||
|
.ends_with("ok"))
|
||||||
|
}
|
||||||
|
|
||||||
fn ssh_command(&self, command: &str) -> Result<String, SshCommandError> {
|
fn ssh_command(&self, command: &str) -> Result<String, SshCommandError> {
|
||||||
ssh_command_ip(
|
ssh_command_ip(
|
||||||
command,
|
command,
|
||||||
@ -524,10 +531,10 @@ mod tests {
|
|||||||
fn check_numa_node_cpus(&self, node_id: usize, cpus: Vec<usize>) -> Result<bool, Error> {
|
fn check_numa_node_cpus(&self, node_id: usize, cpus: Vec<usize>) -> Result<bool, Error> {
|
||||||
for cpu in cpus.iter() {
|
for cpu in cpus.iter() {
|
||||||
let cmd = format!(
|
let cmd = format!(
|
||||||
"[ -d \"/sys/devices/system/node/node{}/cpu{}\" ] && echo ok",
|
"[ -d \"/sys/devices/system/node/node{}/cpu{}\" ]",
|
||||||
node_id, cpu
|
node_id, cpu
|
||||||
);
|
);
|
||||||
if self.ssh_command(cmd.as_str())?.trim() != "ok" {
|
if !self.ssh_command_ok(cmd.as_str())? {
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -549,34 +556,22 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn check_sgx_support(&self) -> Result<bool, Error> {
|
fn check_sgx_support(&self) -> Result<bool, Error> {
|
||||||
if self
|
if !self.ssh_command_ok(
|
||||||
.ssh_command(
|
|
||||||
"cpuid -l 0x7 -s 0 | tr -s [:space:] | grep -q 'SGX: \
|
"cpuid -l 0x7 -s 0 | tr -s [:space:] | grep -q 'SGX: \
|
||||||
Software Guard Extensions supported = true' && echo ok",
|
Software Guard Extensions supported = true'",
|
||||||
)?
|
)? {
|
||||||
.trim()
|
|
||||||
!= "ok"
|
|
||||||
{
|
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
if self
|
if !self.ssh_command_ok(
|
||||||
.ssh_command(
|
|
||||||
"cpuid -l 0x7 -s 0 | tr -s [:space:] | grep -q 'SGX_LC: \
|
"cpuid -l 0x7 -s 0 | tr -s [:space:] | grep -q 'SGX_LC: \
|
||||||
SGX launch config supported = true' && echo ok",
|
SGX launch config supported = true'",
|
||||||
)?
|
)? {
|
||||||
.trim()
|
|
||||||
!= "ok"
|
|
||||||
{
|
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
if self
|
if !self.ssh_command_ok(
|
||||||
.ssh_command(
|
|
||||||
"cpuid -l 0x12 -s 0 | tr -s [:space:] | grep -q 'SGX1 \
|
"cpuid -l 0x12 -s 0 | tr -s [:space:] | grep -q 'SGX1 \
|
||||||
supported = true' && echo ok",
|
supported = true'",
|
||||||
)?
|
)? {
|
||||||
.trim()
|
|
||||||
!= "ok"
|
|
||||||
{
|
|
||||||
return Ok(false);
|
return Ok(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -724,12 +719,7 @@ mod tests {
|
|||||||
assert!(device_query_result.contains("Result = PASS"));
|
assert!(device_query_result.contains("Result = PASS"));
|
||||||
|
|
||||||
// Run NVIDIA DCGM Diagnostics to validate the device is functional
|
// Run NVIDIA DCGM Diagnostics to validate the device is functional
|
||||||
assert_eq!(
|
assert!(self.ssh_command_ok("sudo nv-hostengine").unwrap());
|
||||||
self.ssh_command("sudo nv-hostengine && echo ok")
|
|
||||||
.unwrap()
|
|
||||||
.trim(),
|
|
||||||
"ok"
|
|
||||||
);
|
|
||||||
|
|
||||||
assert!(self
|
assert!(self
|
||||||
.ssh_command("sudo dcgmi discovery -l")
|
.ssh_command("sudo dcgmi discovery -l")
|
||||||
@ -1404,11 +1394,10 @@ mod tests {
|
|||||||
// Mount shared directory through virtio_fs filesystem
|
// Mount shared directory through virtio_fs filesystem
|
||||||
let mount_cmd = format!(
|
let mount_cmd = format!(
|
||||||
"mkdir -p mount_dir && \
|
"mkdir -p mount_dir && \
|
||||||
sudo mount -t virtiofs {} myfs mount_dir/ && \
|
sudo mount -t virtiofs {} myfs mount_dir/",
|
||||||
echo ok",
|
|
||||||
dax_mount_param
|
dax_mount_param
|
||||||
);
|
);
|
||||||
assert_eq!(guest.ssh_command(&mount_cmd).unwrap().trim(), "ok");
|
assert!(guest.ssh_command_ok(&mount_cmd).unwrap());
|
||||||
|
|
||||||
assert!(guest
|
assert!(guest
|
||||||
.valid_virtio_fs_cache_size(dax, cache_size)
|
.valid_virtio_fs_cache_size(dax, cache_size)
|
||||||
@ -1452,13 +1441,7 @@ mod tests {
|
|||||||
|
|
||||||
if hotplug {
|
if hotplug {
|
||||||
// Remove from VM
|
// Remove from VM
|
||||||
assert_eq!(
|
assert!(guest.ssh_command_ok("sudo umount mount_dir").unwrap());
|
||||||
guest
|
|
||||||
.ssh_command("sudo umount mount_dir && echo ok")
|
|
||||||
.unwrap()
|
|
||||||
.trim(),
|
|
||||||
"ok"
|
|
||||||
);
|
|
||||||
assert!(remote_command(&api_socket, "remove-device", Some("myfs0")));
|
assert!(remote_command(&api_socket, "remove-device", Some("myfs0")));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -1488,11 +1471,10 @@ mod tests {
|
|||||||
// Mount shared directory through virtio_fs filesystem
|
// Mount shared directory through virtio_fs filesystem
|
||||||
let mount_cmd = format!(
|
let mount_cmd = format!(
|
||||||
"mkdir -p mount_dir && \
|
"mkdir -p mount_dir && \
|
||||||
sudo mount -t virtiofs {} myfs mount_dir/ && \
|
sudo mount -t virtiofs {} myfs mount_dir/",
|
||||||
echo ok",
|
|
||||||
dax_mount_param
|
dax_mount_param
|
||||||
);
|
);
|
||||||
assert_eq!(guest.ssh_command(&mount_cmd).unwrap().trim(), "ok");
|
assert!(guest.ssh_command_ok(&mount_cmd).unwrap());
|
||||||
// Check file1 exists and its content is "foo"
|
// Check file1 exists and its content is "foo"
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
guest.ssh_command("cat mount_dir/file1").unwrap().trim(),
|
guest.ssh_command("cat mount_dir/file1").unwrap().trim(),
|
||||||
|
Loading…
Reference in New Issue
Block a user