Merge pull request #5439 from jodh-intel/kata-ctl-s390x-disable-tls

kata-ctl: Disable network check on s390x
This commit is contained in:
James O. D. Hunt 2022-10-18 09:58:09 +01:00 committed by GitHub
commit dd60a0298d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 76 additions and 22 deletions

View File

@ -12,9 +12,12 @@ 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"
# See: https://github.com/kata-containers/kata-containers/issues/5438
[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"

View File

@ -7,36 +7,32 @@ use anyhow::Result;
#[cfg(target_arch = "aarch64")]
pub mod aarch64;
#[cfg(target_arch = "aarch64")]
pub use aarch64 as arch_specific;
#[cfg(target_arch = "powerpc64le")]
pub mod powerpc64le;
#[cfg(target_arch = "powerpc64le")]
pub use powerpc64le as arch_specific;
#[cfg(target_arch = "s390x")]
pub mod s390x;
#[cfg(target_arch = "s390x")]
pub use s390x as arch_specific;
#[cfg(target_arch = "x86_64")]
pub mod x86_64;
#[cfg(target_arch = "x86_64")]
pub use x86_64 as arch_specific;
#[cfg(not(any(
target_arch = "aarch64",
target_arch = "powerpc64le",
target_arch = "s390x",
target_arch = "x86_64"
)))]
compile_error!("unknown architecture");
pub fn check() -> 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();
#[cfg(not(any(
target_arch = "aarch64",
target_arch = "powerpc64le",
target_arch = "s390x",
target_arch = "x86_64"
)))]
compile_error!("unknown architecture");
result
arch_specific::check()
}

View File

@ -6,8 +6,19 @@
// Contains checks that are not architecture-specific
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 serde_json::Value;
#[cfg(any(
target_arch = "aarch64",
target_arch = "powerpc64le",
target_arch = "x86_64"
))]
use std::collections::HashMap;
use std::fs;
@ -99,6 +110,11 @@ pub fn run_network_checks() -> Result<()> {
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> {
let content = reqwest::blocking::Client::new()
.get(url)
@ -111,6 +127,11 @@ fn get_kata_version_by_url(url: &str) -> std::result::Result<String, reqwest::Er
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 {
if e.is_connect() {
return anyhow!(e).context("http connection failure: connection refused");
@ -131,6 +152,11 @@ fn handle_reqwest_error(e: reqwest::Error) -> anyhow::Error {
anyhow!(e).context("unknown http connection failure: {:?}")
}
#[cfg(any(
target_arch = "aarch64",
target_arch = "powerpc64le",
target_arch = "x86_64"
))]
pub fn check_version() -> Result<()> {
let version = get_kata_version_by_url(KATA_GITHUB_URL).map_err(handle_reqwest_error)?;
@ -164,6 +190,11 @@ mod tests {
assert_eq!(expected, actual);
}
#[cfg(any(
target_arch = "aarch64",
target_arch = "powerpc64le",
target_arch = "x86_64"
))]
#[test]
fn check_version_by_empty_url() {
const TEST_URL: &str = "http:";
@ -172,6 +203,11 @@ mod tests {
assert_eq!(expected, actual);
}
#[cfg(any(
target_arch = "aarch64",
target_arch = "powerpc64le",
target_arch = "x86_64"
))]
#[test]
fn check_version_by_garbage_url() {
const TEST_URL: &str = "_localhost_";
@ -180,6 +216,11 @@ mod tests {
assert_eq!(expected, actual);
}
#[cfg(any(
target_arch = "aarch64",
target_arch = "powerpc64le",
target_arch = "x86_64"
))]
#[test]
fn check_version_by_invalid_url() {
const TEST_URL: &str = "http://localhost :80";
@ -188,6 +229,11 @@ mod tests {
assert_eq!(expected, actual);
}
#[cfg(any(
target_arch = "aarch64",
target_arch = "powerpc64le",
target_arch = "x86_64"
))]
#[test]
fn check_latest_version() {
let version = get_kata_version_by_url(KATA_GITHUB_URL).unwrap();

View File

@ -32,7 +32,16 @@ pub fn handle_check(checkcmd: CheckArgument) -> Result<()> {
CheckSubCommand::CheckVersionOnly => {
// retrieve latest release
#[cfg(any(
target_arch = "aarch64",
target_arch = "powerpc64le",
target_arch = "x86_64"
))]
check::check_version()?;
// See: https://github.com/kata-containers/kata-containers/issues/5438
#[cfg(target_arch = "s390x")]
unimplemented!("Network check not implemented on s390x")
}
}