@@ -17,7 +17,6 @@ import (
1717 "context"
1818 "fmt"
1919 "strconv"
20- "sync"
2120 "testing"
2221 "time"
2322
@@ -29,6 +28,7 @@ import (
2928 "github.com/firecracker-microvm/firecracker-containerd/runtime/firecrackeroci"
3029 "github.com/firecracker-microvm/firecracker-containerd/snapshotter/internal/integtest/stargz/fs/source"
3130 "github.com/stretchr/testify/require"
31+ "golang.org/x/sync/errgroup"
3232)
3333
3434const (
@@ -58,7 +58,8 @@ func TestLaunchContainerWithRemoteSnapshotter_Isolated(t *testing.T) {
5858 ctx , cancel := context .WithTimeout (context .Background (), testTimeout )
5959 defer cancel ()
6060
61- launchContainerWithRemoteSnapshotterInVM (ctx , t , strconv .Itoa (vmID ))
61+ err := launchContainerWithRemoteSnapshotterInVM (ctx , strconv .Itoa (vmID ))
62+ require .NoError (t , err )
6263}
6364
6465func TestLaunchMultipleContainersWithRemoteSnapshotter_Isolated (t * testing.T ) {
@@ -68,33 +69,43 @@ func TestLaunchMultipleContainersWithRemoteSnapshotter_Isolated(t *testing.T) {
6869 ctx , cancel := context .WithTimeout (context .Background (), testTimeout )
6970 defer cancel ()
7071
71- var wg sync. WaitGroup
72+ eg , ctx := errgroup . WithContext ( ctx )
7273
7374 numberOfVms := integtest .NumberOfVms
7475 for vmID := 0 ; vmID < numberOfVms ; vmID ++ {
75- wg . Add ( 1 )
76- go func ( id int ) {
77- defer wg . Done ()
78- launchContainerWithRemoteSnapshotterInVM (ctx , t , strconv .Itoa (id ))
79- }( vmID )
76+ ctx := ctx
77+ id := vmID
78+ eg . Go ( func () error {
79+ return launchContainerWithRemoteSnapshotterInVM (ctx , strconv .Itoa (id ))
80+ })
8081 }
81- wg .Wait ()
82+ err := eg .Wait ()
83+ require .NoError (t , err )
8284}
8385
84- func launchContainerWithRemoteSnapshotterInVM (ctx context.Context , t * testing. T , vmID string ) {
86+ func launchContainerWithRemoteSnapshotterInVM (ctx context.Context , vmID string ) error {
8587 // For integration testing, assume the namespace is same as the VM ID.
8688 namespace := vmID
8789
8890 ctx = namespaces .WithNamespace (ctx , namespace )
8991
9092 client , err := containerd .New (integtest .ContainerdSockPath , containerd .WithDefaultRuntime (integtest .FirecrackerRuntime ))
91- require .NoError (t , err , "Unable to create client to containerd service at %s, is containerd running?" , integtest .ContainerdSockPath )
93+ if err != nil {
94+ return fmt .Errorf ("Unable to create client to containerd service at %s, is containerd running? [%v]" , integtest .ContainerdSockPath , err )
95+ }
9296
9397 fcClient , err := integtest .NewFCControlClient (integtest .ContainerdSockPath )
94- require .NoError (t , err , "Failed to create fccontrol client" )
98+ if err != nil {
99+ return fmt .Errorf ("Failed to create fccontrol client. [%v]" , err )
100+ }
101+
102+ // Disable 8250 serial device and lessen the number of log messages written to the serial console.
103+ // https://github.com/firecracker-microvm/firecracker/blob/v1.1.0/docs/prod-host-setup.md
104+ kernelArgs := integtest .DefaultRuntimeConfig .KernelArgs + " 8250.nr_uarts=0 quiet loglevel=1"
95105
96106 _ , err = fcClient .CreateVM (ctx , & proto.CreateVMRequest {
97- VMID : vmID ,
107+ VMID : vmID ,
108+ KernelArgs : kernelArgs ,
98109 RootDrive : & proto.FirecrackerRootDrive {
99110 HostPath : "/var/lib/firecracker-containerd/runtime/rootfs-stargz.img" ,
100111 },
@@ -111,23 +122,30 @@ func launchContainerWithRemoteSnapshotterInVM(ctx context.Context, t *testing.T,
111122 VcpuCount : 1 ,
112123 MemSizeMib : 1024 ,
113124 },
125+ TimeoutSeconds : 60 ,
114126 ContainerCount : 1 ,
115127 })
116- require .NoErrorf (t , err , "Failed to create microVM[%s]" , vmID )
128+ if err != nil {
129+ return fmt .Errorf ("Failed to create microVM[%s] [%v]" , vmID , err )
130+ }
117131 defer fcClient .StopVM (ctx , & proto.StopVMRequest {VMID : vmID })
118132
119133 _ , err = fcClient .SetVMMetadata (ctx , & proto.SetVMMetadataRequest {
120134 VMID : vmID ,
121135 Metadata : fmt .Sprintf (dockerMetadataTemplate , "ghcr.io" , noAuth , noAuth ),
122136 })
123- require .NoError (t , err , "Failed to configure VM metadata for registry resolution" )
137+ if err != nil {
138+ return fmt .Errorf ("Failed to configure VM metadata for registry resolution [%v]" , err )
139+ }
124140
125141 image , err := client .Pull (ctx , imageRef ,
126142 containerd .WithPullUnpack ,
127143 containerd .WithPullSnapshotter (snapshotterName ),
128144 containerd .WithImageHandlerWrapper (source .AppendDefaultLabelsHandlerWrapper (imageRef , 10 * 1024 * 1024 )),
129145 )
130- require .NoError (t , err , "Failed to pull image for VM: %s" , vmID )
146+ if err != nil {
147+ return fmt .Errorf ("Failed to pull image for VM: %s [%v]" , vmID , err )
148+ }
131149 defer client .ImageService ().Delete (ctx , image .Name ())
132150
133151 container , err := client .NewContainer (ctx , fmt .Sprintf ("container-%s" , vmID ),
@@ -141,9 +159,14 @@ func launchContainerWithRemoteSnapshotterInVM(ctx context.Context, t *testing.T,
141159 firecrackeroci .WithVMNetwork ,
142160 ),
143161 )
144- require .NoError (t , err , "Failed to create container in VM: %s" , vmID )
162+ if err != nil {
163+ return fmt .Errorf ("Failed to create container in VM: %s, [%v]" , vmID , err )
164+ }
145165 defer container .Delete (ctx , containerd .WithSnapshotCleanup )
146166
147167 _ , err = integtest .RunTask (ctx , container )
148- require .NoError (t , err , "Failed to run task in VM: %s" , vmID )
168+ if err != nil {
169+ return fmt .Errorf ("Failed to run task in VM: %s [%v]" , vmID , err )
170+ }
171+ return nil
149172}
0 commit comments