From 239e2adc6801268a42a8ca4c5f5a796df14a6a0f Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Fri, 28 May 2021 11:58:14 +0200 Subject: [PATCH] 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 --- tests/integration.rs | 72 +++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 45 deletions(-) diff --git a/tests/integration.rs b/tests/integration.rs index 82cbe515c..4bd1c9e85 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -404,6 +404,13 @@ mod tests { ) } + fn ssh_command_ok(&self, command: &str) -> Result { + Ok(self + .ssh_command(&format!("{} && echo ok", command))? + .trim() + .ends_with("ok")) + } + fn ssh_command(&self, command: &str) -> Result { ssh_command_ip( command, @@ -524,10 +531,10 @@ mod tests { fn check_numa_node_cpus(&self, node_id: usize, cpus: Vec) -> Result { for cpu in cpus.iter() { let cmd = format!( - "[ -d \"/sys/devices/system/node/node{}/cpu{}\" ] && echo ok", + "[ -d \"/sys/devices/system/node/node{}/cpu{}\" ]", node_id, cpu ); - if self.ssh_command(cmd.as_str())?.trim() != "ok" { + if !self.ssh_command_ok(cmd.as_str())? { return Ok(false); } } @@ -549,34 +556,22 @@ mod tests { } fn check_sgx_support(&self) -> Result { - if self - .ssh_command( - "cpuid -l 0x7 -s 0 | tr -s [:space:] | grep -q 'SGX: \ - Software Guard Extensions supported = true' && echo ok", - )? - .trim() - != "ok" - { + if !self.ssh_command_ok( + "cpuid -l 0x7 -s 0 | tr -s [:space:] | grep -q 'SGX: \ + Software Guard Extensions supported = true'", + )? { return Ok(false); } - if self - .ssh_command( - "cpuid -l 0x7 -s 0 | tr -s [:space:] | grep -q 'SGX_LC: \ - SGX launch config supported = true' && echo ok", - )? - .trim() - != "ok" - { + if !self.ssh_command_ok( + "cpuid -l 0x7 -s 0 | tr -s [:space:] | grep -q 'SGX_LC: \ + SGX launch config supported = true'", + )? { return Ok(false); } - if self - .ssh_command( - "cpuid -l 0x12 -s 0 | tr -s [:space:] | grep -q 'SGX1 \ - supported = true' && echo ok", - )? - .trim() - != "ok" - { + if !self.ssh_command_ok( + "cpuid -l 0x12 -s 0 | tr -s [:space:] | grep -q 'SGX1 \ + supported = true'", + )? { return Ok(false); } @@ -724,12 +719,7 @@ mod tests { assert!(device_query_result.contains("Result = PASS")); // Run NVIDIA DCGM Diagnostics to validate the device is functional - assert_eq!( - self.ssh_command("sudo nv-hostengine && echo ok") - .unwrap() - .trim(), - "ok" - ); + assert!(self.ssh_command_ok("sudo nv-hostengine").unwrap()); assert!(self .ssh_command("sudo dcgmi discovery -l") @@ -1404,11 +1394,10 @@ mod tests { // Mount shared directory through virtio_fs filesystem let mount_cmd = format!( "mkdir -p mount_dir && \ - sudo mount -t virtiofs {} myfs mount_dir/ && \ - echo ok", + sudo mount -t virtiofs {} myfs mount_dir/", dax_mount_param ); - assert_eq!(guest.ssh_command(&mount_cmd).unwrap().trim(), "ok"); + assert!(guest.ssh_command_ok(&mount_cmd).unwrap()); assert!(guest .valid_virtio_fs_cache_size(dax, cache_size) @@ -1452,13 +1441,7 @@ mod tests { if hotplug { // Remove from VM - assert_eq!( - guest - .ssh_command("sudo umount mount_dir && echo ok") - .unwrap() - .trim(), - "ok" - ); + assert!(guest.ssh_command_ok("sudo umount mount_dir").unwrap()); assert!(remote_command(&api_socket, "remove-device", Some("myfs0"))); } }); @@ -1488,11 +1471,10 @@ mod tests { // Mount shared directory through virtio_fs filesystem let mount_cmd = format!( "mkdir -p mount_dir && \ - sudo mount -t virtiofs {} myfs mount_dir/ && \ - echo ok", + sudo mount -t virtiofs {} myfs mount_dir/", 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" assert_eq!( guest.ssh_command("cat mount_dir/file1").unwrap().trim(),