Skip to content

Commit 1d1d8f5

Browse files
authored
Add collect subcommand that only runs postinstall debug collection (#112)
Adds `edera-check collect` subcommand which skips `postinstall` checks and _only_ gathers the system report bundle, which we already collect as a side effect of the `postinstall` check.
1 parent 7f1abfb commit 1d1d8f5

3 files changed

Lines changed: 68 additions & 2 deletions

File tree

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,16 @@ Run this on a system that has been booted into an Edera installation to validate
6161

6262
---
6363

64+
### Generate system report
65+
66+
```bash
67+
sudo edera-check collect
68+
```
69+
70+
Run this on a system that has been booted into an Edera installation to collect a system report, including logs and other useful troubleshooting information.
71+
72+
---
73+
6474
## Example Output
6575

6676
```text

src/collect_cmd.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use crate::{create_base_path, create_gzip_from, write_group_report};
2+
use edera_check::recorders::postinstall::system::SystemRecorder as postrecorder;
3+
4+
use anyhow::{Result, anyhow};
5+
use console::style;
6+
use edera_check::helpers::{CheckGroup, host_executor::HostNamespaceExecutor};
7+
use std::{env, path::PathBuf};
8+
9+
pub async fn do_collect(report_dir: Option<String>) -> Result<()> {
10+
let host_executor = HostNamespaceExecutor::new();
11+
12+
let groups: Vec<Box<dyn CheckGroup>> = vec![Box::new(postrecorder::new(host_executor.clone()))];
13+
14+
let hostname = host_executor
15+
.spawn_in_host_ns(async { std::fs::read_to_string("/proc/sys/kernel/hostname").unwrap() })
16+
.await?;
17+
18+
let base_dir = if let Some(dir) = report_dir {
19+
PathBuf::from(dir)
20+
} else {
21+
env::temp_dir()
22+
};
23+
24+
let base_path = create_base_path(base_dir, hostname.trim(), "collect")
25+
.map_err(|e| anyhow!("failed to create bundle base path: {e}"))?;
26+
27+
for group in groups {
28+
println!(
29+
"{} {} [{}] - {}",
30+
style("Running Group").cyan(),
31+
style(group.name()).cyan().bold(),
32+
style(group.category()).white().bold(),
33+
group.description()
34+
);
35+
let result = group.run().await;
36+
result.log_individual_checks();
37+
write_group_report(group, &result, &base_path)?;
38+
}
39+
40+
create_gzip_from(base_path, host_executor).await
41+
}

src/main.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
mod collect_cmd;
12
mod postinstall_cmd;
23
mod preinstall_cmd;
34

@@ -82,12 +83,25 @@ struct PostinstallArgs {
8283
report_dir: Option<String>,
8384
}
8485

86+
#[derive(Args)]
87+
struct CollectArgs {
88+
/// Directory path to write report to. Will be created if it doesn't exist. Defaults to `/tmp`
89+
#[arg(short = 'd', long)]
90+
report_dir: Option<String>,
91+
}
92+
8593
#[derive(Subcommand)]
8694
enum Commands {
87-
/// Run before installing Edera to validate hardware/host installation readiness.
95+
#[command(
96+
about = "Run before installing Edera to validate hardware/host installation readiness.\nAlso collects a system information snapshot."
97+
)]
8898
Preinstall(PreinstallArgs),
89-
/// Run after installing Edera to validate workload readiness.
99+
#[command(
100+
about = "Run after installing Edera to validate workload readiness.\nAlso collects a system information snapshot."
101+
)]
90102
Postinstall(PostinstallArgs),
103+
#[command(about = "Run after installing Edera to collect a system information snapshot.")]
104+
Collect(CollectArgs),
91105
}
92106

93107
#[tokio::main(flavor = "multi_thread", worker_threads = 10)]
@@ -120,6 +134,7 @@ async fn main() -> Result<()> {
120134
)
121135
.await
122136
}
137+
Commands::Collect(args) => collect_cmd::do_collect(args.report_dir).await,
123138
}
124139
}
125140

0 commit comments

Comments
 (0)