kata-ctl: fix permission deny issue in test_add_remove

test_add_remove and test_get_sandbox_id_for_volume need root user, but
test_drop_privs can temporarily change the user to "nobody" that can
lead to the failure of these tests.

Serialise these three tests can fix it.

Fixes: #6055
Signed-off-by: Jianyong Wu <jianyong.wu@arm.com>
This commit is contained in:
Jianyong Wu 2023-01-11 09:10:16 +08:00
parent c282a1c709
commit b7dd97cac6
3 changed files with 8 additions and 0 deletions

View File

@ -30,6 +30,7 @@ shim-interface = { path = "../../libs/shim-interface"}
kata-types = { path = "../../libs/kata-types" }
safe-path = { path = "../../libs/safe-path" }
agent = { path = "../../runtime-rs/crates/agent"}
serial_test = "0.5.1"
[target.'cfg(target_arch = "s390x")'.dependencies]
reqwest = { version = "0.11", default-features = false, features = ["json", "blocking", "native-tls"] }

View File

@ -169,11 +169,13 @@ pub fn get_sandbox_id_for_volume(volume_path: &str) -> Result<String> {
mod tests {
use super::*;
use kata_types::mount::DirectVolumeMountInfo;
use serial_test::serial;
use std::{collections::HashMap, fs};
use tempfile::tempdir;
use test_utils::skip_if_not_root;
#[test]
#[serial]
fn test_get_sandbox_id_for_volume() {
// this test has to run as root, so has to manually cleanup afterwards
skip_if_not_root!();
@ -259,6 +261,7 @@ mod tests {
}
#[test]
#[serial]
fn test_add_remove() {
skip_if_not_root!();
// example volume dir is a/b/c, note the behavior of join would take "/a" as absolute path.

View File

@ -147,10 +147,12 @@ pub fn get_generic_cpu_details(cpu_info_file: &str) -> Result<(String, String)>
#[cfg(test)]
mod tests {
use super::*;
use serial_test::serial;
use std::io::Write;
use tempfile::tempdir;
#[test]
#[serial]
fn test_drop_privs() {
let res = drop_privs();
assert!(res.is_ok());
@ -164,6 +166,7 @@ mod tests {
}
#[test]
#[serial]
fn test_kernel_version_valid_input() {
let dir = tempdir().unwrap();
let file_path = dir.path().join("proc-version");
@ -208,6 +211,7 @@ mod tests {
}
#[test]
#[serial]
fn test_get_distro_details_valid_file() {
let dir = tempdir().unwrap();
let file_path = dir.path().join("os-version");