@@ -19,7 +19,6 @@ import (
19
19
"errors"
20
20
"flag"
21
21
"fmt"
22
- "github.com/vishvananda/netns"
23
22
"io"
24
23
"io/ioutil"
25
24
"net"
@@ -35,6 +34,8 @@ import (
35
34
"testing"
36
35
"time"
37
36
37
+ "github.com/vishvananda/netns"
38
+
38
39
"github.com/containerd/fifo"
39
40
"github.com/sirupsen/logrus"
40
41
"github.com/stretchr/testify/assert"
@@ -44,6 +45,7 @@ import (
44
45
models "github.com/firecracker-microvm/firecracker-go-sdk/client/models"
45
46
ops "github.com/firecracker-microvm/firecracker-go-sdk/client/operations"
46
47
"github.com/firecracker-microvm/firecracker-go-sdk/fctesting"
48
+ "github.com/firecracker-microvm/firecracker-go-sdk/internal"
47
49
)
48
50
49
51
const (
@@ -114,10 +116,9 @@ func TestNewMachine(t *testing.T) {
114
116
Config {
115
117
DisableValidation : true ,
116
118
MachineCfg : models.MachineConfiguration {
117
- VcpuCount : Int64 (1 ),
118
- MemSizeMib : Int64 (100 ),
119
- CPUTemplate : models .CPUTemplate (models .CPUTemplateT2 ),
120
- Smt : Bool (false ),
119
+ VcpuCount : Int64 (1 ),
120
+ MemSizeMib : Int64 (100 ),
121
+ Smt : Bool (false ),
121
122
},
122
123
},
123
124
WithLogger (fctesting .NewLogEntry (t )))
@@ -172,7 +173,6 @@ func TestJailerMicroVMExecution(t *testing.T) {
172
173
}
173
174
174
175
var nCpus int64 = 2
175
- cpuTemplate := models .CPUTemplate (models .CPUTemplateT2 )
176
176
var memSz int64 = 256
177
177
178
178
// short names and directory to prevent SUN_LEN error
@@ -210,10 +210,9 @@ func TestJailerMicroVMExecution(t *testing.T) {
210
210
LogLevel : "Debug" ,
211
211
KernelImagePath : vmlinuxPath ,
212
212
MachineCfg : models.MachineConfiguration {
213
- VcpuCount : Int64 (nCpus ),
214
- CPUTemplate : cpuTemplate ,
215
- MemSizeMib : Int64 (memSz ),
216
- Smt : Bool (false ),
213
+ VcpuCount : Int64 (nCpus ),
214
+ MemSizeMib : Int64 (memSz ),
215
+ Smt : Bool (false ),
217
216
},
218
217
Drives : []models.Drive {
219
218
{
@@ -296,7 +295,6 @@ func TestMicroVMExecution(t *testing.T) {
296
295
fctesting .RequiresKVM (t )
297
296
298
297
var nCpus int64 = 2
299
- cpuTemplate := models .CPUTemplate (models .CPUTemplateT2 )
300
298
var memSz int64 = 256
301
299
302
300
dir , err := ioutil .TempDir ("" , t .Name ())
@@ -326,10 +324,9 @@ func TestMicroVMExecution(t *testing.T) {
326
324
MetricsFifo : metricsFifo ,
327
325
LogLevel : "Debug" ,
328
326
MachineCfg : models.MachineConfiguration {
329
- VcpuCount : Int64 (nCpus ),
330
- CPUTemplate : cpuTemplate ,
331
- MemSizeMib : Int64 (memSz ),
332
- Smt : Bool (false ),
327
+ VcpuCount : Int64 (nCpus ),
328
+ MemSizeMib : Int64 (memSz ),
329
+ Smt : Bool (false ),
333
330
},
334
331
DisableValidation : true ,
335
332
NetworkInterfaces : networkIfaces ,
@@ -498,10 +495,9 @@ func testLogAndMetrics(t *testing.T, logLevel string) string {
498
495
DisableValidation : true ,
499
496
KernelImagePath : getVmlinuxPath (t ),
500
497
MachineCfg : models.MachineConfiguration {
501
- VcpuCount : Int64 (1 ),
502
- MemSizeMib : Int64 (64 ),
503
- CPUTemplate : models .CPUTemplate (models .CPUTemplateT2 ),
504
- Smt : Bool (false ),
498
+ VcpuCount : Int64 (1 ),
499
+ MemSizeMib : Int64 (64 ),
500
+ Smt : Bool (false ),
505
501
},
506
502
MetricsPath : filepath .Join (dir , "fc-metrics.out" ),
507
503
LogPath : filepath .Join (dir , "fc.log" ),
@@ -553,12 +549,14 @@ func TestStartVMMOnce(t *testing.T) {
553
549
DisableValidation : true ,
554
550
KernelImagePath : getVmlinuxPath (t ),
555
551
MachineCfg : models.MachineConfiguration {
556
- VcpuCount : Int64 (1 ),
557
- MemSizeMib : Int64 (64 ),
558
- CPUTemplate : models .CPUTemplate (models .CPUTemplateT2 ),
559
- Smt : Bool (false ),
552
+ VcpuCount : Int64 (1 ),
553
+ MemSizeMib : Int64 (64 ),
554
+ Smt : Bool (false ),
560
555
},
561
556
}
557
+ if cpu_temp , err := internal .SupportCPUTemplate (); cpu_temp && err == nil {
558
+ cfg .MachineCfg .CPUTemplate = models .CPUTemplate (models .CPUTemplateT2 )
559
+ }
562
560
ctx := context .Background ()
563
561
cmd := VMCommandBuilder {}.
564
562
WithSocketPath (cfg .SocketPath ).
@@ -844,10 +842,9 @@ func TestStopVMMCleanup(t *testing.T) {
844
842
KernelImagePath : getVmlinuxPath (t ),
845
843
NetworkInterfaces : []NetworkInterface {networkInterface },
846
844
MachineCfg : models.MachineConfiguration {
847
- VcpuCount : Int64 (1 ),
848
- MemSizeMib : Int64 (64 ),
849
- CPUTemplate : models .CPUTemplate (models .CPUTemplateT2 ),
850
- Smt : Bool (false ),
845
+ VcpuCount : Int64 (1 ),
846
+ MemSizeMib : Int64 (64 ),
847
+ Smt : Bool (false ),
851
848
},
852
849
}
853
850
ctx := context .Background ()
@@ -939,7 +936,6 @@ func TestMicroVMExecutionWithMmdsV2(t *testing.T) {
939
936
fctesting .RequiresKVM (t )
940
937
941
938
var nCpus int64 = 2
942
- cpuTemplate := models .CPUTemplate (models .CPUTemplateT2 )
943
939
var memSz int64 = 256
944
940
945
941
dir , err := ioutil .TempDir ("" , t .Name ())
@@ -969,10 +965,9 @@ func TestMicroVMExecutionWithMmdsV2(t *testing.T) {
969
965
MetricsFifo : metricsFifo ,
970
966
LogLevel : "Debug" ,
971
967
MachineCfg : models.MachineConfiguration {
972
- VcpuCount : Int64 (nCpus ),
973
- CPUTemplate : cpuTemplate ,
974
- MemSizeMib : Int64 (memSz ),
975
- Smt : Bool (false ),
968
+ VcpuCount : Int64 (nCpus ),
969
+ MemSizeMib : Int64 (memSz ),
970
+ Smt : Bool (false ),
976
971
},
977
972
DisableValidation : true ,
978
973
NetworkInterfaces : networkIfaces ,
@@ -1344,7 +1339,6 @@ func TestPID(t *testing.T) {
1344
1339
defer os .RemoveAll (dir )
1345
1340
1346
1341
var nCpus int64 = 2
1347
- cpuTemplate := models .CPUTemplate (models .CPUTemplateT2 )
1348
1342
var memSz int64 = 256
1349
1343
socketPath := filepath .Join (dir , "TestPID.sock" )
1350
1344
defer os .Remove (socketPath )
@@ -1361,10 +1355,9 @@ func TestPID(t *testing.T) {
1361
1355
SocketPath : socketPath ,
1362
1356
KernelImagePath : vmlinuxPath ,
1363
1357
MachineCfg : models.MachineConfiguration {
1364
- VcpuCount : Int64 (nCpus ),
1365
- CPUTemplate : cpuTemplate ,
1366
- MemSizeMib : Int64 (memSz ),
1367
- Smt : Bool (false ),
1358
+ VcpuCount : Int64 (nCpus ),
1359
+ MemSizeMib : Int64 (memSz ),
1360
+ Smt : Bool (false ),
1368
1361
},
1369
1362
Drives : []models.Drive {
1370
1363
{
@@ -1675,10 +1668,9 @@ func createValidConfig(t *testing.T, socketPath string, opts ...machineConfigOpt
1675
1668
SocketPath : socketPath ,
1676
1669
KernelImagePath : getVmlinuxPath (t ),
1677
1670
MachineCfg : models.MachineConfiguration {
1678
- VcpuCount : Int64 (2 ),
1679
- CPUTemplate : models .CPUTemplate (models .CPUTemplateT2 ),
1680
- MemSizeMib : Int64 (256 ),
1681
- Smt : Bool (false ),
1671
+ VcpuCount : Int64 (2 ),
1672
+ MemSizeMib : Int64 (256 ),
1673
+ Smt : Bool (false ),
1682
1674
},
1683
1675
Drives : []models.Drive {
1684
1676
{
0 commit comments