Skip to content

RHELMISC-34338: queuetest: allow assigning multiple machines to HLK roles via JSON#81

Open
elizashurov wants to merge 1 commit into
HCK-CI:masterfrom
elizashurov:RHELMISC-34338
Open

RHELMISC-34338: queuetest: allow assigning multiple machines to HLK roles via JSON#81
elizashurov wants to merge 1 commit into
HCK-CI:masterfrom
elizashurov:RHELMISC-34338

Conversation

@elizashurov

Copy link
Copy Markdown
Contributor

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.

…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>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread tools/toolsHCK.ps1
Comment on lines +1310 to 1333
$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)
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

There are two key areas of improvement in this block:

  1. Backward Compatibility: Currently, passing a plain machine name (e.g., 'CL2') to -sup will cause ConvertFrom-Json to throw an exception, breaking existing automation. We can check if $sup starts with { to parse it as JSON, and otherwise fall back to treating it as a single support machine name.
  2. Idiomatic PowerShell Property Access: Instead of using the verbose .PSObject.Properties[...] and .Value syntax, 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)
            }
        }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backward compatibility is not needed since AutoHCK was updated to always send JSON

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants