Skip to main content

asterust_junos/system/
kernel_replication.rs

1//! `kernel-replication`
2//! `system { kernel-replication { ... } }`.
3//!
4//! # See also
5//!
6//! - [kernel-replication](https://networkingdocs.hpe.com/documentation/us/en/software/junos/cli-reference/topics/ref/statement/system-kernel-replication.html)
7
8use crate::{has_leaf, statement_words};
9use asterust::config::ConfigLine;
10
11/// The `system kernel-replication` options.
12#[derive(Clone, Debug, PartialEq, Eq)]
13#[non_exhaustive]
14pub struct KernelReplication {
15    /// Run `ksyncd` in single-thread mode.
16    pub no_multithreading: bool,
17    /// `system-reboot recovery-failure`: reboot the backup Routing Engine when `ksyncd` fails to initialize.
18    pub system_reboot_recovery_failure: bool,
19}
20
21pub(super) fn parse_kernel_replication(replication: &ConfigLine) -> KernelReplication {
22    KernelReplication {
23        no_multithreading: has_leaf(replication, "no-multithreading"),
24        system_reboot_recovery_failure: statement_words(replication, "system-reboot")
25            .is_some_and(|words| words.contains(&"recovery-failure")),
26    }
27}
28
29#[cfg(test)]
30mod tests {
31    use crate::system::system;
32    use asterust::config::juniper;
33
34    // Not from documentation: written from the CLI Reference syntax page. See the README "Sources".
35    #[test]
36    fn extracts_kernel_replication_options() {
37        let replication = system(&juniper::parse_braces(
38            "system {\n    kernel-replication {\n        no-multithreading;\n        system-reboot recovery-failure;\n    }\n}\n",
39        ))
40        .unwrap()
41        .kernel_replication
42        .unwrap();
43        assert!(replication.no_multithreading);
44        assert!(replication.system_reboot_recovery_failure);
45    }
46
47    #[test]
48    fn kernel_replication_options_default_to_off() {
49        let replication = system(&juniper::parse_braces(
50            "system {\n    kernel-replication {\n        no-multithreading;\n    }\n}\n",
51        ))
52        .unwrap()
53        .kernel_replication
54        .unwrap();
55        assert!(!replication.system_reboot_recovery_failure);
56    }
57
58    #[test]
59    fn no_kernel_replication_is_none() {
60        let system = system(&juniper::parse_braces("system {\n    host-name pe1;\n}\n")).unwrap();
61        assert!(system.kernel_replication.is_none());
62    }
63}