@@ -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
@@ -300,10 +308,6 @@ func TestMultipleVMs_Isolated(t *testing.T) {
300308 JailerConfig : jailerConfig ,
301309 }
302310
303- if jailerConfig != nil {
304- req .NetworkInterfaces = nil
305- }
306-
307311 _ , err = fcClient .CreateVM (ctx , req )
308312 require .NoError (t , err , "failed to create vm" )
309313
@@ -320,13 +324,6 @@ func TestMultipleVMs_Isolated(t *testing.T) {
320324 fmt .Sprintf ("/bin/sleep %d" , testTimeout / time .Second ),
321325 }, " && " ))
322326
323- if jailerConfig != nil {
324- // TODO: this if statement block can go away once we add netns
325- processArgs = oci .WithProcessArgs ("/bin/sh" , "-c" , strings .Join ([]string {
326- fmt .Sprintf ("/bin/sleep %d" , testTimeout / time .Second ),
327- }, " && " ))
328- }
329-
330327 // spawn a container that just prints the VM's eth0 mac address (which we have set uniquely per VM)
331328 newContainer , err := client .NewContainer (ctx ,
332329 containerName ,
@@ -455,20 +452,13 @@ func TestMultipleVMs_Isolated(t *testing.T) {
455452
456453 stdoutLines := strings .Split (strings .TrimSpace (taskStdout .String ()), "\n " )
457454 lines := 2
458- if jailerConfig != nil {
459- lines = 1
460- }
461455 require .Len (t , stdoutLines , lines )
462456
463457 printedVMID := strings .TrimSpace (stdoutLines [0 ])
464- // TODO: Remove this if statement once we can add a netns which
465- // will allow firecracker to have visibility of the tap devices.
466- if jailerConfig == nil {
467- require .Equal (t , vmIDtoMacAddr (uint (vmID )), printedVMID , "unexpected VMID output from container %q" , containerName )
458+ require .Equal (t , vmIDtoMacAddr (uint (vmID )), printedVMID , "unexpected VMID output from container %q" , containerName )
468459
469- taskMntNS := strings .TrimSpace (stdoutLines [1 ])
470- require .Equal (t , execMntNS , taskMntNS , "unexpected mnt NS output from container %q" , containerName )
471- }
460+ taskMntNS := strings .TrimSpace (stdoutLines [1 ])
461+ require .Equal (t , execMntNS , taskMntNS , "unexpected mnt NS output from container %q" , containerName )
472462
473463 case <- ctx .Done ():
474464 require .Fail (t , "context cancelled" ,
0 commit comments