diff --git a/src/tools/kata-ctl/src/arch/aarch64/mod.rs b/src/tools/kata-ctl/src/arch/aarch64/mod.rs new file mode 100644 index 0000000000..6df39ce748 --- /dev/null +++ b/src/tools/kata-ctl/src/arch/aarch64/mod.rs @@ -0,0 +1,15 @@ +// Copyright (c) 2022 Intel Corporation +// +// SPDX-License-Identifier: Apache-2.0 +// + +#[cfg(target_arch = "aarch64")] +pub use arch_specific::*; + +mod arch_specific { + use anyhow::Result; + + pub fn check() -> Result<()> { + unimplemented!("Check not implemented in aarch64") + } +} diff --git a/src/tools/kata-ctl/src/arch/mod.rs b/src/tools/kata-ctl/src/arch/mod.rs new file mode 100644 index 0000000000..ee6f926f75 --- /dev/null +++ b/src/tools/kata-ctl/src/arch/mod.rs @@ -0,0 +1,42 @@ +// Copyright (c) 2022 Intel Corporation +// +// SPDX-License-Identifier: Apache-2.0 +// + +use anyhow::{Result}; + +#[cfg(target_arch = "aarch64")] +pub mod aarch64; + +#[cfg(target_arch = "powerpc64le")] +pub mod powerpc64le; + +#[cfg(target_arch = "s390x")] +pub mod s390x; + +#[cfg(target_arch = "x86_64")] +pub mod x86_64; + +pub fn check(global_args: clap::ArgMatches) -> Result<()> { + #[cfg(target_arch = "aarch64")] + let result = aarch64::check(); + + #[cfg(target_arch = "powerpc64le")] + let result = powerpc64le::check(); + + #[cfg(target_arch = "s390x")] + let result = s390x::check(); + + #[cfg(target_arch = "x86_64")] + let result = x86_64::check(global_args); + + #[cfg(not(any( + target_arch = "aarch64", + target_arch = "powerpc64le", + target_arch = "s390x", + target_arch = "x86_64" + )))] + panic!("unknown architecture"); + + result +} diff --git a/src/tools/kata-ctl/src/arch/powerpc64le/mod.rs b/src/tools/kata-ctl/src/arch/powerpc64le/mod.rs new file mode 100644 index 0000000000..a87ab02f8c --- /dev/null +++ b/src/tools/kata-ctl/src/arch/powerpc64le/mod.rs @@ -0,0 +1,15 @@ +// Copyright (c) 2022 Intel Corporation +// +// SPDX-License-Identifier: Apache-2.0 +// + +#[cfg(target_arch = "powerpc64le")] +pub use arch_specific::*; + +mod arch_specific { + use anyhow::Result; + + pub fn check() -> Result<()> { + unimplemented!("Check not implemented in powerpc64le"); + } +} diff --git a/src/tools/kata-ctl/src/arch/s390x/mod.rs b/src/tools/kata-ctl/src/arch/s390x/mod.rs new file mode 100644 index 0000000000..7f6a424c3b --- /dev/null +++ b/src/tools/kata-ctl/src/arch/s390x/mod.rs @@ -0,0 +1,15 @@ +// Copyright (c) 2022 Intel Corporation +// +// SPDX-License-Identifier: Apache-2.0 +// + +#[cfg(target_arch = "s390x")] +pub use arch_specific::*; + +mod arch_specific { + use anyhow::Result; + + pub fn check() -> Result<()> { + unimplemented!("Check not implemented in s390x"); + } +} diff --git a/src/tools/kata-ctl/src/arch/x86_64/mod.rs b/src/tools/kata-ctl/src/arch/x86_64/mod.rs new file mode 100644 index 0000000000..2f27dc2a44 --- /dev/null +++ b/src/tools/kata-ctl/src/arch/x86_64/mod.rs @@ -0,0 +1,17 @@ +// Copyright (c) 2022 Intel Corporation +// +// SPDX-License-Identifier: Apache-2.0 +// + +#[cfg(target_arch = "x86_64")] +pub use arch_specific::*; + +mod arch_specific { + use anyhow::Result; + + pub fn check(_global_args: clap::ArgMatches) -> Result<()> { + println!("INFO: check: x86_64"); + + Ok(()) + } +} diff --git a/src/tools/kata-ctl/src/check.rs b/src/tools/kata-ctl/src/check.rs new file mode 100644 index 0000000000..be39e31e06 --- /dev/null +++ b/src/tools/kata-ctl/src/check.rs @@ -0,0 +1,12 @@ +// Copyright (c) 2022 Intel Corporation +// +// SPDX-License-Identifier: Apache-2.0 +// + +// Contains checks that are not architecture-specific + +use anyhow::{Result}; + +pub fn run_network_checks() -> Result<()> { + unimplemented!("Tests using network checks not implemented"); +} diff --git a/src/tools/kata-ctl/src/main.rs b/src/tools/kata-ctl/src/main.rs index 7368c667e5..9338b4bd61 100644 --- a/src/tools/kata-ctl/src/main.rs +++ b/src/tools/kata-ctl/src/main.rs @@ -9,6 +9,8 @@ use std::process::exit; mod utils; mod version; +mod arch; +mod check; const DESCRIPTION_TEXT: &str = r#"DESCRIPTION: kata-ctl description placeholder."#; @@ -17,6 +19,25 @@ const ABOUT_TEXT: &str = "Kata Containers control tool"; const NAME: &str = "kata-ctl"; +fn run_checks(global_args: clap::ArgMatches) -> Result<()> { + let args = global_args + .subcommand_matches("check") + .ok_or_else(|| anyhow!("BUG: missing sub-command arguments"))?; + + let no_network_check = args.is_present("no-network-checks"); + + // run architecture-agnostic tests + if !no_network_check { + // run code that uses network checks + let _network_checks = check::run_network_checks(); + } + + // run architecture-specific tests + let _all_checks = arch::check(global_args); + + Ok(()) +} + fn real_main() -> Result<()> { let name = crate_name!(); let version = version::get(); @@ -28,15 +49,11 @@ fn real_main() -> Result<()> { .subcommand( SubCommand::with_name("check") .about("tests if system can run Kata Containers") - ) - .subcommand( - SubCommand::with_name("command-example") - .about("(remove when other subcommands have sufficient detail)") .arg( - Arg::with_name("arg-example-1") - .long("arg-example-1") - .help("arg example for command-example") - .takes_value(true) + Arg::with_name("no-network-checks") + .long("no-network-checks") + .help("run check with no network checks") + .takes_value(false) ) ) .subcommand( @@ -80,40 +97,39 @@ fn real_main() -> Result<()> { .ok_or_else(|| anyhow!("need sub-command"))?; match subcmd { - "command-example" => { - println!("{}", utils::command_example(args)); - Ok(()) - } "check" => { - println!("Not implemented"); + match run_checks(args) { + Ok(_result) => println!("check may not be fully implemented"), + Err(err) => println!("{}", err), + } Ok(()) } "direct-volume" => { - println!("Not implemented"); + unimplemented!("Not implemented"); Ok(()) } "env" => { - println!("Not implemented"); + unimplemented!("Not implemented"); Ok(()) } "exec" => { - println!("Not implemented"); + unimplemented!("Not implemented"); Ok(()) } "factory" => { - println!("Not implemented"); + unimplemented!("Not implemented"); Ok(()) } "help" => { - println!("Not implemented"); + unimplemented!("Not implemented"); Ok(()) } "iptables" => { - println!("Not implemented"); + unimplemented!("Not implemented"); Ok(()) } "metrics" => { - println!("Not implemented"); + unimplemented!("Not implemented"); Ok(()) } "version" => { diff --git a/src/tools/kata-ctl/src/utils.rs b/src/tools/kata-ctl/src/utils.rs index b779c2147b..59289ad4a9 100644 --- a/src/tools/kata-ctl/src/utils.rs +++ b/src/tools/kata-ctl/src/utils.rs @@ -2,7 +2,3 @@ // // SPDX-License-Identifier: Apache-2.0 // - -pub fn command_example(_global_args: clap::ArgMatches) -> String { - "test utils command".to_string() -}