Files
leleka/crates/deploy/src/preflight.rs
T
Pavlo Ratushnyi 95f768cfbf STRA-338 S12c: fns and impl blocks of 162 hot-path modules move into child modules (leleka-runtime, cuda-driver, deploy, cpu-sys)
The same lexer-based splitter as S12b, now with explicit re-exports: every moved free fn comes back to its module under its old name and old visibility (cfg attributes carried), so a name can never clash with another glob import. 162 module files of leleka-runtime (68), cuda-driver (84), deploy (10), cpu-sys, igpu and leleka-memory are split into groups of about 250 lines; types, constants, macros, nested modules and tests stay. Not touched: the files kar-off-ab edits, crate roots (lib.rs, main.rs, bin/*), and giant single impl blocks (next). This changes codegen-unit placement of engine code, so it is covered by the bitwise replay and the paired A/B on the 5090, not by a binary comparison.
2026-11-05 15:52:18 +01:00

92 lines
3.0 KiB
Rust

//! Preflight: turn `Facts` + `Profile` + what the plan needs into pass / warn / fail checks with a fix for each.
//!
//! Pure logic over data, so it is unit-tested with synthetic hosts (server, laptop under WSL2, driver too old,
//! no cuBLAS, full disk). `leleka up` refuses to start a step that changes anything while a check fails.
use crate::{
facts::{Facts, Gpu, is_slow_foreign_fs},
profile::{ARCHIVE_BYTES, ExpertSource, KarSource, Profile},
};
use serde::Serialize;
use std::path::PathBuf;
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum Level {
Pass,
Warn,
Fail,
}
#[derive(Clone, Debug, Serialize)]
pub struct Check {
pub id: &'static str,
pub level: Level,
pub title: String,
pub detail: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub fix: Option<String>,
}
#[derive(Clone, Debug, Serialize)]
pub struct Report {
pub profile: String,
pub checks: Vec<Check>,
}
/// What the plan will do, as far as it matters for the checks.
#[derive(Clone, Debug, Default)]
pub struct Needs {
pub gpu_index: u32,
pub assets_dir: PathBuf,
pub state_dir: PathBuf,
pub prefix_dir: PathBuf,
/// Bytes of GGUF shards still to download / of KAR archive still to build (0 when present).
pub shard_bytes_missing: u64,
pub kar_bytes_missing: u64,
/// Install the binaries from `bin_src` into the prefix.
pub install_binaries: bool,
/// cuBLAS 12 will be downloaded when the host has none.
pub may_install_cublas: bool,
pub cublas_download_bytes: u64,
pub wants_systemd: bool,
pub service_ports: Vec<(String, u16)>,
pub require_binaries: bool,
/// The release manifest lists the `sm86` feature (companion PTX for cc 8.6 <= cc < 12.0), when known.
pub binary_has_sm86: Option<bool>,
/// Ports already owned by this deployment's own running service are not conflicts.
pub service_running: bool,
/// The public API is bound beyond the loopback interface (`--api-bind`).
pub api_bind_open: bool,
/// The sealed archive comes from the parent process (`--kar-fd`): the service does not copy it.
pub kar_fd_inherited: bool,
/// Expert profile present, and its digest is the pinned one (only meaningful for profiles that name one).
pub expert_profile: Option<ExpertProfileState>,
/// The resource preset's numbers (`resources.rs`); its shortfalls are reported as checks.
pub resources: Option<crate::resources::ResourcePlan>,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum ExpertProfileState {
Absent,
Valid,
WrongDigest,
/// `--no-expert-tier`: the operator switched the tier off on purpose.
OptedOut,
}
const GIB: u64 = 1 << 30;
#[cfg(test)]
mod tests;
mod impl_report;
#[allow(unused_imports)]
use impl_report::check;
#[allow(unused_imports)]
use impl_report::gib;
#[allow(unused_imports)]
use impl_report::pass;
mod evaluate_fn;
#[allow(unused_imports)]
pub use evaluate_fn::evaluate;