@@ -17,7 +17,6 @@ import (
17
17
"context"
18
18
"fmt"
19
19
"strconv"
20
- "sync"
21
20
"testing"
22
21
"time"
23
22
@@ -29,6 +28,7 @@ import (
29
28
"github.com/firecracker-microvm/firecracker-containerd/runtime/firecrackeroci"
30
29
"github.com/firecracker-microvm/firecracker-containerd/snapshotter/internal/integtest/stargz/fs/source"
31
30
"github.com/stretchr/testify/require"
31
+ "golang.org/x/sync/errgroup"
32
32
)
33
33
34
34
const (
@@ -58,7 +58,8 @@ func TestLaunchContainerWithRemoteSnapshotter_Isolated(t *testing.T) {
58
58
ctx , cancel := context .WithTimeout (context .Background (), testTimeout )
59
59
defer cancel ()
60
60
61
- launchContainerWithRemoteSnapshotterInVM (ctx , t , strconv .Itoa (vmID ))
61
+ err := launchContainerWithRemoteSnapshotterInVM (ctx , strconv .Itoa (vmID ))
62
+ require .NoError (t , err )
62
63
}
63
64
64
65
func TestLaunchMultipleContainersWithRemoteSnapshotter_Isolated (t * testing.T ) {
@@ -68,33 +69,43 @@ func TestLaunchMultipleContainersWithRemoteSnapshotter_Isolated(t *testing.T) {
68
69
ctx , cancel := context .WithTimeout (context .Background (), testTimeout )
69
70
defer cancel ()
70
71
71
- var wg sync. WaitGroup
72
+ eg , ctx := errgroup . WithContext ( ctx )
72
73
73
74
numberOfVms := integtest .NumberOfVms
74
75
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
+ })
80
81
}
81
- wg .Wait ()
82
+ err := eg .Wait ()
83
+ require .NoError (t , err )
82
84
}
83
85
84
- func launchContainerWithRemoteSnapshotterInVM (ctx context.Context , t * testing. T , vmID string ) {
86
+ func launchContainerWithRemoteSnapshotterInVM (ctx context.Context , vmID string ) error {
85
87
// For integration testing, assume the namespace is same as the VM ID.
86
88
namespace := vmID
87
89
88
90
ctx = namespaces .WithNamespace (ctx , namespace )
89
91
90
92
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
+ }
92
96
93
97
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"
95
105
96
106
_ , err = fcClient .CreateVM (ctx , & proto.CreateVMRequest {
97
- VMID : vmID ,
107
+ VMID : vmID ,
108
+ KernelArgs : kernelArgs ,
98
109
RootDrive : & proto.FirecrackerRootDrive {
99
110
HostPath : "/var/lib/firecracker-containerd/runtime/rootfs-stargz.img" ,
100
111
},
@@ -111,23 +122,30 @@ func launchContainerWithRemoteSnapshotterInVM(ctx context.Context, t *testing.T,
111
122
VcpuCount : 1 ,
112
123
MemSizeMib : 1024 ,
113
124
},
125
+ TimeoutSeconds : 60 ,
114
126
ContainerCount : 1 ,
115
127
})
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
+ }
117
131
defer fcClient .StopVM (ctx , & proto.StopVMRequest {VMID : vmID })
118
132
119
133
_ , err = fcClient .SetVMMetadata (ctx , & proto.SetVMMetadataRequest {
120
134
VMID : vmID ,
121
135
Metadata : fmt .Sprintf (dockerMetadataTemplate , "ghcr.io" , noAuth , noAuth ),
122
136
})
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
+ }
124
140
125
141
image , err := client .Pull (ctx , imageRef ,
126
142
containerd .WithPullUnpack ,
127
143
containerd .WithPullSnapshotter (snapshotterName ),
128
144
containerd .WithImageHandlerWrapper (source .AppendDefaultLabelsHandlerWrapper (imageRef , 10 * 1024 * 1024 )),
129
145
)
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
+ }
131
149
defer client .ImageService ().Delete (ctx , image .Name ())
132
150
133
151
container , err := client .NewContainer (ctx , fmt .Sprintf ("container-%s" , vmID ),
@@ -141,9 +159,14 @@ func launchContainerWithRemoteSnapshotterInVM(ctx context.Context, t *testing.T,
141
159
firecrackeroci .WithVMNetwork ,
142
160
),
143
161
)
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
+ }
145
165
defer container .Delete (ctx , containerd .WithSnapshotCleanup )
146
166
147
167
_ , 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
149
172
}
0 commit comments