-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor kernel interface to remove mock and global var
When a unit testing scheme was originally designed for the kernel interface module in 2017 it was turned into a stateful struct to accomodate a mock test environment that allowed the tests to call the real functions and specify what exact commands they expected to be run. This structure has not been maintained, new tests are not written in that style and instead use separate testing functions. But the original tests have not been modified much since that time. Leaving Rita with a KI global variable that in production doesn't actually do anything all to support mocking during tests. This commit removes the mock structure and turns kernel interface into just a grab bag of utility functions where tests functions are all split out internally rather than relying on mock. While we are touching all of these files it will also be renamed to system_interface rather than kernel interface as we now interface with a lot more than just linux kernel functions from this module.
- Loading branch information
Showing
81 changed files
with
3,180 additions
and
4,175 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
use crate::KernelInterface; | ||
use crate::run_command; | ||
|
||
impl dyn KernelInterface { | ||
pub fn restart_babel(&self) { | ||
let _res = self.run_command("/etc/init.d/babeld", &["restart"]); | ||
} | ||
pub fn restart_babel() { | ||
let _res = run_command("/etc/init.d/babeld", &["restart"]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,13 @@ | ||
//! Simple helper functions for brctl | ||
use super::KernelInterface; | ||
use crate::run_command; | ||
use crate::KernelInterfaceError as Error; | ||
use std::process::Output; | ||
|
||
impl dyn KernelInterface { | ||
pub fn add_if_to_bridge(&self, br: &str, iface: &str) -> Result<Output, Error> { | ||
self.run_command("brctl", &["addif", br, iface]) | ||
} | ||
pub fn add_if_to_bridge(br: &str, iface: &str) -> Result<Output, Error> { | ||
run_command("brctl", &["addif", br, iface]) | ||
} | ||
|
||
pub fn del_if_from_bridge(&self, br: &str, iface: &str) -> Result<Output, Error> { | ||
self.run_command("brctl", &["delif", br, iface]) | ||
} | ||
pub fn del_if_from_bridge(br: &str, iface: &str) -> Result<Output, Error> { | ||
run_command("brctl", &["delif", br, iface]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,16 @@ | ||
use super::KernelInterface; | ||
use crate::KernelInterfaceError as Error; | ||
use std::process::{Command, Stdio}; | ||
|
||
impl dyn KernelInterface { | ||
/// Checks if the cron service is running and starts it if it's not | ||
pub fn check_cron(&self) -> Result<(), Error> { | ||
Command::new("/etc/init.d/cron") | ||
.args(["enable"]) | ||
.stdout(Stdio::piped()) | ||
.output()?; | ||
Command::new("/etc/init.d/cron") | ||
.args(["start"]) | ||
.stdout(Stdio::piped()) | ||
.output()?; | ||
/// Checks if the cron service is running and starts it if it's not | ||
pub fn check_cron() -> Result<(), Error> { | ||
Command::new("/etc/init.d/cron") | ||
.args(["enable"]) | ||
.stdout(Stdio::piped()) | ||
.output()?; | ||
Command::new("/etc/init.d/cron") | ||
.args(["start"]) | ||
.stdout(Stdio::piped()) | ||
.output()?; | ||
|
||
Ok(()) | ||
} | ||
Ok(()) | ||
} |
Oops, something went wrong.