Skip to content

Commit ffc760c

Browse files
adding warning when using new-azvmss and not using "latest" image version (#12300)
* adding warning when not using latest image version when creading vmss * update to tabified file * add missing bracket * remove new lines from Get-Content call * minor fixes * using assert-true method * removing some commmented out code * align * indent * newline at the end * Update ChangeLog.md Co-authored-by: Yabo Hu <[email protected]>
1 parent 21719e6 commit ffc760c

File tree

6 files changed

+3871
-2
lines changed

6 files changed

+3871
-2
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,13 @@ public void TestVirtualMachineScaleSetAutoRepair()
163163
{
164164
TestRunner.RunTestScript("Test-VirtualMachineScaleSetAutoRepair");
165165
}
166+
167+
168+
[Fact]
169+
[Trait(Category.AcceptanceType, Category.CheckIn)]
170+
public void TestVirtualMachineScaleSetImageVersion()
171+
{
172+
TestRunner.RunTestScript("Test-VirtualMachineScaleSetImageVersion");
173+
}
166174
}
167-
}
175+
}

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

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2370,4 +2370,100 @@ function Test-VirtualMachineScaleSetAutoRepair
23702370
# Cleanup
23712371
Clean-ResourceGroup $rgname
23722372
}
2373+
2374+
}
2375+
2376+
<#
2377+
.SYNOPSIS
2378+
Test Virtual Machine Scale Set warning if not using latest image version
2379+
#>
2380+
function Test-VirtualMachineScaleSetImageVersion
2381+
{
2382+
# Setup
2383+
$rgname = Get-ComputeTestResourceName
2384+
2385+
try
2386+
{
2387+
# Common
2388+
$loc = "westus" ;
2389+
New-AzResourceGroup -Name $rgname -Location $loc -Force;
2390+
2391+
# SRP
2392+
$stoname = 'sto' + $rgname;
2393+
$stotype = 'Standard_GRS';
2394+
New-AzStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type $stotype;
2395+
$stoaccount = Get-AzStorageAccount -ResourceGroupName $rgname -Name $stoname;
2396+
2397+
# NRP
2398+
$subnet = New-AzVirtualNetworkSubnetConfig -Name ('subnet' + $rgname-AddressPrefix "10.0.0.0/24";
2399+
$vnet = New-AzVirtualNetwork -Force -Name ('vnet' + $rgname-ResourceGroupName $rgname -Location $loc -AddressPrefix "10.0.0.0/16" -Subnet $subnet;
2400+
$vnet = Get-AzVirtualNetwork -Name ('vnet' + $rgname-ResourceGroupName $rgname;
2401+
$subnetId = $vnet.Subnets[0].Id;
2402+
$pubip = New-AzPublicIpAddress -Force -Name ('pubip' + $rgname-ResourceGroupName $rgname -Location $loc -AllocationMethod Dynamic -DomainNameLabel ('pubip' + $rgname);
2403+
$pubip = Get-AzPublicIpAddress -Name ('pubip' + $rgname-ResourceGroupName $rgname;
2404+
2405+
# Create LoadBalancer
2406+
$frontendName = Get-ResourceName
2407+
$backendAddressPoolName = Get-ResourceName
2408+
$probeName = Get-ResourceName
2409+
$inboundNatPoolName = Get-ResourceName
2410+
$lbruleName = Get-ResourceName
2411+
$lbName = Get-ResourceName
2412+
2413+
$frontend = New-AzLoadBalancerFrontendIpConfig -Name $frontendName -PublicIpAddress $pubip
2414+
$backendAddressPool = New-AzLoadBalancerBackendAddressPoolConfig -Name $backendAddressPoolName
2415+
$probe = New-AzLoadBalancerProbeConfig -Name $probeName -RequestPath healthcheck.aspx -Protocol http -Port 80 -IntervalInSeconds 15 -ProbeCount 2
2416+
$inboundNatPool = New-AzLoadBalancerInboundNatPoolConfig -Name $inboundNatPoolName -FrontendIPConfigurationId `
2417+
$frontend.Id -Protocol Tcp -FrontendPortRangeStart 3360 -FrontendPortRangeEnd 3368 -BackendPort 3370;
2418+
$lbrule = New-AzLoadBalancerRuleConfig -Name $lbruleName `
2419+
-FrontendIPConfiguration $frontend -BackendAddressPool $backendAddressPool `
2420+
-Probe $probe -Protocol Tcp -FrontendPort 80 -BackendPort 80 `
2421+
-IdleTimeoutInMinutes 15 -EnableFloatingIP -LoadDistribution SourceIP;
2422+
$actualLb = New-AzLoadBalancer -Name $lbName -ResourceGroupName $rgname -Location $loc `
2423+
-FrontendIpConfiguration $frontend -BackendAddressPool $backendAddressPool `
2424+
-Probe $probe -LoadBalancingRule $lbrule -InboundNatPool $inboundNatPool;
2425+
$expectedLb = Get-AzLoadBalancer -Name $lbName -ResourceGroupName $rgname
2426+
2427+
# New VMSS Parameters
2428+
$vmssName = 'vmss' + $rgname;
2429+
$adminUsername = 'Foo12';
2430+
$adminPassword = $PLACEHOLDER;
2431+
2432+
$imgRef = Get-DefaultCRPImage -loc $loc;
2433+
$vhdContainer = "https://" + $stoname + ".blob.core.windows.net/" + $vmssName;
2434+
2435+
$ExtName = "CSETest";
2436+
$Publisher = "Microsoft.Compute";
2437+
$ExtType = "BGInfo";
2438+
$ExtVer = "2.1";
2439+
2440+
$ipCfg = New-AzVmssIPConfig -Name 'test' `
2441+
-LoadBalancerInboundNatPoolsId $expectedLb.InboundNatPools[0].Id `
2442+
-LoadBalancerBackendAddressPoolsId $expectedLb.BackendAddressPools[0].Id `
2443+
-SubnetId $subnetId;
2444+
2445+
$vmss = New-AzVmssConfig -Location $loc -SkuCapacity 2 -SkuName 'Standard_E4-2ds_v4' -UpgradePolicyMode 'Automatic' `
2446+
| Add-AzVmssNetworkInterfaceConfiguration -Name 'test' -Primary $true -IPConfiguration $ipCfg `
2447+
| Add-AzVmssNetworkInterfaceConfiguration -Name 'test2' -IPConfiguration $IPCfg `
2448+
| Set-AzVmssOSProfile -ComputerNamePrefix 'test' -AdminUsername $adminUsername -AdminPassword $adminPassword `
2449+
| Set-AzVmssStorageProfile -Name 'test' -OsDiskCreateOption 'FromImage' -OsDiskCaching 'None' `
2450+
-ImageReferenceOffer $imgRef.Offer -ImageReferenceSku $imgRef.Skus -ImageReferenceVersion $imgRef.version `
2451+
-ImageReferencePublisher $imgRef.PublisherName -VhdContainer $vhdContainer `
2452+
| Add-AzVmssExtension -Name $ExtName -Publisher $Publisher -Type $ExtType -TypeHandlerVersion $ExtVer -AutoUpgradeMinorVersion $True
2453+
2454+
Start-Transcript -Path "transcript.txt"
2455+
#create the vmss 
2456+
New-AzVmss -ResourceGroup $rgname -Name $vmssName -VirtualMachineScaleSet $vmss
2457+
Stop-Transcript
2458+
2459+
$wordToFind="You are deploying VMSS pinned to a specific image version from Azure Marketplace.";
2460+
$file = (Get-Content -path "transcript.txt") -join ' ';
2461+
Assert-True { $file -match $wordToFind } ;
2462+
2463+
}
2464+
finally
2465+
{
2466+
# Cleanup
2467+
Clean-ResourceGroup $rgname
2468+
}
23732469
}

0 commit comments

Comments
 (0)