-
Notifications
You must be signed in to change notification settings - Fork 55
/
test-arm.ps1
259 lines (219 loc) · 9.34 KB
/
test-arm.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
. (Get-Item "C:\src\github\Microsoft\navcontainerhelper\*ContainerHelper.ps1").FullName -exportTelemetryFunctions
$VerbosePreference = "Continue"
$ErrorActionPreference = "stop"
$ConfirmPreference = "none"
if (!($licenseFileSecret)) {
Get-AzKeyVaultSecret -VaultName "BuildVariables" | % {
Write-Host $_.Name
Set-Variable -Name "$($_.Name)Secret" -Value (Get-AzKeyVaultSecret -VaultName "BuildVariables" -Name $_.Name)
}
}
# My subscriptions
$FreddysSubscription = "97d6b765-89fc-40e9-b253-baee2b19d6db"
$subscriptionId = $FreddysSubscription
try {
Set-AzContext -Subscription $subscriptionId
} catch {
Connect-AzAccount -Environment AzureCloud -TenantId 'd5c7cb1f-b4df-4224-b710-522adc1f049c'
Set-AzContext -Subscription $subscriptionId
}
$remotedesktopaccess = "-"
$getnavProperties = @{
"artifactUrl" = "bcartifacts/onprem/14/w1/latest"
"autoShutdown" = "Enabled"
"includeCSIDE" = "No"
"enableSymbolLoading" = "No"
}
$getnavextProperties = @{
"artifactUrl" = "bcartifacts/onprem/14.0.29537.31096/nl/closest"
"winRmAccess" = "$remotedesktopaccess"
"StorageAccountType" = "Premium_LRS"
"includeCSIDE" = "Yes"
"enableSymbolLoading" = "Yes"
"requestToken" = $PasswordSecret.SecretValue | Get-PlainText
}
$getbcProperties = @{
"artifactUrl" = "bcartifacts/sandbox//dk/latest"
}
$getbcextProperties = @{
"artifactUrl" = "bcinsider/sandbox//us/latest/$($InsiderSasTokenSecret.SecretValue | Get-PlainText)"
"winRmAccess" = "$remotedesktopaccess"
"StorageAccountType" = "Premium_LRS"
"includeAL" = "Yes"
"SQLServerType" = "SQLDeveloper"
"CreateStorageQueue" = "Yes"
"FinalSetupScriptUrl" = "https://raw.githubusercontent.com/microsoft/nav-arm-templates/dev/additional-install.ps1"
}
$licensefile = $licenseFileSecret.SecretValue | Get-PlainText
$username = "student"
$vmSize = "Standard_D4s_v3"
$oss = @("Windows Server 2022","Windows Server 2019")
$vmPrefix = "fk"
$jsons = @('getbc','getbcext','getnav','getnavext')
$traefiks = @('Yes','No')
$branch = "dev"
$password = $PasswordSecret.SecretValue | Get-PlainText
$resLocation = "West Europe"
$credential = New-Object pscredential $username, $PasswordSecret.SecretValue
$pair ="$($UserName):$($Password)"
$bytes = [System.Text.Encoding]::ASCII.GetBytes($pair)
$base64 = [System.Convert]::ToBase64String($bytes)
$basicAuthValue = "Basic $base64"
$headers = @{ Authorization = $basicAuthValue }
$authParam = @{ "headers" = $headers }
#throw "init done"
$oss | ForEach-Object {
$operatingSystem = $_
$osp = $operatingSystem[$operatingSystem.Length-1]
$traefiks | ForEach-Object {
$AddTraefik = $_
$jsons | % {
$tp = "bc"
if ("$_".StartsWith('getnav')) {
$tp = "nav"
}
$ext = ("$_".EndsWith('ext'))
$traefik = "n"
if ($AddTraefik -eq "Yes") {
$traefik = "t"
}
$vmname = "$vmPrefix$traefik$osp$_"
$resgroup = "$vmName"
# ARM template
$templateUri = "https://raw.githubusercontent.com/microsoft/nav-arm-templates/$branch/$($_).json"
# Setup parameter array for ARM template
$Parameters = New-Object -TypeName Hashtable
$Parameters.Add("vmName", $vmName)
$Parameters.Add("vmSize", $vmSize)
$Parameters.Add("OperatingSystem", $operatingSystem)
$Parameters.Add("accepteula", "Yes")
$Parameters.Add("remotedesktopaccess", $remotedesktopaccess)
$Parameters.Add("vmAdminUsername", $username)
$Parameters.Add("$($tp)AdminUsername", $username)
$Parameters.Add("licensefileuri", $licensefile)
$Parameters.Add("adminPassword", (ConvertTo-SecureString -String $password -AsPlainText -Force))
$properties = Get-Variable "$($_)Properties"
$properties.Value.GetEnumerator() | % {
$Parameters.Add($_.Name, $_.Value)
}
$Parameters.Add("contactemailforletsencrypt", "fk@freddy.dk")
$Parameters.Add("RunWindowsUpdate", "No")
$Parameters.Add("AddTraefik", $AddTraefik)
# GO!
$resourceGroup = Get-AzResourceGroup -name $resGroup -ErrorAction Ignore
if ($resourceGroup) {
Write-Host "Removing Resource Group $resGroup"
Remove-AzResourceGroup -Name $resGroup -Force
}
$resourceGroup = New-AzResourceGroup -Name $resGroup -Location $resLocation -Force
$err = $resourceGroup | Test-AzResourceGroupDeployment -TemplateUri $templateUri -TemplateParameterObject $Parameters
if ($err) {
$err
throw "stop"
}
$resourceGroup | New-AzResourceGroupDeployment -TemplateUri $templateUri -TemplateParameterObject $Parameters -Name $vmName -ErrorAction Ignore
}
}
}
get-date
throw "Run the following in 1 hour"
$oss | ForEach-Object {
$operatingSystem = $_
$osp = $operatingSystem[$operatingSystem.Length-1]
$traefiks | ForEach-Object {
$AddTraefik = $_
$traefik = "n"
if ($AddTraefik -eq "Yes") {
$traefik = "t"
}
$jsons | ForEach-Object {
$vmname = "$vmPrefix$traefik$osp$_"
$url = "$($vmName).westeurope.cloudapp.azure.com"
if ($AddTraefik -eq "Yes") {
$landingPageUrl = "http://$($url):8180"
}
else {
$landingPageUrl = "http://$url"
}
$landingPage = Invoke-WebRequest -Uri $landingPageUrl
$landingPage.Links | Where-Object {$_.href -like “http*”} | ForEach-Object {
if ($_.innerText -eq "Web Client") {
$LoginPage = Invoke-WebRequest -Uri $_.href -UseBasicParsing
$userNameField = $LoginPage.InputFields | Where-Object { $_.name -eq "Username" }
$PasswordField = $LoginPage.InputFields | Where-Object { $_.name -eq "Password" }
if ((-not $userNameField) -or (-not $passwordField)) {
throw "Web Client login page not found"
}
}
elseif ($_.innerText -eq "View SOAP Web Services") {
$SoapResult = Invoke-WebRequest -Method Get -Uri $_.href.Replace('s//s','s/s') @AuthParam
[xml]$xml = $SoapResult.Content
$systemService = $xml.discovery.contractRef | Where-Object { $_.ref -like "*systemservice*" }
if (-not $systemService) {
throw "Soap not exposed correctly"
}
}
elseif ($_.innerText -eq "View OData Web Services") {
$ODataResult = Invoke-RestMethod -Method Get -Uri $_.href @AuthParam
if (-not $ODataResult.service.workspace.collection.href -contains "Company") {
throw "OData not exposed correctly"
}
}
elseif ($_.innerText.EndsWith("api/v1.0/companies")) {
$ApiResult = Invoke-RestMethod -Method Get -Uri $_.href @AuthParam
if (-not $ApiResult.value.name -like "CRONUS*") {
throw "API doesn't include CRONUS company"
}
}
elseif ($_.innerText.EndsWith(".vsix")) {
Download-File -sourceUrl $_.href -destinationFile "c:\temp\$($_.innerText).vsix"
}
}
}
}
}
#'ngetbcext','tgetbcext','ngetnavext','tgetnavext' | % {
#
# $publicDnsName = "$VmPrefix$_.westeurope.cloudapp.azure.com"
# $selfSigned = "$_".startswith("t")
#
# if ($selfSigned) {
# $sessionOption = New-PSSessionOption -SkipCACheck -SkipCNCheck
# }
# else {
# $sessionOption = New-PSSessionOption
# }
#
# Invoke-Command -ComputerName $publicDnsName -Credential $credential -UseSSL -SessionOption $sessionOption -ScriptBlock {
#
# $hostname = hostname
# Write-Output "Hostname : $hostname"
#
# }
#}
throw "Next lines removes the VMs"
$oss | ForEach-Object {
$operatingSystem = $_
$osp = $operatingSystem[$operatingSystem.Length-1]
$traefiks | ForEach-Object {
$AddTraefik = $_
$jsons | % {
$tp = "bc"
if ("$_".StartsWith('getnav')) {
$tp = "nav"
}
$ext = ("$_".EndsWith('ext'))
$traefik = "n"
if ($AddTraefik -eq "Yes") {
$traefik = "t"
}
$vmname = "$vmPrefix$traefik$osp$_"
$resgroup = "$vmName"
$resourceGroup = Get-AzResourceGroup -name $resGroup -ErrorAction Ignore
if ($resourceGroup) {
Write-Host "Removing Resource Group $resGroup"
Remove-AzResourceGroup -Name $resGroup -Force -AsJob
}
}
}
}