diff --git a/internal/test/e2e/run.go b/internal/test/e2e/run.go index e5b97abaa5b9..b1ade83bd504 100644 --- a/internal/test/e2e/run.go +++ b/internal/test/e2e/run.go @@ -2,6 +2,7 @@ package e2e import ( "fmt" + "math/rand" "os" "regexp" "sort" @@ -217,6 +218,9 @@ func RunTests(conf instanceRunConf, inventoryCatalogue map[string]*hardwareCatal } else { hardwareCatalogue = inventoryCatalogue[nonAirgappedHardware] } + conf.Logger.Info("Shuffling hardware inventory for tinkerbell") + // shuffle hardware to introduce randomness during hardware reservation. + shuffleHardwareInventory(hardwareCatalogue) err = reserveTinkerbellHardware(&conf, hardwareCatalogue) if err != nil { return "", nil, err @@ -592,3 +596,10 @@ func logTinkerbellTestHardwareInfo(conf *instanceRunConf, action string) { } conf.Logger.V(1).Info(action+" hardware for TestRunner", "hardwarePool", strings.Join(hardwareInfo, ", ")) } + +func shuffleHardwareInventory(invCatalogue *hardwareCatalogue) { + random := rand.New(rand.NewSource(time.Now().UnixNano())) + random.Shuffle(len(invCatalogue.hws), func(i, j int) { + invCatalogue.hws[i], invCatalogue.hws[j] = invCatalogue.hws[j], invCatalogue.hws[i] + }) +}