asterust_junos/system/
kernel_replication.rs1use crate::{has_leaf, statement_words};
9use asterust::config::ConfigLine;
10
11#[derive(Clone, Debug, PartialEq, Eq)]
13#[non_exhaustive]
14pub struct KernelReplication {
15 pub no_multithreading: bool,
17 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 #[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}