Skip to content

Commit

Permalink
Merge pull request Azure#143 from Azure/vnext
Browse files Browse the repository at this point in the history
Merging vnext to master
  • Loading branch information
MatthewMcGlynn authored Apr 6, 2017
2 parents 621adae + 42584db commit deee204
Show file tree
Hide file tree
Showing 24 changed files with 5,048 additions and 637 deletions.
135 changes: 95 additions & 40 deletions CanaryValidator/Canary.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ param (
[ValidateNotNullOrEmpty()]
[string]$EnvironmentName = "AzureStackCanaryCloud",
[parameter(HelpMessage="Resource group under which all the utilities need to be placed")]
[Parameter(ParameterSetName="default", Mandatory=$false)]
[Parameter(ParameterSetName="tenant", Mandatory=$false)]
[Parameter(ParameterSetName="default", Mandatory=$false)] [Parameter(ParameterSetName="tenant", Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[string]$CanaryUtilitiesRG = "canur" + [Random]::new().Next(1,999),
[parameter(HelpMessage="Resource group under which the virtual machines need to be placed")]
Expand All @@ -73,7 +72,7 @@ param (
[Parameter(ParameterSetName="tenant", Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[string]$ResourceLocation = "local",
[parameter(HelpMessage="Flag to cleanup resources after exception")]
[parameter(HelpMessage="Flag to indicate whether to continue Canary after an exception")]
[Parameter(ParameterSetName="default", Mandatory=$false)]
[Parameter(ParameterSetName="tenant", Mandatory=$false)]
[bool] $ContinueOnFailure = $false,
Expand All @@ -91,12 +90,12 @@ param (
[Parameter(ParameterSetName="default", Mandatory=$false)]
[Parameter(ParameterSetName="tenant", Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[string]$CanaryLogPath = $env:TMP + "\CanaryLogs$((Get-Date).ToString("-yyMMdd-hhmmss"))",
[string]$CanaryLogPath = $env:TMP + "\CanaryLogs$((Get-Date).Ticks)",
[parameter(HelpMessage="Specifies the file name for canary log file")]
[Parameter(ParameterSetName="default", Mandatory=$false)]
[Parameter(ParameterSetName="tenant", Mandatory=$false)]
[ValidateNotNullOrEmpty()]
[string]$CanaryLogFileName = "Canary-Basic$((Get-Date).ToString("-yyMMdd-hhmmss")).log"
[string]$CanaryLogFileName = "Canary-Basic-$((Get-Date).Ticks).log"
)

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

$runCount = 1
$tmpLogname = $CanaryLogFileName
while ($runCount -le $NumberOfIterations)
{
if (Test-Path -Path $canaryUtilPath)
Expand All @@ -129,8 +129,9 @@ while ($runCount -le $NumberOfIterations)

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

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

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

Invoke-Usecase -Name 'UploadLinuxImageToPIR' -Description "Uploads Linux image to the PIR" -UsecaseBlock `
if ((Get-Volume ((Get-Item -Path $ENV:TMP).PSDrive.Name)).SizeRemaining/1GB -gt 35)
{
if (-not (Get-AzureRmVMImage -Location $ResourceLocation -PublisherName $linuxImagePublisher -Offer $linuxImageOffer -Sku $LinuxOSSku -ErrorAction SilentlyContinue))
Invoke-Usecase -Name 'UploadLinuxImageToPIR' -Description "Uploads Linux image to the PIR" -UsecaseBlock `
{
$CanaryCustomImageFolder = Join-Path -Path $env:TMP -childPath "CanaryCustomImage$((Get-Date).ToString("-yyMMdd-hhmmss"))"
if (Test-Path -Path $CanaryCustomImageFolder)
try
{
Remove-Item -Path $CanaryCustomImageFolder -Force -Recurse
if (-not (Get-AzureRmVMImage -Location $ResourceLocation -PublisherName $linuxImagePublisher -Offer $linuxImageOffer -Sku $LinuxOSSku -ErrorAction SilentlyContinue))
{
$CanaryCustomImageFolder = Join-Path -Path $env:TMP -childPath "CanaryCustomImage$((Get-Date).Ticks)"
if (Test-Path -Path $CanaryCustomImageFolder)
{
Remove-Item -Path $CanaryCustomImageFolder -Force -Recurse
}
New-Item -Path $CanaryCustomImageFolder -ItemType Directory
$CustomVHDPath = CopyImage -ImagePath $LinuxImagePath -OutputFolder $CanaryCustomImageFolder
Add-VMImage -publisher $linuxImagePublisher -offer $linuxImageOffer -sku $LinuxOSSku -version $linuxImageVersion -osDiskLocalPath $CustomVHDPath -osType Linux -tenantID $TenantID -azureStackCredentials $ServiceAdminCredentials -CreateGalleryItem $false -EnvironmentName $SvcAdminEnvironmentName
Remove-Item $CanaryCustomImageFolder -Force -Recurse
}
}
catch
{
Remove-Item -Path $CanaryCustomImageFolder -Force -Recurse
throw [System.Exception]"Failed to upload the linux image to PIR. `n$($_.Exception.Message)"
}
New-Item -Path $CanaryCustomImageFolder -ItemType Directory
$CustomVHDPath = CopyImage -ImagePath $LinuxImagePath -OutputFolder $CanaryCustomImageFolder
Add-VMImage -publisher $linuxImagePublisher -offer $linuxImageOffer -sku $LinuxOSSku -version $linuxImageVersion -osDiskLocalPath $CustomVHDPath -osType Linux -tenantID $TenantID -azureStackCredentials $ServiceAdminCredentials -CreateGalleryItem $false -ArmEndpoint $AdminArmEndpoint
Remove-Item $CanaryCustomImageFolder -Recurse
}
}

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

if (-not $TenantArmEndpoint)
{
Expand Down Expand Up @@ -352,28 +364,38 @@ while ($runCount -le $NumberOfIterations)
}

Invoke-Usecase -Name 'UploadUtilitiesToBlobStorage' -Description "Upload the canary utilities to the blob storage" -UsecaseBlock `
{
$asStorageAccountKey = Get-AzureRmStorageAccountKey -ResourceGroupName $CanaryUtilitiesRG -Name $storageAccName -ErrorAction Stop
if ($asStorageAccountKey)
{
$storageAccountKey = $asStorageAccountKey.Key1
}
$asStorageContext = New-AzureStorageContext -StorageAccountName $storageAccName -StorageAccountKey $storageAccountKey -ErrorAction Stop
if ($asStorageContext)
{
$files = Get-ChildItem -Path $canaryUtilPath -File
foreach ($file in $files)
{
try
{
$asStorageAccountKey = Get-AzureRmStorageAccountKey -ResourceGroupName $CanaryUtilitiesRG -Name $storageAccName -ErrorAction Stop
if ($asStorageAccountKey)
{
if ($file.Extension -match "VHD")
{
Set-AzureStorageBlobContent -Container $storageCtrName -File $file.FullName -BlobType Page -Context $asStorageContext -Force -ErrorAction Stop
}
else
$storageAccountKey = $asStorageAccountKey.Key1
}
$asStorageContext = New-AzureStorageContext -StorageAccountName $storageAccName -StorageAccountKey $storageAccountKey -ErrorAction Stop
if ($asStorageContext)
{
$files = Get-ChildItem -Path $canaryUtilPath -File
foreach ($file in $files)
{
Set-AzureStorageBlobContent -Container $storageCtrName -File $file.FullName -Context $asStorageContext -Force -ErrorAction Stop
if ($file.Extension -match "VHD")
{
Set-AzureStorageBlobContent -Container $storageCtrName -File $file.FullName -BlobType Page -Context $asStorageContext -Force -ErrorAction Stop
}
else
{
Set-AzureStorageBlobContent -Container $storageCtrName -File $file.FullName -Context $asStorageContext -Force -ErrorAction Stop
}
}
}
}
finally
{
if (Test-Path -Path $canaryUtilPath)
{
Remove-Item -Path $canaryUtilPath -Recurse -Force
}
}
}

Invoke-Usecase -Name 'CreateKeyVaultStoreForCertSecret' -Description "Create a key vault store to put the certificate secret" -UsecaseBlock `
Expand Down Expand Up @@ -433,8 +455,13 @@ while ($runCount -le $NumberOfIterations)
elseif (Get-AzureRmVMImage -Location $ResourceLocation -PublisherName "MicrosoftWindowsServer" -Offer "WindowsServer" -Sku "2012-R2-Datacenter" -ErrorAction SilentlyContinue)
{
$osVersion = "2012-R2-Datacenter"
}

}
$linuxImgExists = $false
if (Get-AzureRmVMImage -Location $ResourceLocation -PublisherName "Canonical" -Offer "UbuntuServer" -Sku $LinuxOSSku -ErrorAction SilentlyContinue)
{
$linuxImgExists = $true
}

$templateDeploymentName = "CanaryVMDeployment"
$parameters = @{"VMAdminUserName" = $VMAdminUserName;
"VMAdminUserPassword" = $VMAdminUserPass;
Expand All @@ -447,11 +474,22 @@ while ($runCount -le $NumberOfIterations)
"LinuxImagePublisher" = $linuxImagePublisher;
"LinuxImageOffer" = $linuxImageOffer;
"LinuxImageSku" = $LinuxOSSku}
$templateError = Test-AzureRmResourceGroupDeployment -ResourceGroupName $CanaryVMRG -TemplateFile $PSScriptRoot\azuredeploy.json -TemplateParameterObject $parameters
if (-not $templateError)
if (-not $linuxImgExists)
{
$templateError = Test-AzureRmResourceGroupDeployment -ResourceGroupName $CanaryVMRG -TemplateFile $PSScriptRoot\azuredeploy.json -TemplateParameterObject $parameters
}
elseif ($linuxImgExists)
{
$templateError = Test-AzureRmResourceGroupDeployment -ResourceGroupName $CanaryVMRG -TemplateFile $PSScriptRoot\azuredeploy.nolinux.json -TemplateParameterObject $parameters
}

if ((-not $templateError) -and ($linuxImgExists))
{
New-AzureRmResourceGroupDeployment -Name $templateDeploymentName -ResourceGroupName $CanaryVMRG -TemplateFile $PSScriptRoot\azuredeploy.json -TemplateParameterObject $parameters -Verbose -ErrorAction Stop
}
elseif (-not $templateError) {
New-AzureRmResourceGroupDeployment -Name $templateDeploymentName -ResourceGroupName $CanaryVMRG -TemplateFile $PSScriptRoot\azuredeploy.nolinux.json -TemplateParameterObject $parameters -Verbose -ErrorAction Stop
}
else
{
throw [System.Exception] "Template validation failed. `n$($templateError.Message)"
Expand Down Expand Up @@ -685,6 +723,23 @@ while ($runCount -le $NumberOfIterations)
}
}
}

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 `
{
$sa = Get-AzureRmStorageAccount -ResourceGroupName $CanaryVMRG -Name "$($CanaryVMRG)2sa"
$diagSC = $sa | Get-AzureStorageContainer | Where-Object {$_.Name -like "bootdiagnostics-$CanaryVMRG*"}
$screenShotBlob = $diagSC | Get-AzureStorageBlob | Where-Object {$_.Name -like "$privateVMName*screenshot.bmp"}
$sa | Get-AzureStorageBlobContent -Blob $screenShotBlob.Name -Container $diagSC.Name -Destination $CanaryLogPath -Force
if (-not (Get-ChildItem -Path $CanaryLogPath -File -Filter $screenShotBlob.name))
{
throw [System.Exception]"Unable to download screen shot for a Windows VM with private IP"
}
}

Invoke-Usecase -Name 'EnumerateAllResources' -Description "List out all the resources that have been deployed" -UsecaseBlock `
{
Get-AzureRmResource
}

if (-not $NoCleanup)
{
Expand Down
11 changes: 9 additions & 2 deletions CanaryValidator/Canary.Utilities.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ function Invoke-Usecase
catch [System.Exception]
{
Log-Exception ($_.Exception)
Log-Info ("###### <FAULTING SCRIPTBLOCK> ######")
Log-Info ("$UsecaseBlock")
Log-Info ("###### </FAULTING SCRIPTBLOCK> ######")
Log-Error ("###### [END] Usecase: $Name ###### [RESULT = FAIL] ######`n")
if ($Global:wttLogFileName)
{
Expand Down Expand Up @@ -501,8 +504,12 @@ function NewAzureStackToken
)

$endpoints = GetAzureStackEndpoints -EnvironmentDomainFQDN $EnvironmentDomainFQDN -ArmEndPoint $ArmEndpoint
$asToken = Get-AzureStackToken -Authority $endpoints.ActiveDirectoryEndpoint -Resource $endpoints.ActiveDirectoryServiceEndpointResourceId -AadTenantId $aadTenantId -Credential $Credentials -ErrorAction Stop
return $asToken
$clientId = "1950a258-227b-4e31-a9cf-717495945fc2"

$contextAuthorityEndpoint = ([System.IO.Path]::Combine($endpoints.ActiveDirectoryEndpoint, $AADTenantID)).Replace('\','/')
$authContext = New-Object Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext($contextAuthorityEndpoint, $false)
$userCredential = New-Object Microsoft.IdentityModel.Clients.ActiveDirectory.UserCredential($Credentials.UserName, $Credentials.Password)
return ($authContext.AcquireToken($endpoints.ActiveDirectoryServiceEndpointResourceId, $clientId, $userCredential)).AccessToken
}

function NewAzureStackDefaultQuotas
Expand Down
21 changes: 12 additions & 9 deletions CanaryValidator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,32 @@ Set-Location -Path ".\AzureStack-Tools-master\CanaryValidator" -PassThru

# To execute Canary as Tenant Administrator (if Windows Server 2016 or Windows Server 2012-R2 images are already present in the PIR)
```powershell
# Install-Module AzureRM -RequiredVersion 1.2.8 -Scope CurrentUser
# Install-Module AzureStack -RequiredVersion 1.2.8 -Force
# Install-Module -Name 'AzureRm.Bootstrapper' -Scope CurrentUser
# Install-AzureRmProfile -profile '2017-03-09-profile' -Force -Scope CurrentUser
# Install-Module -Name AzureStack -RequiredVersion 1.2.9 -Scope CurrentUser
$TenantAdminCreds = New-Object System.Management.Automation.PSCredential "<Tenant Admin username>", (ConvertTo-SecureString "<Tenant Admin password>" -AsPlainText -Force)
$ServiceAdminCreds = New-Object System.Management.Automation.PSCredential "<Service Admin username>", (ConvertTo-SecureString "<Service Admin password>" -AsPlainText -Force)
.\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>"
.\Canary.Tests.ps1 -TenantID "<TenantID from Azure Active Directory>" -AdminArmEndpoint "<Administrative ARM endpoint>" -ServiceAdminCredentials $ServiceAdminCreds -TenantArmEndpoint "<Tenant ARM endpoint>" -TenantAdminCredentials $TenantAdminCreds
```

# To execute Canary as Tenant Administrator (if Windows Server 2016 or Windows Server 2012-R2 images are not present in PIR)
```powershell
# Download the WS2016 ISO image from: https://www.microsoft.com/en-us/evalcenter/evaluate-windows-server-2016, and place it on your local machine
# Install-Module AzureRM -RequiredVersion 1.2.8 -Scope CurrentUser
# Install-Module AzureStack-RequiredVersion 1.2.8 -Force
# Install-Module -Name 'AzureRm.Bootstrapper' -Scope CurrentUser
# Install-AzureRmProfile -profile '2017-03-09-profile' -Force -Scope CurrentUser
# Install-Module -Name AzureStack -RequiredVersion 1.2.9 -Scope CurrentUser
$TenantAdminCreds = New-Object System.Management.Automation.PSCredential "<Tenant Admin username>", (ConvertTo-SecureString "<Tenant Admin password>" -AsPlainText -Force)
$ServiceAdminCreds = New-Object System.Management.Automation.PSCredential "<Service Admin username>", (ConvertTo-SecureString "<Service Admin password>" -AsPlainText -Force)
.\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>"
.\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>"
```

# To execute Canary as Service Administrator
```powershell
# Install-Module AzureRM -RequiredVersion 1.2.8 -Scope CurrentUser
# Install-Module AzureStack-RequiredVersion 1.2.8 -Force
# Install-Module -Name 'AzureRm.Bootstrapper' -Scope CurrentUser
# Install-AzureRmProfile -profile '2017-03-09-profile' -Force -Scope CurrentUser
# Install-Module -Name AzureStack -RequiredVersion 1.2.9 -Scope CurrentUser
$ServiceAdminCreds = New-Object System.Management.Automation.PSCredential "<Service Admin username>", (ConvertTo-SecureString "<Service Admin password>" -AsPlainText -Force)
.\Canary.Tests.ps1 -TenantID "<TenantID from Azure Active Directory>" -AdminArmEndpoint "<Administrative ARM endpoint>" -ServiceAdminCredentials $ServiceAdminCreds -WindowsISOPath "<path where the WS2016 ISO is present>"
.\Canary.Tests.ps1 -TenantID "<TenantID from Azure Active Directory>" -AdminArmEndpoint "<Administrative ARM endpoint>" -ServiceAdminCredentials $ServiceAdminCreds
```
# Reading the results & logs
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.
Expand Down
Loading

0 comments on commit deee204

Please sign in to comment.