@@ -355,6 +355,9 @@ func testMultipleVMs(ctx context.Context, t *testing.T, count int) {
355355 stopped int64
356356 )
357357
358+ gen , err := integtest .NewVMIDGen ()
359+ require .NoError (t , err , "Failed to create a VMIDGen" )
360+
358361 // This test spawns separate VMs in parallel and ensures containers are spawned within each expected VM. It asserts each
359362 // container ends up in the right VM by assigning each VM a network device with a unique mac address and having each container
360363 // print the mac address it sees inside its VM.
@@ -371,7 +374,7 @@ func testMultipleVMs(ctx context.Context, t *testing.T, count int) {
371374
372375 rootfsPath := cfg .RootDrive
373376
374- vmIDStr := strconv . Itoa (vmID )
377+ vmIDStr := gen . VMID (vmID )
375378 req := & proto.CreateVMRequest {
376379 KernelArgs : kernelArgs ,
377380 VMID : vmIDStr ,
@@ -426,6 +429,7 @@ func testMultipleVMs(ctx context.Context, t *testing.T, count int) {
426429 return testMultipleExecs (
427430 containerCtx ,
428431 vmID ,
432+ gen ,
429433 containerID ,
430434 client , image ,
431435 jailerConfig ,
@@ -435,21 +439,21 @@ func testMultipleVMs(ctx context.Context, t *testing.T, count int) {
435439 }
436440
437441 // 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 })
439443 if err == nil {
440444 return fmt .Errorf ("creating the same VM must return an error" )
441445 }
442446
443447 // 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 })
445449 if err != nil {
446450 return err
447451 }
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 )
450454 }
451455
452- nspVMid := defaultNamespace + "#" + strconv . Itoa ( vmID )
456+ nspVMid := defaultNamespace + "#" + vmIDStr
453457 cfg , err := config .LoadConfig ("" )
454458 if err != nil {
455459 return err
@@ -465,7 +469,7 @@ func testMultipleVMs(ctx context.Context, t *testing.T, count int) {
465469 // just verify that updating the metadata doesn't return an error, a separate test case is needed
466470 // to very the MMDS update propagates to the container correctly
467471 _ , err = fcClient .SetVMMetadata (ctx , & proto.SetVMMetadataRequest {
468- VMID : strconv . Itoa ( vmID ) ,
472+ VMID : vmIDStr ,
469473 Metadata : "{}" ,
470474 })
471475 if err != nil {
@@ -477,7 +481,7 @@ func testMultipleVMs(ctx context.Context, t *testing.T, count int) {
477481 return fmt .Errorf ("unexpected error from the containers in VM %d: %w" , vmID , err )
478482 }
479483
480- _ , err = fcClient .StopVM (ctx , & proto.StopVMRequest {VMID : strconv . Itoa ( vmID ) , TimeoutSeconds : 5 })
484+ _ , err = fcClient .StopVM (ctx , & proto.StopVMRequest {VMID : vmIDStr , TimeoutSeconds : 5 })
481485 atomic .AddInt64 (& stopped , 1 )
482486 return err
483487 }
@@ -515,13 +519,14 @@ loop:
515519func testMultipleExecs (
516520 ctx context.Context ,
517521 vmID int ,
522+ gen * integtest.VMIDGen ,
518523 containerID int ,
519524 client * containerd.Client ,
520525 image containerd.Image ,
521526 jailerConfig * proto.JailerConfig ,
522527 cgroupPath string ,
523528) error {
524- vmIDStr := strconv . Itoa (vmID )
529+ vmIDStr := gen . VMID (vmID )
525530 testTimeout := 600 * time .Second
526531
527532 containerName := fmt .Sprintf ("container-%d-%d" , vmID , containerID )
@@ -826,6 +831,9 @@ func TestStubBlockDevices_Isolated(t *testing.T) {
826831
827832 const vmID = 0
828833
834+ gen , err := integtest .NewVMIDGen ()
835+ require .NoError (t , err , "failed to create VMIDGen" )
836+
829837 ctx := namespaces .WithNamespace (context .Background (), "default" )
830838
831839 client , err := containerd .New (integtest .ContainerdSockPath , containerd .WithDefaultRuntime (firecrackerRuntime ))
@@ -846,7 +854,7 @@ func TestStubBlockDevices_Isolated(t *testing.T) {
846854 require .NoError (t , err , "failed to create fccontrol client" )
847855
848856 _ , err = fcClient .CreateVM (ctx , & proto.CreateVMRequest {
849- VMID : strconv . Itoa (vmID ),
857+ VMID : gen . VMID (vmID ),
850858 NetworkInterfaces : []* proto.FirecrackerNetworkInterface {
851859 {
852860 AllowMMDS : true ,
@@ -865,7 +873,7 @@ func TestStubBlockDevices_Isolated(t *testing.T) {
865873 containerd .WithSnapshotter (defaultSnapshotterName ),
866874 containerd .WithNewSnapshot (snapshotName , image ),
867875 containerd .WithNewSpec (
868- firecrackeroci .WithVMID (strconv . Itoa (vmID )),
876+ firecrackeroci .WithVMID (gen . VMID (vmID )),
869877 oci .WithProcessArgs ("/bin/sh" , "/var/firecracker-containerd-test/scripts/lsblk.sh" ),
870878
871879 oci .WithMounts ([]specs.Mount {
@@ -1447,6 +1455,9 @@ func TestMemoryBalloon_Isolated(t *testing.T) {
14471455 }
14481456 t .Logf ("TestMemoryBalloon_Isolated: will run %d vm's" , numberOfVms )
14491457
1458+ gen , err := integtest .NewVMIDGen ()
1459+ require .NoError (t , err , "Failed to create a VMIDGen" )
1460+
14501461 var vmGroup sync.WaitGroup
14511462 for i := 0 ; i < numberOfVms ; i ++ {
14521463 vmGroup .Add (1 )
@@ -1462,7 +1473,7 @@ func TestMemoryBalloon_Isolated(t *testing.T) {
14621473 require .NoError (t , err , "failed to create fccontrol client" )
14631474
14641475 _ , err = fcClient .CreateVM (ctx , & proto.CreateVMRequest {
1465- VMID : strconv . Itoa (vmID ),
1476+ VMID : gen . VMID (vmID ),
14661477 MachineCfg : & proto.FirecrackerMachineConfiguration {
14671478 MemSizeMib : 512 ,
14681479 },
@@ -1484,7 +1495,7 @@ func TestMemoryBalloon_Isolated(t *testing.T) {
14841495 require .NoError (t , err , "failed to create vm" )
14851496
14861497 // Test UpdateBalloon correctly updates amount of memory for the balloon device
1487- vmIDStr := strconv . Itoa (vmID )
1498+ vmIDStr := gen . VMID (vmID )
14881499 newAmountMib := int64 (50 )
14891500 _ , err = fcClient .UpdateBalloon (ctx , & proto.UpdateBalloonRequest {
14901501 VMID : vmIDStr ,
0 commit comments