kata-ctl: add code for framework for arch

Add framework for different architectures for check. In the existing
kata-runtime check, the network checks do not appear to be
architecture-specific while the kernel module, cpu, and kvm checks do
have separate implementations for different architectures.

Signed-off-by: Chelsea Mafrica <chelsea.e.mafrica@intel.com>
This commit is contained in:
Chelsea Mafrica 2022-08-17 02:56:28 -07:00 committed by James O. D. Hunt
parent 303fc8b118
commit 8e7bb8521c
8 changed files with 152 additions and 24 deletions

View File

@ -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")
}
}

View File

@ -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
}

View File

@ -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");
}
}

View File

@ -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");
}
}

View File

@ -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(())
}
}

View File

@ -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");
}

View File

@ -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" => {

View File

@ -2,7 +2,3 @@
//
// SPDX-License-Identifier: Apache-2.0
//
pub fn command_example(_global_args: clap::ArgMatches) -> String {
"test utils command".to_string()
}