mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-27 15:57:09 +00:00
runtime-rs: add load_test_config for unit test
add load_test_config for unit test Fixes:#7539 Signed-off-by: Zhongtao Hu <zhongtaohu.tim@linux.alibaba.com>
This commit is contained in:
parent
7f48a69379
commit
e44919f0da
3
src/runtime-rs/Cargo.lock
generated
3
src/runtime-rs/Cargo.lock
generated
@ -2762,6 +2762,7 @@ dependencies = [
|
|||||||
"slog-scope",
|
"slog-scope",
|
||||||
"tempfile",
|
"tempfile",
|
||||||
"test-utils",
|
"test-utils",
|
||||||
|
"tests_utils",
|
||||||
"tokio",
|
"tokio",
|
||||||
"tracing",
|
"tracing",
|
||||||
"uuid",
|
"uuid",
|
||||||
@ -3325,6 +3326,8 @@ dependencies = [
|
|||||||
name = "tests_utils"
|
name = "tests_utils"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"anyhow",
|
||||||
|
"kata-types",
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ tempfile = "3.2.0"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "^1.0"
|
anyhow = "^1.0"
|
||||||
|
actix-rt = "2.7.0"
|
||||||
async-trait = "0.1.48"
|
async-trait = "0.1.48"
|
||||||
bitflags = "1.2.1"
|
bitflags = "1.2.1"
|
||||||
byte-unit = "4.0.14"
|
byte-unit = "4.0.14"
|
||||||
@ -40,7 +41,7 @@ kata-types = { path = "../../../libs/kata-types" }
|
|||||||
kata-sys-util = { path = "../../../libs/kata-sys-util" }
|
kata-sys-util = { path = "../../../libs/kata-sys-util" }
|
||||||
logging = { path = "../../../libs/logging" }
|
logging = { path = "../../../libs/logging" }
|
||||||
oci = { path = "../../../libs/oci" }
|
oci = { path = "../../../libs/oci" }
|
||||||
actix-rt = "2.7.0"
|
|
||||||
persist = { path = "../persist"}
|
persist = { path = "../persist"}
|
||||||
|
tests_utils = { path = "../../tests/utils" }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
@ -6,11 +6,12 @@
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::{fs, path::Path, sync::Arc};
|
use std::sync::Arc;
|
||||||
|
|
||||||
use anyhow::{anyhow, Context, Result};
|
use anyhow::{anyhow, Context, Result};
|
||||||
use netlink_packet_route::MACVLAN_MODE_PRIVATE;
|
use netlink_packet_route::MACVLAN_MODE_PRIVATE;
|
||||||
use scopeguard::defer;
|
use scopeguard::defer;
|
||||||
|
use tests_utils::load_test_config;
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
|
|
||||||
use crate::network::{
|
use crate::network::{
|
||||||
@ -24,22 +25,13 @@ mod tests {
|
|||||||
utils::link::net_test_utils::delete_link,
|
utils::link::net_test_utils::delete_link,
|
||||||
};
|
};
|
||||||
use hypervisor::{device::device_manager::DeviceManager, qemu::Qemu};
|
use hypervisor::{device::device_manager::DeviceManager, qemu::Qemu};
|
||||||
use kata_types::config::{QemuConfig, TomlConfig};
|
|
||||||
|
|
||||||
async fn get_device_manager() -> Result<Arc<RwLock<DeviceManager>>> {
|
async fn get_device_manager() -> Result<Arc<RwLock<DeviceManager>>> {
|
||||||
let path = env!("CARGO_MANIFEST_DIR");
|
|
||||||
let path = Path::new(path)
|
|
||||||
.join("../../../libs/kata-types/tests/texture/configuration-anno-0.toml");
|
|
||||||
|
|
||||||
let content = fs::read_to_string(path).context("read configuration failed")?;
|
|
||||||
// just for test, use x/kata-types/tests/texture/configuration-anno-0.toml as
|
|
||||||
// the test configuration.toml which is for qemu.
|
|
||||||
let hypervisor_name: &str = "qemu";
|
let hypervisor_name: &str = "qemu";
|
||||||
|
if let Err(e) = load_test_config(hypervisor_name.to_owned()) {
|
||||||
let qemu = QemuConfig::new();
|
println!("Test failed with error: {}", e);
|
||||||
qemu.register();
|
}
|
||||||
|
let toml_config = load_test_config(hypervisor_name.to_owned())?;
|
||||||
let toml_config = TomlConfig::load(&content).context("load toml config failed")?;
|
|
||||||
let hypervisor_config = toml_config
|
let hypervisor_config = toml_config
|
||||||
.hypervisor
|
.hypervisor
|
||||||
.get(hypervisor_name)
|
.get(hypervisor_name)
|
||||||
|
90
src/runtime-rs/tests/texture/configuration-qemu.toml
Normal file
90
src/runtime-rs/tests/texture/configuration-qemu.toml
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
[hypervisor.qemu]
|
||||||
|
path = "/usr/bin/lsns"
|
||||||
|
valid_hypervisor_paths = ["/usr/bin/qemu*", "/opt/qemu?","/usr/bin/ls*","./hypervisor_path"]
|
||||||
|
valid_jailer_paths = ["/usr/lib/rust","./test_jailer_path"]
|
||||||
|
ctlpath = "/usr/bin/"
|
||||||
|
valid_ctlpaths = ["/usr/lib/jvm","usr/bin/qemu-io","./jvm"]
|
||||||
|
disable_nesting_checks = true
|
||||||
|
enable_iothreads = true
|
||||||
|
jailer_path = "/usr/local"
|
||||||
|
kernel = "/usr/bin/../bin/zcmp"
|
||||||
|
image = "/usr/bin/./tabs"
|
||||||
|
kernel_params = "ro"
|
||||||
|
firmware = "/etc/hostname"
|
||||||
|
|
||||||
|
cpu_features="pmu=off,vmx=off"
|
||||||
|
default_vcpus = 2
|
||||||
|
default_maxvcpus = 64
|
||||||
|
|
||||||
|
machine_type = "q35"
|
||||||
|
confidential_guest = true
|
||||||
|
rootless = true
|
||||||
|
enable_annotations = ["shared_fs","path", "ctlpath","jailer_path","enable_iothreads","default_memory","memory_slots","enable_mem_prealloc","enable_hugepages","file_mem_backend","enable_virtio_mem","enable_swap","enable_guest_swap","default_vcpus","virtio_fs_extra_args","block_device_driver","vhost_user_store_path","kernel","guest_hook_path","block_device_cache_noflush","virtio_fs_daemon"]
|
||||||
|
machine_accelerators="noapic"
|
||||||
|
default_bridges = 2
|
||||||
|
default_memory = 128
|
||||||
|
memory_slots = 128
|
||||||
|
memory_offset = 0x100000
|
||||||
|
enable_virtio_mem = true
|
||||||
|
disable_block_device_use = false
|
||||||
|
shared_fs = "virtio-fs"
|
||||||
|
virtio_fs_daemon = "/usr/bin/uptime"
|
||||||
|
valid_virtio_fs_daemon_paths = ["/usr/local/bin/virtiofsd*","./virtio_fs"]
|
||||||
|
virtio_fs_cache_size = 512
|
||||||
|
virtio_fs_extra_args = ["-o", "arg1=xxx,arg2", "-o", "hello world", "--arg3=yyy"]
|
||||||
|
virtio_fs_cache = "always"
|
||||||
|
block_device_driver = "virtio-blk"
|
||||||
|
block_device_cache_set = true
|
||||||
|
block_device_cache_direct = true
|
||||||
|
block_device_cache_noflush = true
|
||||||
|
enable_mem_prealloc = true
|
||||||
|
enable_hugepages = true
|
||||||
|
enable_vhost_user_store = true
|
||||||
|
vhost_user_store_path = "/tmp"
|
||||||
|
valid_vhost_user_store_paths = ["/var/kata/vhost-user-store*", "/tmp/kata?","/var/tmp","./store_path"]
|
||||||
|
enable_iommu = true
|
||||||
|
enable_iommu_platform = true
|
||||||
|
file_mem_backend = "/dev/shm"
|
||||||
|
valid_file_mem_backends = ["/dev/shm","/dev/snd","./test_file_backend_mem_root"]
|
||||||
|
enable_swap = true
|
||||||
|
pflashes = ["/proc/mounts"]
|
||||||
|
enable_debug = true
|
||||||
|
msize_9p = 16384
|
||||||
|
disable_image_nvdimm = true
|
||||||
|
hotplug_vfio_on_root_bus = true
|
||||||
|
pcie_root_port = 2
|
||||||
|
disable_vhost_net = true
|
||||||
|
entropy_source= "/dev/urandom"
|
||||||
|
valid_entropy_sources = ["/dev/urandom", "/dev/random"]
|
||||||
|
guest_hook_path = "/usr/share"
|
||||||
|
rx_rate_limiter_max_rate = 10000
|
||||||
|
tx_rate_limiter_max_rate = 10000
|
||||||
|
guest_memory_dump_path="/var/crash/kata"
|
||||||
|
guest_memory_dump_paging = true
|
||||||
|
enable_guest_swap = true
|
||||||
|
|
||||||
|
[agent.agent0]
|
||||||
|
enable_tracing = true
|
||||||
|
debug_console_enabled = true
|
||||||
|
debug = true
|
||||||
|
dial_timeout = 1
|
||||||
|
kernel_modules = ["e1000e InterruptThrottleRate=3000,3000,3000 EEE=1","i915_enabled_ppgtt=0"]
|
||||||
|
container_pipe_size = 2
|
||||||
|
[runtime]
|
||||||
|
enable_debug = true
|
||||||
|
internetworking_model="macvtap"
|
||||||
|
disable_guest_seccomp=false
|
||||||
|
enable_tracing = true
|
||||||
|
jaeger_endpoint = "localhost:1234"
|
||||||
|
jaeger_user = "user"
|
||||||
|
jaeger_password = "pw"
|
||||||
|
disable_new_netns = true
|
||||||
|
sandbox_cgroup_only=true
|
||||||
|
sandbox_bind_mounts=["/proc/self"]
|
||||||
|
vfio_mode="vfio"
|
||||||
|
experimental=["a", "b"]
|
||||||
|
enable_pprof = true
|
||||||
|
hypervisor_name = "qemu"
|
||||||
|
agent_name = "agent0"
|
||||||
|
|
||||||
|
|
@ -1,11 +0,0 @@
|
|||||||
[runtime]
|
|
||||||
enable_debug = true
|
|
||||||
|
|
||||||
[hypervisor]
|
|
||||||
|
|
||||||
[hypervisor.dragonball]
|
|
||||||
default_vcpus = 2
|
|
||||||
|
|
||||||
[hypervisor.qemu]
|
|
||||||
default_vcpus = 4
|
|
||||||
|
|
@ -8,4 +8,6 @@ license = "Apache-2.0"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
anyhow = "^1.0"
|
||||||
rand = "0.8.4"
|
rand = "0.8.4"
|
||||||
|
kata-types = { path = "../../../libs/kata-types" }
|
||||||
|
@ -6,17 +6,20 @@
|
|||||||
|
|
||||||
// This crate is used to share code among tests
|
// This crate is used to share code among tests
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use anyhow::{anyhow, Result};
|
||||||
|
use kata_types::config::{QemuConfig, TomlConfig};
|
||||||
|
use std::{fs, path::PathBuf};
|
||||||
|
|
||||||
use rand::{
|
use rand::{
|
||||||
distributions::Alphanumeric,
|
distributions::Alphanumeric,
|
||||||
{thread_rng, Rng},
|
{thread_rng, Rng},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn get_kata_config_file() -> PathBuf {
|
fn get_kata_config_file(hypervisor_name: String) -> PathBuf {
|
||||||
let target = format!(
|
let target = format!(
|
||||||
"{}/../texture/kata-containers-configuration.toml",
|
"{}/../texture/configuration-{}.toml",
|
||||||
env!("CARGO_MANIFEST_DIR")
|
env!("CARGO_MANIFEST_DIR"),
|
||||||
|
hypervisor_name
|
||||||
);
|
);
|
||||||
std::fs::canonicalize(target).unwrap()
|
std::fs::canonicalize(target).unwrap()
|
||||||
}
|
}
|
||||||
@ -33,3 +36,18 @@ pub fn gen_id(len: usize) -> String {
|
|||||||
.map(char::from)
|
.map(char::from)
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn load_test_config(hypervisor_name: String) -> Result<TomlConfig> {
|
||||||
|
match hypervisor_name.as_str() {
|
||||||
|
"qemu" => {
|
||||||
|
let qemu = QemuConfig::new();
|
||||||
|
qemu.register();
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
return Err(anyhow!("invalid hypervisor {}", hypervisor_name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let content = fs::read_to_string(get_kata_config_file(hypervisor_name))?;
|
||||||
|
Ok(TomlConfig::load(&content)?)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user