use crate::{has_leaf, statement_words};
use asterust::config::ConfigLine;
#[derive(Clone, Debug, PartialEq, Eq)]
#[non_exhaustive]
pub struct KernelReplication {
pub no_multithreading: bool,
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;
#[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());
}
}