mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-10-12 15:26:14 -08:00
ci: parallelize Linux tests and skip HAR packaging on PRs (#2678)
This commit is contained in:
1 parent
f8a45ccc20
commit
1649ec0013
9 files changed
+1032
-555
No files matched your search
File diff suppressed because it is too large.
Load diff
+46
-51
@@ -1,6 +1,9 @@
|
||||
#[cfg(target_os = "linux")]
|
||||
mod three_node;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
mod network;
|
||||
|
||||
mod ipv6_test;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
@@ -68,21 +71,35 @@ pub fn del_netns(name: &str) {
|
||||
.output();
|
||||
}
|
||||
|
||||
fn run_network_command(program: &str, args: &[&str]) {
|
||||
let output = std::process::Command::new(program)
|
||||
.args(args)
|
||||
.output()
|
||||
.unwrap();
|
||||
assert!(
|
||||
output.status.success(),
|
||||
"{} {:?} failed ({}): stdout={}, stderr={}",
|
||||
program,
|
||||
args,
|
||||
output.status,
|
||||
String::from_utf8_lossy(&output.stdout),
|
||||
String::from_utf8_lossy(&output.stderr)
|
||||
);
|
||||
}
|
||||
|
||||
pub fn create_netns(name: &str, ipv4: &str, ipv6: &str) {
|
||||
// create netns
|
||||
let _ = std::process::Command::new("ip")
|
||||
.args(["netns", "add", name])
|
||||
.output()
|
||||
.unwrap();
|
||||
run_network_command("ip", &["netns", "add", name]);
|
||||
|
||||
// set lo up
|
||||
let _ = std::process::Command::new("ip")
|
||||
.args(["netns", "exec", name, "ip", "link", "set", "lo", "up"])
|
||||
.output()
|
||||
.unwrap();
|
||||
run_network_command(
|
||||
"ip",
|
||||
&["netns", "exec", name, "ip", "link", "set", "lo", "up"],
|
||||
);
|
||||
|
||||
let _ = std::process::Command::new("ip")
|
||||
.args([
|
||||
run_network_command(
|
||||
"ip",
|
||||
&[
|
||||
"link",
|
||||
"add",
|
||||
get_host_veth_name(name),
|
||||
@@ -91,17 +108,17 @@ pub fn create_netns(name: &str, ipv4: &str, ipv6: &str) {
|
||||
"peer",
|
||||
"name",
|
||||
get_guest_veth_name(name),
|
||||
])
|
||||
.output()
|
||||
.unwrap();
|
||||
],
|
||||
);
|
||||
|
||||
let _ = std::process::Command::new("ip")
|
||||
.args(["link", "set", get_guest_veth_name(name), "netns", name])
|
||||
.output()
|
||||
.unwrap();
|
||||
run_network_command(
|
||||
"ip",
|
||||
&["link", "set", get_guest_veth_name(name), "netns", name],
|
||||
);
|
||||
|
||||
let _ = std::process::Command::new("ip")
|
||||
.args([
|
||||
run_network_command(
|
||||
"ip",
|
||||
&[
|
||||
"netns",
|
||||
"exec",
|
||||
name,
|
||||
@@ -110,18 +127,15 @@ pub fn create_netns(name: &str, ipv4: &str, ipv6: &str) {
|
||||
"set",
|
||||
get_guest_veth_name(name),
|
||||
"up",
|
||||
])
|
||||
.output()
|
||||
.unwrap();
|
||||
],
|
||||
);
|
||||
|
||||
let _ = std::process::Command::new("ip")
|
||||
.args(["link", "set", get_host_veth_name(name), "up"])
|
||||
.output()
|
||||
.unwrap();
|
||||
run_network_command("ip", &["link", "set", get_host_veth_name(name), "up"]);
|
||||
|
||||
for ip in [ipv4, ipv6] {
|
||||
let _ = std::process::Command::new("ip")
|
||||
.args([
|
||||
run_network_command(
|
||||
"ip",
|
||||
&[
|
||||
"netns",
|
||||
"exec",
|
||||
name,
|
||||
@@ -131,36 +145,17 @@ pub fn create_netns(name: &str, ipv4: &str, ipv6: &str) {
|
||||
ip,
|
||||
"dev",
|
||||
get_guest_veth_name(name),
|
||||
])
|
||||
.output()
|
||||
.unwrap();
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn prepare_bridge(name: &str) {
|
||||
// del bridge with brctl
|
||||
let _ = std::process::Command::new("brctl")
|
||||
.args(["delbr", name])
|
||||
.output();
|
||||
|
||||
// create new br
|
||||
let _ = std::process::Command::new("brctl")
|
||||
.args(["addbr", name])
|
||||
.output();
|
||||
}
|
||||
|
||||
pub fn add_ns_to_bridge(br_name: &str, ns_name: &str) {
|
||||
// use brctl to add ns to bridge
|
||||
let _ = std::process::Command::new("brctl")
|
||||
.args(["addif", br_name, get_host_veth_name(ns_name)])
|
||||
.output()
|
||||
.unwrap();
|
||||
run_network_command("brctl", &["addif", br_name, get_host_veth_name(ns_name)]);
|
||||
|
||||
// set bridge up
|
||||
let _ = std::process::Command::new("ip")
|
||||
.args(["link", "set", br_name, "up"])
|
||||
.output()
|
||||
.unwrap();
|
||||
run_network_command("ip", &["link", "set", br_name, "up"]);
|
||||
}
|
||||
|
||||
fn check_route(
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
use crate::common::netns::{NetNS, ROOT_NETNS_NAME};
|
||||
|
||||
use super::{add_ns_to_bridge, create_netns, del_netns, run_network_command};
|
||||
|
||||
/// Owns one test's host links and namespaces. Keep this alive until its
|
||||
/// instances and background tasks have stopped, including on setup failures.
|
||||
pub(super) struct TestNetwork {
|
||||
directory: tempfile::TempDir,
|
||||
namespaces: Vec<(&'static str, String)>,
|
||||
links: Vec<(&'static str, String)>,
|
||||
}
|
||||
|
||||
impl TestNetwork {
|
||||
pub(super) fn new() -> Self {
|
||||
Self {
|
||||
directory: tempfile::Builder::new()
|
||||
.prefix("et")
|
||||
.rand_bytes(4)
|
||||
.tempdir()
|
||||
.unwrap(),
|
||||
namespaces: Vec::new(),
|
||||
links: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn prefix(&self) -> &str {
|
||||
self.directory.path().file_name().unwrap().to_str().unwrap()
|
||||
}
|
||||
|
||||
pub(super) fn namespace(&self, name: &str) -> &str {
|
||||
&self
|
||||
.namespaces
|
||||
.iter()
|
||||
.find(|(key, _)| *key == name)
|
||||
.unwrap()
|
||||
.1
|
||||
}
|
||||
|
||||
pub(super) fn link(&self, name: &str) -> &str {
|
||||
&self.links.iter().find(|(key, _)| *key == name).unwrap().1
|
||||
}
|
||||
|
||||
fn add_namespace(&mut self, name: &'static str) {
|
||||
// veth_<namespace>_h must fit Linux's 15-byte interface name limit.
|
||||
let actual = format!("{}{:02x}", self.prefix(), self.namespaces.len());
|
||||
assert!(actual.len() <= 8);
|
||||
assert!(!self.namespaces.iter().any(|(key, _)| *key == name));
|
||||
self.namespaces.push((name, actual));
|
||||
}
|
||||
|
||||
pub(super) fn create_namespace(&mut self, name: &'static str, ipv4: &str, ipv6: &str) {
|
||||
self.add_namespace(name);
|
||||
create_netns(self.namespace(name), ipv4, ipv6);
|
||||
}
|
||||
|
||||
pub(super) fn create_empty_namespace(&mut self, name: &'static str) {
|
||||
self.add_namespace(name);
|
||||
let actual = self.namespace(name);
|
||||
run_network_command("ip", &["netns", "add", actual]);
|
||||
run_network_command(
|
||||
"ip",
|
||||
&["netns", "exec", actual, "ip", "link", "set", "lo", "up"],
|
||||
);
|
||||
}
|
||||
|
||||
pub(super) fn add_link(&mut self, name: &'static str) {
|
||||
let actual = format!("{}l{:02x}", self.prefix(), self.links.len());
|
||||
assert!(!self.links.iter().any(|(key, _)| *key == name));
|
||||
self.links.push((name, actual));
|
||||
}
|
||||
|
||||
pub(super) fn create_bridge(&mut self, name: &'static str) {
|
||||
self.add_link(name);
|
||||
run_network_command("brctl", &["addbr", self.link(name)]);
|
||||
run_network_command("ip", &["link", "set", self.link(name), "up"]);
|
||||
}
|
||||
|
||||
pub(super) fn add_to_bridge(&self, bridge: &str, namespace: &str) {
|
||||
add_ns_to_bridge(self.link(bridge), self.namespace(namespace));
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for TestNetwork {
|
||||
fn drop(&mut self) {
|
||||
let _guard = NetNS::new(Some(ROOT_NETNS_NAME.to_owned())).guard();
|
||||
for (_, namespace) in &self.namespaces {
|
||||
del_netns(namespace);
|
||||
}
|
||||
for (_, link) in self.links.iter().rev() {
|
||||
let _ = std::process::Command::new("ip")
|
||||
.args(["link", "del", link])
|
||||
.output();
|
||||
}
|
||||
}
|
||||
}
|
||||
+473
-312
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user