@@ -62,17 +62,12 @@ func TestFindNextAvailableVsockCID_Isolated(t *testing.T) {
62
62
63
63
func TestBuildVMConfiguration (t * testing.T ) {
64
64
namespace := "TestBuildVMConfiguration"
65
- rootfsDrive := models.Drive {
66
- DriveID : firecracker .String ("stub0" ),
67
- PathOnHost : nil , // will be populated in the for loop
68
- IsReadOnly : firecracker .Bool (false ),
69
- IsRootDevice : firecracker .Bool (false ),
70
- }
71
65
testcases := []struct {
72
- name string
73
- request * proto.CreateVMRequest
74
- config * Config
75
- expectedCfg * firecracker.Config
66
+ name string
67
+ request * proto.CreateVMRequest
68
+ config * Config
69
+ expectedCfg * firecracker.Config
70
+ expectedStubDriveCount int
76
71
}{
77
72
{
78
73
name : "ConfigFile" ,
@@ -88,7 +83,6 @@ func TestBuildVMConfiguration(t *testing.T) {
88
83
KernelArgs : "KERNEL ARGS" ,
89
84
KernelImagePath : "KERNEL IMAGE" ,
90
85
Drives : []models.Drive {
91
- rootfsDrive ,
92
86
{
93
87
DriveID : firecracker .String ("root_drive" ),
94
88
PathOnHost : firecracker .String ("ROOT DRIVE" ),
@@ -103,6 +97,7 @@ func TestBuildVMConfiguration(t *testing.T) {
103
97
HtEnabled : firecracker .Bool (false ),
104
98
},
105
99
},
100
+ expectedStubDriveCount : 1 ,
106
101
},
107
102
{
108
103
name : "Input" ,
@@ -122,7 +117,6 @@ func TestBuildVMConfiguration(t *testing.T) {
122
117
KernelArgs : "REQUEST KERNEL ARGS" ,
123
118
KernelImagePath : "REQUEST KERNEL IMAGE" ,
124
119
Drives : []models.Drive {
125
- rootfsDrive ,
126
120
{
127
121
DriveID : firecracker .String ("root_drive" ),
128
122
PathOnHost : firecracker .String ("REQUEST ROOT DRIVE" ),
@@ -137,6 +131,7 @@ func TestBuildVMConfiguration(t *testing.T) {
137
131
HtEnabled : firecracker .Bool (false ),
138
132
},
139
133
},
134
+ expectedStubDriveCount : 1 ,
140
135
},
141
136
{
142
137
name : "Priority" ,
@@ -160,7 +155,6 @@ func TestBuildVMConfiguration(t *testing.T) {
160
155
KernelArgs : "REQUEST KERNEL ARGS" ,
161
156
KernelImagePath : "KERNEL IMAGE" ,
162
157
Drives : []models.Drive {
163
- rootfsDrive ,
164
158
{
165
159
DriveID : firecracker .String ("root_drive" ),
166
160
PathOnHost : firecracker .String ("REQUEST ROOT DRIVE" ),
@@ -175,6 +169,37 @@ func TestBuildVMConfiguration(t *testing.T) {
175
169
HtEnabled : firecracker .Bool (false ),
176
170
},
177
171
},
172
+ expectedStubDriveCount : 1 ,
173
+ },
174
+ {
175
+ name : "Container Count" ,
176
+ request : & proto.CreateVMRequest {ContainerCount : 2 },
177
+ config : & Config {
178
+ KernelArgs : "KERNEL ARGS" ,
179
+ KernelImagePath : "KERNEL IMAGE" ,
180
+ RootDrive : "ROOT DRIVE" ,
181
+ CPUTemplate : "C3" ,
182
+ CPUCount : 2 ,
183
+ },
184
+ expectedCfg : & firecracker.Config {
185
+ KernelArgs : "KERNEL ARGS" ,
186
+ KernelImagePath : "KERNEL IMAGE" ,
187
+ Drives : []models.Drive {
188
+ {
189
+ DriveID : firecracker .String ("root_drive" ),
190
+ PathOnHost : firecracker .String ("ROOT DRIVE" ),
191
+ IsReadOnly : firecracker .Bool (false ),
192
+ IsRootDevice : firecracker .Bool (true ),
193
+ },
194
+ },
195
+ MachineCfg : models.MachineConfiguration {
196
+ CPUTemplate : models .CPUTemplateC3 ,
197
+ VcpuCount : firecracker .Int64 (2 ),
198
+ MemSizeMib : firecracker .Int64 (defaultMemSizeMb ),
199
+ HtEnabled : firecracker .Bool (false ),
200
+ },
201
+ },
202
+ expectedStubDriveCount : 2 ,
178
203
},
179
204
}
180
205
@@ -197,11 +222,21 @@ func TestBuildVMConfiguration(t *testing.T) {
197
222
tc .expectedCfg .VsockDevices = []firecracker.VsockDevice {{Path : "root" , CID : svc .machineCID }}
198
223
tc .expectedCfg .LogFifo = svc .shimDir .FirecrackerLogFifoPath ()
199
224
tc .expectedCfg .MetricsFifo = svc .shimDir .FirecrackerMetricsFifoPath ()
200
- tc .expectedCfg .Drives [0 ].PathOnHost = firecracker .String (filepath .Join (tempDir , "stub0" ))
225
+
226
+ drives := make ([]models.Drive , tc .expectedStubDriveCount )
227
+ for i := 0 ; i < tc .expectedStubDriveCount ; i ++ {
228
+ drives [i ].PathOnHost = firecracker .String (filepath .Join (tempDir , fmt .Sprintf ("stub%d" , i )))
229
+ drives [i ].DriveID = firecracker .String (fmt .Sprintf ("stub%d" , i ))
230
+ drives [i ].IsReadOnly = firecracker .Bool (false )
231
+ drives [i ].IsRootDevice = firecracker .Bool (false )
232
+ }
233
+ tc .expectedCfg .Drives = append (drives , tc .expectedCfg .Drives ... )
201
234
202
235
actualCfg , err := svc .buildVMConfiguration (tc .request )
203
236
assert .NoError (t , err )
204
237
require .Equal (t , tc .expectedCfg , actualCfg )
238
+
239
+ require .Equal (t , tc .expectedStubDriveCount , len (svc .stubDriveHandler .drives ), "The stub driver only knows stub drives" )
205
240
})
206
241
}
207
242
}
0 commit comments