Skip to content

Commit

Permalink
kata-ctl: Limit running tests to x86 and use native-tls on s390x
Browse files Browse the repository at this point in the history
For s390x, use native-tls for reqwest because the rustls-tls/ring
dependency is not available for s390x.

Also exclude s390x, powerpc64le, and aarch64 from running the cpu
check due to the lack of the arch-specific implementation. In this
case, rust complains about unused functions in src/check.rs (both
normal and test context).

Fixes: kata-containers#5438

Co-authored-by: James O. D. Hunt <[email protected]>
Signed-off-by: Hendrik Brueckner <[email protected]>
  • Loading branch information
hbrueckner and jodh-intel committed Oct 20, 2022
1 parent 9f2c7e4 commit 8aa4a5d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/tools/kata-ctl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
# SPDX-License-Identifier: Apache-2.0
#

[workspace]
resolver = "2"

[package]
name = "kata-ctl"
version = "0.0.1"
Expand All @@ -12,9 +15,14 @@ edition = "2018"
[dependencies]
anyhow = "1.0.31"
clap = { version = "3.2.20", features = ["derive", "cargo"] }
reqwest = { version = "0.11", default-features = false, features = ["json", "blocking", "rustls-tls"] }
serde_json = "1.0.85"
thiserror = "1.0.35"

[target.'cfg(target_arch = "s390x")'.dependencies]
reqwest = { version = "0.11", default-features = false, features = ["json", "blocking", "native-tls"] }

[target.'cfg(not(target_arch = "s390x"))'.dependencies]
reqwest = { version = "0.11", default-features = false, features = ["json", "blocking", "rustls-tls"] }

[dev-dependencies]
semver = "1.0.12"
24 changes: 22 additions & 2 deletions src/tools/kata-ctl/src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,23 @@ use anyhow::{anyhow, Result};
use reqwest::header::{CONTENT_TYPE, USER_AGENT};
use serde_json::Value;
use std::collections::HashMap;
use std::fs;

const KATA_GITHUB_URL: &str =
"https://api.github.com/repos/kata-containers/kata-containers/releases/latest";

#[cfg(any(
target_arch = "x86_64"
))]
fn get_cpu_info(cpu_info_file: &str) -> Result<String> {
let contents = fs::read_to_string(cpu_info_file)?;
let contents = std::fs::read_to_string(cpu_info_file)?;
Ok(contents)
}

// get_single_cpu_info returns the contents of the first cpu from
// the specified cpuinfo file by parsing based on a specified delimiter
#[cfg(any(
target_arch = "x86_64"
))]
pub fn get_single_cpu_info(cpu_info_file: &str, substring: &str) -> Result<String> {
let contents = get_cpu_info(cpu_info_file)?;

Expand All @@ -40,6 +45,9 @@ pub fn get_single_cpu_info(cpu_info_file: &str, substring: &str) -> Result<Strin

// get_cpu_flags returns a string of cpu flags from cpuinfo, passed in
// as a string
#[cfg(any(
target_arch = "x86_64"
))]
pub fn get_cpu_flags(cpu_info: &str, cpu_flags_tag: &str) -> Result<String> {
if cpu_info.is_empty() {
return Err(anyhow!("cpu_info string is empty"))?;
Expand All @@ -63,6 +71,9 @@ pub fn get_cpu_flags(cpu_info: &str, cpu_flags_tag: &str) -> Result<String> {

// get_missing_strings searches for required (strings) in data and returns
// a vector containing the missing strings
#[cfg(any(
target_arch = "x86_64"
))]
fn get_missing_strings(data: &str, required: &'static [&'static str]) -> Result<Vec<String>> {
let mut missing: Vec<String> = Vec::new();

Expand All @@ -75,6 +86,9 @@ fn get_missing_strings(data: &str, required: &'static [&'static str]) -> Result<
Ok(missing)
}

#[cfg(any(
target_arch = "x86_64"
))]
pub fn check_cpu_flags(
retrieved_flags: &str,
required_flags: &'static [&'static str],
Expand All @@ -84,6 +98,9 @@ pub fn check_cpu_flags(
Ok(missing_flags)
}

#[cfg(any(
target_arch = "x86_64"
))]
pub fn check_cpu_attribs(
cpu_info: &str,
required_attribs: &'static [&'static str],
Expand Down Expand Up @@ -139,6 +156,9 @@ pub fn check_version() -> Result<()> {
Ok(())
}

#[cfg(any(
target_arch = "x86_64"
))]
#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit 8aa4a5d

Please sign in to comment.