summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryan McLellan <btm@loftninjas.org>2020-04-05 20:23:31 -0400
committerBryan McLellan <btm@loftninjas.org>2020-04-06 10:52:14 -0400
commit36d254fe1e2c2d0a274854ce627add1f622459b7 (patch)
treecc7523f63cef3606a1be9f6aa1a9d339bdb01de3
parent94a775e15b7d30845032db0b3dbe86d5bf09aa2b (diff)
downloadchef-btm/15-fix-win-func-test.tar.gz
Download and verify the Ruby installer, then move into placebtm/15-fix-win-func-test
This should reduce or remove race conditions while downloading the same file on multiple container instances. Signed-off-by: Bryan McLellan <btm@loftninjas.org>
-rw-r--r--scripts/bk_tests/bk_win_functional.ps147
1 files changed, 33 insertions, 14 deletions
diff --git a/scripts/bk_tests/bk_win_functional.ps1 b/scripts/bk_tests/bk_win_functional.ps1
index 5eb17769d4..9a9d50a63b 100644
--- a/scripts/bk_tests/bk_win_functional.ps1
+++ b/scripts/bk_tests/bk_win_functional.ps1
@@ -12,16 +12,39 @@ $RubyS3Path = "s3://public-cd-buildkite-cache/$RubyFilename"
Function DownloadRuby
{
+ $RandDigits = Get-Random
echo "Downloading Ruby + DevKit"
- aws s3 cp $RubyS3Path $RubyPath | Out-Null # Out-Null is a hack to wait for the process to complete
- if ($LASTEXITCODE -ne 0)
- {
+ aws s3 cp "$RubyS3Path" "$RubyPath.$RandDigits" | Out-Null # Out-Null is a hack to wait for the process to complete
+
+ if ($LASTEXITCODE -ne 0) {
echo "aws s3 download failed: $LASTEXITCODE"
exit $LASTEXITCODE
}
- $DownloadedHash = (Get-FileHash $RubyPath -Algorithm SHA256).Hash
- echo "Downloaded SHA256: $DownloadedHash"
+
+ $FileHash = (Get-FileHash "$RubyPath.$RandDigits" -Algorithm SHA256).Hash
+ If ($FileHash -eq $RubySHA256) {
+ echo "Downloaded SHA256 matches: $FileHash"
+ } Else {
+ echo "Downloaded file hash $FileHash does not match desired $RubySHA256"
+ exit 1
+ }
+
+ # On a shared filesystem, sometimes a good file appears while we are downloading
+ If (Test-Path $RubyPath) {
+ $FileHash = (Get-FileHash "$RubyPath" -Algorithm SHA256).Hash
+ If ($FileHash -eq $RubySHA256) {
+ echo "A matching file appeared while downloading, using it."
+ Remove-Item "$RubyPath.$RandDigits" -Force
+ Return
+ } Else {
+ echo "Existing file does not match, bad hash: $FileHash"
+ Remove-Item $RubyPath -Force
+ }
+ }
+
+ echo "Moving file installer into place"
+ Rename-Item -Path "$RubyPath.$RandDigits" -NewName $RubyFilename
}
Function InstallRuby
@@ -29,16 +52,12 @@ Function InstallRuby
If (Test-Path $RubyPath) {
echo "$RubyPath already exists"
- $ExistingRubyHash = (Get-FileHash $RubyPath -Algorithm SHA256).Hash
-
- echo "Verifying file SHA256 hash $ExistingRubyHash to desired hash $RubySHA256"
-
- If ($ExistingRubyHash -ne $RubySHA256) {
- echo "SHA256 hash mismatch, attempting to remove and re-download"
- Remove-Item $RubyPath -Force
- DownloadRuby
- } Else {
+ $FileHash = (Get-FileHash "$RubyPath" -Algorithm SHA256).Hash
+ If ($FileHash -eq $RubySHA256) {
echo "Found matching Ruby + DevKit on disk"
+ } Else {
+ echo "SHA256 hash mismatch, re-downloading"
+ DownloadRuby
}
} Else {
echo "No Ruby found at $RubyPath, downloading"