mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-27 07:48:55 +00:00
runtime-rs:refactor network model with netlink
add unit test for tcfilter Fixes: #4289 Signed-off-by: Zhongtao Hu <zhongtaohu.tim@linux.alibaba.com>
This commit is contained in:
parent
9c526292e7
commit
07231b2f3f
@ -29,5 +29,5 @@ kata-types = { path = "../../../libs/kata-types" }
|
||||
kata-sys-util = { path = "../../../libs/kata-sys-util" }
|
||||
logging = { path = "../../../libs/logging" }
|
||||
oci = { path = "../../../libs/oci" }
|
||||
|
||||
actix-rt = "2.7.0"
|
||||
[features]
|
||||
|
@ -7,7 +7,7 @@
|
||||
pub mod none_model;
|
||||
pub mod route_model;
|
||||
pub mod tc_filter_model;
|
||||
|
||||
pub mod test_network_model;
|
||||
use std::sync::Arc;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
|
@ -91,7 +91,7 @@ impl NetworkModel for TcFilterModel {
|
||||
}
|
||||
}
|
||||
|
||||
async fn fetch_index(handle: &Handle, name: &str) -> Result<u32> {
|
||||
pub async fn fetch_index(handle: &Handle, name: &str) -> Result<u32> {
|
||||
let link = crate::network::network_pair::get_link_by_name(handle, name)
|
||||
.await
|
||||
.context("get link by name")?;
|
||||
|
@ -0,0 +1,39 @@
|
||||
// Copyright (c) 2019-2022 Alibaba Cloud
|
||||
// Copyright (c) 2019-2022 Ant Group
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::network::{
|
||||
network_model::{tc_filter_model::fetch_index, TC_FILTER_NET_MODEL_STR},
|
||||
network_pair::NetworkPair,
|
||||
};
|
||||
use anyhow::Context;
|
||||
use scopeguard::defer;
|
||||
#[actix_rt::test]
|
||||
async fn test_tc_redirect_network() {
|
||||
if let Ok((connection, handle, _)) = rtnetlink::new_connection().context("new connection") {
|
||||
let thread_handler = tokio::spawn(connection);
|
||||
defer!({
|
||||
thread_handler.abort();
|
||||
});
|
||||
|
||||
handle
|
||||
.link()
|
||||
.add()
|
||||
.veth("foo".to_string(), "bar".to_string());
|
||||
|
||||
if let Ok(net_pair) =
|
||||
NetworkPair::new(&handle, 1, "bar", TC_FILTER_NET_MODEL_STR, 2).await
|
||||
{
|
||||
if let Ok(index) = fetch_index(&handle, "bar").await {
|
||||
assert!(net_pair.add_network_model().await.is_ok());
|
||||
assert!(net_pair.del_network_model().await.is_ok());
|
||||
assert!(handle.link().del(index).execute().await.is_ok());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user