Skip to content

Commit c83302a

Browse files
authored
Merge pull request #35 from twangboy/fix_34
Handle double-digit minor versions properly on Windows
2 parents e5ce2e1 + 7c4de84 commit c83302a

File tree

4 files changed

+163
-12
lines changed

4 files changed

+163
-12
lines changed

tests/windows/integration/test_install_3006.ps1 renamed to tests/windows/integration/test_install_exact_ver.ps1

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# Copyright 2021-2023 VMware, Inc.
22
# SPDX-License-Identifier: Apache-2
33

4+
$test_version = "3006.9"
5+
46
function setUpScript {
57

68
Write-Host "Resetting environment: " -NoNewline
79
Reset-Environment *> $null
810
Write-Done
911

10-
$MinionVersion = "3006.9"
12+
$MinionVersion = $test_version
1113
Write-Host "Installing salt ($MinionVersion): " -NoNewline
1214
function Get-GuestVars { "master=gv_master id=gv_minion" }
1315
Install *> $null
@@ -91,3 +93,15 @@ function test_salt_call {
9193
if (!($result -like "*True")) { $failed = 1 }
9294
return $failed
9395
}
96+
97+
function test_version {
98+
$failed = 0
99+
$result = & "$salt_dir\salt-call" --version
100+
if (!($result -like "*$test_version*")) {
101+
Write-Host ""
102+
Write-Host $result
103+
Write-Host $test_version
104+
$failed = 1
105+
}
106+
return $failed
107+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Copyright 2021-2023 VMware, Inc.
2+
# SPDX-License-Identifier: Apache-2
3+
4+
$test_version = "3006"
5+
6+
function setUpScript {
7+
8+
Write-Host "Resetting environment: " -NoNewline
9+
Reset-Environment *> $null
10+
Write-Done
11+
12+
$MinionVersion = $test_version
13+
Write-Host "Installing salt ($MinionVersion): " -NoNewline
14+
function Get-GuestVars { "master=gv_master id=gv_minion" }
15+
Install *> $null
16+
Write-Done
17+
18+
}
19+
20+
function tearDownScript {
21+
Write-Host "Resetting environment: " -NoNewline
22+
Reset-Environment *> $null
23+
Write-Done
24+
}
25+
26+
function test_status_installed {
27+
# Is the status set to installed
28+
try {
29+
$current_status = Get-ItemPropertyValue -Path $vmtools_base_reg -Name $vmtools_salt_minion_status_name
30+
} catch {
31+
$current_status = $STATUS_CODES["notInstalled"]
32+
}
33+
if ($current_status -ne $STATUS_CODES["installed"]) { return 1 }
34+
return 0
35+
}
36+
37+
function test_ssm_binary_present {
38+
# Is the SSM Binary present
39+
if (!(Test-Path $ssm_bin)) { return 1 }
40+
return 0
41+
}
42+
43+
function test_binaries_present {
44+
# Is salt-call.bat present
45+
if (!(Test-Path "$salt_dir\salt-call.exe")) { return 1 }
46+
if (!(Test-Path "$salt_dir\salt-minion.exe")) { return 1 }
47+
return 0
48+
}
49+
50+
function test_service_installed {
51+
# Is the salt-minion service registerd
52+
$service = Get-Service -Name salt-minion -ErrorAction SilentlyContinue
53+
if (!($service)) { return 1 }
54+
return 0
55+
}
56+
57+
function test_service_running {
58+
# Is the salt minion service running
59+
if ((Get-Service -Name salt-minion).Status -ne "Running") { return 1 }
60+
return 0
61+
}
62+
63+
function test_config_present {
64+
# Is the minion config file present
65+
if (!(Test-Path $salt_config_file)) { return 1 }
66+
return 0
67+
}
68+
69+
function test_config_correct {
70+
# We have to do it this way so -bor will return 0 when both are 0
71+
$minion_not_found = 1
72+
$master_not_found = 1
73+
# Verify that the old minion id is commented out
74+
foreach ($line in Get-Content $salt_config_file) {
75+
if ($line -match "^id: gv_minion$") { $minion_not_found = 0}
76+
if ($line -match "^master: gv_master$") { $master_not_found = 0}
77+
}
78+
return $minion_not_found -bor $master_not_found
79+
}
80+
81+
function test_salt_added_to_path {
82+
# Has salt been added to the system path
83+
$path_reg_key = "HKLM:\System\CurrentControlSet\Control\Session Manager\Environment"
84+
$current_path = (Get-ItemProperty -Path $path_reg_key -Name Path).Path
85+
if (!($current_path -like "*$salt_dir*")) { return 1 }
86+
return 0
87+
}
88+
89+
function test_salt_call {
90+
$failed = 0
91+
$result = & "$salt_dir\salt-call" --local test.ping
92+
if (!($result -like "local:*")) { $failed = 1 }
93+
if (!($result -like "*True")) { $failed = 1 }
94+
return $failed
95+
}
96+
97+
function test_version {
98+
# This is kind of using the script itself to test the script... maybe need
99+
# to get the latest version a different way
100+
$versions = Get-AvailableVersions
101+
$expected_version = $versions[$test_version]
102+
$failed = 0
103+
$result = & "$salt_dir\salt-call" --version
104+
if (!($result -like "*$expected_version*")) {
105+
Write-Host ""
106+
Write-Host $result
107+
Write-Host $test_version
108+
$failed = 1
109+
}
110+
return $failed
111+
}

tests/windows/integration/test_upgrade_3006.ps1 renamed to tests/windows/integration/test_upgrade.ps1

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
# Copyright 2021-2024 VMware, Inc.
22
# SPDX-License-Identifier: Apache-2
33

4+
$start_ver = "3006.0"
5+
$upgrade_ver = "3006.1"
6+
47
function setUpScript {
58

69
Write-Host "Resetting environment: " -NoNewline
710
Reset-Environment *> $null
811
Write-Done
912

10-
$MinionVersion = "3006.0"
13+
$MinionVersion = $start_ver
1114
Write-Host "Installing salt ($MinionVersion): " -NoNewline
1215
function Get-GuestVars { "master=existing_master id=existing_minion" }
1316
Install *> $null
1417
Write-Done
1518

16-
$MinionVersion = "3006.1"
19+
$MinionVersion = $upgrade_ver
1720
$Upgrade = $true
1821
Write-Host "Upgrading salt ($MinionVersion): " -NoNewline
1922
function Get-GuestVars { "master=gv_master id=gv_minion" }
@@ -93,3 +96,15 @@ function test_salt_call {
9396
if (!($result -like "*True")) { $failed = 1 }
9497
return $failed
9598
}
99+
100+
function test_version {
101+
$failed = 0
102+
$result = & "$salt_dir\salt-call" --version
103+
if (!($result -like "*$upgrade_ver*")) {
104+
Write-Host ""
105+
Write-Host $result
106+
Write-Host $upgrade_ver
107+
$failed = 1
108+
}
109+
return $failed
110+
}

windows/svtminion.ps1

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ if ($help) {
287287
}
288288

289289
# This value is populated via CICD during build
290-
$SCRIPT_VERSION = "2024.12.05"
290+
$SCRIPT_VERSION = "SCRIPT_VERSION_REPLACE"
291291
if ($Version) {
292292
Write-Host $SCRIPT_VERSION
293293
exit 0
@@ -1828,25 +1828,36 @@ function Get-AvailableVersions {
18281828
Write-Log "- $_" -Level debug
18291829
}
18301830

1831-
# Get the latest version, should be the last in the list
1832-
Write-Log "Getting latest available version" -Level debug
1833-
$latest = $available_versions | Select-Object -Last 1
1834-
Write-Log "Latest available version: $latest" -Level debug
1835-
18361831
# Create a versions table
18371832
# This will have the latest version available, the latest version available
18381833
# for each major version, and every version available. This makes the
18391834
# version lookup logic easier. The contents of the versions table can be
18401835
# found in the log or by passing -LogLevel debug
18411836
Write-Log "Populating the versions table" -Level debug
1842-
$versions_table = [ordered]@{"latest"=$latest}
1837+
$versions_table = [ordered]@{}
18431838
$available_versions | ForEach-Object {
1844-
$versions_table[$(Get-MajorVersion $_)] = $_
1839+
$major_version = $(Get-MajorVersion $_)
1840+
if ( $versions_table.Keys -contains $major_version ) {
1841+
if ( [System.Version]$_ -gt [System.Version]$versions_table[$major_version] ) {
1842+
$versions_table[$major_version] = $_
1843+
}
1844+
} else {
1845+
$versions_table[$major_version] = $_
1846+
}
1847+
1848+
if ( $versions_table -contains "latest" ) {
1849+
if ( [System.Version]$_ -gt [System.Version]$versions_table["latest"] ) {
1850+
$versions_table["latest"] = $_
1851+
}
1852+
} else {
1853+
$versions_table["latest"] = $_
1854+
}
1855+
18451856
$versions_table[$_.ToLower()] = $_.ToLower()
18461857
}
18471858

18481859
Write-Log "Versions Table:" -Level debug
1849-
$versions_table | Sort-Object Name | Out-String | ForEach-Object {
1860+
$versions_table.GetEnumerator() | Sort-Object Name | Out-String | ForEach-Object {
18501861
Write-Log "$_" -Level debug
18511862
}
18521863

0 commit comments

Comments
 (0)