Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/holger

server/lib/src/admin_view/disks_off.rs

//! **No Disks pane and no disk speed test** (a build without `estate`, H2's estate
//! cut): the upstream and the downstream link no edda `disk-snapshot`, and no
//! nordisk-twin to read a twin's credential with. The pane says so by name instead of
//! guessing; the capacity door (`AdminService.Capacity`, statvfs over rustix) is in
//! every build and still measures the data root.

use super::*;

/// Why this build's admin view has no disks.
pub const NO_DISKS: &str = "not measured: this holger was built without the estate (feature `estate`), so the admin view links no disk snapshot (edda disk-snapshot); AdminService.Capacity still measures the data root";
/// Why this build's disk speed is not measured.
pub const NO_DISK_SPEED: &str = "not measured: this holger was built without the estate (feature `estate`), so it runs no disk speed test";
/// The Disks pane's floor rule, said in this build too.
pub const FLOOR_RULE: &str = "advisory: 5 % of the filesystem or 2 GiB, whichever is larger (edda disk-snapshot Floor::DEFAULT, gunnar's --disk-floor rule) — holger refuses no write at it today";

/// A path the Disks pane would measure; this build measures none.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Volume;

/// No volumes are measured in this build.
pub fn volumes(_data_root: Option<&Path>, _places: &crate::metering::StoragePlaces) -> Vec<Volume> {
    Vec::new()
}

/// The Disks pane in this build: empty, and why.
pub fn disks(_volumes: &[Volume]) -> pb::AdminDisks {
    pb::AdminDisks {
        problems: vec![NO_DISKS.to_string()],
        floor_rule: FLOOR_RULE.to_string(),
        ..Default::default()
    }
}

/// No disk speed test in this build: never started.
pub fn start_disk_speed(_data_root: PathBuf) -> bool {
    false
}

/// The disk speed figure in this build: not measured, and why.
pub fn disk_speed() -> pb::AdminDiskSpeed {
    pb::AdminDiskSpeed {
        measured: false,
        why: NO_DISK_SPEED.into(),
        ..Default::default()
    }
}

/// An installed credential onto the pane: none can be installed in this build.
pub(crate) fn installed(
    _c: &mut pb::AdminTwinCredential,
    cred: &crate::twin_tls::Credential,
    _now_unix: i64,
) {
    match *cred {}
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn without_the_estate_the_disks_and_the_speed_say_why() {
        let places = crate::metering::StoragePlaces::new();
        let d = disks(&volumes(Some(Path::new("/data")), &places));
        assert!(d.mounts.is_empty() && d.block_devices.is_empty());
        assert_eq!(d.problems, [NO_DISKS]);
        assert!(
            !start_disk_speed(PathBuf::from("/data")),
            "no test is started"
        );
        let s = disk_speed();
        assert!(!s.measured && s.why.contains("without the estate"), "{s:?}");
    }
}