Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/engines/hckinstall/hckinstall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ def prepare_setup_scripts_config
kit_type:,
hlk_kit_ver: kit_version,
debug: options_install.debug,
no_reboot_after_bugcheck: options_install.no_reboot_after_bugcheck
no_reboot_after_bugcheck: options_install.no_reboot_after_bugcheck,
vmnames: ['STUDIO'] + @clients_name.map(&:upcase)
}

prepare_kit_installer(kit_type, kit_version)
Expand Down
1 change: 1 addition & 0 deletions lib/engines/hckinstall/setup-scripts/args.ps1.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
$VMNAMES = @("STUDIO", "CL1", "CL2")
$KITTYPE = "HLK"
$HLKKITVER = 2004
$REMOVEGUI = $false
Expand Down
3 changes: 1 addition & 2 deletions lib/engines/hckinstall/setup-scripts/auxiliary.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
$FILTERS = "https://go.microsoft.com/fwlink/?linkid=875139"
$STUDIOCOMPUTERNAME = "STUDIO"
$CLIENTCOMPUTERNAME = "CL"
$VMNAMES = @("STUDIO", "CL1", "CL2")
$CONTROLNET = "192.168.100" # The =FIRST THREE= octets of the IP
$STUDIOIP = "${CONTROLNET}.1"
$KITTYPE = "HLK"
Expand Down
10 changes: 5 additions & 5 deletions lib/engines/hckinstall/setup-scripts/client.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function Stage-One {
if (($macSegments[5] -eq "CC") -and ($macSegments[4] -eq "CC")) {
$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


Write-Output "Renaming hostname to $clientName"
Rename-Computer -NewName "$clientName"
Expand All @@ -49,7 +49,7 @@ function Stage-One {
}
}

"$STUDIOIP $STUDIOCOMPUTERNAME #STUDIO VM IP" | Out-File -encoding ASCII -append 'C:\Windows\System32\drivers\etc\hosts'
"$STUDIOIP $($VMNAMES[0]) #STUDIO VM IP" | Out-File -encoding ASCII -append 'C:\Windows\System32\drivers\etc\hosts'

Enable-PowerShellRemoting

Expand All @@ -73,17 +73,17 @@ function Stage-Three {
Set-NewStage -Stage "Four"

do {
Write-Output "Waiting for ping to $STUDIOCOMPUTERNAME..."
Write-Output "Waiting for ping to $($VMNAMES[0])..."
# The correct parameter is -ComputerName for PowerShell v5.1. The parameter changed to -TargetName in PowerShell v6.
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/test-connection?view=powershell-7.1
# https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/test-connection?view=powershell-5.1
$pingStatus = Test-Connection -ComputerName "$STUDIOCOMPUTERNAME" -Quiet
$pingStatus = Test-Connection -ComputerName "$($VMNAMES[0])" -Quiet
} until ($pingStatus)

Write-Output "Copying $KITTYPE client installation from studio to client..."

$clientInstallerFolder = "$env:TEMP\Client"
Copy-Item -Path "\\$STUDIOCOMPUTERNAME\${KITTYPE}Install\Client" -Destination "$clientInstallerFolder" -Recurse
Copy-Item -Path "\\$($VMNAMES[0])\${KITTYPE}Install\Client" -Destination "$clientInstallerFolder" -Recurse

Write-Output "Starting $KITTYPE client installation..."
# HLK Installer
Expand Down
2 changes: 1 addition & 1 deletion lib/engines/hckinstall/setup-scripts/studio.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function Stage-One {
Disable-Screensaver
Disable-PowerSavingOptions

Rename-Computer -NewName "$STUDIOCOMPUTERNAME"
Rename-Computer -NewName "$($VMNAMES[0])"

Get-NetAdapter | ForEach-Object {
$adapterName = $_.Name
Expand Down
6 changes: 5 additions & 1 deletion lib/engines/hckinstall/setup_scripts_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module Helper
hlk_kit_ver: '',
remove_gui: '',
debug: '',
no_reboot_after_bugcheck: ''
no_reboot_after_bugcheck: '',
vmnames: []
}.freeze

sig { params(workspace_hlk_setup_scripts_path: Pathname, hck_setup_scripts_template_path: Pathname).void }
Expand Down Expand Up @@ -71,6 +72,9 @@ def create_setup_scripts_config(workspace_hlk_setup_scripts_path, config)
value = "'#{v}'"
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

value = "@(#{items})"
else
@logger.fatal("Unexpected value #{v} for config")
Kernel.raise(AutoHCKError, "Unexpected value #{v} for config")
Expand Down
10 changes: 7 additions & 3 deletions lib/setupmanagers/hckclient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ def initialize(setup_manager, scope, studio, name, run_opts)
@replacement_map = @project.project_replacement_map.merge(setup_manager.client_replacement_map(name))
end

def machine_name_match?(machine_name)
machine_name.casecmp?(@name)
end
Comment on lines +28 to +30

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


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

end
end

Expand Down Expand Up @@ -152,8 +156,8 @@ def copy_dvl
end

def machine_info
@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

end

def recognize_client_wait
Expand Down
Loading