RHELMISC-34338: queuetest: allow assigning multiple machines to HLK roles via JSON#81
RHELMISC-34338: queuetest: allow assigning multiple machines to HLK roles via JSON#81elizashurov wants to merge 1 commit into
Conversation
…oles via JSON The -sup parameter now accepts a JSON object that maps role names to machine lists instead of a single machine name. This allows tests with multiple roles (e.g. MC, SC) to each get their own machine. Roles not specified in the JSON fall back to the primary test machine. Signed-off-by: Elizabeth Ashurov <eashurov@redhat.com>
There was a problem hiding this comment.
Code Review
This pull request updates the queuetest function in tools/toolsHCK.ps1 to allow the -sup parameter to accept a JSON object mapping HLK role names to arrays of machine names, replacing the previous single-machine string behavior. The reviewer recommended addressing backward compatibility for cases where a plain machine name is still passed, and suggested using more idiomatic PowerShell dynamic member access instead of verbose .PSObject.Properties syntax.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| $supData = ConvertFrom-Json $sup | ||
| $MachineSet = $WntdTest.GetMachineRole() | ||
| $RoleMachines = [System.Collections.Generic.List[object]]::new() | ||
|
|
||
| $roleAliases = @{ 'MasterClient' = 'MC'; 'StressClient' = 'SC' } | ||
|
|
||
| foreach ($Role in $MachineSet.Roles) { | ||
| $RoleMachines.AddRange($Role.GetMachines()) | ||
| $RoleMachines | foreach { $Role.RemoveMachine($_) } | ||
| $RoleMachines.Clear() | ||
| if ($Role.Name -eq "Client") { | ||
| $Role.AddMachine($WntdMachine) | ||
| $existing = [System.Collections.Generic.List[object]]::new() | ||
| $existing.AddRange($Role.GetMachines()) | ||
| $existing | ForEach-Object { $Role.RemoveMachine($_) } | ||
|
|
||
| $machineNames = $supData.PSObject.Properties[$Role.Name] | ||
| if (-Not $machineNames -and $roleAliases.ContainsKey($Role.Name)) { | ||
| $machineNames = $supData.PSObject.Properties[$roleAliases[$Role.Name]] | ||
| } | ||
| if ($Role.Name -eq "Support") { | ||
| $Role.AddMachine($WntdSMachine) | ||
| if ($machineNames) { | ||
| foreach ($machineName in $machineNames.Value) { | ||
| if (-Not ($sm = $WntdPool.GetMachines() | Where-Object { $_.Name -eq $machineName.Trim() })) { throw "Machine '$machineName' for role '$($Role.Name)' was not found, aborting..." } | ||
| $Role.AddMachine($sm) | ||
| } | ||
| } else { | ||
| # Roles not listed in $supData (e.g. "Client"/"SUT") default to the primary test machine. | ||
| $Role.AddMachine($WntdMachine) | ||
| } | ||
| } |
There was a problem hiding this comment.
There are two key areas of improvement in this block:
- Backward Compatibility: Currently, passing a plain machine name (e.g.,
'CL2') to-supwill causeConvertFrom-Jsonto throw an exception, breaking existing automation. We can check if$supstarts with{to parse it as JSON, and otherwise fall back to treating it as a single support machine name. - Idiomatic PowerShell Property Access: Instead of using the verbose
.PSObject.Properties[...]and.Valuesyntax, we can use standard PowerShell dynamic member access (e.g.,$supData.$($Role.Name)). Wrapping the result in@(...)ensures it is always treated as an array, whether it's a single string or a list of strings.
$supData = $null
if ($sup -like '{*') {
$supData = ConvertFrom-Json $sup
} else {
# Backward compatibility: treat $sup as a single support machine name
$supData = [PSCustomObject]@{ 'Support' = @($sup) }
}
$MachineSet = $WntdTest.GetMachineRole()
$roleAliases = @{ 'MasterClient' = 'MC'; 'StressClient' = 'SC' }
foreach ($Role in $MachineSet.Roles) {
$existing = [System.Collections.Generic.List[object]]::new()
$existing.AddRange($Role.GetMachines())
$existing | ForEach-Object { $Role.RemoveMachine($_) }
$machineNames = $supData.$($Role.Name)
if (-Not $machineNames -and $roleAliases.ContainsKey($Role.Name)) {
$machineNames = $supData.$($roleAliases[$Role.Name])
}
if ($machineNames) {
foreach ($machineName in @($machineNames)) {
if (-Not ($sm = $WntdPool.GetMachines() | Where-Object { $_.Name -eq $machineName.Trim() })) { throw "Machine '$machineName' for role '$($Role.Name)' was not found, aborting..." }
$Role.AddMachine($sm)
}
} else {
# Roles not listed in $supData (e.g. "Client"/"SUT") default to the primary test machine.
$Role.AddMachine($WntdMachine)
}
}
There was a problem hiding this comment.
Backward compatibility is not needed since AutoHCK was updated to always send JSON
The sup parameter now accepts a JSON object that maps role names to machine lists instead of a single machine name. This allows tests with multiple roles (e.g. MC, SC) to each get their own machine. Roles not specified in the JSON fall back to the primary test machine.