From 0ef71126721a7cba6f8898d7b04f1dba46285d8d Mon Sep 17 00:00:00 2001 From: Rahul Ganesh Date: Fri, 7 Jun 2024 17:04:45 -0700 Subject: [PATCH] shuffle hardware inventory for tinkerbell before reservation Signed-off-by: Rahul Ganesh --- internal/test/e2e/run.go | 11 +++++++++++ 1 file changed, 11 insertions(+) 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] + }) +}