mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
test_infra: Move remote_command to test_infra
Move remote_command() and remote_command_w_output() from tests/common/utils.rs into test_infra/src/lib.rs to allow reuse across crates. The cloud-hypervisor integration tests already use 'use test_infra::*', so the functions are available without any caller changes. Signed-off-by: Muminul Islam <muislam@microsoft.com>
This commit is contained in:
committed by
Rob Bradford
parent
1400e614cb
commit
c8bfac66f4
@@ -255,41 +255,6 @@ pub(crate) fn prepare_swtpm_daemon(tmp_dir: &TempDir) -> (std::process::Command,
|
||||
(swtpm_command, swtpm_socket_path)
|
||||
}
|
||||
|
||||
pub(crate) fn remote_command(api_socket: &str, command: &str, arg: Option<&str>) -> bool {
|
||||
let mut cmd = Command::new(clh_command("ch-remote"));
|
||||
cmd.args([&format!("--api-socket={api_socket}"), command]);
|
||||
|
||||
if let Some(arg) = arg {
|
||||
cmd.arg(arg);
|
||||
}
|
||||
let output = cmd.output().unwrap();
|
||||
if output.status.success() {
|
||||
true
|
||||
} else {
|
||||
eprintln!("Error running ch-remote command: {:?}", &cmd);
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
eprintln!("stderr: {stderr}");
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn remote_command_w_output(
|
||||
api_socket: &str,
|
||||
command: &str,
|
||||
arg: Option<&str>,
|
||||
) -> (bool, Vec<u8>) {
|
||||
let mut cmd = Command::new(clh_command("ch-remote"));
|
||||
cmd.args([&format!("--api-socket={api_socket}"), command]);
|
||||
|
||||
if let Some(arg) = arg {
|
||||
cmd.arg(arg);
|
||||
}
|
||||
|
||||
let output = cmd.output().expect("Failed to launch ch-remote");
|
||||
|
||||
(output.status.success(), output.stdout)
|
||||
}
|
||||
|
||||
pub(crate) fn resize_command(
|
||||
api_socket: &str,
|
||||
desired_vcpus: Option<u8>,
|
||||
|
||||
@@ -1776,6 +1776,42 @@ pub fn clh_command(cmd: &str) -> String {
|
||||
String::from(full_path.to_str().unwrap())
|
||||
}
|
||||
|
||||
pub fn remote_command(api_socket: &str, command: &str, arg: Option<&str>) -> bool {
|
||||
let mut cmd = Command::new(clh_command("ch-remote"));
|
||||
cmd.args([&format!("--api-socket={api_socket}"), command]);
|
||||
|
||||
if let Some(arg) = arg {
|
||||
cmd.arg(arg);
|
||||
}
|
||||
|
||||
let output = cmd.output().unwrap();
|
||||
if output.status.success() {
|
||||
true
|
||||
} else {
|
||||
eprintln!("Error running ch-remote command: {:?}", &cmd);
|
||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
||||
eprintln!("stderr: {stderr}");
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
pub fn remote_command_w_output(
|
||||
api_socket: &str,
|
||||
command: &str,
|
||||
arg: Option<&str>,
|
||||
) -> (bool, Vec<u8>) {
|
||||
let mut cmd = Command::new(clh_command("ch-remote"));
|
||||
cmd.args([&format!("--api-socket={api_socket}"), command]);
|
||||
|
||||
if let Some(arg) = arg {
|
||||
cmd.arg(arg);
|
||||
}
|
||||
|
||||
let output = cmd.output().expect("Failed to launch ch-remote");
|
||||
|
||||
(output.status.success(), output.stdout)
|
||||
}
|
||||
|
||||
pub fn parse_iperf3_output(output: &[u8], sender: bool, bandwidth: bool) -> Result<f64, Error> {
|
||||
std::panic::catch_unwind(|| {
|
||||
let s = String::from_utf8_lossy(output);
|
||||
|
||||
Reference in New Issue
Block a user