mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-12-22 13:45:20 +00:00
tests: Port test_tap_from_fd to use net_util::open_tap
This removes the need for manually creating the interface and assigning the IP. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
5db9b0ec99
commit
5209026f52
@ -5671,33 +5671,19 @@ mod tests {
|
||||
fn test_tap_from_fd() {
|
||||
let mut focal = UbuntuDiskConfig::new(FOCAL_IMAGE_NAME.to_string());
|
||||
let guest = Guest::new(&mut focal);
|
||||
|
||||
std::process::Command::new("bash")
|
||||
.args(&["-c", "sudo ip tuntap add name chtap0 mode tap"])
|
||||
.status()
|
||||
.expect("Expected creating interface to work");
|
||||
|
||||
std::process::Command::new("bash")
|
||||
.args(&[
|
||||
"-c",
|
||||
&format!("sudo ip addr add {}/24 dev chtap0", guest.network.host_ip),
|
||||
])
|
||||
.status()
|
||||
.expect("Expected programming interface to work");
|
||||
|
||||
std::process::Command::new("bash")
|
||||
.args(&["-c", "sudo ip link set dev chtap0 up"])
|
||||
.status()
|
||||
.expect("Expected upping interface to work");
|
||||
|
||||
let mut workload_path = dirs::home_dir().unwrap();
|
||||
workload_path.push("workloads");
|
||||
|
||||
let kernel_path = direct_kernel_boot_path().unwrap();
|
||||
|
||||
let tap = net_util::Tap::open_named("chtap0", 1, Some(libc::O_RDWR | libc::O_NONBLOCK))
|
||||
.expect("Expect to be able to open tap");
|
||||
let tap_fd = tap.as_raw_fd();
|
||||
use std::str::FromStr;
|
||||
let taps = net_util::open_tap(
|
||||
Some("chtap0"),
|
||||
Some(std::net::Ipv4Addr::from_str(&guest.network.host_ip).unwrap()),
|
||||
None,
|
||||
&mut None,
|
||||
1,
|
||||
Some(libc::O_RDWR | libc::O_NONBLOCK),
|
||||
)
|
||||
.unwrap();
|
||||
let tap_fd = taps[0].as_raw_fd();
|
||||
|
||||
let mut child = GuestCommand::new(&guest)
|
||||
.args(&["--cpus", "boot=1"])
|
||||
|
Loading…
Reference in New Issue
Block a user