@@ -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 ,
@@ -435,21 +438,21 @@ func testMultipleVMs(ctx context.Context, t *testing.T, count int) {
435438 }
436439
437440 // verify duplicate CreateVM call fails with right error
438- _ , err = fcClient .CreateVM (ctx , & proto.CreateVMRequest {VMID : strconv . Itoa ( vmID ) })
441+ _ , err = fcClient .CreateVM (ctx , & proto.CreateVMRequest {VMID : vmIDStr })
439442 if err == nil {
440443 return fmt .Errorf ("creating the same VM must return an error" )
441444 }
442445
443446 // verify GetVMInfo returns expected data
444- vmInfoResp , err := fcClient .GetVMInfo (ctx , & proto.GetVMInfoRequest {VMID : strconv . Itoa ( vmID ) })
447+ vmInfoResp , err := fcClient .GetVMInfo (ctx , & proto.GetVMInfoRequest {VMID : vmIDStr })
445448 if err != nil {
446449 return err
447450 }
448- if vmInfoResp .VMID != strconv . Itoa ( vmID ) {
449- return fmt .Errorf ("%q must be %q" , vmInfoResp .VMID , strconv . Itoa ( vmID ) )
451+ if vmInfoResp .VMID != vmIDStr {
452+ return fmt .Errorf ("%q must be %q" , vmInfoResp .VMID , vmIDStr )
450453 }
451454
452- nspVMid := defaultNamespace + "#" + strconv . Itoa ( vmID )
455+ nspVMid := defaultNamespace + "#" + vmIDStr
453456 cfg , err := config .LoadConfig ("" )
454457 if err != nil {
455458 return err
@@ -465,7 +468,7 @@ func testMultipleVMs(ctx context.Context, t *testing.T, count int) {
465468 // just verify that updating the metadata doesn't return an error, a separate test case is needed
466469 // to very the MMDS update propagates to the container correctly
467470 _ , err = fcClient .SetVMMetadata (ctx , & proto.SetVMMetadataRequest {
468- VMID : strconv . Itoa ( vmID ) ,
471+ VMID : vmIDStr ,
469472 Metadata : "{}" ,
470473 })
471474 if err != nil {
@@ -477,7 +480,7 @@ func testMultipleVMs(ctx context.Context, t *testing.T, count int) {
477480 return fmt .Errorf ("unexpected error from the containers in VM %d: %w" , vmID , err )
478481 }
479482
480- _ , err = fcClient .StopVM (ctx , & proto.StopVMRequest {VMID : strconv . Itoa ( vmID ) , TimeoutSeconds : 5 })
483+ _ , err = fcClient .StopVM (ctx , & proto.StopVMRequest {VMID : vmIDStr , TimeoutSeconds : 5 })
481484 atomic .AddInt64 (& stopped , 1 )
482485 return err
483486 }
@@ -515,13 +518,14 @@ loop:
515518func testMultipleExecs (
516519 ctx context.Context ,
517520 vmID int ,
521+ gen * integtest.VMIDGen ,
518522 containerID int ,
519523 client * containerd.Client ,
520524 image containerd.Image ,
521525 jailerConfig * proto.JailerConfig ,
522526 cgroupPath string ,
523527) error {
524- vmIDStr := strconv . Itoa (vmID )
528+ vmIDStr := gen . VMID (vmID )
525529 testTimeout := 600 * time .Second
526530
527531 containerName := fmt .Sprintf ("container-%d-%d" , vmID , containerID )
@@ -826,6 +830,9 @@ func TestStubBlockDevices_Isolated(t *testing.T) {
826830
827831 const vmID = 0
828832
833+ gen , err := integtest .NewVMIDGen ()
834+ require .NoError (t , err , "failed to create VMIDGen" )
835+
829836 ctx := namespaces .WithNamespace (context .Background (), "default" )
830837
831838 client , err := containerd .New (integtest .ContainerdSockPath , containerd .WithDefaultRuntime (firecrackerRuntime ))
@@ -846,7 +853,7 @@ func TestStubBlockDevices_Isolated(t *testing.T) {
846853 require .NoError (t , err , "failed to create fccontrol client" )
847854
848855 _ , err = fcClient .CreateVM (ctx , & proto.CreateVMRequest {
849- VMID : strconv . Itoa (vmID ),
856+ VMID : gen . VMID (vmID ),
850857 NetworkInterfaces : []* proto.FirecrackerNetworkInterface {
851858 {
852859 AllowMMDS : true ,
@@ -865,7 +872,7 @@ func TestStubBlockDevices_Isolated(t *testing.T) {
865872 containerd .WithSnapshotter (defaultSnapshotterName ),
866873 containerd .WithNewSnapshot (snapshotName , image ),
867874 containerd .WithNewSpec (
868- firecrackeroci .WithVMID (strconv . Itoa (vmID )),
875+ firecrackeroci .WithVMID (gen . VMID (vmID )),
869876 oci .WithProcessArgs ("/bin/sh" , "/var/firecracker-containerd-test/scripts/lsblk.sh" ),
870877
871878 oci .WithMounts ([]specs.Mount {
@@ -1447,6 +1454,9 @@ func TestMemoryBalloon_Isolated(t *testing.T) {
14471454 }
14481455 t .Logf ("TestMemoryBalloon_Isolated: will run %d vm's" , numberOfVms )
14491456
1457+ gen , err := integtest .NewVMIDGen ()
1458+ require .NoError (t , err , "Failed to create a VMIDGen" )
1459+
14501460 var vmGroup sync.WaitGroup
14511461 for i := 0 ; i < numberOfVms ; i ++ {
14521462 vmGroup .Add (1 )
@@ -1462,7 +1472,7 @@ func TestMemoryBalloon_Isolated(t *testing.T) {
14621472 require .NoError (t , err , "failed to create fccontrol client" )
14631473
14641474 _ , err = fcClient .CreateVM (ctx , & proto.CreateVMRequest {
1465- VMID : strconv . Itoa (vmID ),
1475+ VMID : gen . VMID (vmID ),
14661476 MachineCfg : & proto.FirecrackerMachineConfiguration {
14671477 MemSizeMib : 512 ,
14681478 },
@@ -1484,7 +1494,7 @@ func TestMemoryBalloon_Isolated(t *testing.T) {
14841494 require .NoError (t , err , "failed to create vm" )
14851495
14861496 // Test UpdateBalloon correctly updates amount of memory for the balloon device
1487- vmIDStr := strconv . Itoa (vmID )
1497+ vmIDStr := gen . VMID (vmID )
14881498 newAmountMib := int64 (50 )
14891499 _ , err = fcClient .UpdateBalloon (ctx , & proto.UpdateBalloonRequest {
14901500 VMID : vmIDStr ,
0 commit comments