mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-17 08:53:26 +00:00
Merge pull request #5447 from hbrueckner/fix-5438
kata-ctl: Re-enable network tests on s390x (fixes 5438)
This commit is contained in:
commit
7248cf51c5
@ -3,6 +3,9 @@
|
|||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
#
|
#
|
||||||
|
|
||||||
|
[workspace]
|
||||||
|
resolver = "2"
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "kata-ctl"
|
name = "kata-ctl"
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
@ -15,7 +18,9 @@ clap = { version = "3.2.20", features = ["derive", "cargo"] }
|
|||||||
serde_json = "1.0.85"
|
serde_json = "1.0.85"
|
||||||
thiserror = "1.0.35"
|
thiserror = "1.0.35"
|
||||||
|
|
||||||
# See: https://github.com/kata-containers/kata-containers/issues/5438
|
[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]
|
[target.'cfg(not(target_arch = "s390x"))'.dependencies]
|
||||||
reqwest = { version = "0.11", default-features = false, features = ["json", "blocking", "rustls-tls"] }
|
reqwest = { version = "0.11", default-features = false, features = ["json", "blocking", "rustls-tls"] }
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
// Copyright (c) 2022 Intel Corporation
|
// Copyright (c) 2022 Intel Corporation
|
||||||
|
// Copyright (c) 2022 IBM Corp.
|
||||||
//
|
//
|
||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
//
|
//
|
||||||
@ -7,9 +8,44 @@
|
|||||||
pub use arch_specific::*;
|
pub use arch_specific::*;
|
||||||
|
|
||||||
mod arch_specific {
|
mod arch_specific {
|
||||||
use anyhow::Result;
|
use crate::check;
|
||||||
|
use anyhow::{anyhow, Result};
|
||||||
|
|
||||||
|
const PROC_CPUINFO: &str = "/proc/cpuinfo";
|
||||||
|
const CPUINFO_DELIMITER: &str = "processor ";
|
||||||
|
const CPUINFO_FEATURES_TAG: &str = "features";
|
||||||
|
const CPU_FEATURES_REQ: &[&str] = &["sie"];
|
||||||
|
|
||||||
|
// check cpu
|
||||||
|
fn check_cpu() -> Result<()> {
|
||||||
|
println!("INFO: check CPU: s390x");
|
||||||
|
|
||||||
|
let cpu_info = check::get_single_cpu_info(PROC_CPUINFO, CPUINFO_DELIMITER)?;
|
||||||
|
|
||||||
|
let cpu_features = check::get_cpu_flags(&cpu_info, CPUINFO_FEATURES_TAG).map_err(|e| {
|
||||||
|
anyhow!(
|
||||||
|
"Error parsing CPU features, file {:?}, {:?}",
|
||||||
|
PROC_CPUINFO,
|
||||||
|
e
|
||||||
|
)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let missing_cpu_features = check::check_cpu_flags(&cpu_features, CPU_FEATURES_REQ)?;
|
||||||
|
if !missing_cpu_features.is_empty() {
|
||||||
|
eprintln!("WARNING: Missing CPU flags {:?}", missing_cpu_features);
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn check() -> Result<()> {
|
pub fn check() -> Result<()> {
|
||||||
unimplemented!("Check not implemented in s390x");
|
println!("INFO: check: s390x");
|
||||||
|
|
||||||
|
let _cpu_result = check_cpu();
|
||||||
|
|
||||||
|
// TODO: add additional checks, e.g, kernel modules as in go runtime
|
||||||
|
// TODO: collect outcome of tests to determine if checks pass or not
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,32 +6,22 @@
|
|||||||
// Contains checks that are not architecture-specific
|
// Contains checks that are not architecture-specific
|
||||||
|
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
// See: https://github.com/kata-containers/kata-containers/issues/5438
|
|
||||||
#[cfg(any(
|
|
||||||
target_arch = "aarch64",
|
|
||||||
target_arch = "powerpc64le",
|
|
||||||
target_arch = "x86_64"
|
|
||||||
))]
|
|
||||||
use reqwest::header::{CONTENT_TYPE, USER_AGENT};
|
use reqwest::header::{CONTENT_TYPE, USER_AGENT};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
#[cfg(any(
|
|
||||||
target_arch = "aarch64",
|
|
||||||
target_arch = "powerpc64le",
|
|
||||||
target_arch = "x86_64"
|
|
||||||
))]
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fs;
|
|
||||||
|
|
||||||
const KATA_GITHUB_URL: &str =
|
const KATA_GITHUB_URL: &str =
|
||||||
"https://api.github.com/repos/kata-containers/kata-containers/releases/latest";
|
"https://api.github.com/repos/kata-containers/kata-containers/releases/latest";
|
||||||
|
|
||||||
|
#[cfg(any(target_arch = "s390x", target_arch = "x86_64"))]
|
||||||
fn get_cpu_info(cpu_info_file: &str) -> Result<String> {
|
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)
|
Ok(contents)
|
||||||
}
|
}
|
||||||
|
|
||||||
// get_single_cpu_info returns the contents of the first cpu from
|
// get_single_cpu_info returns the contents of the first cpu from
|
||||||
// the specified cpuinfo file by parsing based on a specified delimiter
|
// the specified cpuinfo file by parsing based on a specified delimiter
|
||||||
|
#[cfg(any(target_arch = "s390x", target_arch = "x86_64"))]
|
||||||
pub fn get_single_cpu_info(cpu_info_file: &str, substring: &str) -> Result<String> {
|
pub fn get_single_cpu_info(cpu_info_file: &str, substring: &str) -> Result<String> {
|
||||||
let contents = get_cpu_info(cpu_info_file)?;
|
let contents = get_cpu_info(cpu_info_file)?;
|
||||||
|
|
||||||
@ -51,6 +41,7 @@ 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
|
// get_cpu_flags returns a string of cpu flags from cpuinfo, passed in
|
||||||
// as a string
|
// as a string
|
||||||
|
#[cfg(any(target_arch = "s390x", target_arch = "x86_64"))]
|
||||||
pub fn get_cpu_flags(cpu_info: &str, cpu_flags_tag: &str) -> Result<String> {
|
pub fn get_cpu_flags(cpu_info: &str, cpu_flags_tag: &str) -> Result<String> {
|
||||||
if cpu_info.is_empty() {
|
if cpu_info.is_empty() {
|
||||||
return Err(anyhow!("cpu_info string is empty"))?;
|
return Err(anyhow!("cpu_info string is empty"))?;
|
||||||
@ -74,6 +65,7 @@ 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
|
// get_missing_strings searches for required (strings) in data and returns
|
||||||
// a vector containing the missing strings
|
// a vector containing the missing strings
|
||||||
|
#[cfg(any(target_arch = "s390x", target_arch = "x86_64"))]
|
||||||
fn get_missing_strings(data: &str, required: &'static [&'static str]) -> Result<Vec<String>> {
|
fn get_missing_strings(data: &str, required: &'static [&'static str]) -> Result<Vec<String>> {
|
||||||
let mut missing: Vec<String> = Vec::new();
|
let mut missing: Vec<String> = Vec::new();
|
||||||
|
|
||||||
@ -86,6 +78,7 @@ fn get_missing_strings(data: &str, required: &'static [&'static str]) -> Result<
|
|||||||
Ok(missing)
|
Ok(missing)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(any(target_arch = "s390x", target_arch = "x86_64"))]
|
||||||
pub fn check_cpu_flags(
|
pub fn check_cpu_flags(
|
||||||
retrieved_flags: &str,
|
retrieved_flags: &str,
|
||||||
required_flags: &'static [&'static str],
|
required_flags: &'static [&'static str],
|
||||||
@ -95,6 +88,7 @@ pub fn check_cpu_flags(
|
|||||||
Ok(missing_flags)
|
Ok(missing_flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(any(target_arch = "x86_64"))]
|
||||||
pub fn check_cpu_attribs(
|
pub fn check_cpu_attribs(
|
||||||
cpu_info: &str,
|
cpu_info: &str,
|
||||||
required_attribs: &'static [&'static str],
|
required_attribs: &'static [&'static str],
|
||||||
@ -110,11 +104,6 @@ pub fn run_network_checks() -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(
|
|
||||||
target_arch = "aarch64",
|
|
||||||
target_arch = "powerpc64le",
|
|
||||||
target_arch = "x86_64"
|
|
||||||
))]
|
|
||||||
fn get_kata_version_by_url(url: &str) -> std::result::Result<String, reqwest::Error> {
|
fn get_kata_version_by_url(url: &str) -> std::result::Result<String, reqwest::Error> {
|
||||||
let content = reqwest::blocking::Client::new()
|
let content = reqwest::blocking::Client::new()
|
||||||
.get(url)
|
.get(url)
|
||||||
@ -127,11 +116,6 @@ fn get_kata_version_by_url(url: &str) -> std::result::Result<String, reqwest::Er
|
|||||||
Ok(version.to_string())
|
Ok(version.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(
|
|
||||||
target_arch = "aarch64",
|
|
||||||
target_arch = "powerpc64le",
|
|
||||||
target_arch = "x86_64"
|
|
||||||
))]
|
|
||||||
fn handle_reqwest_error(e: reqwest::Error) -> anyhow::Error {
|
fn handle_reqwest_error(e: reqwest::Error) -> anyhow::Error {
|
||||||
if e.is_connect() {
|
if e.is_connect() {
|
||||||
return anyhow!(e).context("http connection failure: connection refused");
|
return anyhow!(e).context("http connection failure: connection refused");
|
||||||
@ -152,11 +136,6 @@ fn handle_reqwest_error(e: reqwest::Error) -> anyhow::Error {
|
|||||||
anyhow!(e).context("unknown http connection failure: {:?}")
|
anyhow!(e).context("unknown http connection failure: {:?}")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(
|
|
||||||
target_arch = "aarch64",
|
|
||||||
target_arch = "powerpc64le",
|
|
||||||
target_arch = "x86_64"
|
|
||||||
))]
|
|
||||||
pub fn check_version() -> Result<()> {
|
pub fn check_version() -> Result<()> {
|
||||||
let version = get_kata_version_by_url(KATA_GITHUB_URL).map_err(handle_reqwest_error)?;
|
let version = get_kata_version_by_url(KATA_GITHUB_URL).map_err(handle_reqwest_error)?;
|
||||||
|
|
||||||
@ -165,6 +144,7 @@ pub fn check_version() -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(any(target_arch = "s390x", target_arch = "x86_64"))]
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
@ -190,11 +170,6 @@ mod tests {
|
|||||||
assert_eq!(expected, actual);
|
assert_eq!(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(
|
|
||||||
target_arch = "aarch64",
|
|
||||||
target_arch = "powerpc64le",
|
|
||||||
target_arch = "x86_64"
|
|
||||||
))]
|
|
||||||
#[test]
|
#[test]
|
||||||
fn check_version_by_empty_url() {
|
fn check_version_by_empty_url() {
|
||||||
const TEST_URL: &str = "http:";
|
const TEST_URL: &str = "http:";
|
||||||
@ -203,11 +178,6 @@ mod tests {
|
|||||||
assert_eq!(expected, actual);
|
assert_eq!(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(
|
|
||||||
target_arch = "aarch64",
|
|
||||||
target_arch = "powerpc64le",
|
|
||||||
target_arch = "x86_64"
|
|
||||||
))]
|
|
||||||
#[test]
|
#[test]
|
||||||
fn check_version_by_garbage_url() {
|
fn check_version_by_garbage_url() {
|
||||||
const TEST_URL: &str = "_localhost_";
|
const TEST_URL: &str = "_localhost_";
|
||||||
@ -216,11 +186,6 @@ mod tests {
|
|||||||
assert_eq!(expected, actual);
|
assert_eq!(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(
|
|
||||||
target_arch = "aarch64",
|
|
||||||
target_arch = "powerpc64le",
|
|
||||||
target_arch = "x86_64"
|
|
||||||
))]
|
|
||||||
#[test]
|
#[test]
|
||||||
fn check_version_by_invalid_url() {
|
fn check_version_by_invalid_url() {
|
||||||
const TEST_URL: &str = "http://localhost :80";
|
const TEST_URL: &str = "http://localhost :80";
|
||||||
@ -229,11 +194,6 @@ mod tests {
|
|||||||
assert_eq!(expected, actual);
|
assert_eq!(expected, actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(
|
|
||||||
target_arch = "aarch64",
|
|
||||||
target_arch = "powerpc64le",
|
|
||||||
target_arch = "x86_64"
|
|
||||||
))]
|
|
||||||
#[test]
|
#[test]
|
||||||
fn check_latest_version() {
|
fn check_latest_version() {
|
||||||
let version = get_kata_version_by_url(KATA_GITHUB_URL).unwrap();
|
let version = get_kata_version_by_url(KATA_GITHUB_URL).unwrap();
|
||||||
|
@ -32,16 +32,7 @@ pub fn handle_check(checkcmd: CheckArgument) -> Result<()> {
|
|||||||
|
|
||||||
CheckSubCommand::CheckVersionOnly => {
|
CheckSubCommand::CheckVersionOnly => {
|
||||||
// retrieve latest release
|
// retrieve latest release
|
||||||
#[cfg(any(
|
|
||||||
target_arch = "aarch64",
|
|
||||||
target_arch = "powerpc64le",
|
|
||||||
target_arch = "x86_64"
|
|
||||||
))]
|
|
||||||
check::check_version()?;
|
check::check_version()?;
|
||||||
|
|
||||||
// See: https://github.com/kata-containers/kata-containers/issues/5438
|
|
||||||
#[cfg(target_arch = "s390x")]
|
|
||||||
unimplemented!("Network check not implemented on s390x")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user