@@ -355,6 +355,9 @@ func testMultipleVMs(ctx context.Context, t *testing.T, count int) {
355
355
stopped int64
356
356
)
357
357
358
+ gen , err := integtest .NewVMIDGen ()
359
+ require .NoError (t , err , "Failed to create a VMIDGen" )
360
+
358
361
// This test spawns separate VMs in parallel and ensures containers are spawned within each expected VM. It asserts each
359
362
// container ends up in the right VM by assigning each VM a network device with a unique mac address and having each container
360
363
// print the mac address it sees inside its VM.
@@ -371,7 +374,7 @@ func testMultipleVMs(ctx context.Context, t *testing.T, count int) {
371
374
372
375
rootfsPath := cfg .RootDrive
373
376
374
- vmIDStr := strconv . Itoa (vmID )
377
+ vmIDStr := gen . VMID (vmID )
375
378
req := & proto.CreateVMRequest {
376
379
KernelArgs : kernelArgs ,
377
380
VMID : vmIDStr ,
@@ -426,6 +429,7 @@ func testMultipleVMs(ctx context.Context, t *testing.T, count int) {
426
429
return testMultipleExecs (
427
430
containerCtx ,
428
431
vmID ,
432
+ gen ,
429
433
containerID ,
430
434
client , image ,
431
435
jailerConfig ,
@@ -435,21 +439,21 @@ func testMultipleVMs(ctx context.Context, t *testing.T, count int) {
435
439
}
436
440
437
441
// verify duplicate CreateVM call fails with right error
438
- _ , err = fcClient .CreateVM (ctx , & proto.CreateVMRequest {VMID : strconv . Itoa ( vmID ) })
442
+ _ , err = fcClient .CreateVM (ctx , & proto.CreateVMRequest {VMID : vmIDStr })
439
443
if err == nil {
440
444
return fmt .Errorf ("creating the same VM must return an error" )
441
445
}
442
446
443
447
// verify GetVMInfo returns expected data
444
- vmInfoResp , err := fcClient .GetVMInfo (ctx , & proto.GetVMInfoRequest {VMID : strconv . Itoa ( vmID ) })
448
+ vmInfoResp , err := fcClient .GetVMInfo (ctx , & proto.GetVMInfoRequest {VMID : vmIDStr })
445
449
if err != nil {
446
450
return err
447
451
}
448
- if vmInfoResp .VMID != strconv . Itoa ( vmID ) {
449
- return fmt .Errorf ("%q must be %q" , vmInfoResp .VMID , strconv . Itoa ( vmID ) )
452
+ if vmInfoResp .VMID != vmIDStr {
453
+ return fmt .Errorf ("%q must be %q" , vmInfoResp .VMID , vmIDStr )
450
454
}
451
455
452
- nspVMid := defaultNamespace + "#" + strconv . Itoa ( vmID )
456
+ nspVMid := defaultNamespace + "#" + vmIDStr
453
457
cfg , err := config .LoadConfig ("" )
454
458
if err != nil {
455
459
return err
@@ -465,7 +469,7 @@ func testMultipleVMs(ctx context.Context, t *testing.T, count int) {
465
469
// just verify that updating the metadata doesn't return an error, a separate test case is needed
466
470
// to very the MMDS update propagates to the container correctly
467
471
_ , err = fcClient .SetVMMetadata (ctx , & proto.SetVMMetadataRequest {
468
- VMID : strconv . Itoa ( vmID ) ,
472
+ VMID : vmIDStr ,
469
473
Metadata : "{}" ,
470
474
})
471
475
if err != nil {
@@ -477,7 +481,7 @@ func testMultipleVMs(ctx context.Context, t *testing.T, count int) {
477
481
return fmt .Errorf ("unexpected error from the containers in VM %d: %w" , vmID , err )
478
482
}
479
483
480
- _ , err = fcClient .StopVM (ctx , & proto.StopVMRequest {VMID : strconv . Itoa ( vmID ) , TimeoutSeconds : 5 })
484
+ _ , err = fcClient .StopVM (ctx , & proto.StopVMRequest {VMID : vmIDStr , TimeoutSeconds : 5 })
481
485
atomic .AddInt64 (& stopped , 1 )
482
486
return err
483
487
}
@@ -515,13 +519,14 @@ loop:
515
519
func testMultipleExecs (
516
520
ctx context.Context ,
517
521
vmID int ,
522
+ gen * integtest.VMIDGen ,
518
523
containerID int ,
519
524
client * containerd.Client ,
520
525
image containerd.Image ,
521
526
jailerConfig * proto.JailerConfig ,
522
527
cgroupPath string ,
523
528
) error {
524
- vmIDStr := strconv . Itoa (vmID )
529
+ vmIDStr := gen . VMID (vmID )
525
530
testTimeout := 600 * time .Second
526
531
527
532
containerName := fmt .Sprintf ("container-%d-%d" , vmID , containerID )
@@ -826,6 +831,9 @@ func TestStubBlockDevices_Isolated(t *testing.T) {
826
831
827
832
const vmID = 0
828
833
834
+ gen , err := integtest .NewVMIDGen ()
835
+ require .NoError (t , err , "failed to create VMIDGen" )
836
+
829
837
ctx := namespaces .WithNamespace (context .Background (), "default" )
830
838
831
839
client , err := containerd .New (integtest .ContainerdSockPath , containerd .WithDefaultRuntime (firecrackerRuntime ))
@@ -846,7 +854,7 @@ func TestStubBlockDevices_Isolated(t *testing.T) {
846
854
require .NoError (t , err , "failed to create fccontrol client" )
847
855
848
856
_ , err = fcClient .CreateVM (ctx , & proto.CreateVMRequest {
849
- VMID : strconv . Itoa (vmID ),
857
+ VMID : gen . VMID (vmID ),
850
858
NetworkInterfaces : []* proto.FirecrackerNetworkInterface {
851
859
{
852
860
AllowMMDS : true ,
@@ -865,7 +873,7 @@ func TestStubBlockDevices_Isolated(t *testing.T) {
865
873
containerd .WithSnapshotter (defaultSnapshotterName ),
866
874
containerd .WithNewSnapshot (snapshotName , image ),
867
875
containerd .WithNewSpec (
868
- firecrackeroci .WithVMID (strconv . Itoa (vmID )),
876
+ firecrackeroci .WithVMID (gen . VMID (vmID )),
869
877
oci .WithProcessArgs ("/bin/sh" , "/var/firecracker-containerd-test/scripts/lsblk.sh" ),
870
878
871
879
oci .WithMounts ([]specs.Mount {
@@ -1447,6 +1455,9 @@ func TestMemoryBalloon_Isolated(t *testing.T) {
1447
1455
}
1448
1456
t .Logf ("TestMemoryBalloon_Isolated: will run %d vm's" , numberOfVms )
1449
1457
1458
+ gen , err := integtest .NewVMIDGen ()
1459
+ require .NoError (t , err , "Failed to create a VMIDGen" )
1460
+
1450
1461
var vmGroup sync.WaitGroup
1451
1462
for i := 0 ; i < numberOfVms ; i ++ {
1452
1463
vmGroup .Add (1 )
@@ -1462,7 +1473,7 @@ func TestMemoryBalloon_Isolated(t *testing.T) {
1462
1473
require .NoError (t , err , "failed to create fccontrol client" )
1463
1474
1464
1475
_ , err = fcClient .CreateVM (ctx , & proto.CreateVMRequest {
1465
- VMID : strconv . Itoa (vmID ),
1476
+ VMID : gen . VMID (vmID ),
1466
1477
MachineCfg : & proto.FirecrackerMachineConfiguration {
1467
1478
MemSizeMib : 512 ,
1468
1479
},
@@ -1484,7 +1495,7 @@ func TestMemoryBalloon_Isolated(t *testing.T) {
1484
1495
require .NoError (t , err , "failed to create vm" )
1485
1496
1486
1497
// Test UpdateBalloon correctly updates amount of memory for the balloon device
1487
- vmIDStr := strconv . Itoa (vmID )
1498
+ vmIDStr := gen . VMID (vmID )
1488
1499
newAmountMib := int64 (50 )
1489
1500
_ , err = fcClient .UpdateBalloon (ctx , & proto.UpdateBalloonRequest {
1490
1501
VMID : vmIDStr ,
0 commit comments