mirror of
https://github.com/faas-rs/faasd-in-rust.git
synced 2025-06-08 15:56:48 +00:00
33 lines
684 B
Rust
33 lines
684 B
Rust
use netns_rs::{Error, NetNs};
|
|
|
|
pub(super) fn create(netns: &str) -> Result<NetNs, Error> {
|
|
NetNs::new(netns)
|
|
}
|
|
|
|
pub(super) fn remove(netns: &str) -> Result<(), Error> {
|
|
match NetNs::get(netns) {
|
|
Ok(ns) => {
|
|
ns.remove()?;
|
|
Ok(())
|
|
}
|
|
Err(e) => {
|
|
log::error!("Failed to get netns {}: {}", netns, e);
|
|
Err(e)
|
|
}
|
|
}
|
|
}
|
|
|
|
/// THESE TESTS SHOULD BE RUN WITH ROOT PRIVILEGES
|
|
#[cfg(test)]
|
|
mod test {
|
|
use super::*;
|
|
|
|
#[test]
|
|
#[ignore]
|
|
fn test_create_and_remove() {
|
|
let netns_name = "test_netns";
|
|
create(netns_name).unwrap();
|
|
assert!(remove(netns_name).is_ok());
|
|
}
|
|
}
|