Skip to content

Commit 97f182c

Browse files
author
Shriram Natarajan
committed
Merge remote-tracking branch 'upstream/vnext' into vnext
Merging from original fork
2 parents 1ecc194 + 40433a1 commit 97f182c

36 files changed

Lines changed: 5747 additions & 953 deletions

CanaryValidator/Canary.Tests.ps1

Lines changed: 197 additions & 51 deletions
Large diffs are not rendered by default.

CanaryValidator/Canary.Utilities.psm1

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ if (Test-Path -Path "$PSScriptRoot\..\WTTLog.ps1")
1212

1313
$CurrentUseCase = @{}
1414
[System.Collections.Stack] $UseCaseStack = New-Object System.Collections.Stack
15-
filter timestamp {"$(Get-Date -Format HH:mm:ss.ffff): $_"}
15+
filter timestamp {"$(Get-Date -Format "yyyy-MM-dd HH:mm:ss.ffff") $_"}
1616

1717

1818
function Log-Info
@@ -51,14 +51,11 @@ function Log-JSONReport
5151
[string] $Message
5252
)
5353
if ($Message)
54-
{
55-
if ($Message.Contains(": ["))
56-
{
57-
$time = $Message.Substring(0, $Message.IndexOf(": ["))
58-
}
54+
{
5955
if ($Message.Contains("[START]"))
6056
{
61-
$name = $Message.Substring($Message.LastIndexOf(":") + 1).Trim().Replace("######", "").Trim()
57+
$time = $Message.Substring(0, $Message.IndexOf("[")).Trim()
58+
$name = $Message.Substring($Message.LastIndexOf(":") + 1).Trim()
6259
if ($UseCaseStack.Count)
6360
{
6461
$nestedUseCase = @{
@@ -81,14 +78,19 @@ function Log-JSONReport
8178
}
8279
elseif ($Message.Contains("[END]"))
8380
{
81+
$time = $Message.Substring(0, $Message.IndexOf("[")).Trim()
8482
$result = ""
8583
if ($UseCaseStack.Peek().UseCase -and ($UseCaseStack.Peek().UseCase | Where-Object {$_.Result -eq "FAIL"}))
8684
{
8785
$result = "FAIL"
8886
}
89-
else
87+
elseif ($Message.Contains("[RESULT = PASS]"))
88+
{
89+
$result = "PASS"
90+
}
91+
elseif ($Message.Contains("[RESULT = FAIL]"))
9092
{
91-
$result = $Message.Substring($Message.LastIndexOf("=") + 1).Trim().Replace("] ######", "").Trim()
93+
$result = "FAIL"
9294
}
9395
$UseCaseStack.Peek().Add("Result", $result)
9496
$UseCaseStack.Peek().Add("EndTime", $time)
@@ -149,6 +151,16 @@ function Get-CanaryLonghaulResult
149151
@{Expression={$pCount = ($_.Group | Where-Object Result -eq "PASS").Count; $times = ($_.Group | Where-Object Result -eq "PASS" | ForEach-Object {((Get-Date $_.EndTime) - (Get-Date $_.StartTime)).TotalMilliseconds}); $avgTime = ($times | Measure-Object -Average).Average; $sd = 0; foreach ($time in $times){$sd += [math]::Pow(($time - $avgTime), 2)}; [math]::Round(([math]::Round([math]::Sqrt($sd/$pCount), 0)/$avgTime), 0) * 100};Label="RelativeStdDev`n[Goal: <50%]"; Align = "Left"}
150152
}
151153

154+
function Get-CanaryFailureStatus
155+
{
156+
$logContent = Get-Content -Raw -Path $Global:JSONLogFile | ConvertFrom-Json
157+
if ($logContent.Usecases.Result -contains "FAIL")
158+
{
159+
return $true
160+
}
161+
return $false
162+
}
163+
152164
function Start-Scenario
153165
{
154166
[CmdletBinding()]
@@ -256,7 +268,7 @@ function Invoke-Usecase
256268
Log-Info ("Skipping Usecase: $Name")
257269
return
258270
}
259-
Log-Info ("###### [START] Usecase: $Name ######`n")
271+
Log-Info ("[START] Usecase: $Name`n")
260272
if ($Global:wttLogFileName)
261273
{
262274
StartTest "CanaryGate:$Name"
@@ -278,7 +290,7 @@ function Invoke-Usecase
278290
{
279291
EndTest "CanaryGate:$Name" $true
280292
}
281-
Log-Info ("###### [END] Usecase: $Name ###### [RESULT = PASS] ######`n")
293+
Log-Info ("[END] [RESULT = PASS] Usecase: $Name`n")
282294
return $result | Out-Null
283295
}
284296
catch [System.Exception]
@@ -287,7 +299,7 @@ function Invoke-Usecase
287299
Log-Info ("###### <FAULTING SCRIPTBLOCK> ######")
288300
Log-Info ("$UsecaseBlock")
289301
Log-Info ("###### </FAULTING SCRIPTBLOCK> ######")
290-
Log-Error ("###### [END] Usecase: $Name ###### [RESULT = FAIL] ######`n")
302+
Log-Error ("[END] [RESULT = FAIL] Usecase: $Name`n")
291303
if ($Global:wttLogFileName)
292304
{
293305
EndTest "CanaryGate:$Name" $false

ComputeAdmin/AzureStack.ComputeAdmin.psm1

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,36 @@
33

44
#requires -Modules AzureStack.Connect
55

6+
<#
7+
.SYNOPSIS
8+
Add-AzureStackVMSSGalleryItem: Adds the VMSS Gallery Item to your Azure Stack Marketplace.
9+
Remove-AzureStackVMSSGalleryItem: Adds the VMSS Gallery Item from your Azure Stack Marketplace.
10+
Add-VMImage: Uploads a VM Image to your Azure Stack and creates a Marketplace item for it.
11+
Remove-VMImage: Removes an existing VM Image from your Azure Stack. Does not delete any
12+
maketplace items created by Add-VMImage.
13+
New-Server2016VMImage: Creates and Uploads a new Server 2016 Core and / or Full Image and
14+
creates a Marketplace item for it.
15+
Get-VMImage: Gets a VM Image from your Azure Stack as an Administrator to view the provisioning state of the image.
16+
Add-VMExtension: Uploads a VM extension to your Azure Stack.
17+
Remove-VMExtension: Removes an existing VM extension from your Azure Stack.
18+
#>
19+
620
function Add-AzureStackVMSSGalleryItem {
21+
[CmdletBinding()]
22+
Param(
23+
[Parameter(Mandatory=$false)]
24+
[ValidatePattern("^[0-9a-zA-Z]+$")]
25+
[ValidateLength(1,128)]
26+
[String] $Location = 'local'
27+
)
728

829
$rgName = "vmss.gallery"
930

10-
New-AzureRmResourceGroup -Name $rgName -Location local -Force
31+
New-AzureRmResourceGroup -Name $rgName -Location $Location -Force
1132

1233
$saName = "vmssgallery"
1334

14-
$sa = New-AzureRmStorageAccount -ResourceGroupName $rgName -Location local -Name $saName -Type Standard_LRS
35+
$sa = New-AzureRmStorageAccount -ResourceGroupName $rgName -Location $Location -Name $saName -Type Standard_LRS
1536

1637
$cName = "gallery"
1738

@@ -24,7 +45,8 @@ function Add-AzureStackVMSSGalleryItem {
2445

2546
$fileName = "microsoft.vmss.1.3.6.azpkg"
2647

27-
$blob = $container| Set-AzureStorageBlobContent –File ([System.IO.Path]::GetDirectoryName($PSCommandPath) + "\" + $fileName) –Blob $fileName -Force
48+
$blob = Set-AzureStorageBlobContent –File ($PSScriptRoot + "\" + $fileName) –Blob $fileName -Container $cName -Force
49+
$container = Get-AzureStorageContainer -Name $cName -ErrorAction SilentlyContinue
2850

2951
$uri = $blob.Context.BlobEndPoint + $container.Name + "/" + $blob.Name
3052

@@ -39,19 +61,6 @@ function Remove-AzureStackVMSSGalleryItem {
3961
}
4062
}
4163

42-
<#
43-
.SYNOPSIS
44-
Contains 6 functions.
45-
Add-VMImage: Uploads a VM Image to your Azure Stack and creates a Marketplace item for it.
46-
Remove-VMImage: Removes an existing VM Image from your Azure Stack. Does not delete any
47-
maketplace items created by Add-VMImage.
48-
New-Server2016VMImage: Creates and Uploads a new Server 2016 Core and / or Full Image and
49-
creates a Marketplace item for it.
50-
Get-VMImage: Gets a VM Image from your Azure Stack as an Administrator to view the provisioning state of the image.
51-
Add-VMExtension: Uploads a VM extension to your Azure Stack.
52-
Remove-VMExtension: Removes an existing VM extension from your Azure Stack.
53-
#>
54-
5564
Function Add-VMImage{
5665

5766
[CmdletBinding(DefaultParameterSetName='VMImageFromLocal')]
@@ -160,9 +169,9 @@ Function Add-VMImage{
160169
#same for storage
161170
$storageAccount = Get-AzureRmStorageAccount -Name $storageAccountName -ResourceGroupName $resourceGroupName -ErrorAction SilentlyContinue
162171
if (-not ($storageAccount)) {
163-
$storageAccount = New-AzureRmStorageAccount -Name $storageAccountName -Location $location -ResourceGroupName $resourceGroupName -Type Standard_LRS
172+
$storageAccount = New-AzureRmStorageAccount -Name $storageAccountName -Location $location -ResourceGroupName $resourceGroupName -Type Standard_LRS
164173
}
165-
Set-AzureRmCurrentStorageAccount -StorageAccountName $storageAccountName -ResourceGroupName $resourceGroupName
174+
Set-AzureRmCurrentStorageAccount -StorageAccountName $storageAccountName -ResourceGroupName $resourceGroupName
166175
#same for container
167176
$container = Get-AzureStorageContainer -Name $containerName -ErrorAction SilentlyContinue
168177
if (-not ($container)) {
@@ -297,11 +306,7 @@ Function Add-VMImage{
297306
$galleryItemURI = '{0}{1}/{2}' -f $storageAccount.PrimaryEndpoints.Blob.AbsoluteUri, $containerName,$galleryItem.Name
298307

299308

300-
if((Get-Module AzureStack).Version -ge [System.Version] "1.2.9"){
301-
Add-AzureRMGalleryItem -GalleryItemUri $galleryItemURI
302-
}else{
303-
Add-AzureRMGalleryItem -SubscriptionId $subscription -GalleryItemUri $galleryItemURI -ApiVersion 2015-04-01
304-
}
309+
Add-AzureRMGalleryItem -GalleryItemUri $galleryItemURI
305310

306311
#cleanup
307312
Remove-Item $GalleryItem
@@ -383,12 +388,7 @@ Function Remove-VMImage{
383388
$name = "$offer$sku"
384389
#Remove periods so that the offer and sku can be retrieved from the Marketplace Item name
385390
$name =$name -replace "\.","-"
386-
if((Get-Module AzureStack).Version -ge [System.Version] "1.2.9"){
387-
Get-AzureRMGalleryItem | Where-Object {$_.Name -contains "$publisher.$name.$version"} | Remove-AzureRMGalleryItem
388-
}else{
389-
Get-AzureRMGalleryItem -ApiVersion 2015-04-01 | Where-Object {$_.Name -contains "$publisher.$name.$version"} | Remove-AzureRMGalleryItem -ApiVersion 2015-04-01
390-
}
391-
391+
Get-AzureRMGalleryItem | Where-Object {$_.Name -contains "$publisher.$name.$version"} | Remove-AzureRMGalleryItem
392392
}
393393

394394
}
@@ -431,7 +431,8 @@ function New-Server2016VMImage {
431431
[Parameter()]
432432
[bool] $CreateGalleryItem = $true,
433433

434-
[switch] $Net35
434+
[Parameter()]
435+
[bool] $Net35 = $true
435436
)
436437
begin {
437438
function CreateWindowsVHD {
@@ -460,7 +461,7 @@ function New-Server2016VMImage {
460461
Write-Verbose -Message "Preparing VHD"
461462

462463
$VHDMount = Mount-DiskImage -ImagePath $VHDPath -PassThru -ErrorAction Stop
463-
$disk = $VHDMount | Get-DiskImage | Get-Disk -ErrorAction Stop
464+
$disk = $VHDMount | Get-DiskImage -ErrorAction Stop | Get-Disk -ErrorAction SilentlyContinue
464465
$disk | Initialize-Disk -PartitionStyle MBR -ErrorAction Stop
465466
$partition = New-Partition -UseMaximumSize -Disknumber $disk.DiskNumber -IsActive:$True -AssignDriveLetter -ErrorAction Stop
466467
$volume = Format-Volume -Partition $partition -FileSystem NTFS -confirm:$false -ErrorAction Stop
@@ -677,7 +678,7 @@ Function CreateGalleyItem{
677678
[string] $title,
678679
[string] $description
679680
)
680-
$workdir = '{0}\{1}' -f $env:TEMP, [System.Guid]::NewGuid().ToString()
681+
$workdir = '{0}{1}' -f [System.IO.Path]::GetTempPath(), [System.Guid]::NewGuid().ToString()
681682
New-Item $workdir -ItemType Directory | Out-Null
682683
$basePath = (Get-Module AzureStack.ComputeAdmin).ModuleBase
683684
$compressedGalleryItemPath = Join-Path $basePath 'CustomizedVMGalleryItem.azpkg'
@@ -818,7 +819,6 @@ Function Add-VMExtension{
818819

819820
[Parameter(Mandatory=$true, ParameterSetName='VMExtensionFromLocal')]
820821
[Parameter(Mandatory=$true, ParameterSetName='VMExtesionFromAzure')]
821-
[ValidatePattern(\d+\.\d+\.\d+)]
822822
[String] $version,
823823

824824
[Parameter(ParameterSetName='VMExtensionFromLocal')]
@@ -904,7 +904,7 @@ Function Add-VMExtension{
904904
$uri = $armEndpoint + '/subscriptions/' + $subscription + '/providers/Microsoft.Compute.Admin/locations/' + $location + '/artifactTypes/VMExtension/publishers/' + $publisher
905905
$uri = $uri + '/types/' + $type + '/versions/' + $version + '?api-version=2015-12-01-preview'
906906

907-
Log-Info $uri
907+
Write-Verbose $uri
908908

909909
#building request body JSON
910910
if($pscmdlet.ParameterSetName -eq "VMExtensionFromLocal") {
@@ -958,10 +958,9 @@ Function Remove-VMExtension{
958958
[String] $publisher,
959959

960960
[Parameter(Mandatory=$true)]
961-
[ValidatePattern(\d+\.\d+\.\d+)]
962961
[String] $version,
963962

964-
[String] $type = "CustomScriptExtension",
963+
[String] $type,
965964

966965
[Parameter(Mandatory=$true)]
967966
[ValidateSet('Windows' ,'Linux')]
@@ -989,7 +988,7 @@ Function Remove-VMExtension{
989988
$uri = $armEndpoint + '/subscriptions/' + $subscription + '/providers/Microsoft.Compute.Admin/locations/' + $location + '/artifactTypes/VMExtension/publishers/' + $publisher
990989
$uri = $uri + '/types/' + $type + '/versions/' + $version + '?api-version=2015-12-01-preview'
991990

992-
Log-Info $uri
991+
Write-Verbose $uri
993992

994993
try{
995994
Invoke-RestMethod -Method DELETE -Uri $uri -ContentType 'application/json' -Headers $headers

ComputeAdmin/README.md

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,22 @@ Import-Module ..\Connect\AzureStack.Connect.psm1
1515
Import-Module .\AzureStack.ComputeAdmin.psm1
1616
```
1717

18-
Adding a VM Image requires that you obtain the GUID value of your Directory Tenant. If you know the non-GUID form of the Azure Active Directory Tenant used to deploy your Azure Stack instance, you can retrieve the GUID value with the following:
18+
You will need to reference your Azure Stack Administrator environment. To create an administrator environment use the below. The ARM endpoint below is the administrator default for a one-node environment.
1919

2020
```powershell
21-
$aadTenant = Get-AADTenantGUID -AADTenantName "<myaadtenant>.onmicrosoft.com"
21+
Add-AzureStackAzureRmEnvironment -Name "AzureStackAdmin" -ArmEndpoint "https://adminmanagement.local.azurestack.external"
2222
```
2323

24-
Otherwise, it can be retrieved directly from your Azure Stack deployment. This method can also be used for AD FS. First, add your host to the list of TrustedHosts:
24+
Adding a VM Image requires that you obtain the value of your Directory Tenant ID. For **Azure Active Directory** environments provide your directory tenant name:
25+
2526
```powershell
26-
Set-Item wsman:\localhost\Client\TrustedHosts -Value "<Azure Stack host address>" -Concatenate
27+
$TenantID = Get-DirectoryTenantID -AADTenantName "<mydirectorytenant>.onmicrosoft.com" -EnvironmentName AzureStackAdmin
2728
```
28-
Then execute the following:
29+
30+
For **ADFS** environments use the following:
31+
2932
```powershell
30-
$Password = ConvertTo-SecureString "<Admin password provided when deploying Azure Stack>" -AsPlainText -Force
31-
$AadTenant = Get-AzureStackAadTenant -HostComputer <Host IP Address> -Password $Password
33+
$TenantID = Get-DirectoryTenantID -ADFS -EnvironmentName AzureStackAdmin
3234
```
3335

3436
## Add the WS2016 Evaluation VM Image
@@ -37,16 +39,10 @@ The New-Server2016VMImage allows you to add a Windows Server 2016 Evaluation VM
3739

3840
As a prerequisite, you need to obtain the Windows Server 2016 Evaluation ISO which can be found [here](https://www.microsoft.com/en-us/evalcenter/evaluate-windows-server-2016).
3941

40-
You will need to reference your Azure Stack Administrator environment. To create an administrator environment use the below. The ARM endpoint below is the administrator default for a one-node environment.
41-
42-
```powershell
43-
Add-AzureStackAzureRmEnvironment -Name "AzureStackAdmin" -ArmEndpoint "https://adminmanagement.local.azurestack.external"
44-
```
45-
4642
An example usage is the following:
4743
```powershell
4844
$ISOPath = "<Path to ISO>"
49-
New-Server2016VMImage -ISOPath $ISOPath -TenantId $aadTenant -EnvironmentName "AzureStackAdmin"
45+
New-Server2016VMImage -ISOPath $ISOPath -TenantId $TenantID -EnvironmentName "AzureStackAdmin"
5046
```
5147
Please make sure to specify the correct administrator ARM endpoint for your environment.
5248

@@ -116,7 +112,7 @@ An example usage is the following:
116112

117113
```powershell
118114
$path = "<Path to vm extension zip>"
119-
Add-VMExtension -publisher "Publisher" -type "Type" -version $version -extensionLocalPath $path -osType Windows -tenantID $aadTenant -azureStackCredentials $azureStackCredentials -EnvironmentName "AzureStackAdmin"
115+
Add-VMExtension -publisher "Publisher" -type "Type" -version "1.0.0.0" -extensionLocalPath $path -osType Windows -tenantID $TenantID -azureStackCredentials $azureStackCredentials -EnvironmentName "AzureStackAdmin"
120116
```
121117

122118

@@ -130,7 +126,7 @@ Add-AzureStackAzureRmEnvironment -Name "AzureStackAdmin" -ArmEndpoint "https://a
130126
Run the below command to remove an uploaded VM extension.
131127

132128
```powershell
133-
Remove-VMExtension -publisher "Publisher" -type "Type" -version "1.0.0.0" -osType Windows -tenantID $tenantId -azureStackCredentials $azureStackCredentials -EnvironmentName "AzureStackAdmin"
129+
Remove-VMExtension -publisher "Publisher" -type "Type" -version "1.0.0.0" -osType Windows -tenantID $TenantID -azureStackCredentials $azureStackCredentials -EnvironmentName "AzureStackAdmin"
134130
```
135131

136132
## VM Scale Set gallery item
@@ -144,20 +140,21 @@ VM Scale Set allows deployment of multi-VM collections. To add a gallery item wi
144140
3. Add VM Scale Set gallery item as follows
145141

146142
```powershell
147-
$Tenant = "<AAD Tenant Id used to connect to AzureStack>"
143+
$TenantId = "<AAD Tenant Id used to connect to AzureStack>"
148144
$Arm = "<AzureStack administrative Azure Resource Manager endpoint URL>"
145+
$Location = "<The location name of your AzureStack Environment>"
149146
150147
Add-AzureStackAzureRmEnvironment -Name AzureStackAdmin -ArmEndpoint $Arm
151148
152149
$Password = ConvertTo-SecureString -AsPlainText -Force "<your AzureStack admin user password>"
153150
$User = "<your AzureStack admin user name>"
154151
$Creds = New-Object System.Management.Automation.PSCredential $User, $Password
155152
156-
Login-AzureRmAccount -EnvironmentName AzureStackAdmin -Credential $Creds -TenantId $Tenant
153+
Login-AzureRmAccount -EnvironmentName AzureStackAdmin -Credential $Creds -TenantId $TenantId
157154
158155
Select-AzureRmSubscription -SubscriptionName "Default Provider Subscription"
159156
160-
Add-AzureStackVMSSGalleryItem
157+
Add-AzureStackVMSSGalleryItem -Location $Location
161158
```
162159
To remove VM Scale Set gallery item run the following command:
163160

ComputeAdmin/Tests/ComputeAdmin.Tests.ps1

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,13 +85,7 @@ InModuleScope $script:ModuleName {
8585
It 'Remove-VMImage and Removing Marketplace Item should successfully complete' {
8686
{
8787
Remove-VMImage -publisher $publisher -offer $offer -sku $gallerySku -version $version -tenantID $AadTenant -EnvironmentName $EnvironmentName -AzureStackCredential $stackLoginCreds
88-
if((Get-Module AzureStack).Version -ge [System.Version] "1.2.9"){
89-
Get-AzureRMGalleryItem
90-
Get-AzureRMGalleryItem | Where-Object {$_.Name -contains "$publisher.$offer$gallerySku.$version"} | Remove-AzureRMGalleryItem
91-
}else{
92-
Get-AzureRMGalleryItem -ApiVersion 2015-04-01
93-
Get-AzureRMGalleryItem -ApiVersion 2015-04-01 | Where-Object {$_.Name -contains "$publisher.$offer$gallerySku.$version"} | Remove-AzureRMGalleryItem -ApiVersion 2015-04-01
94-
}
88+
Get-AzureRMGalleryItem | Where-Object {$_.Name -contains "$publisher.$offer$gallerySku.$version"} | Remove-AzureRMGalleryItem
9589
} | Should Not Throw
9690
}
9791

@@ -109,11 +103,7 @@ InModuleScope $script:ModuleName {
109103
Remove-VMImage -publisher $newPub -offer $newOffer -sku $newSKU -version $newVersion -tenantID $AadTenant -EnvironmentName $EnvironmentName -AzureStackCredential $stackLoginCreds
110104
$GalleryItemName = "$newOffer$newSKU"
111105
$GalleryItemName = $GalleryItemName -replace "\.","-"
112-
if((Get-Module AzureStack).Version -ge [System.Version] "1.2.9"){
113-
Get-AzureRMGalleryItem | Where-Object {$_.Name -contains "$newPub.$GalleryItemName.$newVersion"} | Remove-AzureRMGalleryItem
114-
}else{
115-
Get-AzureRMGalleryItem -ApiVersion 2015-04-01 | Where-Object {$_.Name -contains "$newPub.$GalleryItemName.$newVersion"} | Remove-AzureRMGalleryItem -ApiVersion 2015-04-01
116-
}
106+
Get-AzureRMGalleryItem | Where-Object {$_.Name -contains "$newPub.$GalleryItemName.$newVersion"} | Remove-AzureRMGalleryItem
117107
} | Should Not Throw
118108
}
119109

0 commit comments

Comments
 (0)