Skip to content

Commit a4a5643

Browse files
committed
system checks
1 parent 32b9983 commit a4a5643

3 files changed

Lines changed: 62 additions & 28 deletions

File tree

hack/debug/local.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ docker run --privileged --pid="host" \
1111
-e RUST_LOG="debug" \
1212
-e EDERA_PREFLIGHT_VERBOSE=true \
1313
-e EDERA_PREFLIGHT_TARGET_DIR='/host' \
14-
-e EDERA_PREFLIGHT_SKIP_GROUPS='KernelChecks;ScriptedChecks;SystemChecks' \
14+
-e EDERA_PREFLIGHT_SKIP_GROUPS='ScriptedChecks' \
1515
-e EDERA_PREFLIGHT_SCRIPTS_DIR=/scripts \
1616
"${REGISTRY}/${USERIMG}-preflight-debug:${VER}"

src/checkers/system.rs

Lines changed: 60 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
use crate::helpers::{
22
CheckGroup, CheckGroupResult, CheckResult,
33
CheckResultValue::{Errored, Failed, Passed},
4+
host_executor::HostNamespaceExecutor,
45
};
56

7+
use futures::{FutureExt, future::join_all};
68
use async_trait::async_trait;
79
use log::debug;
810
use sysinfo::{Disks, System};
@@ -12,11 +14,16 @@ const NAME: &str = "System Checks";
1214
const MINIMUM_MEMORY: u64 = 4 * 1024 * 1024 * 1024; // 4GB
1315
const MINIMUM_DISK: u64 = 20 * 1024 * 1024 * 1024; // 20GB
1416

15-
pub struct SystemChecks;
17+
pub struct SystemChecks {
18+
host_executor: HostNamespaceExecutor,
19+
}
1620

1721
impl SystemChecks {
18-
pub fn run_all(&self) -> CheckGroupResult {
19-
let results = vec![self.enough_memory(), self.enough_disk()];
22+
pub fn new(host_executor: HostNamespaceExecutor) -> Self {
23+
SystemChecks { host_executor }
24+
}
25+
pub async fn run_all(&self) -> CheckGroupResult {
26+
let results = join_all([self.enough_memory().boxed(), self.enough_disk().boxed()]).await;
2027

2128
let mut group_result = Passed;
2229
for res in results.iter() {
@@ -37,12 +44,25 @@ impl SystemChecks {
3744
}
3845
}
3946

40-
fn enough_memory(&self) -> CheckResult {
47+
async fn enough_memory(&self) -> CheckResult {
4148
let name = String::from("Enough Memory");
42-
let mut sys = System::new_all();
43-
sys.refresh_all();
4449

45-
let total_mem = sys.total_memory();
50+
let total_mem = match self
51+
.host_executor
52+
.spawn_in_host_ns(async {
53+
let mut sys = System::new_all();
54+
sys.refresh_all();
55+
56+
sys.total_memory()
57+
})
58+
.await
59+
{
60+
Ok(mem) => mem,
61+
Err(e) => {
62+
return CheckResult::new(&name, Errored(e.to_string()));
63+
}
64+
};
65+
4666
debug!("total memory = {total_mem}");
4767

4868
let mut result = Passed;
@@ -53,26 +73,40 @@ impl SystemChecks {
5373
CheckResult::new(&name, result)
5474
}
5575

56-
fn enough_disk(&self) -> CheckResult {
76+
async fn enough_disk(&self) -> CheckResult {
5777
let name = String::from("Enough Disk");
58-
let mut result = Failed(String::from("Not enough disk space on any disk"));
59-
let disks = Disks::new_with_refreshed_list();
60-
for disk in &disks {
61-
if disk.available_space() < MINIMUM_DISK {
62-
debug!(
63-
"Not enough space on disk mounted at {} - {}",
64-
disk.mount_point().display(),
65-
disk.available_space()
66-
);
67-
} else {
68-
debug!(
69-
"Enough space on disk mounted at {} - {}",
70-
disk.mount_point().display(),
71-
disk.available_space()
72-
);
73-
result = Passed;
78+
79+
let result = match self
80+
.host_executor
81+
.spawn_in_host_ns(async {
82+
let mut result = Failed(String::from("Not enough disk space on any disk"));
83+
let disks = Disks::new_with_refreshed_list();
84+
for disk in &disks {
85+
if disk.available_space() < MINIMUM_DISK {
86+
debug!(
87+
"Not enough space on disk mounted at {} - {}",
88+
disk.mount_point().display(),
89+
disk.available_space()
90+
);
91+
} else {
92+
debug!(
93+
"Enough space on disk mounted at {} - {}",
94+
disk.mount_point().display(),
95+
disk.available_space()
96+
);
97+
result = Passed;
98+
}
99+
}
100+
result
101+
})
102+
.await
103+
{
104+
Ok(result) => result,
105+
Err(e) => {
106+
return CheckResult::new(&name, Errored(e.to_string()));
74107
}
75-
}
108+
};
109+
76110
CheckResult::new(&name, result)
77111
}
78112
}
@@ -92,6 +126,6 @@ impl CheckGroup for SystemChecks {
92126
}
93127

94128
async fn run(&self) -> CheckGroupResult {
95-
self.run_all()
129+
self.run_all().await
96130
}
97131
}

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ async fn main() -> Result<()> {
108108
let host_executor = HostNamespaceExecutor::new();
109109

110110
let groups: Vec<Box<dyn CheckGroup>> = vec![
111-
Box::new(SystemChecks),
111+
Box::new(SystemChecks::new(host_executor.clone())),
112112
Box::new(ScriptChecks),
113113
Box::new(KernelChecks::new(host_executor.clone())),
114114
Box::new(SystemRecorder::new(host_executor.clone())),

0 commit comments

Comments
 (0)