Skip to content

Commit

Permalink
shuffle hardware inventory for tinkerbell before reservation
Browse files Browse the repository at this point in the history
Signed-off-by: Rahul Ganesh <rahulgab@amazon.com>
  • Loading branch information
Rahul Ganesh committed Jun 8, 2024
1 parent d485120 commit 0ef7112
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions internal/test/e2e/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package e2e

import (
"fmt"
"math/rand"
"os"
"regexp"
"sort"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
})
}

0 comments on commit 0ef7112

Please sign in to comment.