kata-ctl: Have function to get cpu details to run on specific arch

This function relies on get_single_cpu function which has configured
to compile on amd64 and s390x.
Making the function get_generic_cpu_details to compile on these
architectures until we resolve the compilation for functions defined
in check.rs. This is a temporary solution until we cleanup check.rs to
make it build on all architectures.

Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
This commit is contained in:
Archana Shinde 2022-12-09 16:16:58 -08:00
parent 594b57d082
commit 64c11a66fd
3 changed files with 12 additions and 2 deletions

View File

@ -16,7 +16,9 @@ mod arch_specific {
const CPUINFO_FEATURES_TAG: &str = "features"; const CPUINFO_FEATURES_TAG: &str = "features";
const CPU_FEATURES_REQ: &[&str] = &["sie"]; const CPU_FEATURES_REQ: &[&str] = &["sie"];
#[allow(dead_code)]
pub const ARCH_CPU_VENDOR_FIELD: &str = check::GENERIC_CPU_VENDOR_FIELD; pub const ARCH_CPU_VENDOR_FIELD: &str = check::GENERIC_CPU_VENDOR_FIELD;
#[allow(dead_code)]
pub const ARCH_CPU_MODEL_FIELD: &str = "machine"; pub const ARCH_CPU_MODEL_FIELD: &str = "machine";
// check cpu // check cpu

View File

@ -26,6 +26,7 @@ const USER_AGT: &str = "kata";
pub const GENERIC_CPU_VENDOR_FIELD: &str = "vendor_id"; pub const GENERIC_CPU_VENDOR_FIELD: &str = "vendor_id";
pub const GENERIC_CPU_MODEL_FIELD: &str = "model name"; pub const GENERIC_CPU_MODEL_FIELD: &str = "model name";
#[allow(dead_code)]
pub const PROC_CPUINFO: &str = "/proc/cpuinfo"; pub const PROC_CPUINFO: &str = "/proc/cpuinfo";
#[cfg(any(target_arch = "s390x", target_arch = "x86_64"))] #[cfg(any(target_arch = "s390x", target_arch = "x86_64"))]

View File

@ -5,8 +5,11 @@
#![allow(dead_code)] #![allow(dead_code)]
#[cfg(any(target_arch = "s390x", target_arch = "x86_64"))]
use crate::arch::arch_specific; use crate::arch::arch_specific;
#[cfg(any(target_arch = "s390x", target_arch = "x86_64"))]
use crate::check::get_single_cpu_info; use crate::check::get_single_cpu_info;
use anyhow::{anyhow, Context, Result}; use anyhow::{anyhow, Context, Result};
use std::fs; use std::fs;
@ -103,6 +106,7 @@ pub fn get_distro_details(os_release: &str, os_release_clr: &str) -> Result<(Str
Ok((name, version)) Ok((name, version))
} }
#[cfg(any(target_arch = "s390x", target_arch = "x86_64"))]
pub fn get_generic_cpu_details(cpu_info_file: &str) -> Result<(String, String)> { pub fn get_generic_cpu_details(cpu_info_file: &str) -> Result<(String, String)> {
let cpu_info = get_single_cpu_info(cpu_info_file, "\n\n")?; let cpu_info = get_single_cpu_info(cpu_info_file, "\n\n")?;
let lines = cpu_info.lines(); let lines = cpu_info.lines();
@ -143,7 +147,6 @@ pub fn get_generic_cpu_details(cpu_info_file: &str) -> Result<(String, String)>
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;
use crate::check::PROC_CPUINFO;
use std::io::Write; use std::io::Write;
use tempfile::tempdir; use tempfile::tempdir;
@ -223,12 +226,14 @@ mod tests {
assert!(res.is_ok()); assert!(res.is_ok());
} }
#[cfg(any(target_arch = "x86_64"))]
#[test] #[test]
fn get_generic_cpu_details_system() { fn get_generic_cpu_details_system() {
let res = get_generic_cpu_details(PROC_CPUINFO); let res = get_generic_cpu_details(crate::check::PROC_CPUINFO);
assert!(res.is_ok()); assert!(res.is_ok());
} }
#[cfg(any(target_arch = "s390x", target_arch = "x86_64"))]
#[test] #[test]
fn get_generic_cpu_details_valid_contents() { fn get_generic_cpu_details_valid_contents() {
let dir = tempdir().unwrap(); let dir = tempdir().unwrap();
@ -250,12 +255,14 @@ mod tests {
assert_eq!(res.as_ref().unwrap().1, expected_model_name); assert_eq!(res.as_ref().unwrap().1, expected_model_name);
} }
#[cfg(any(target_arch = "s390x", target_arch = "x86_64"))]
#[test] #[test]
fn get_generic_cpu_details_invalid_file() { fn get_generic_cpu_details_invalid_file() {
let res = get_generic_cpu_details("/tmp/missing.txt"); let res = get_generic_cpu_details("/tmp/missing.txt");
assert!(res.is_err()); assert!(res.is_err());
} }
#[cfg(any(target_arch = "s390x", target_arch = "x86_64"))]
#[test] #[test]
fn get_generic_cpu_details_invalid_contents() { fn get_generic_cpu_details_invalid_contents() {
let dir = tempdir().unwrap(); let dir = tempdir().unwrap();