Skip to content

Commit 582807f

Browse files
committed
Added tests and records, Modified Changelog + Generated Files
1 parent ff1bc90 commit 582807f

File tree

9 files changed

+10468
-0
lines changed

9 files changed

+10468
-0
lines changed

src/Compute/Compute.Test/ScenarioTests/VirtualMachineScaleSetTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,5 +486,12 @@ public void TestVirtualMachineScaleSetAddProxyAgentExtension()
486486
{
487487
TestRunner.RunTestScript("Test-VirtualMachineScaleSetAddProxyAgentExtension");
488488
}
489+
490+
[Fact]
491+
[Trait(Category.AcceptanceType, Category.CheckIn)]
492+
public void TestVirtualMachineScaleSetGalleryApplicationFlags()
493+
{
494+
TestRunner.RunTestScript("Test-VirtualMachineScaleSetGalleryApplicationFlags");
495+
}
489496
}
490497
}

src/Compute/Compute.Test/ScenarioTests/VirtualMachineScaleSetTests.ps1

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6015,4 +6015,132 @@ function Test-VirtualMachineScaleSetAddProxyAgentExtension
60156015
# Cleanup
60166016
Clean-ResourceGroup $rgname;
60176017
}
6018+
}
6019+
6020+
<#
6021+
.SYNOPSIS
6022+
Test-VirtualMachineScaleSetGalleryApplicationFlags creates a VMSS with Enabled ProxyAgent and added ProxyAgentExtension
6023+
#>
6024+
function Test-VirtualMachineScaleSetGalleryApplicationFlags
6025+
{
6026+
# Setup
6027+
$rgname = Get-ComputeTestResourceName
6028+
$loc = "eastus2"
6029+
6030+
# Skip in playback (data plane + gallery operations)
6031+
if ((Get-ComputeTestMode) -eq [Microsoft.Azure.Test.HttpRecorder.HttpRecorderMode]::Playback)
6032+
{
6033+
Write-Verbose "Skipping Test-VirtualMachineScaleSetGalleryApplicationFlags in Playback mode."
6034+
Assert-True { $true }
6035+
return
6036+
}
6037+
6038+
try
6039+
{
6040+
New-AzResourceGroup -Name $rgname -Location $loc -Force
6041+
6042+
# Basic VMSS inputs
6043+
$vmssName = "vmss" + $rgname
6044+
$domainNameLabel = "d1" + $rgname
6045+
$adminUsername = Get-ComputeTestResourceName
6046+
$adminPassword = Get-PasswordForVM | ConvertTo-SecureString -AsPlainText -Force
6047+
$cred = New-Object System.Management.Automation.PSCredential ($adminUsername, $adminPassword)
6048+
$linuxImage = "Canonical:0001-com-ubuntu-server-jammy:22_04-lts:latest"
6049+
6050+
# Storage account + page blob package
6051+
$storageName = ("pkg" + ($rgname.ToLower()))[0..([Math]::Min(23,("pkg" + ($rgname.ToLower())).Length-1))] -join ''
6052+
New-AzStorageAccount -ResourceGroupName $rgname -Name $storageName -Location $loc -Type Standard_LRS | Out-Null
6053+
$acctKeys = Get-AzStorageAccountKey -ResourceGroupName $rgname -Name $storageName
6054+
$ctx = New-AzStorageContext -StorageAccountName $storageName -StorageAccountKey $acctKeys[0].Value
6055+
$containerName = "packages"
6056+
$blobName = "apppkg.zip"
6057+
New-AzStorageContainer -Name $containerName -Context $ctx -Permission Blob | Out-Null
6058+
6059+
$localPackage = Join-Path $TestOutputRoot $blobName
6060+
if (Test-Path $localPackage) { Remove-Item $localPackage -Force }
6061+
# Create minimal valid zip then pad to 512-byte multiple for page blob
6062+
$tmpDir = Join-Path $TestOutputRoot "pkgtmp"
6063+
if (Test-Path $tmpDir) { Remove-Item $tmpDir -Recurse -Force }
6064+
New-Item -ItemType Directory -Path $tmpDir | Out-Null
6065+
Add-Type -AssemblyName System.IO.Compression.FileSystem
6066+
[System.IO.Compression.ZipFile]::CreateFromDirectory($tmpDir, $localPackage)
6067+
Remove-Item $tmpDir -Force
6068+
$bytes = [IO.File]::ReadAllBytes($localPackage)
6069+
$pad = 512 - ($bytes.Length % 512)
6070+
if ($pad -ne 512) {
6071+
$bytes += (0..($pad-1) | ForEach-Object { 0 })
6072+
[IO.File]::WriteAllBytes($localPackage, $bytes)
6073+
}
6074+
Set-AzStorageBlobContent -File $localPackage -Container $containerName -Blob $blobName -Context $ctx -BlobType Page | Out-Null
6075+
$packageUri = (Get-AzStorageBlob -Container $containerName -Blob $blobName -Context $ctx).ICloudBlob.Uri.AbsoluteUri
6076+
6077+
# Gallery + two application definitions (distinct names required)
6078+
$galleryName = "gal" + $rgname
6079+
$appName1 = "app" + $rgname
6080+
$appName2 = "app2" + $rgname
6081+
$appVersion = "1.0.0"
6082+
6083+
New-AzGallery -ResourceGroupName $rgname -Name $galleryName -Location $loc | Out-Null
6084+
New-AzGalleryApplication -ResourceGroupName $rgname -GalleryName $galleryName -Name $appName1 -Location $loc -SupportedOSType Linux | Out-Null
6085+
New-AzGalleryApplication -ResourceGroupName $rgname -GalleryName $galleryName -Name $appName2 -Location $loc -SupportedOSType Linux | Out-Null
6086+
6087+
$installCmd = "echo install"
6088+
$removeCmd = "echo remove"
6089+
6090+
# Version for app1
6091+
New-AzGalleryApplicationVersion -ResourceGroupName $rgname -GalleryName $galleryName -GalleryApplicationName $appName1 -Name $appVersion -Location $loc -PackageFileLink $packageUri -Install $installCmd -Remove $removeCmd -TargetRegion @(@{ Name = $loc; ReplicaCount = 1 }) | Out-Null
6092+
do {
6093+
Start-Sleep -Seconds 5
6094+
$ver1 = Get-AzGalleryApplicationVersion -ResourceGroupName $rgname -GalleryName $galleryName -GalleryApplicationName $appName1 -Name $appVersion -ErrorAction SilentlyContinue
6095+
} while ($ver1.ProvisioningState -ne "Succeeded")
6096+
$pkgId1 = $ver1.Id
6097+
6098+
# Version for app2
6099+
New-AzGalleryApplicationVersion -ResourceGroupName $rgname -GalleryName $galleryName -GalleryApplicationName $appName2 -Name $appVersion -Location $loc -PackageFileLink $packageUri -Install $installCmd -Remove $removeCmd -TargetRegion @(@{ Name = $loc; ReplicaCount = 1 }) | Out-Null
6100+
do {
6101+
Start-Sleep -Seconds 5
6102+
$ver2 = Get-AzGalleryApplicationVersion -ResourceGroupName $rgname -GalleryName $galleryName -GalleryApplicationName $appName2 -Name $appVersion -ErrorAction SilentlyContinue
6103+
} while ($ver2.ProvisioningState -ne "Succeeded")
6104+
$pkgId2 = $ver2.Id
6105+
6106+
# Create VMSS (no gallery apps initially)
6107+
$vmss = New-AzVmss -ResourceGroupName $rgname -Location $loc -Credential $cred -VMScaleSetName $vmssName -DomainNameLabel $domainNameLabel -Image $linuxImage -EnableProxyAgent -AddProxyAgentExtension
6108+
6109+
# Case 0: Add first gallery application with both flags false
6110+
$galApp0 = New-AzVmssGalleryApplication -PackageReferenceId $pkgId1 -EnableAutomaticUpgrade:$false -TreatFailureAsDeploymentFailure:$false
6111+
$profile = Add-AzVmssGalleryApplication -VirtualMachineScaleSetVM $vmss.VirtualMachineProfile -GalleryApplication $galApp0
6112+
$vmss.VirtualMachineProfile = $profile
6113+
$vmss | Update-AzVmss -ResourceGroupName $rgname -Name $vmssName | Out-Null
6114+
$vmssAfter0 = Get-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName
6115+
$gal0 = $vmssAfter0.VirtualMachineProfile.ApplicationProfile.GalleryApplications[0]
6116+
Assert-AreEqual $pkgId1 $gal0.PackageReferenceId
6117+
Assert-AreEqual $false $gal0.EnableAutomaticUpgrade
6118+
Assert-AreEqual $false $gal0.TreatFailureAsDeploymentFailure
6119+
6120+
# Case 1: Update existing application flags to true (modify in place, no duplicate)
6121+
$vmssMod = Get-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName
6122+
$vmssMod.VirtualMachineProfile.ApplicationProfile.GalleryApplications[0].EnableAutomaticUpgrade = $true
6123+
$vmssMod.VirtualMachineProfile.ApplicationProfile.GalleryApplications[0].TreatFailureAsDeploymentFailure = $true
6124+
Update-AzVmss -ResourceGroupName $rgname -Name $vmssName -VirtualMachineScaleSet $vmssMod | Out-Null
6125+
$vmssAfter1 = Get-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName
6126+
$gal1 = $vmssAfter1.VirtualMachineProfile.ApplicationProfile.GalleryApplications[0]
6127+
Assert-AreEqual $pkgId1 $gal1.PackageReferenceId
6128+
Assert-AreEqual $true $gal1.EnableAutomaticUpgrade
6129+
Assert-AreEqual $true $gal1.TreatFailureAsDeploymentFailure
6130+
6131+
# Case 2: Add second application (different name) with preset true flags
6132+
$galApp2 = New-AzVmssGalleryApplication -PackageReferenceId $pkgId2 -EnableAutomaticUpgrade:$true -TreatFailureAsDeploymentFailure:$true
6133+
$profile2 = Add-AzVmssGalleryApplication -VirtualMachineScaleSetVM $vmssAfter1.VirtualMachineProfile -GalleryApplication $galApp2
6134+
$vmssAfter1.VirtualMachineProfile = $profile2
6135+
Update-AzVmss -ResourceGroupName $rgname -Name $vmssName -VirtualMachineScaleSet $vmssAfter1 | Out-Null
6136+
$vmssAfter2 = Get-AzVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName
6137+
$gal2 = $vmssAfter2.VirtualMachineProfile.ApplicationProfile.GalleryApplications | Where-Object { $_.PackageReferenceId -eq $pkgId2 }
6138+
Assert-AreEqual $pkgId2 $gal2.PackageReferenceId
6139+
Assert-AreEqual $true $gal2.EnableAutomaticUpgrade
6140+
Assert-AreEqual $true $gal2.TreatFailureAsDeploymentFailure
6141+
}
6142+
finally
6143+
{
6144+
Clean-ResourceGroup $rgname
6145+
}
60186146
}

src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,5 +696,12 @@ public void TestVirtualMachineAddProxyAgentExtension()
696696
{
697697
TestRunner.RunTestScript("Test-VirtualMachineAddProxyAgentExtension");
698698
}
699+
700+
[Fact]
701+
[Trait(Category.AcceptanceType, Category.CheckIn)]
702+
public void TestVirtualMachineGalleryApplicationFlags()
703+
{
704+
TestRunner.RunTestScript("Test-VirtualMachineGalleryApplicationFlags");
705+
}
699706
}
700707
}

src/Compute/Compute.Test/ScenarioTests/VirtualMachineTests.ps1

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7975,3 +7975,144 @@ function Test-VirtualMachineAddProxyAgentExtension
79757975
Clean-ResourceGroup $resourceGroupName;
79767976
}
79777977
}
7978+
7979+
<#
7980+
.SYNOPSIS
7981+
Test-VirtualMachineGalleryApplicationFlags tests GalleryApplication Creation and Addition of TreatFailureAsDeploymentFailure and EnableAutomaticUpgrade flags
7982+
#>
7983+
function Test-VirtualMachineGalleryApplicationFlags
7984+
{
7985+
if ((Get-ComputeTestMode) -eq 'Playback') {
7986+
Write-Verbose "Skipping Test-VirtualMachineGalleryApplicationFlags in Playback (uses storage & gallery live operations)";
7987+
Assert-True { $true }
7988+
return
7989+
}
7990+
7991+
# Setup
7992+
$resourceGroupName = Get-ComputeTestResourceName;
7993+
$adminUsername = Get-ComputeTestResourceName;
7994+
$adminPassword = Get-PasswordForVM | ConvertTo-SecureString -AsPlainText -Force;
7995+
$cred = New-Object System.Management.Automation.PSCredential ($adminUsername, $adminPassword);
7996+
$vmName = 'VM1';
7997+
$imageName = "Canonical:0001-com-ubuntu-server-jammy:22_04-lts:latest";
7998+
$domainNameLabel = "d1" + $resourceGroupName;
7999+
$loc = 'eastus2';
8000+
8001+
try {
8002+
# Create VM
8003+
New-AzVM -ResourceGroupName $resourceGroupName -Name $vmName -Credential $cred -Image $imageName -DomainNameLabel $domainNameLabel -Location $loc -EnableProxyAgent -AddProxyAgentExtension | Out-Null
8004+
$VM = Get-AzVM -ResourceGroupName $resourceGroupName -Name $vmName
8005+
8006+
# Names
8007+
$galleryName = "gal" + $resourceGroupName
8008+
$galleryAppName1 = "app" + $resourceGroupName
8009+
$galleryAppName2 = "app2" + $resourceGroupName
8010+
$galleryAppVersion1 = "1.0.0"
8011+
$galleryAppVersion2 = "1.0.0" # version string can be same; application name must differ
8012+
8013+
# Storage account + package blob (page blob with valid minimal ZIP)
8014+
$storageName = ("pkg" + ($resourceGroupName.ToLower()))[0..([Math]::Min(23,("pkg" + ($resourceGroupName.ToLower())).Length-1))] -join ''
8015+
$containerName = "packages"
8016+
$blobName = "apppkg.zip"
8017+
8018+
New-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageName -Location $loc -Type Standard_LRS | Out-Null
8019+
$acctKeys = Get-AzStorageAccountKey -ResourceGroupName $resourceGroupName -Name $storageName
8020+
$ctx = New-AzStorageContext -StorageAccountName $storageName -StorageAccountKey $acctKeys[0].Value
8021+
New-AzStorageContainer -Name $containerName -Context $ctx -Permission Blob | Out-Null
8022+
8023+
$localPackage = Join-Path $TestOutputRoot $blobName
8024+
if (Test-Path $localPackage) { Remove-Item $localPackage -Force }
8025+
8026+
# Create a minimal valid ZIP (empty directory) then pad to 512-byte multiple for page blob
8027+
$tmpDir = Join-Path $TestOutputRoot "pkgtmp"
8028+
if (Test-Path $tmpDir) { Remove-Item $tmpDir -Recurse -Force }
8029+
New-Item -ItemType Directory -Path $tmpDir | Out-Null
8030+
Add-Type -AssemblyName System.IO.Compression.FileSystem
8031+
[System.IO.Compression.ZipFile]::CreateFromDirectory($tmpDir, $localPackage)
8032+
Remove-Item $tmpDir -Force
8033+
$bytes = [IO.File]::ReadAllBytes($localPackage)
8034+
$pad = 512 - ($bytes.Length % 512)
8035+
if ($pad -ne 512) {
8036+
$bytes += (0..($pad-1) | ForEach-Object { 0 })
8037+
[IO.File]::WriteAllBytes($localPackage, $bytes)
8038+
}
8039+
8040+
Set-AzStorageBlobContent -File $localPackage -Container $containerName -Blob $blobName -Context $ctx -BlobType Page | Out-Null
8041+
$packageUri = (Get-AzStorageBlob -Container $containerName -Blob $blobName -Context $ctx).ICloudBlob.Uri.AbsoluteUri
8042+
8043+
# Gallery + application definitions
8044+
New-AzGallery -ResourceGroupName $resourceGroupName -Name $galleryName -Location $loc | Out-Null
8045+
New-AzGalleryApplication -ResourceGroupName $resourceGroupName -GalleryName $galleryName -Name $galleryAppName1 -Location $loc -SupportedOSType Linux -Description "Test gallery app flags - app1" | Out-Null
8046+
New-AzGalleryApplication -ResourceGroupName $resourceGroupName -GalleryName $galleryName -Name $galleryAppName2 -Location $loc -SupportedOSType Linux -Description "Test gallery app flags - app2" | Out-Null
8047+
8048+
$installCmd = "echo install"
8049+
$removeCmd = "echo remove"
8050+
8051+
function Wait-GalleryAppVersionSucceeded {
8052+
param(
8053+
[string] $RG,
8054+
[string] $Gal,
8055+
[string] $App,
8056+
[string] $Ver,
8057+
[int] $TimeoutSeconds = 300
8058+
)
8059+
$start = Get-Date
8060+
do {
8061+
try {
8062+
$v = Get-AzGalleryApplicationVersion -ResourceGroupName $RG -GalleryName $Gal -GalleryApplicationName $App -Name $Ver -ErrorAction Stop
8063+
if ($v.ProvisioningState -eq 'Succeeded') { return $v }
8064+
}
8065+
catch {
8066+
# transient – ignore during creation
8067+
}
8068+
Start-Sleep -Seconds 5
8069+
} while ((Get-Date) - $start -lt [TimeSpan]::FromSeconds($TimeoutSeconds))
8070+
throw "Gallery Application Version $App/$Ver did not reach Succeeded within timeout."
8071+
}
8072+
8073+
# Version for app1
8074+
New-AzGalleryApplicationVersion -ResourceGroupName $resourceGroupName -GalleryName $galleryName -GalleryApplicationName $galleryAppName1 -Name $galleryAppVersion1 -Location $loc -PackageFileLink $packageUri -Install $installCmd -Remove $removeCmd -TargetRegion @(@{ Name = $loc; ReplicaCount = 1 }) | Out-Null
8075+
$galVerApp1 = Wait-GalleryAppVersionSucceeded -RG $resourceGroupName -Gal $galleryName -App $galleryAppName1 -Ver $galleryAppVersion1
8076+
$pkgId1 = $galVerApp1.Id
8077+
8078+
# Version for app2
8079+
New-AzGalleryApplicationVersion -ResourceGroupName $resourceGroupName -GalleryName $galleryName -GalleryApplicationName $galleryAppName2 -Name $galleryAppVersion2 -Location $loc -PackageFileLink $packageUri -Install $installCmd -Remove $removeCmd -TargetRegion @(@{ Name = $loc; ReplicaCount = 1 }) | Out-Null
8080+
$galVerApp2 = Wait-GalleryAppVersionSucceeded -RG $resourceGroupName -Gal $galleryName -App $galleryAppName2 -Ver $galleryAppVersion2
8081+
$pkgId2 = $galVerApp2.Id
8082+
8083+
# Case 0: Add first gallery application with both flags false
8084+
$vmGalleryApplication0 = New-AzVmGalleryApplication -PackageReferenceId $pkgId1 -EnableAutomaticUpgrade:$false -TreatFailureAsDeploymentFailure:$false
8085+
$VM = Add-AzVmGalleryApplication -VM $VM -GalleryApplication $vmGalleryApplication0
8086+
$VM | Update-AzVM
8087+
$vmAfter0 = Get-AzVM -ResourceGroupName $resourceGroupName -Name $vmName
8088+
$gal0 = $vmAfter0.ApplicationProfile.GalleryApplications[0]
8089+
Assert-AreEqual $pkgId1 $gal0.PackageReferenceId
8090+
Assert-AreEqual $false $gal0.EnableAutomaticUpgrade
8091+
Assert-AreEqual $false $gal0.TreatFailureAsDeploymentFailure
8092+
8093+
# Case 1: Update existing application flags to true
8094+
$VM = Get-AzVM -ResourceGroupName $resourceGroupName -Name $vmName
8095+
$VM.ApplicationProfile.GalleryApplications[0].EnableAutomaticUpgrade = $true
8096+
$VM.ApplicationProfile.GalleryApplications[0].TreatFailureAsDeploymentFailure = $true
8097+
Update-AzVM -ResourceGroupName $resourceGroupName -VM $VM
8098+
$vmAfter1 = Get-AzVM -ResourceGroupName $resourceGroupName -Name $vmName
8099+
$gal1 = $vmAfter1.ApplicationProfile.GalleryApplications[0]
8100+
Assert-AreEqual $pkgId1 $gal1.PackageReferenceId
8101+
Assert-AreEqual $true $gal1.EnableAutomaticUpgrade
8102+
Assert-AreEqual $true $gal1.TreatFailureAsDeploymentFailure
8103+
8104+
# Case 2: Add second (distinct) application with preset true flags
8105+
$vmGalleryApplication2 = New-AzVmGalleryApplication -PackageReferenceId $pkgId2 -EnableAutomaticUpgrade:$true -TreatFailureAsDeploymentFailure:$true
8106+
$VM = Get-AzVM -ResourceGroupName $resourceGroupName -Name $vmName
8107+
$VM = Add-AzVmGalleryApplication -VM $VM -GalleryApplication $vmGalleryApplication2
8108+
$VM | Update-AzVM
8109+
$vmAfter2 = Get-AzVM -ResourceGroupName $resourceGroupName -Name $vmName
8110+
$gal2 = $vmAfter2.ApplicationProfile.GalleryApplications | Where-Object { $_.PackageReferenceId -eq $pkgId2 }
8111+
Assert-AreEqual $pkgId2 $gal2.PackageReferenceId
8112+
Assert-AreEqual $true $gal2.EnableAutomaticUpgrade
8113+
Assert-AreEqual $true $gal2.TreatFailureAsDeploymentFailure
8114+
}
8115+
finally {
8116+
Clean-ResourceGroup $resourceGroupName
8117+
}
8118+
}

0 commit comments

Comments
 (0)