Skip to content

Commit e68e1cc

Browse files
Updated Tests and README
1 parent e7305e9 commit e68e1cc

2 files changed

Lines changed: 25 additions & 16 deletions

File tree

ComputeAdmin/AzureStack.ComputeAdmin.psm1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,11 @@ Function Add-VMImage{
257257
$platformImage = Invoke-RestMethod -Method GET -Uri $uri -ContentType 'application/json' -Headers $Headers
258258
}
259259

260-
if($CreateGalleryItem -eq $true -And $platformImage.Properties.ProvisioningState -eq 'Succeeded') {
261-
#reaquire storage account context
262-
Set-AzureRmCurrentStorageAccount -StorageAccountName $storageAccountName -ResourceGroupName $resourceGroupName
263-
$container = Get-AzureStorageContainer -Name $containerName -ErrorAction SilentlyContinue
260+
#reaquire storage account context
261+
Set-AzureRmCurrentStorageAccount -StorageAccountName $storageAccountName -ResourceGroupName $resourceGroupName
262+
$container = Get-AzureStorageContainer -Name $containerName -ErrorAction SilentlyContinue
264263

264+
if($CreateGalleryItem -eq $true -And $platformImage.Properties.ProvisioningState -eq 'Succeeded') {
265265
$GalleryItem = CreateGalleyItem -publisher $publisher -offer $offer -sku $sku -version $version -osType $osType -title $title -description $description
266266
$blob = $container| Set-AzureStorageBlobContent –File $GalleryItem.FullName –Blob $galleryItem.Name
267267
$galleryItemURI = '{0}{1}/{2}' -f $storageAccount.PrimaryEndpoints.Blob.AbsoluteUri, $containerName,$galleryItem.Name

ComputeAdmin/Tests/ComputeAdmin.Tests.ps1

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Describe $script:ModuleName {
1717
}
1818

1919
It 'Remove-VMImage should be exported' {
20-
Get-Command -Name Add-VMImage -ErrorAction SilentlyContinue |
20+
Get-Command -Name Remove-VMImage -ErrorAction SilentlyContinue |
2121
Should Not Be $null
2222
}
2323
}
@@ -57,39 +57,44 @@ InModuleScope $script:ModuleName {
5757

5858
Describe 'ComputeAdmin - Functional Tests' {
5959
It 'CreateGalleryItem = "$false" -and title = specified should throw' {
60-
{ Add-VMImage -publisher $publisher -offer $offer -sku $sku -version $version -osType $osType -osDiskLocalPath $osDiskPath -tenantID $AadTenant -AzureStackCredential $stackLoginCreds -CreateGalleryItem $false -title 'testTitle' } |
60+
{ Add-VMImage -publisher $publisher -offer $offer -sku $sku -version $version -osType $osType -osDiskLocalPath $osDiskPath -tenantID $AadTenant -ArmEndpoint $ArmEndpoint -AzureStackCredential $stackLoginCreds -CreateGalleryItem $false -title 'testTitle' } |
6161
Should Throw
6262
}
6363

6464
It 'CreateGalleryItem = "$false" -and description = specified should throw' {
65-
{ Add-VMImage -publisher $publisher -offer $offer -sku $sku -version $version -osType $osType -osDiskLocalPath $osDiskPath -tenantID $AadTenant -AzureStackCredential $stackLoginCreds -CreateGalleryItem $false -title 'testTitle' -CreateGalleryItem $false -description 'testdescription' } | Should Throw
65+
{ Add-VMImage -publisher $publisher -offer $offer -sku $sku -version $version -osType $osType -osDiskLocalPath $osDiskPath -tenantID $AadTenant -ArmEndpoint $ArmEndpoint -AzureStackCredential $stackLoginCreds -CreateGalleryItem $false -title 'testTitle' -CreateGalleryItem $false -description 'testdescription' } | Should Throw
6666
}
6767

6868
It 'Add-VMImage via local path and upload to storage account should succeed' {
69-
{ Add-VMImage -publisher $publisher -offer $offer -sku $sku -version $version -osType $osType -osDiskLocalPath $osDiskPath -tenantID $AadTenant -AzureStackCredential $stackLoginCreds -CreateGalleryItem $false } |
69+
{ Add-VMImage -publisher $publisher -offer $offer -sku $sku -version $version -osType $osType -osDiskLocalPath $osDiskPath -tenantID $AadTenant -ArmEndpoint $ArmEndpoint -AzureStackCredential $stackLoginCreds -CreateGalleryItem $false } |
7070
Should Not Throw
7171
}
7272

7373
It 'Remove-VMImage should successfully remove added VM Image' {
74-
{ Remove-VMImage -publisher $publisher -offer $offer -sku $sku -version $version -osType $osType -tenantID $AadTenant -AzureStackCredential $stackLoginCreds} |
74+
{ Remove-VMImage -publisher $publisher -offer $offer -sku $sku -version $version -tenantID $AadTenant -ArmEndpoint $ArmEndpoint -AzureStackCredential $stackLoginCreds} |
7575
Should Not Throw
7676
}
7777

7878
It 'Add-VMImage via local path and upload to storage account with gallery item should succeed' {
79-
{ Add-VMImage -publisher $publisher -offer $offer -sku $gallerySku -version $version -osType $osType -osDiskLocalPath $osDiskPath -tenantID $AadTenant -AzureStackCredential $stackLoginCreds } |
79+
{ Add-VMImage -publisher $publisher -offer $offer -sku $gallerySku -version $version -osType $osType -osDiskLocalPath $osDiskPath -tenantID $AadTenant -ArmEndpoint $ArmEndpoint -AzureStackCredential $stackLoginCreds } |
8080
Should Not Throw
8181
}
8282

8383
It 'Remove-VMImage and Removing Marketplace Item should successfully complete' {
8484
{
85-
Remove-VMImage -publisher $publisher -offer $offer -sku $gallerySku -version $version -osType $osType -tenantID $AadTenant -AzureStackCredential $stackLoginCreds
86-
Get-AzureRMGalleryItem -ApiVersion 2015-04-01
87-
Get-AzureRMGalleryItem -ApiVersion 2015-04-01 | Where-Object {$_.Name -contains "$publisher.$offer$gallerySku.$version"} | Remove-AzureRMGalleryItem -ApiVersion 2015-04-01
85+
Remove-VMImage -publisher $publisher -offer $offer -sku $gallerySku -version $version -tenantID $AadTenant -ArmEndpoint $ArmEndpoint -AzureStackCredential $stackLoginCreds
86+
if((Get-Module AzureStack).Version -ge [System.Version] "1.2.9"){
87+
Get-AzureRMGalleryItem
88+
Get-AzureRMGalleryItem | Where-Object {$_.Name -contains "$publisher.$offer$gallerySku.$version"} | Remove-AzureRMGalleryItem
89+
}else{
90+
Get-AzureRMGalleryItem -ApiVersion 2015-04-01
91+
Get-AzureRMGalleryItem -ApiVersion 2015-04-01 | Where-Object {$_.Name -contains "$publisher.$offer$gallerySku.$version"} | Remove-AzureRMGalleryItem -ApiVersion 2015-04-01
92+
}
8893
} | Should Not Throw
8994
}
9095

9196
It 'Adding Ubuntu Linux 16.04 Image and Marketplace Item Succeeds' {
92-
{ Add-VMImage -publisher "Canonical" -offer "UbuntuServer" -sku "16.04.1-LTS" -version "1.0.4" -osType Linux -osDiskLocalPath $ubuntuPath -tenantID $AadTenant -AzureStackCredential $stackLoginCreds} |
97+
{ Add-VMImage -publisher "Canonical" -offer "UbuntuServer" -sku "16.04.1-LTS" -version "1.0.4" -osType Linux -ArmEndpoint $ArmEndpoint -osDiskLocalPath $ubuntuPath -tenantID $AadTenant -AzureStackCredential $stackLoginCreds} |
9398
Should Not Throw
9499
}
95100

@@ -99,10 +104,14 @@ InModuleScope $script:ModuleName {
99104
$newOffer = "UbuntuServer"
100105
$newSKU = "16.04.1-LTS"
101106
$newVersion = "1.0.4"
102-
Remove-VMImage -publisher $newPub -offer $newOffer -sku $newSKU -version $newVersion -osType Linux -tenantID $AadTenant -AzureStackCredential $stackLoginCreds
107+
Remove-VMImage -publisher $newPub -offer $newOffer -sku $newSKU -version $newVersion -tenantID $AadTenant -ArmEndpoint $ArmEndpoint -AzureStackCredential $stackLoginCreds
103108
$GalleryItemName = "$newOffer$newSKU"
104109
$GalleryItemName = $GalleryItemName -replace "\.","-"
105-
Get-AzureRMGalleryItem -ApiVersion 2015-04-01 | Where-Object {$_.Name -contains "$newPub.$GalleryItemName.$newVersion"} | Remove-AzureRMGalleryItem -ApiVersion 2015-04-01
110+
if((Get-Module AzureStack).Version -ge [System.Version] "1.2.9"){
111+
Get-AzureRMGalleryItem | Where-Object {$_.Name -contains "$newPub.$GalleryItemName.$newVersion"} | Remove-AzureRMGalleryItem
112+
}else{
113+
Get-AzureRMGalleryItem -ApiVersion 2015-04-01 | Where-Object {$_.Name -contains "$newPub.$GalleryItemName.$newVersion"} | Remove-AzureRMGalleryItem -ApiVersion 2015-04-01
114+
}
106115
} | Should Not Throw
107116
}
108117

0 commit comments

Comments
 (0)