@@ -19,7 +19,6 @@ import (
1919 "errors"
2020 "flag"
2121 "fmt"
22- "github.com/vishvananda/netns"
2322 "io"
2423 "io/ioutil"
2524 "net"
@@ -35,6 +34,8 @@ import (
3534 "testing"
3635 "time"
3736
37+ "github.com/vishvananda/netns"
38+
3839 "github.com/containerd/fifo"
3940 "github.com/sirupsen/logrus"
4041 "github.com/stretchr/testify/assert"
@@ -44,6 +45,7 @@ import (
4445 models "github.com/firecracker-microvm/firecracker-go-sdk/client/models"
4546 ops "github.com/firecracker-microvm/firecracker-go-sdk/client/operations"
4647 "github.com/firecracker-microvm/firecracker-go-sdk/fctesting"
48+ "github.com/firecracker-microvm/firecracker-go-sdk/internal"
4749)
4850
4951const (
@@ -114,10 +116,9 @@ func TestNewMachine(t *testing.T) {
114116 Config {
115117 DisableValidation : true ,
116118 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 ),
121122 },
122123 },
123124 WithLogger (fctesting .NewLogEntry (t )))
@@ -172,7 +173,6 @@ func TestJailerMicroVMExecution(t *testing.T) {
172173 }
173174
174175 var nCpus int64 = 2
175- cpuTemplate := models .CPUTemplate (models .CPUTemplateT2 )
176176 var memSz int64 = 256
177177
178178 // short names and directory to prevent SUN_LEN error
@@ -210,10 +210,9 @@ func TestJailerMicroVMExecution(t *testing.T) {
210210 LogLevel : "Debug" ,
211211 KernelImagePath : vmlinuxPath ,
212212 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 ),
217216 },
218217 Drives : []models.Drive {
219218 {
@@ -296,7 +295,6 @@ func TestMicroVMExecution(t *testing.T) {
296295 fctesting .RequiresKVM (t )
297296
298297 var nCpus int64 = 2
299- cpuTemplate := models .CPUTemplate (models .CPUTemplateT2 )
300298 var memSz int64 = 256
301299
302300 dir , err := ioutil .TempDir ("" , t .Name ())
@@ -326,10 +324,9 @@ func TestMicroVMExecution(t *testing.T) {
326324 MetricsFifo : metricsFifo ,
327325 LogLevel : "Debug" ,
328326 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 ),
333330 },
334331 DisableValidation : true ,
335332 NetworkInterfaces : networkIfaces ,
@@ -498,10 +495,9 @@ func testLogAndMetrics(t *testing.T, logLevel string) string {
498495 DisableValidation : true ,
499496 KernelImagePath : getVmlinuxPath (t ),
500497 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 ),
505501 },
506502 MetricsPath : filepath .Join (dir , "fc-metrics.out" ),
507503 LogPath : filepath .Join (dir , "fc.log" ),
@@ -553,12 +549,14 @@ func TestStartVMMOnce(t *testing.T) {
553549 DisableValidation : true ,
554550 KernelImagePath : getVmlinuxPath (t ),
555551 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 ),
560555 },
561556 }
557+ if cpu_temp , err := internal .SupportCPUTemplate (); cpu_temp && err == nil {
558+ cfg .MachineCfg .CPUTemplate = models .CPUTemplate (models .CPUTemplateT2 )
559+ }
562560 ctx := context .Background ()
563561 cmd := VMCommandBuilder {}.
564562 WithSocketPath (cfg .SocketPath ).
@@ -844,10 +842,9 @@ func TestStopVMMCleanup(t *testing.T) {
844842 KernelImagePath : getVmlinuxPath (t ),
845843 NetworkInterfaces : []NetworkInterface {networkInterface },
846844 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 ),
851848 },
852849 }
853850 ctx := context .Background ()
@@ -939,7 +936,6 @@ func TestMicroVMExecutionWithMmdsV2(t *testing.T) {
939936 fctesting .RequiresKVM (t )
940937
941938 var nCpus int64 = 2
942- cpuTemplate := models .CPUTemplate (models .CPUTemplateT2 )
943939 var memSz int64 = 256
944940
945941 dir , err := ioutil .TempDir ("" , t .Name ())
@@ -969,10 +965,9 @@ func TestMicroVMExecutionWithMmdsV2(t *testing.T) {
969965 MetricsFifo : metricsFifo ,
970966 LogLevel : "Debug" ,
971967 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 ),
976971 },
977972 DisableValidation : true ,
978973 NetworkInterfaces : networkIfaces ,
@@ -1344,7 +1339,6 @@ func TestPID(t *testing.T) {
13441339 defer os .RemoveAll (dir )
13451340
13461341 var nCpus int64 = 2
1347- cpuTemplate := models .CPUTemplate (models .CPUTemplateT2 )
13481342 var memSz int64 = 256
13491343 socketPath := filepath .Join (dir , "TestPID.sock" )
13501344 defer os .Remove (socketPath )
@@ -1361,10 +1355,9 @@ func TestPID(t *testing.T) {
13611355 SocketPath : socketPath ,
13621356 KernelImagePath : vmlinuxPath ,
13631357 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 ),
13681361 },
13691362 Drives : []models.Drive {
13701363 {
@@ -1675,10 +1668,9 @@ func createValidConfig(t *testing.T, socketPath string, opts ...machineConfigOpt
16751668 SocketPath : socketPath ,
16761669 KernelImagePath : getVmlinuxPath (t ),
16771670 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 ),
16821674 },
16831675 Drives : []models.Drive {
16841676 {
0 commit comments