-
Notifications
You must be signed in to change notification settings - Fork 285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shuffle hardware inventory for tinkerbell before reservation #8264
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: why the use of inventory and catalogue? aren't they representing the same thing? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not make this a method in I fact, don't you need to use the mutex? If I'm not mistaken the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! I should have seen this. |
||
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] | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I would expand more on why randomness is desired. We don't do this to introduce randomness, we do this to avoid picking up the same machines on every run. Randomness is just the mechanism to achieve that goal.