Skip to content

VIRTWINKVM-1882: Read VM names from config#1041

Open
bhbhatt wants to merge 1 commit into
HCK-CI:masterfrom
bhbhatt:VIRTWINKVM-1882-vm-names-from-config
Open

VIRTWINKVM-1882: Read VM names from config#1041
bhbhatt wants to merge 1 commit into
HCK-CI:masterfrom
bhbhatt:VIRTWINKVM-1882-vm-names-from-config

Conversation

@bhbhatt

@bhbhatt bhbhatt commented Jul 16, 2026

Copy link
Copy Markdown
Contributor
  1. Hostnames come from platform JSON — not hardcoded "CL" + number, so custom names work.
  2. One source of truth — Ruby + Windows + HLK use the same client names from the platform.
  3. Works with any client count — 1, 2, 3+ clients via args.ps1 ($VMNAMES length matches platform).
  4. Lowercase / uppercase JSON both work — install upcases for Windows; test uses casecmp? for HLK.
  5. Aligns with Windows/HLK — hostnames are case-insensitive; AutoHCK no longer fails on cl1 vs CL1.
  6. Safer for future platforms — change names in JSON + reinstall; no PowerShell formula to update.

Signed-off-by: Bhanuja Bhatt <bhbhatt@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 introduces dynamic VM naming using a $VMNAMES array across setup scripts and helper engines, replacing hardcoded computer names. Feedback highlights two potential issues: a possible NoMethodError in machine_name_match? if machine_name is nil, and a potential out-of-bounds array access in client.ps1 if $clientNumber exceeds the $VMNAMES array bounds.

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 on lines +28 to +30
def machine_name_match?(machine_name)
machine_name.casecmp?(@name)
end

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

If machine_name is nil, calling casecmp? on it will raise a NoMethodError because NilClass does not implement casecmp?. Previously, machine['name'].eql?(@name) would safely return false if machine['name'] was nil. To prevent potential crashes, we should ensure machine_name is not nil before calling casecmp?.

    def machine_name_match?(machine_name)
      machine_name && machine_name.casecmp?(@name)
    end

$clientNumber = [int32]("0x" + $macSegments[3])
$clientIp = $clientNumber + 1
$clientName = "$CLIENTCOMPUTERNAME$clientNumber"
$clientName = $VMNAMES[$clientNumber]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

If $clientNumber is out of bounds of the $VMNAMES array (for example, due to an unexpected MAC address or mismatched configuration), $clientName will be $null. Passing $null to Rename-Computer -NewName will result in an empty string argument error. Adding a check to ensure $clientName is valid before proceeding improves robustness and error reporting.

            $clientName = $VMNAMES[$clientNumber]
            if (-not $clientName) {
                Write-Error "No VM name found in VMNAMES for client number $clientNumber"
            }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

will be useful

when Integer
value = v
when Array
items = v.map { |item| "'#{item.to_s.gsub("'", "''")}'" }.join(', ')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is there any reason why in example " is used ("STUDIO", "CL1", "CL2") while there we wrap strings in '?

3.3.7 :001 > list = ["Name1", "Name2", "Name3"]
 => ["Name1", "Name2", "Name3"] 
3.3.7 :002 > list.map { |item| "'#{item.to_s.gsub("'", "''")}'" }.join(', ')
 => "'Name1', 'Name2', 'Name3'" 

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.

sorry by mistake will change this to single case

def pool
@studio.list_pools.each do |pool|
return pool['name'] if pool['machines'].any? { |machine| machine['name'].eql?(@name) }
return pool['name'] if pool['machines'].any? { |machine| machine_name_match?(machine['name']) }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just replace .eql? with casecmp?, no need for extra function

@studio.list_pools.flat_map { |pool| pool['machines'] }
.detect { |machine| machine['name'].eql?(@name) }
machines = @studio.list_pools.flat_map { |pool| pool['machines'] }
machines.detect { |machine| machine_name_match?(machine['name']) }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same

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