@@ -33,7 +33,8 @@ function Verify-GalleryImageDefinition
33
33
[string ] $publisherName , [string ] $offerName , [string ] $skuName ,
34
34
[int ] $minVCPU , [int ] $maxVCPU , [int ] $minMemory , [int ] $maxMemory ,
35
35
[string ] $disallowedDiskType ,
36
- [string ] $purchasePlanName , [string ] $purchasePlanPublisher , [string ] $purchasePlanProduct )
36
+ [string ] $purchasePlanName , [string ] $purchasePlanPublisher , [string ] $purchasePlanProduct ,
37
+ [string ] $hyperVGeneration )
37
38
38
39
Assert-AreEqual $rgname $imageDefinition.ResourceGroupName ;
39
40
Assert-AreEqual $imageDefinitionName $imageDefinition.Name ;
@@ -62,20 +63,30 @@ function Verify-GalleryImageDefinition
62
63
Assert-AreEqual $purchasePlanName $imageDefinition.PurchasePlan.Name ;
63
64
Assert-AreEqual $purchasePlanPublisher $imageDefinition.PurchasePlan.Publisher ;
64
65
Assert-AreEqual $purchasePlanProduct $imageDefinition.PurchasePlan.Product ;
66
+
67
+ if (-not [string ]::IsNullOrEmpty($hyperVGeneration ))
68
+ {
69
+ Assert-AreEqual $hyperVGeneration $imageDefinition.HyperVGeneration ;
70
+ }
65
71
}
66
72
67
73
function Verify-GalleryImageVersion
68
74
{
69
75
param ($imageVersion , [string ] $rgname , [string ] $imageVersionName , [string ] $loc ,
70
- [string ] $sourceImageId , [int ] $replicaCount , $endOfLifeDate , $targetRegions )
76
+ [string ] $sourceImageId , [int ] $replicaCount , $endOfLifeDate , $targetRegions ,
77
+ $osDiskImage , $dataDiskImages )
71
78
72
79
Assert-AreEqual $rgname $imageVersion.ResourceGroupName ;
73
80
Assert-AreEqual $imageVersionName $imageVersion.Name ;
74
81
Assert-AreEqual $loc $imageVersion.Location ;
75
82
Assert-AreEqual " Microsoft.Compute/galleries/images/versions" $imageVersion.Type ;
76
83
Assert-NotNull $imageVersion.Id ;
77
84
78
- Assert-AreEqual $sourceImageId $imageVersion.StorageProfile.Source.Id ;
85
+ if (-not [string ]::IsNullOrEmpty($sourceImageId ))
86
+ {
87
+ Assert-AreEqual $sourceImageId $imageVersion.StorageProfile.Source.Id ;
88
+ }
89
+
79
90
Assert-AreEqual $replicaCount $imageVersion.PublishingProfile.ReplicaCount ;
80
91
Assert-False { $imageVersion.PublishingProfile.ExcludeFromLatest };
81
92
@@ -95,6 +106,17 @@ function Verify-GalleryImageVersion
95
106
Assert-AreEqual $targetRegions [$i ].ReplicaCount $imageVersion.PublishingProfile.TargetRegions [$i ].RegionalReplicaCount;
96
107
}
97
108
}
109
+
110
+ if ($osDiskImage -ne $null )
111
+ {
112
+ Assert-AreEqual $osDiskImage.Source.Id $imageVersion.StorageProfile.OSDiskImage.Source.Id ;
113
+ }
114
+
115
+ for ($i = 0 ; $i -lt $dataDiskImages.Count ; ++ $i )
116
+ {
117
+ Assert-AreEqual $dataDiskImages [$i ].Source.Id $imageVersion.StorageProfile.DataDiskImages [$i ].Source.Id;
118
+ Assert-AreEqual $dataDiskImages [$i ].Lun $imageVersion.StorageProfile.DataDiskImages [$i ].Lun;
119
+ }
98
120
}
99
121
100
122
<#
@@ -574,3 +596,115 @@ function Test-GalleryImageVersion
574
596
Clean - ResourceGroup $rgname
575
597
}
576
598
}
599
+
600
+ <#
601
+ . SYNOPSIS
602
+ Testing gallery image version with disk image parameters
603
+ #>
604
+ function Test-GalleryImageVersionDiskImage
605
+ {
606
+ # Setup
607
+ $rgname = Get-ComputeTestResourceName ;
608
+ $galleryName = ' gallery' + $rgname ;
609
+ $galleryImageName = ' galleryimage' + $rgname ;
610
+ $galleryImageVersionName = ' imageversion' + $rgname ;
611
+
612
+ try
613
+ {
614
+ # Common
615
+ [string ]$loc = Get-ComputeVMLocation ;
616
+ $loc = $loc.Replace (' ' , ' ' );
617
+ New-AzResourceGroup - Name $rgname - Location $loc - Force;
618
+ $description1 = " Original Description" ;
619
+
620
+ # Gallery
621
+ New-AzGallery - ResourceGroupName $rgname - Name $galleryName - Description $description1 - Location $loc ;
622
+
623
+ $gallery = Get-AzGallery - ResourceGroupName $rgname - Name $galleryName ;
624
+ Verify- Gallery $gallery $rgname $galleryName $loc $description1 ;
625
+ $output = $gallery | Out-String ;
626
+
627
+ # Gallery Image Definition
628
+ $publisherName = " galleryPublisher20180927" ;
629
+ $offerName = " galleryOffer20180927" ;
630
+ $skuName = " gallerySku20180927" ;
631
+ $eula = " eula" ;
632
+ $privacyStatementUri = " https://www.microsoft.com" ;
633
+ $releaseNoteUri = " https://www.microsoft.com" ;
634
+ $disallowedDiskTypes = " Premium_LRS" ;
635
+ $endOfLifeDate = [DateTime ]::ParseExact(' 12 07 2025 18 02' , ' HH mm yyyy dd MM' , $null );
636
+ $minMemory = 1 ;
637
+ $maxMemory = 100 ;
638
+ $minVCPU = 2 ;
639
+ $maxVCPU = 32 ;
640
+ $purchasePlanName = " purchasePlanName" ;
641
+ $purchasePlanProduct = " purchasePlanProduct" ;
642
+ $purchasePlanPublisher = " " ;
643
+ $osState = " Generalized" ;
644
+ $osType = " Windows" ;
645
+
646
+ New-AzGalleryImageDefinition - ResourceGroupName $rgname - GalleryName $galleryName - Name $galleryImageName `
647
+ - Location $loc - Publisher $publisherName - Offer $offerName - Sku $skuName `
648
+ - OsState $osState - OsType $osType `
649
+ - Description $description1 - Eula $eula `
650
+ - PrivacyStatementUri $privacyStatementUri - ReleaseNoteUri $releaseNoteUri `
651
+ - DisallowedDiskType $disallowedDiskTypes - EndOfLifeDate $endOfLifeDate `
652
+ - MinimumMemory $minMemory - MaximumMemory $maxMemory `
653
+ - MinimumVCPU $minVCPU - MaximumVCPU $maxVCPU `
654
+ - PurchasePlanName $purchasePlanName `
655
+ - PurchasePlanProduct $purchasePlanProduct `
656
+ - PurchasePlanPublisher $purchasePlanPublisher `
657
+ - HyperVGeneration ' V1' ;
658
+
659
+ $definition = Get-AzGalleryImageDefinition - ResourceGroupName $rgname - GalleryName $galleryName - Name $galleryImageName ;
660
+ $output = $definition | Out-String ;
661
+ Verify- GalleryImageDefinition $definition $rgname $galleryImageName $loc $description1 `
662
+ $eula $privacyStatementUri $releaseNoteUri `
663
+ $osType $osState $endOfLifeDate `
664
+ $publisherName $offerName $skuName `
665
+ $minVCPU $maxVCPU $minMemory $maxMemory `
666
+ $disallowedDiskTypes `
667
+ $purchasePlanName $purchasePlanPublisher $purchasePlanProduct ' V1' ;
668
+
669
+ # Gallery Image Version
670
+ $galleryImageVersionName = " 1.0.0" ;
671
+
672
+ $snapshotname1 = ' ossnapshot' + $rgname ;
673
+ $snapshotconfig = New-AzSnapshotConfig - Location $loc - DiskSizeGB 5 - AccountType Standard_LRS - OsType Windows - CreateOption Empty - HyperVGeneration " V1" ;
674
+ $snapshot1 = New-AzSnapshot - ResourceGroupName $rgname - SnapshotName $snapshotname1 - Snapshot $snapshotconfig
675
+
676
+ $snapshotname2 = ' data1snapshot' + $rgname ;
677
+ $snapshotconfig = New-AzSnapshotConfig - Location $loc - DiskSizeGB 5 - AccountType Standard_LRS - OsType Windows - CreateOption Empty - HyperVGeneration " V1" ;
678
+ $snapshot2 = New-AzSnapshot - ResourceGroupName $rgname - SnapshotName $snapshotname2 - Snapshot $snapshotconfig
679
+
680
+ $snapshotname3 = ' data2snapshot' + $rgname ;
681
+ $snapshotconfig = New-AzSnapshotConfig - Location $loc - DiskSizeGB 5 - AccountType Standard_LRS - OsType Windows - CreateOption Empty - HyperVGeneration " V1" ;
682
+ $snapshot3 = New-AzSnapshot - ResourceGroupName $rgname - SnapshotName $snapshotname3 - Snapshot $snapshotconfig
683
+
684
+
685
+ $targetRegions = @ (@ {Name = ' South Central US' ;ReplicaCount = 1 ;StorageAccountType = ' Standard_LRS' }, @ {Name = ' East US' ;ReplicaCount = 2 }, @ {Name = ' Central US' });
686
+ $tag = @ {test1 = " testval1" ; test2 = " testval2" };
687
+
688
+ $osDiskImage = @ {Source = @ {Id = " $ ( $snapshot1.Id ) " }}
689
+ $dataDiskImage1 = @ {Source = @ {Id = " $ ( $snapshot2.Id ) " };Lun = 1 }
690
+ $dataDiskImage2 = @ {Source = @ {Id = " $ ( $snapshot3.Id ) " };Lun = 2 }
691
+
692
+ New-AzGalleryImageVersion - ResourceGroupName $rgname - GalleryName $galleryName `
693
+ - GalleryImageDefinitionName $galleryImageName - Name $galleryImageVersionName `
694
+ - Location $loc - ReplicaCount 1 `
695
+ - PublishingProfileEndOfLifeDate $endOfLifeDate `
696
+ - StorageAccountType Standard_LRS `
697
+ - TargetRegion $targetRegions `
698
+ - OSDiskImage $osDiskImage - DataDiskImage $dataDiskImage1 , $dataDiskImage2 ;
699
+
700
+ $version = Get-AzGalleryImageVersion - ResourceGroupName $rgname - GalleryName $galleryName - GalleryImageDefinitionName $galleryImageName - Name $galleryImageVersionName ;
701
+
702
+ Verify- GalleryImageVersion $version $rgname $galleryImageVersionName $loc `
703
+ $null 1 $endOfLifeDate $targetRegions $osDiskImage @ ($dataDiskImage1 , $dataDiskImage2 )
704
+ }
705
+ finally
706
+ {
707
+ # Cleanup
708
+ Clean - ResourceGroup $rgname
709
+ }
710
+ }
0 commit comments