From 5209026f528bf57d06165a6150d2420b0151cf1f Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Wed, 27 Jan 2021 17:53:56 +0000 Subject: [PATCH] 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 --- tests/integration.rs | 36 +++++++++++------------------------- 1 file changed, 11 insertions(+), 25 deletions(-) diff --git a/tests/integration.rs b/tests/integration.rs index d401d9b44..d58670975 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -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"])