mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-15 06:34:03 +00:00
utils: Add function to check vhost-vsock
Add function to check if the host-system has the vhost-vsock kernel module. Signed-off-by: Archana Shinde <archana.m.shinde@intel.com>
This commit is contained in:
parent
968f5b4031
commit
d3bb254188
@ -144,6 +144,12 @@ pub fn get_generic_cpu_details(cpu_info_file: &str) -> Result<(String, String)>
|
|||||||
Ok((vendor, model))
|
Ok((vendor, model))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const VHOST_VSOCK_DEVICE: &str = "/dev/vhost-vsock";
|
||||||
|
pub fn supports_vsocks(vsock_path: &str) -> Result<bool> {
|
||||||
|
let metadata = fs::metadata(vsock_path)?;
|
||||||
|
Ok(metadata.is_file())
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
@ -283,4 +289,30 @@ mod tests {
|
|||||||
);
|
);
|
||||||
assert_eq!(actual, expected);
|
assert_eq!(actual, expected);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn check_supports_vsocks_valid() {
|
||||||
|
let dir = tempdir().unwrap();
|
||||||
|
let file_path = dir.path().join("vhost-vsock");
|
||||||
|
let path = file_path.clone();
|
||||||
|
let _file = fs::File::create(file_path).unwrap();
|
||||||
|
let res = supports_vsocks(path.to_str().unwrap()).unwrap();
|
||||||
|
assert!(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn check_supports_vsocks_dir() {
|
||||||
|
let dir = tempdir().unwrap();
|
||||||
|
let file_path = dir.path().join("vhost-vsock");
|
||||||
|
let path = file_path.clone();
|
||||||
|
let _dir = fs::create_dir(file_path).unwrap();
|
||||||
|
let res = supports_vsocks(path.to_str().unwrap()).unwrap();
|
||||||
|
assert!(!res);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn check_supports_vsocks_missing_file() {
|
||||||
|
let res = supports_vsocks("/xyz/vhost-vsock");
|
||||||
|
assert!(res.is_err());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user