Skip to content

Commit deee204

Browse files
Merge pull request Azure#143 from Azure/vnext
Merging vnext to master
2 parents 621adae + 42584db commit deee204

24 files changed

+5048
-637
lines changed

CanaryValidator/Canary.Tests.ps1

Lines changed: 95 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ param (
5959
[ValidateNotNullOrEmpty()]
6060
[string]$EnvironmentName = "AzureStackCanaryCloud",
6161
[parameter(HelpMessage="Resource group under which all the utilities need to be placed")]
62-
[Parameter(ParameterSetName="default", Mandatory=$false)]
63-
[Parameter(ParameterSetName="tenant", Mandatory=$false)]
62+
[Parameter(ParameterSetName="default", Mandatory=$false)] [Parameter(ParameterSetName="tenant", Mandatory=$false)]
6463
[ValidateNotNullOrEmpty()]
6564
[string]$CanaryUtilitiesRG = "canur" + [Random]::new().Next(1,999),
6665
[parameter(HelpMessage="Resource group under which the virtual machines need to be placed")]
@@ -73,7 +72,7 @@ param (
7372
[Parameter(ParameterSetName="tenant", Mandatory=$false)]
7473
[ValidateNotNullOrEmpty()]
7574
[string]$ResourceLocation = "local",
76-
[parameter(HelpMessage="Flag to cleanup resources after exception")]
75+
[parameter(HelpMessage="Flag to indicate whether to continue Canary after an exception")]
7776
[Parameter(ParameterSetName="default", Mandatory=$false)]
7877
[Parameter(ParameterSetName="tenant", Mandatory=$false)]
7978
[bool] $ContinueOnFailure = $false,
@@ -91,12 +90,12 @@ param (
9190
[Parameter(ParameterSetName="default", Mandatory=$false)]
9291
[Parameter(ParameterSetName="tenant", Mandatory=$false)]
9392
[ValidateNotNullOrEmpty()]
94-
[string]$CanaryLogPath = $env:TMP + "\CanaryLogs$((Get-Date).ToString("-yyMMdd-hhmmss"))",
93+
[string]$CanaryLogPath = $env:TMP + "\CanaryLogs$((Get-Date).Ticks)",
9594
[parameter(HelpMessage="Specifies the file name for canary log file")]
9695
[Parameter(ParameterSetName="default", Mandatory=$false)]
9796
[Parameter(ParameterSetName="tenant", Mandatory=$false)]
9897
[ValidateNotNullOrEmpty()]
99-
[string]$CanaryLogFileName = "Canary-Basic$((Get-Date).ToString("-yyMMdd-hhmmss")).log"
98+
[string]$CanaryLogFileName = "Canary-Basic-$((Get-Date).Ticks).log"
10099
)
101100

102101
#Requires -Modules AzureRM
@@ -113,12 +112,13 @@ $keyvaultCertName = "ASCanaryVMCertificate"
113112
$kvSecretName = $keyvaultName.ToLowerInvariant() + "secret"
114113
$VMAdminUserName = "CanaryAdmin"
115114
$VMAdminUserPass = "CanaryAdmin@123"
116-
$canaryUtilPath = Join-Path -Path $env:TEMP -ChildPath "CanaryUtilities$((Get-Date).ToString("-yyMMdd-hhmmss"))"
115+
$canaryUtilPath = Join-Path -Path $env:TEMP -ChildPath "CanaryUtilities$((Get-Date).Ticks)"
117116
$linuxImagePublisher = "Canonical"
118117
$linuxImageOffer = "UbuntuServer"
119118
$linuxImageVersion = "1.0.0"
120119

121120
$runCount = 1
121+
$tmpLogname = $CanaryLogFileName
122122
while ($runCount -le $NumberOfIterations)
123123
{
124124
if (Test-Path -Path $canaryUtilPath)
@@ -129,8 +129,9 @@ while ($runCount -le $NumberOfIterations)
129129

130130
#
131131
# Start Canary
132-
#
133-
$CanaryLogFile = $CanaryLogPath + "\$CanaryLogFileName"
132+
#
133+
$CanaryLogFileName = [IO.Path]::GetFileNameWithoutExtension($tmpLogname) + "-$runCount" + [IO.Path]::GetExtension($tmpLogname)
134+
$CanaryLogFile = Join-Path -Path $CanaryLogPath -ChildPath $CanaryLogFileName
134135

135136
Start-Scenario -Name 'Canary' -Type 'Basic' -LogFilename $CanaryLogFile -ContinueOnFailure $ContinueOnFailure
136137

@@ -179,24 +180,35 @@ while ($runCount -le $NumberOfIterations)
179180
{
180181
if (-not (Get-AzureRmVMImage -Location $ResourceLocation -PublisherName "MicrosoftWindowsServer" -Offer "WindowsServer" -Sku "2016-Datacenter-Core" -ErrorAction SilentlyContinue))
181182
{
182-
New-Server2016VMImage -ISOPath $WindowsISOPath -TenantId $TenantID -ArmEndpoint $AdminArmEndpoint -Version Core -AzureStackCredentials $ServiceAdminCredentials -CreateGalleryItem $false
183+
New-Server2016VMImage -ISOPath $WindowsISOPath -TenantId $TenantID -EnvironmentName $SvcAdminEnvironmentName -Version Core -AzureStackCredentials $ServiceAdminCredentials -CreateGalleryItem $false
183184
}
184185
}
185186
}
186187

187-
Invoke-Usecase -Name 'UploadLinuxImageToPIR' -Description "Uploads Linux image to the PIR" -UsecaseBlock `
188+
if ((Get-Volume ((Get-Item -Path $ENV:TMP).PSDrive.Name)).SizeRemaining/1GB -gt 35)
188189
{
189-
if (-not (Get-AzureRmVMImage -Location $ResourceLocation -PublisherName $linuxImagePublisher -Offer $linuxImageOffer -Sku $LinuxOSSku -ErrorAction SilentlyContinue))
190+
Invoke-Usecase -Name 'UploadLinuxImageToPIR' -Description "Uploads Linux image to the PIR" -UsecaseBlock `
190191
{
191-
$CanaryCustomImageFolder = Join-Path -Path $env:TMP -childPath "CanaryCustomImage$((Get-Date).ToString("-yyMMdd-hhmmss"))"
192-
if (Test-Path -Path $CanaryCustomImageFolder)
192+
try
193193
{
194-
Remove-Item -Path $CanaryCustomImageFolder -Force -Recurse
194+
if (-not (Get-AzureRmVMImage -Location $ResourceLocation -PublisherName $linuxImagePublisher -Offer $linuxImageOffer -Sku $LinuxOSSku -ErrorAction SilentlyContinue))
195+
{
196+
$CanaryCustomImageFolder = Join-Path -Path $env:TMP -childPath "CanaryCustomImage$((Get-Date).Ticks)"
197+
if (Test-Path -Path $CanaryCustomImageFolder)
198+
{
199+
Remove-Item -Path $CanaryCustomImageFolder -Force -Recurse
200+
}
201+
New-Item -Path $CanaryCustomImageFolder -ItemType Directory
202+
$CustomVHDPath = CopyImage -ImagePath $LinuxImagePath -OutputFolder $CanaryCustomImageFolder
203+
Add-VMImage -publisher $linuxImagePublisher -offer $linuxImageOffer -sku $LinuxOSSku -version $linuxImageVersion -osDiskLocalPath $CustomVHDPath -osType Linux -tenantID $TenantID -azureStackCredentials $ServiceAdminCredentials -CreateGalleryItem $false -EnvironmentName $SvcAdminEnvironmentName
204+
Remove-Item $CanaryCustomImageFolder -Force -Recurse
205+
}
206+
}
207+
catch
208+
{
209+
Remove-Item -Path $CanaryCustomImageFolder -Force -Recurse
210+
throw [System.Exception]"Failed to upload the linux image to PIR. `n$($_.Exception.Message)"
195211
}
196-
New-Item -Path $CanaryCustomImageFolder -ItemType Directory
197-
$CustomVHDPath = CopyImage -ImagePath $LinuxImagePath -OutputFolder $CanaryCustomImageFolder
198-
Add-VMImage -publisher $linuxImagePublisher -offer $linuxImageOffer -sku $LinuxOSSku -version $linuxImageVersion -osDiskLocalPath $CustomVHDPath -osType Linux -tenantID $TenantID -azureStackCredentials $ServiceAdminCredentials -CreateGalleryItem $false -ArmEndpoint $AdminArmEndpoint
199-
Remove-Item $CanaryCustomImageFolder -Recurse
200212
}
201213
}
202214

@@ -206,7 +218,7 @@ while ($runCount -le $NumberOfIterations)
206218
$tenantPlanName = "ascantenantplan" + [Random]::new().Next(1,999)
207219
$tenantOfferName = "ascantenantoffer" + [Random]::new().Next(1,999)
208220
$tenantSubscriptionName = "ascanarytenantsubscription" + [Random]::new().Next(1,999)
209-
$canaryDefaultTenantSubscription = "canarytenantdefaultsubscription"
221+
$canaryDefaultTenantSubscription = "canarytenantdefaultsubscription" + [Random]::new().Next(1,999)
210222

211223
if (-not $TenantArmEndpoint)
212224
{
@@ -352,28 +364,38 @@ while ($runCount -le $NumberOfIterations)
352364
}
353365

354366
Invoke-Usecase -Name 'UploadUtilitiesToBlobStorage' -Description "Upload the canary utilities to the blob storage" -UsecaseBlock `
355-
{
356-
$asStorageAccountKey = Get-AzureRmStorageAccountKey -ResourceGroupName $CanaryUtilitiesRG -Name $storageAccName -ErrorAction Stop
357-
if ($asStorageAccountKey)
358-
{
359-
$storageAccountKey = $asStorageAccountKey.Key1
360-
}
361-
$asStorageContext = New-AzureStorageContext -StorageAccountName $storageAccName -StorageAccountKey $storageAccountKey -ErrorAction Stop
362-
if ($asStorageContext)
363-
{
364-
$files = Get-ChildItem -Path $canaryUtilPath -File
365-
foreach ($file in $files)
367+
{
368+
try
369+
{
370+
$asStorageAccountKey = Get-AzureRmStorageAccountKey -ResourceGroupName $CanaryUtilitiesRG -Name $storageAccName -ErrorAction Stop
371+
if ($asStorageAccountKey)
366372
{
367-
if ($file.Extension -match "VHD")
368-
{
369-
Set-AzureStorageBlobContent -Container $storageCtrName -File $file.FullName -BlobType Page -Context $asStorageContext -Force -ErrorAction Stop
370-
}
371-
else
373+
$storageAccountKey = $asStorageAccountKey.Key1
374+
}
375+
$asStorageContext = New-AzureStorageContext -StorageAccountName $storageAccName -StorageAccountKey $storageAccountKey -ErrorAction Stop
376+
if ($asStorageContext)
377+
{
378+
$files = Get-ChildItem -Path $canaryUtilPath -File
379+
foreach ($file in $files)
372380
{
373-
Set-AzureStorageBlobContent -Container $storageCtrName -File $file.FullName -Context $asStorageContext -Force -ErrorAction Stop
381+
if ($file.Extension -match "VHD")
382+
{
383+
Set-AzureStorageBlobContent -Container $storageCtrName -File $file.FullName -BlobType Page -Context $asStorageContext -Force -ErrorAction Stop
384+
}
385+
else
386+
{
387+
Set-AzureStorageBlobContent -Container $storageCtrName -File $file.FullName -Context $asStorageContext -Force -ErrorAction Stop
388+
}
374389
}
375390
}
376391
}
392+
finally
393+
{
394+
if (Test-Path -Path $canaryUtilPath)
395+
{
396+
Remove-Item -Path $canaryUtilPath -Recurse -Force
397+
}
398+
}
377399
}
378400

379401
Invoke-Usecase -Name 'CreateKeyVaultStoreForCertSecret' -Description "Create a key vault store to put the certificate secret" -UsecaseBlock `
@@ -433,8 +455,13 @@ while ($runCount -le $NumberOfIterations)
433455
elseif (Get-AzureRmVMImage -Location $ResourceLocation -PublisherName "MicrosoftWindowsServer" -Offer "WindowsServer" -Sku "2012-R2-Datacenter" -ErrorAction SilentlyContinue)
434456
{
435457
$osVersion = "2012-R2-Datacenter"
436-
}
437-
458+
}
459+
$linuxImgExists = $false
460+
if (Get-AzureRmVMImage -Location $ResourceLocation -PublisherName "Canonical" -Offer "UbuntuServer" -Sku $LinuxOSSku -ErrorAction SilentlyContinue)
461+
{
462+
$linuxImgExists = $true
463+
}
464+
438465
$templateDeploymentName = "CanaryVMDeployment"
439466
$parameters = @{"VMAdminUserName" = $VMAdminUserName;
440467
"VMAdminUserPassword" = $VMAdminUserPass;
@@ -447,11 +474,22 @@ while ($runCount -le $NumberOfIterations)
447474
"LinuxImagePublisher" = $linuxImagePublisher;
448475
"LinuxImageOffer" = $linuxImageOffer;
449476
"LinuxImageSku" = $LinuxOSSku}
450-
$templateError = Test-AzureRmResourceGroupDeployment -ResourceGroupName $CanaryVMRG -TemplateFile $PSScriptRoot\azuredeploy.json -TemplateParameterObject $parameters
451-
if (-not $templateError)
477+
if (-not $linuxImgExists)
478+
{
479+
$templateError = Test-AzureRmResourceGroupDeployment -ResourceGroupName $CanaryVMRG -TemplateFile $PSScriptRoot\azuredeploy.json -TemplateParameterObject $parameters
480+
}
481+
elseif ($linuxImgExists)
482+
{
483+
$templateError = Test-AzureRmResourceGroupDeployment -ResourceGroupName $CanaryVMRG -TemplateFile $PSScriptRoot\azuredeploy.nolinux.json -TemplateParameterObject $parameters
484+
}
485+
486+
if ((-not $templateError) -and ($linuxImgExists))
452487
{
453488
New-AzureRmResourceGroupDeployment -Name $templateDeploymentName -ResourceGroupName $CanaryVMRG -TemplateFile $PSScriptRoot\azuredeploy.json -TemplateParameterObject $parameters -Verbose -ErrorAction Stop
454489
}
490+
elseif (-not $templateError) {
491+
New-AzureRmResourceGroupDeployment -Name $templateDeploymentName -ResourceGroupName $CanaryVMRG -TemplateFile $PSScriptRoot\azuredeploy.nolinux.json -TemplateParameterObject $parameters -Verbose -ErrorAction Stop
492+
}
455493
else
456494
{
457495
throw [System.Exception] "Template validation failed. `n$($templateError.Message)"
@@ -685,6 +723,23 @@ while ($runCount -le $NumberOfIterations)
685723
}
686724
}
687725
}
726+
727+
Invoke-Usecase -Name 'CheckExistenceOfScreenShotForVMWithPrivateIP' -Description "Check if screen shots are available for Windows VM with private IP and store the screen shot in log folder" -UsecaseBlock `
728+
{
729+
$sa = Get-AzureRmStorageAccount -ResourceGroupName $CanaryVMRG -Name "$($CanaryVMRG)2sa"
730+
$diagSC = $sa | Get-AzureStorageContainer | Where-Object {$_.Name -like "bootdiagnostics-$CanaryVMRG*"}
731+
$screenShotBlob = $diagSC | Get-AzureStorageBlob | Where-Object {$_.Name -like "$privateVMName*screenshot.bmp"}
732+
$sa | Get-AzureStorageBlobContent -Blob $screenShotBlob.Name -Container $diagSC.Name -Destination $CanaryLogPath -Force
733+
if (-not (Get-ChildItem -Path $CanaryLogPath -File -Filter $screenShotBlob.name))
734+
{
735+
throw [System.Exception]"Unable to download screen shot for a Windows VM with private IP"
736+
}
737+
}
738+
739+
Invoke-Usecase -Name 'EnumerateAllResources' -Description "List out all the resources that have been deployed" -UsecaseBlock `
740+
{
741+
Get-AzureRmResource
742+
}
688743

689744
if (-not $NoCleanup)
690745
{

CanaryValidator/Canary.Utilities.psm1

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,9 @@ function Invoke-Usecase
242242
catch [System.Exception]
243243
{
244244
Log-Exception ($_.Exception)
245+
Log-Info ("###### <FAULTING SCRIPTBLOCK> ######")
246+
Log-Info ("$UsecaseBlock")
247+
Log-Info ("###### </FAULTING SCRIPTBLOCK> ######")
245248
Log-Error ("###### [END] Usecase: $Name ###### [RESULT = FAIL] ######`n")
246249
if ($Global:wttLogFileName)
247250
{
@@ -501,8 +504,12 @@ function NewAzureStackToken
501504
)
502505

503506
$endpoints = GetAzureStackEndpoints -EnvironmentDomainFQDN $EnvironmentDomainFQDN -ArmEndPoint $ArmEndpoint
504-
$asToken = Get-AzureStackToken -Authority $endpoints.ActiveDirectoryEndpoint -Resource $endpoints.ActiveDirectoryServiceEndpointResourceId -AadTenantId $aadTenantId -Credential $Credentials -ErrorAction Stop
505-
return $asToken
507+
$clientId = "1950a258-227b-4e31-a9cf-717495945fc2"
508+
509+
$contextAuthorityEndpoint = ([System.IO.Path]::Combine($endpoints.ActiveDirectoryEndpoint, $AADTenantID)).Replace('\','/')
510+
$authContext = New-Object Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext($contextAuthorityEndpoint, $false)
511+
$userCredential = New-Object Microsoft.IdentityModel.Clients.ActiveDirectory.UserCredential($Credentials.UserName, $Credentials.Password)
512+
return ($authContext.AcquireToken($endpoints.ActiveDirectoryServiceEndpointResourceId, $clientId, $userCredential)).AccessToken
506513
}
507514

508515
function NewAzureStackDefaultQuotas

CanaryValidator/README.md

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,32 @@ Set-Location -Path ".\AzureStack-Tools-master\CanaryValidator" -PassThru
1313

1414
# To execute Canary as Tenant Administrator (if Windows Server 2016 or Windows Server 2012-R2 images are already present in the PIR)
1515
```powershell
16-
# Install-Module AzureRM -RequiredVersion 1.2.8 -Scope CurrentUser
17-
# Install-Module AzureStack -RequiredVersion 1.2.8 -Force
16+
# Install-Module -Name 'AzureRm.Bootstrapper' -Scope CurrentUser
17+
# Install-AzureRmProfile -profile '2017-03-09-profile' -Force -Scope CurrentUser
18+
# Install-Module -Name AzureStack -RequiredVersion 1.2.9 -Scope CurrentUser
1819
$TenantAdminCreds = New-Object System.Management.Automation.PSCredential "<Tenant Admin username>", (ConvertTo-SecureString "<Tenant Admin password>" -AsPlainText -Force)
1920
$ServiceAdminCreds = New-Object System.Management.Automation.PSCredential "<Service Admin username>", (ConvertTo-SecureString "<Service Admin password>" -AsPlainText -Force)
20-
.\Canary.Tests.ps1 -TenantID "<TenantID from Azure Active Directory>" -AdminArmEndpoint "<Administrative ARM endpoint>" -ServiceAdminCredentials $ServiceAdminCreds -TenantArmEndpoint "<Tenant ARM endpoint>" -TenantAdminCredentials $TenantAdminCreds -WindowsISOPath "<path where the WS2016 ISO is present>"
21+
.\Canary.Tests.ps1 -TenantID "<TenantID from Azure Active Directory>" -AdminArmEndpoint "<Administrative ARM endpoint>" -ServiceAdminCredentials $ServiceAdminCreds -TenantArmEndpoint "<Tenant ARM endpoint>" -TenantAdminCredentials $TenantAdminCreds
2122
```
2223

2324
# To execute Canary as Tenant Administrator (if Windows Server 2016 or Windows Server 2012-R2 images are not present in PIR)
2425
```powershell
2526
# Download the WS2016 ISO image from: https://www.microsoft.com/en-us/evalcenter/evaluate-windows-server-2016, and place it on your local machine
26-
# Install-Module AzureRM -RequiredVersion 1.2.8 -Scope CurrentUser
27-
# Install-Module AzureStack-RequiredVersion 1.2.8 -Force
27+
# Install-Module -Name 'AzureRm.Bootstrapper' -Scope CurrentUser
28+
# Install-AzureRmProfile -profile '2017-03-09-profile' -Force -Scope CurrentUser
29+
# Install-Module -Name AzureStack -RequiredVersion 1.2.9 -Scope CurrentUser
2830
$TenantAdminCreds = New-Object System.Management.Automation.PSCredential "<Tenant Admin username>", (ConvertTo-SecureString "<Tenant Admin password>" -AsPlainText -Force)
2931
$ServiceAdminCreds = New-Object System.Management.Automation.PSCredential "<Service Admin username>", (ConvertTo-SecureString "<Service Admin password>" -AsPlainText -Force)
30-
.\Canary.Tests.ps1 -TenantID "<TenantID from Azure Active Directory>" -AdminArmEndpoint "<Administrative ARM endpoint>" -ServiceAdminCredentials $ServiceAdminCreds -TenantArmEndpoint "<Tenant ARM endpoint>" -TenantAdminCredentials $TenantAdminCreds -WindowsISOPath "<path where the WS2016 ISO is present>" -WindowsISOPath "<Local ISO path>"
32+
.\Canary.Tests.ps1 -TenantID "<TenantID from Azure Active Directory>" -AdminArmEndpoint "<Administrative ARM endpoint>" -ServiceAdminCredentials $ServiceAdminCreds -TenantArmEndpoint "<Tenant ARM endpoint>" -TenantAdminCredentials $TenantAdminCreds -WindowsISOPath "<path where the WS2016 ISO is present>"
3133
```
3234

3335
# To execute Canary as Service Administrator
3436
```powershell
35-
# Install-Module AzureRM -RequiredVersion 1.2.8 -Scope CurrentUser
36-
# Install-Module AzureStack-RequiredVersion 1.2.8 -Force
37+
# Install-Module -Name 'AzureRm.Bootstrapper' -Scope CurrentUser
38+
# Install-AzureRmProfile -profile '2017-03-09-profile' -Force -Scope CurrentUser
39+
# Install-Module -Name AzureStack -RequiredVersion 1.2.9 -Scope CurrentUser
3740
$ServiceAdminCreds = New-Object System.Management.Automation.PSCredential "<Service Admin username>", (ConvertTo-SecureString "<Service Admin password>" -AsPlainText -Force)
38-
.\Canary.Tests.ps1 -TenantID "<TenantID from Azure Active Directory>" -AdminArmEndpoint "<Administrative ARM endpoint>" -ServiceAdminCredentials $ServiceAdminCreds -WindowsISOPath "<path where the WS2016 ISO is present>"
41+
.\Canary.Tests.ps1 -TenantID "<TenantID from Azure Active Directory>" -AdminArmEndpoint "<Administrative ARM endpoint>" -ServiceAdminCredentials $ServiceAdminCreds
3942
```
4043
# Reading the results & logs
4144
Canary generates log files in the TMP directory ($env:TMP). The logs can be found under the directory "CanaryLogs[DATETIME]". There are two types of logs generated, a text log and a JSON log. JSON log provides a quick and easy view of all the usecases and their corresponding results. Text log provides a more detailed output of each usecase execution, its output and results.

0 commit comments

Comments
 (0)