diff --git a/src/agent/rustjail/src/cgroups/mock.rs b/src/agent/rustjail/src/cgroups/mock.rs new file mode 100644 index 0000000000..ef827f234a --- /dev/null +++ b/src/agent/rustjail/src/cgroups/mock.rs @@ -0,0 +1,74 @@ +// Copyright (c) 2020 Intel Corporation +// +// SPDX-License-Identifier: Apache-2.0 +// + +use protobuf::{CachedSize, SingularPtrField, UnknownFields}; + +use crate::cgroups::Manager as CgroupManager; +use crate::protocols::agent::{BlkioStats, CgroupStats, CpuStats, MemoryStats, PidsStats}; +use anyhow::Result; +use cgroups::freezer::FreezerState; +use libc::{self, pid_t}; +use oci::LinuxResources; +use std::collections::HashMap; +use std::string::String; + +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct Manager { + pub paths: HashMap, + pub mounts: HashMap, + pub cpath: String, +} + +impl CgroupManager for Manager { + fn apply(&self, _: pid_t) -> Result<()> { + Ok(()) + } + + fn set(&self, _: &LinuxResources, _: bool) -> Result<()> { + Ok(()) + } + + fn get_stats(&self) -> Result { + Ok(CgroupStats { + cpu_stats: SingularPtrField::some(CpuStats::default()), + memory_stats: SingularPtrField::some(MemoryStats::new()), + pids_stats: SingularPtrField::some(PidsStats::new()), + blkio_stats: SingularPtrField::some(BlkioStats::new()), + hugetlb_stats: HashMap::new(), + unknown_fields: UnknownFields::default(), + cached_size: CachedSize::default(), + }) + } + + fn freeze(&self, _: FreezerState) -> Result<()> { + Ok(()) + } + + fn destroy(&mut self) -> Result<()> { + Ok(()) + } + + fn get_pids(&self) -> Result> { + Ok(Vec::new()) + } +} + +impl Manager { + pub fn new(cpath: &str) -> Result { + Ok(Self { + paths: HashMap::new(), + mounts: HashMap::new(), + cpath: cpath.to_string(), + }) + } + + pub fn update_cpuset_path(&self, _: &str) -> Result<()> { + Ok(()) + } + + pub fn get_cg_path(&self, _: &str) -> Option { + Some("".to_string()) + } +} diff --git a/src/agent/rustjail/src/cgroups/mod.rs b/src/agent/rustjail/src/cgroups/mod.rs index abcaccb673..389ff79faf 100644 --- a/src/agent/rustjail/src/cgroups/mod.rs +++ b/src/agent/rustjail/src/cgroups/mod.rs @@ -10,6 +10,7 @@ use protocols::agent::CgroupStats; use cgroups::freezer::FreezerState; pub mod fs; +pub mod mock; pub mod notifier; pub mod systemd;