diff --git a/src/agent/Cargo.lock b/src/agent/Cargo.lock index f09ae2ca44..af8c590404 100644 --- a/src/agent/Cargo.lock +++ b/src/agent/Cargo.lock @@ -696,6 +696,7 @@ dependencies = [ "tracing-subscriber", "ttrpc", "vsock-exporter", + "which", ] [[package]] @@ -2184,13 +2185,13 @@ checksum = "6a89911bd99e5f3659ec4acf9c4d93b0a90fe4a2a11f15328472058edc5261be" [[package]] name = "which" -version = "4.2.5" +version = "4.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c4fb54e6113b6a8772ee41c3404fb0301ac79604489467e0a9ce1f3e97c24ae" +checksum = "1c831fbbee9e129a8cf93e7747a82da9d95ba8e16621cae60ec2cdc849bacb7b" dependencies = [ "either", - "lazy_static", "libc", + "once_cell", ] [[package]] diff --git a/src/agent/Cargo.toml b/src/agent/Cargo.toml index b0e2ec8cce..54a2f1f33d 100644 --- a/src/agent/Cargo.toml +++ b/src/agent/Cargo.toml @@ -69,6 +69,7 @@ clap = { version = "3.0.1", features = ["derive"] } [dev-dependencies] tempfile = "3.1.0" test-utils = { path = "../libs/test-utils" } +which = "4.3.0" [workspace] members = [ diff --git a/src/agent/src/rpc.rs b/src/agent/src/rpc.rs index bf6420e9b7..58d571a363 100644 --- a/src/agent/src/rpc.rs +++ b/src/agent/src/rpc.rs @@ -2032,6 +2032,11 @@ mod tests { use tempfile::{tempdir, TempDir}; use test_utils::{assert_result, skip_if_not_root}; use ttrpc::{r#async::TtrpcContext, MessageHeader}; + use which::which; + + fn check_command(cmd: &str) -> bool { + which(cmd).is_ok() + } fn mk_ttrpc_context() -> TtrpcContext { TtrpcContext { @@ -2751,6 +2756,18 @@ OtherField:other async fn test_ip_tables() { skip_if_not_root!(); + if !check_command(IPTABLES_SAVE) + || !check_command(IPTABLES_RESTORE) + || !check_command(IP6TABLES_SAVE) + || !check_command(IP6TABLES_RESTORE) + { + warn!( + sl!(), + "one or more commands for ip tables test are missing, skip it" + ); + return; + } + let logger = slog::Logger::root(slog::Discard, o!()); let sandbox = Sandbox::new(&logger).unwrap(); let agent_service = Box::new(AgentService {