Skip to content

Commit 14b4b10

Browse files
committed
Pulling vnext changes-3
1 parent f912522 commit 14b4b10

1 file changed

Lines changed: 61 additions & 26 deletions

File tree

CanaryValidator/Canary.Tests.ps1

Lines changed: 61 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -707,40 +707,69 @@ while ($runCount -le $NumberOfIterations)
707707
New-AzureRmResourceGroup -Name $CanaryVMRG -Location $ResourceLocation -ErrorAction Stop
708708
}
709709

710-
Invoke-Usecase -Name 'DeployARMTemplate' -Description "Deploy ARM template to setup the virtual machines" -UsecaseBlock `
711-
{
712-
$kvSecretId = (Get-AzureKeyVaultSecret -VaultName $keyVaultName -Name $kvSecretName -IncludeVersions -ErrorAction Stop).Id
710+
$pirQueryRes = Invoke-Usecase -Name 'QueryImagesFromPIR' -Description "Queries the images in Platform Image Repository to retrieve the OS Version to deploy on the VMs" -UsecaseBlock `
711+
{
713712
$osVersion = ""
714-
if (Get-AzureRmVMImage -Location $ResourceLocation -PublisherName "MicrosoftWindowsServer" -Offer "WindowsServer" -Sku "2016-Datacenter-Core" -ErrorAction SilentlyContinue)
713+
[boolean]$linuxImgExists = $false
714+
$sw = [system.diagnostics.stopwatch]::startNew()
715+
while (([string]::IsNullOrEmpty($osVersion)) -and ($sw.ElapsedMilliseconds -lt 300000))
715716
{
716-
$osVersion = "2016-Datacenter-Core"
717-
}
718-
elseif (Get-AzureRmVMImage -Location $ResourceLocation -PublisherName "MicrosoftWindowsServer" -Offer "WindowsServer" -Sku "2016-Datacenter" -ErrorAction SilentlyContinue)
717+
# Returns all the images that are available in the PIR
718+
$pirImages = Get-AzureRmVMImagePublisher -Location $ResourceLocation | Get-AzureRmVMImageOffer | Get-AzureRmVMImageSku | Get-AzureRMVMImage | Get-AzureRmVMImage
719+
720+
foreach($image in $pirImages)
721+
{
722+
# Canary specific check to see if the required Ubuntu image was successfully uploaded and available in PIR
723+
if ($image.PublisherName.Equals("Canonical") -and $image.Offer.Equals("UbuntuServer") -and $image.Skus.Equals($LinuxOSSku))
724+
{
725+
$linuxImgExists = $true
726+
}
727+
728+
if ($image.PublisherName.Equals("MicrosoftWindowsServer") -and $image.Offer.Equals("WindowsServer") -and $image.Skus.Equals("2016-Datacenter-Core"))
729+
{
730+
$osVersion = "2016-Datacenter-Core"
731+
}
732+
elseif ($image.PublisherName.Equals("MicrosoftWindowsServer") -and $image.Offer.Equals("WindowsServer") -and $image.Skus.Equals("2016-Datacenter"))
733+
{
734+
$osVersion = "2016-Datacenter"
735+
}
736+
elseif ($image.PublisherName.Equals("MicrosoftWindowsServer") -and $image.Offer.Equals("WindowsServer") -and $image.Skus.Equals("2012-R2-Datacenter"))
737+
{
738+
$osVersion = "2012-R2-Datacenter"
739+
}
740+
}
741+
Start-Sleep -Seconds 20
742+
}
743+
$sw.Stop()
744+
if (($linuxUpload) -and (-not $linuxImgExists))
719745
{
720-
$osVersion = "2016-Datacenter"
746+
throw [System.Exception] "Unable to find Ubuntu image (Ubuntu $LinuxOSSku) in PIR or failed to retrieve the image from PIR"
721747
}
722-
elseif (Get-AzureRmVMImage -Location $ResourceLocation -PublisherName "MicrosoftWindowsServer" -Offer "WindowsServer" -Sku "2012-R2-Datacenter" -ErrorAction SilentlyContinue)
748+
if ([string]::IsNullOrEmpty($osVersion))
723749
{
724-
$osVersion = "2012-R2-Datacenter"
725-
}
726-
$linuxImgExists = $false
727-
if (Get-AzureRmVMImage -Location $ResourceLocation -PublisherName "Canonical" -Offer "UbuntuServer" -Sku $LinuxOSSku -ErrorAction SilentlyContinue)
728-
{
729-
$linuxImgExists = $true
750+
throw [System.Exception] "Unable to find windows image in PIR or failed to retrieve the image from PIR"
730751
}
752+
$osVersion, $linuxImgExists
753+
}
754+
[string]$osVersion = $pirQueryRes[2]
755+
[boolean]$linuxImgExists = $pirQueryRes[3]
731756

757+
Invoke-Usecase -Name 'DeployARMTemplate' -Description "Deploy ARM template to setup the virtual machines" -UsecaseBlock `
758+
{
759+
$kvSecretId = (Get-AzureKeyVaultSecret -VaultName $keyVaultName -Name $kvSecretName -IncludeVersions -ErrorAction Stop).Id
732760
$templateDeploymentName = "CanaryVMDeployment"
733-
$parameters = @{"VMAdminUserName" = $VMAdminUserName;
734-
"VMAdminUserPassword" = $VMAdminUserPass;
735-
"ASCanaryUtilRG" = $CanaryUtilitiesRG;
736-
"ASCanaryUtilSA" = $storageAccName;
737-
"ASCanaryUtilSC" = $storageCtrName;
738-
"vaultName" = $keyvaultName;
739-
"windowsOSVersion" = $osVersion;
740-
"secretUrlWithVersion" = $kvSecretId;
741-
"LinuxImagePublisher" = $linuxImagePublisher;
742-
"LinuxImageOffer" = $linuxImageOffer;
743-
"LinuxImageSku" = $LinuxOSSku}
761+
$parameters = @{"VMAdminUserName" = $VMAdminUserName;
762+
"VMAdminUserPassword" = $VMAdminUserPass;
763+
"ASCanaryUtilRG" = $CanaryUtilitiesRG;
764+
"ASCanaryUtilSA" = $storageAccName;
765+
"ASCanaryUtilSC" = $storageCtrName;
766+
"vaultName" = $keyvaultName;
767+
"windowsOSVersion" = $osVersion;
768+
"secretUrlWithVersion" = $kvSecretId;
769+
"LinuxImagePublisher" = $linuxImagePublisher;
770+
"LinuxImageOffer" = $linuxImageOffer;
771+
"LinuxImageSku" = $LinuxOSSku;
772+
"storageAccountEndPoint" = "https://$EnvironmentDomainFQDN/"}
744773
if (-not $linuxImgExists)
745774
{
746775
$templateError = Test-AzureRmResourceGroupDeployment -ResourceGroupName $CanaryVMRG -TemplateFile $PSScriptRoot\azuredeploy.json -TemplateParameterObject $parameters
@@ -763,6 +792,12 @@ while ($runCount -le $NumberOfIterations)
763792
}
764793
}
765794

795+
Invoke-Usecase -Name 'RetrieveResourceDeploymentTimes' -Description "Retrieves the resources deployment times from the ARM template deployment" -UsecaseBlock `
796+
{
797+
$templateDeploymentName = "CanaryVMDeployment"
798+
(Get-AzureRmResourceGroupDeploymentOperation -Deploymentname $templateDeploymentName -ResourceGroupName $CanaryVMRG).Properties | Select-Object ProvisioningOperation,Duration,ProvisioningState,StatusCode,TargetResource | Format-Table -AutoSize
799+
}
800+
766801
$canaryWindowsVMList = @()
767802
$canaryWindowsVMList = Invoke-Usecase -Name 'QueryTheVMsDeployed' -Description "Queries for the VMs that were deployed using the ARM template" -UsecaseBlock `
768803
{

0 commit comments

Comments
 (0)