asterust-junos 0.5.11

Typed Juniper JunOS config views (interfaces, protocols, routing instances and options, policy options, firewall filters, class of service, system, services) extracted from an asterust config tree.
Documentation
//! `kernel-replication`
//! `system { kernel-replication { ... } }`.
//!
//! # See also
//!
//! - [kernel-replication](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/system-kernel-replication.html)

use crate::{has_leaf, statement_words};
use asterust::config::ConfigLine;

/// The `system kernel-replication` options.
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct KernelReplication {
    /// Run `ksyncd` in single-thread mode.
    pub no_multithreading: bool,
    /// `system-reboot recovery-failure`: reboot the backup Routing Engine when `ksyncd` fails to initialize.
    pub system_reboot_recovery_failure: bool,
}

pub(super) fn parse_kernel_replication(replication: &ConfigLine) -> KernelReplication {
    KernelReplication {
        no_multithreading: has_leaf(replication, "no-multithreading"),
        system_reboot_recovery_failure: statement_words(replication, "system-reboot")
            .is_some_and(|words| words.contains(&"recovery-failure")),
    }
}

#[cfg(test)]
mod tests {
    use crate::system::system;
    use asterust::config::juniper;

    // Not from documentation: written from the CLI Reference syntax page. See the README "Sources".
    #[test]
    fn extracts_kernel_replication_options() {
        let replication = system(&juniper::parse_braces(
            "system {\n    kernel-replication {\n        no-multithreading;\n        system-reboot recovery-failure;\n    }\n}\n",
        ))
        .unwrap()
        .kernel_replication
        .unwrap();
        assert!(replication.no_multithreading);
        assert!(replication.system_reboot_recovery_failure);
    }

    #[test]
    fn kernel_replication_options_default_to_off() {
        let replication = system(&juniper::parse_braces(
            "system {\n    kernel-replication {\n        no-multithreading;\n    }\n}\n",
        ))
        .unwrap()
        .kernel_replication
        .unwrap();
        assert!(!replication.system_reboot_recovery_failure);
    }

    #[test]
    fn no_kernel_replication_is_none() {
        let system = system(&juniper::parse_braces("system {\n    host-name pe1;\n}\n")).unwrap();
        assert!(system.kernel_replication.is_none());
    }
}