Skip to content

Commit 5697a75

Browse files
azure-sdkbenbp
andauthored
Sync eng/common directory with azure-sdk-tools for PR 2027 (#20798)
* Handle assembly already loaded errors in deploy stress test script * Add dependency checks and installation links to deploy-stress-tests.ps1 Co-authored-by: Ben Broderick Phillips <[email protected]>
1 parent 883bdae commit 5697a75

File tree

1 file changed

+45
-6
lines changed

1 file changed

+45
-6
lines changed

eng/common/scripts/stress-testing/deploy-stress-tests.ps1

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,12 @@ $ErrorActionPreference = 'Stop'
2121
$FailedCommands = New-Object Collections.Generic.List[hashtable]
2222

2323
. (Join-Path $PSScriptRoot "../Helpers" PSModule-Helpers.ps1)
24-
Install-ModuleIfNotInstalled "powershell-yaml" "0.4.1" | Import-Module
25-
Install-ModuleIfNotInstalled "az" "6.4.0" | Import-Module
2624

2725
# Powershell does not (at time of writing) treat exit codes from external binaries
2826
# as cause for stopping execution, so do this via a wrapper function.
2927
# See https://github.com/PowerShell/PowerShell-RFC/pull/277
30-
function Run() {
28+
function Run()
29+
{
3130
Write-Host "`n==> $args`n" -ForegroundColor Green
3231
$command, $arguments = $args
3332
& $command $arguments
@@ -37,14 +36,16 @@ function Run() {
3736
}
3837
}
3938

40-
function RunOrExitOnFailure() {
39+
function RunOrExitOnFailure()
40+
{
4141
run @args
4242
if ($LASTEXITCODE) {
4343
exit $LASTEXITCODE
4444
}
4545
}
4646

47-
function Login([string]$subscription, [string]$clusterGroup, [boolean]$pushImages) {
47+
function Login([string]$subscription, [string]$clusterGroup, [boolean]$pushImages)
48+
{
4849
Write-Host "Logging in to subscription, cluster and container registry"
4950
az account show *> $null
5051
if ($LASTEXITCODE) {
@@ -165,7 +166,7 @@ function DeployStressPackage(
165166
Write-Warning "The issue may be fixable by first running 'helm rollback -n $($pkg.Namespace) $($pkg.ReleaseName)'"
166167
return
167168
}
168-
169+
169170
# Helm 3 stores release information in kubernetes secrets. The only way to add extra labels around
170171
# specific releases (thereby enabling filtering on `helm list`) is to label the underlying secret resources.
171172
# There is not currently support for setting these labels via the helm cli.
@@ -177,7 +178,45 @@ function DeployStressPackage(
177178
Run kubectl label secret -n $pkg.Namespace --overwrite $helmReleaseConfig deployId=$deployId
178179
}
179180

181+
function CheckDependencies()
182+
{
183+
$deps = @(
184+
@{
185+
Command = "docker";
186+
Help = "Docker must be installed: https://docs.docker.com/get-docker/";
187+
}
188+
@{
189+
Command = "kubectl";
190+
Help = "kubectl must be installed: https://kubernetes.io/docs/tasks/tools/#kubectl";
191+
},
192+
@{
193+
Command = "helm";
194+
Help = "helm must be installed: https://helm.sh/docs/intro/install/";
195+
},
196+
@{
197+
Command = "az";
198+
Help = "Azure CLI must be installed: https://docs.microsoft.com/en-us/cli/azure/install-azure-cli";
199+
}
200+
)
201+
202+
Install-ModuleIfNotInstalled "powershell-yaml" "0.4.1" | Import-Module
203+
204+
$shouldError = $false
205+
foreach ($dep in $deps) {
206+
if (!(Get-Command $dep.Command -ErrorAction SilentlyContinue)) {
207+
$shouldError = $true
208+
Write-Error $dep.Help
209+
}
210+
}
211+
212+
if ($shouldError) {
213+
exit 1
214+
}
215+
216+
}
217+
180218
# Don't call functions when the script is being dot sourced
181219
if ($MyInvocation.InvocationName -ne ".") {
220+
CheckDependencies
182221
DeployStressTests @PSBoundParameters
183222
}

0 commit comments

Comments
 (0)