tests: Remove ssh_command_ok()

There's no need for ssh_command_ok() anymore since ssh_command() now
returns an error in case the executed command returned with an exit code
different than 0.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2021-06-04 00:53:07 +02:00
parent 650cbce017
commit 3d8728488d

View File

@ -376,13 +376,6 @@ 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,
@ -500,18 +493,16 @@ mod tests {
.map_err(Error::WaitForBoot) .map_err(Error::WaitForBoot)
} }
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<(), Error> {
for cpu in cpus.iter() { for cpu in cpus.iter() {
let cmd = format!( let cmd = format!(
"[ -d \"/sys/devices/system/node/node{}/cpu{}\" ]", "[ -d \"/sys/devices/system/node/node{}/cpu{}\" ]",
node_id, cpu node_id, cpu
); );
if !self.ssh_command_ok(cmd.as_str())? { self.ssh_command(cmd.as_str())?;
return Ok(false);
}
} }
Ok(true) Ok(())
} }
fn check_numa_node_distances( fn check_numa_node_distances(
@ -527,27 +518,21 @@ mod tests {
} }
} }
fn check_sgx_support(&self) -> Result<bool, Error> { fn check_sgx_support(&self) -> Result<(), Error> {
if !self.ssh_command_ok( self.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'", Software Guard Extensions supported = true'",
)? { )?;
return Ok(false); self.ssh_command(
}
if !self.ssh_command_ok(
"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'", SGX launch config supported = true'",
)? { )?;
return Ok(false); self.ssh_command(
}
if !self.ssh_command_ok(
"cpuid -l 0x12 -s 0 | tr -s [:space:] | grep -q 'SGX1 \ "cpuid -l 0x12 -s 0 | tr -s [:space:] | grep -q 'SGX1 \
supported = true'", supported = true'",
)? { )?;
return Ok(false);
}
Ok(true) Ok(())
} }
fn get_entropy(&self) -> Result<u32, Error> { fn get_entropy(&self) -> Result<u32, Error> {
@ -691,7 +676,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!(self.ssh_command_ok("sudo nv-hostengine").unwrap()); self.ssh_command("sudo nv-hostengine").unwrap();
assert!(self assert!(self
.ssh_command("sudo dcgmi discovery -l") .ssh_command("sudo dcgmi discovery -l")
@ -1369,7 +1354,7 @@ mod tests {
sudo mount -t virtiofs {} myfs mount_dir/", sudo mount -t virtiofs {} myfs mount_dir/",
dax_mount_param dax_mount_param
); );
assert!(guest.ssh_command_ok(&mount_cmd).unwrap()); guest.ssh_command(&mount_cmd).unwrap();
assert!(guest assert!(guest
.valid_virtio_fs_cache_size(dax, cache_size) .valid_virtio_fs_cache_size(dax, cache_size)
@ -1413,7 +1398,7 @@ mod tests {
if hotplug { if hotplug {
// Remove from VM // Remove from VM
assert!(guest.ssh_command_ok("sudo umount mount_dir").unwrap()); guest.ssh_command("sudo umount mount_dir").unwrap();
assert!(remote_command(&api_socket, "remove-device", Some("myfs0"))); assert!(remote_command(&api_socket, "remove-device", Some("myfs0")));
} }
}); });
@ -1446,7 +1431,7 @@ mod tests {
sudo mount -t virtiofs {} myfs mount_dir/", sudo mount -t virtiofs {} myfs mount_dir/",
dax_mount_param dax_mount_param
); );
assert!(guest.ssh_command_ok(&mount_cmd).unwrap()); guest.ssh_command(&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(),
@ -2298,9 +2283,9 @@ mod tests {
assert!(guest.get_numa_node_memory(2).unwrap_or_default() > 2_880_000); assert!(guest.get_numa_node_memory(2).unwrap_or_default() > 2_880_000);
// Check each NUMA node has been assigned the right CPUs set. // Check each NUMA node has been assigned the right CPUs set.
assert!(guest.check_numa_node_cpus(0, vec![0, 1, 2]).unwrap()); guest.check_numa_node_cpus(0, vec![0, 1, 2]).unwrap();
assert!(guest.check_numa_node_cpus(1, vec![3, 4]).unwrap()); guest.check_numa_node_cpus(1, vec![3, 4]).unwrap();
assert!(guest.check_numa_node_cpus(2, vec![5]).unwrap()); guest.check_numa_node_cpus(2, vec![5]).unwrap();
// Check each NUMA node has been assigned the right distances. // Check each NUMA node has been assigned the right distances.
assert!(guest.check_numa_node_distances(0, "10 15 20").unwrap()); assert!(guest.check_numa_node_distances(0, "10 15 20").unwrap());
@ -4323,9 +4308,9 @@ mod tests {
1 1
); );
// And check the block device can be read. // And check the block device can be read.
assert!(guest guest
.ssh_command("sudo dd if=/dev/vdc of=/dev/null bs=1M iflag=direct count=16") .ssh_command("sudo dd if=/dev/vdc of=/dev/null bs=1M iflag=direct count=16")
.is_ok()); .unwrap();
// Let's remove it the extra disk. // Let's remove it the extra disk.
assert!(remote_command(&api_socket, "remove-device", Some("test0"))); assert!(remote_command(&api_socket, "remove-device", Some("test0")));
@ -4364,9 +4349,9 @@ mod tests {
1 1
); );
// And check the block device can be read. // And check the block device can be read.
assert!(guest guest
.ssh_command("sudo dd if=/dev/vdc of=/dev/null bs=1M iflag=direct count=16") .ssh_command("sudo dd if=/dev/vdc of=/dev/null bs=1M iflag=direct count=16")
.is_ok()); .unwrap();
// Reboot the VM. // Reboot the VM.
guest.reboot_linux(0, None); guest.reboot_linux(0, None);
@ -4736,21 +4721,21 @@ mod tests {
// Check the guest RAM // Check the guest RAM
assert!(guest.get_total_memory().unwrap_or_default() > 3_840_000); assert!(guest.get_total_memory().unwrap_or_default() > 3_840_000);
// Check block devices are readable // Check block devices are readable
assert!(guest guest
.ssh_command("sudo dd if=/dev/vda of=/dev/null bs=1M iflag=direct count=1024") .ssh_command("sudo dd if=/dev/vda of=/dev/null bs=1M iflag=direct count=1024")
.is_ok()); .unwrap();
assert!(guest guest
.ssh_command("sudo dd if=/dev/vdb of=/dev/null bs=1M iflag=direct count=8") .ssh_command("sudo dd if=/dev/vdb of=/dev/null bs=1M iflag=direct count=8")
.is_ok()); .unwrap();
// Check if the rng device is readable // Check if the rng device is readable
assert!(guest guest
.ssh_command("sudo head -c 1000 /dev/hwrng > /dev/null") .ssh_command("sudo head -c 1000 /dev/hwrng > /dev/null")
.is_ok()); .unwrap();
// Check vsock // Check vsock
guest.check_vsock(socket.as_str()); guest.check_vsock(socket.as_str());
// Check if the console is usable // Check if the console is usable
assert!(guest.ssh_command(&console_cmd).is_ok()); guest.ssh_command(&console_cmd).unwrap();
// We check that removing and adding back the virtio-net device // We check that removing and adding back the virtio-net device
// does not break the snapshot/restore support for virtio-pci. // does not break the snapshot/restore support for virtio-pci.
@ -4822,17 +4807,17 @@ mod tests {
// Perform same checks to validate VM has been properly restored // Perform same checks to validate VM has been properly restored
assert_eq!(guest.get_cpu_count().unwrap_or_default(), 4); assert_eq!(guest.get_cpu_count().unwrap_or_default(), 4);
assert!(guest.get_total_memory().unwrap_or_default() > 3_840_000); assert!(guest.get_total_memory().unwrap_or_default() > 3_840_000);
assert!(guest guest
.ssh_command("sudo dd if=/dev/vda of=/dev/null bs=1M iflag=direct count=1024") .ssh_command("sudo dd if=/dev/vda of=/dev/null bs=1M iflag=direct count=1024")
.is_ok()); .unwrap();
assert!(guest guest
.ssh_command("sudo dd if=/dev/vdb of=/dev/null bs=1M iflag=direct count=8") .ssh_command("sudo dd if=/dev/vdb of=/dev/null bs=1M iflag=direct count=8")
.is_ok()); .unwrap();
assert!(guest guest
.ssh_command("sudo head -c 1000 /dev/hwrng > /dev/null") .ssh_command("sudo head -c 1000 /dev/hwrng > /dev/null")
.is_ok()); .unwrap();
guest.check_vsock(socket.as_str()); guest.check_vsock(socket.as_str());
assert!(guest.ssh_command(&console_cmd).is_ok()); guest.ssh_command(&console_cmd).unwrap();
// Shutdown the target VM and check console output // Shutdown the target VM and check console output
}); });
let _ = child.kill(); let _ = child.kill();
@ -4868,9 +4853,9 @@ mod tests {
guest.wait_vm_boot(None).unwrap(); guest.wait_vm_boot(None).unwrap();
let orig_counters = get_counters(&api_socket); let orig_counters = get_counters(&api_socket);
assert!(guest guest
.ssh_command("dd if=/dev/zero of=test count=8 bs=1M") .ssh_command("dd if=/dev/zero of=test count=8 bs=1M")
.is_ok()); .unwrap();
let new_counters = get_counters(&api_socket); let new_counters = get_counters(&api_socket);
@ -5259,15 +5244,15 @@ mod tests {
let r = std::panic::catch_unwind(|| { let r = std::panic::catch_unwind(|| {
guest1.wait_vm_boot(None).unwrap(); guest1.wait_vm_boot(None).unwrap();
assert!(guest1 guest1
.ssh_command_ok(&format!( .ssh_command(&format!(
"sudo ip addr add 172.100.0.1/24 dev {}", "sudo ip addr add 172.100.0.1/24 dev {}",
guest_net_iface guest_net_iface
)) ))
.unwrap()); .unwrap();
assert!(guest1 guest1
.ssh_command_ok(&format!("sudo ip link set up dev {}", guest_net_iface)) .ssh_command(&format!("sudo ip link set up dev {}", guest_net_iface))
.unwrap()); .unwrap();
let guest_ip = guest1.network.guest_ip.clone(); let guest_ip = guest1.network.guest_ip.clone();
thread::spawn(move || { thread::spawn(move || {
@ -5304,18 +5289,18 @@ mod tests {
let r = std::panic::catch_unwind(|| { let r = std::panic::catch_unwind(|| {
guest2.wait_vm_boot(None).unwrap(); guest2.wait_vm_boot(None).unwrap();
assert!(guest2 guest2
.ssh_command_ok(&format!( .ssh_command(&format!(
"sudo ip addr add 172.100.0.2/24 dev {}", "sudo ip addr add 172.100.0.2/24 dev {}",
guest_net_iface guest_net_iface
)) ))
.unwrap()); .unwrap();
assert!(guest2 guest2
.ssh_command_ok(&format!("sudo ip link set up dev {}", guest_net_iface)) .ssh_command(&format!("sudo ip link set up dev {}", guest_net_iface))
.unwrap()); .unwrap();
// Check the connection works properly between the two VMs // Check the connection works properly between the two VMs
assert!(guest2.ssh_command_ok("nc -vz 172.100.0.1 12345").unwrap()); guest2.ssh_command("nc -vz 172.100.0.1 12345").unwrap();
// Remove one of the two ports from the OVS bridge // Remove one of the two ports from the OVS bridge
std::process::Command::new("bash") std::process::Command::new("bash")
@ -5348,7 +5333,7 @@ mod tests {
.expect("Expected 'ovs-vsctl add-port ovsbr0 vhost-user1 -- set Interface vhost-user1 type=dpdkvhostuserclient options:vhost-server-path=/tmp/dpdkvhostclient1' to work"); .expect("Expected 'ovs-vsctl add-port ovsbr0 vhost-user1 -- set Interface vhost-user1 type=dpdkvhostuserclient options:vhost-server-path=/tmp/dpdkvhostclient1' to work");
// And finally check the connection is functional again // And finally check the connection is functional again
assert!(guest2.ssh_command_ok("nc -vz 172.100.0.1 12345").unwrap()); guest2.ssh_command("nc -vz 172.100.0.1 12345").unwrap();
}); });
let _ = child1.kill(); let _ = child1.kill();
@ -6176,7 +6161,7 @@ mod tests {
guest.wait_vm_boot(None).unwrap(); guest.wait_vm_boot(None).unwrap();
// Check if SGX is correctly detected in the guest. // Check if SGX is correctly detected in the guest.
assert!(guest.check_sgx_support().unwrap()); guest.check_sgx_support().unwrap();
// Validate the SGX EPC section is 64MiB. // Validate the SGX EPC section is 64MiB.
assert_eq!( assert_eq!(