@@ -37,6 +37,7 @@ import (
3737 "github.com/containerd/containerd/pkg/ttrpcutil"
3838 "github.com/containerd/containerd/runtime"
3939 "github.com/containerd/typeurl"
40+ "github.com/containernetworking/plugins/pkg/ns"
4041 "github.com/opencontainers/runtime-spec/specs-go"
4142 "github.com/pkg/errors"
4243 "github.com/shirou/gopsutil/process"
@@ -225,6 +226,8 @@ func TestMultipleVMs_Isolated(t *testing.T) {
225226 cfg .JailerConfig .RuncBinaryPath = "/usr/local/bin/runc"
226227 })
227228
229+ netns , err := ns .GetCurrentNS ()
230+
228231 cases := []struct {
229232 MaxContainers int32
230233 JailerConfig * proto.JailerConfig
@@ -240,11 +243,15 @@ func TestMultipleVMs_Isolated(t *testing.T) {
240243 },
241244 {
242245 MaxContainers : 3 ,
243- JailerConfig : & proto.JailerConfig {},
246+ JailerConfig : & proto.JailerConfig {
247+ NetworkNamespace : netns .Path (),
248+ },
244249 },
245250 {
246251 MaxContainers : 3 ,
247- JailerConfig : & proto.JailerConfig {},
252+ JailerConfig : & proto.JailerConfig {
253+ NetworkNamespace : netns .Path (),
254+ },
248255 },
249256 }
250257
@@ -273,6 +280,7 @@ func TestMultipleVMs_Isolated(t *testing.T) {
273280
274281 tapName := fmt .Sprintf ("tap%d" , vmID )
275282 err = createTapDevice (ctx , tapName )
283+
276284 require .NoError (t , err , "failed to create tap device for vm %d" , vmID )
277285
278286 rootfsPath := defaultVMRootfsPath
@@ -299,10 +307,6 @@ func TestMultipleVMs_Isolated(t *testing.T) {
299307 JailerConfig : jailerConfig ,
300308 }
301309
302- if jailerConfig != nil {
303- req .NetworkInterfaces = nil
304- }
305-
306310 _ , err = fcClient .CreateVM (ctx , req )
307311 require .NoError (t , err , "failed to create vm" )
308312
@@ -319,13 +323,6 @@ func TestMultipleVMs_Isolated(t *testing.T) {
319323 fmt .Sprintf ("/bin/sleep %d" , testTimeout / time .Second ),
320324 }, " && " ))
321325
322- if jailerConfig != nil {
323- // TODO: this if statement block can go away once we add netns
324- processArgs = oci .WithProcessArgs ("/bin/sh" , "-c" , strings .Join ([]string {
325- fmt .Sprintf ("/bin/sleep %d" , testTimeout / time .Second ),
326- }, " && " ))
327- }
328-
329326 // spawn a container that just prints the VM's eth0 mac address (which we have set uniquely per VM)
330327 newContainer , err := client .NewContainer (ctx ,
331328 containerName ,
@@ -454,20 +451,13 @@ func TestMultipleVMs_Isolated(t *testing.T) {
454451
455452 stdoutLines := strings .Split (strings .TrimSpace (taskStdout .String ()), "\n " )
456453 lines := 2
457- if jailerConfig != nil {
458- lines = 1
459- }
460454 require .Len (t , stdoutLines , lines )
461455
462456 printedVMID := strings .TrimSpace (stdoutLines [0 ])
463- // TODO: Remove this if statement once we can add a netns which
464- // will allow firecracker to have visibility of the tap devices.
465- if jailerConfig == nil {
466- require .Equal (t , vmIDtoMacAddr (uint (vmID )), printedVMID , "unexpected VMID output from container %q" , containerName )
457+ require .Equal (t , vmIDtoMacAddr (uint (vmID )), printedVMID , "unexpected VMID output from container %q" , containerName )
467458
468- taskMntNS := strings .TrimSpace (stdoutLines [1 ])
469- require .Equal (t , execMntNS , taskMntNS , "unexpected mnt NS output from container %q" , containerName )
470- }
459+ taskMntNS := strings .TrimSpace (stdoutLines [1 ])
460+ require .Equal (t , execMntNS , taskMntNS , "unexpected mnt NS output from container %q" , containerName )
471461
472462 case <- ctx .Done ():
473463 require .Fail (t , "context cancelled" ,
0 commit comments