Skip to content

Commit ab8b1e0

Browse files
committed
Resolved type build issues, Added test for VM and VMSS
1 parent cbae334 commit ab8b1e0

File tree

5 files changed

+87
-3
lines changed

5 files changed

+87
-3
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,11 +682,26 @@ public void TestEncryptionIdentityNotPartOfAssignedIdentitiesInAzureVm()
682682
{
683683
TestRunner.RunTestScript("Test-EncryptionIdentityNotPartOfAssignedIdentitiesInAzureVm");
684684
}
685+
685686
[Fact]
686687
[Trait(Category.AcceptanceType, Category.CheckIn)]
687688
public void TestVirtualMachinePlacement()
688689
{
689690
TestRunner.RunTestScript("Test-VirtualMachinePlacement");
690691
}
692+
693+
[Fact]
694+
[Trait(Category.AcceptanceType, Category.CheckIn)]
695+
public void TestVMAddProxyAgentExtension()
696+
{
697+
TestRunner.RunTestScript("Test-VMAddProxyAgentExtension");
698+
}
699+
700+
[Fact]
701+
[Trait(Category.AcceptanceType, Category.CheckIn)]
702+
public void TestVMSSAddProxyAgentExtension()
703+
{
704+
TestRunner.RunTestScript("Test-VMSSAddProxyAgentExtension");
705+
}
691706
}
692707
}

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

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7938,4 +7938,73 @@ function Test-VirtualMachinePlacement
79387938
# Cleanup
79397939
Clean-ResourceGroup $rgname;
79407940
}
7941+
}
7942+
7943+
<#
7944+
.SYNOPSIS
7945+
Test-VMAddProxyAgentExtension creates a VM with Enabled ProxyAgent and added ProxyAgentExtension
7946+
#>
7947+
function Test-VMAddProxyAgentExtension
7948+
{
7949+
# Setup
7950+
$resourceGroupName = "resourceGroup1";
7951+
$adminUsername = "adminUser";
7952+
$adminPassword = "Pssword123" | ConvertTo-SecureString -AsPlainText -Force;
7953+
$cred = New-Object System.Management.Automation.PSCredential ($adminUsername, $adminPassword);
7954+
$vmName = 'VM1';
7955+
$imageName = "Canonical:0001-com-ubuntu-server-jammy:22_04-lts:latest";
7956+
Connect-AzAccount
7957+
7958+
try
7959+
{
7960+
New-AzVM -ResourceGroupName $resourceGroupName -Name $VMName -Credential $cred -image $imageName -EnableProxyAgent -AddProxyAgentExtension
7961+
7962+
# Update vm to add proxy agent extension
7963+
$VM = Get-AzVM -ResourceGroupName $resourceGroupName -VMName $vmName
7964+
$VM = Set-AzVMProxyAgentSetting -VM $VM -EnableProxyAgent $true -AddProxyAgentExtension false
7965+
Update-AzVM -ResourceGroupName $resourceGroupName -VM $VM
7966+
7967+
# Validate
7968+
Assert-AreEqual $VM.SecurityProfile.ProxyAgentSettings.Enabled $true
7969+
Assert-AreEqual $VM.SecurityProfile.ProxyAgentSettings.AddProxyAgentExtension $false
7970+
}
7971+
finally
7972+
{
7973+
# Cleanup
7974+
Clean-ResourceGroup $resourceGroupName;
7975+
}
7976+
}
7977+
7978+
<#
7979+
.SYNOPSIS
7980+
Test-VMSSAddProxyAgentExtension creates a VMSS with Enabled ProxyAgent and added ProxyAgentExtension
7981+
#>
7982+
function Test-VMSSAddProxyAgentExtension
7983+
{
7984+
# Setup
7985+
$resourceGroupName = "resourceGroup1";
7986+
$adminUsername = "adminUser";
7987+
$adminPassword = "Pssword123" | ConvertTo-SecureString -AsPlainText -Force;
7988+
$cred = New-Object System.Management.Automation.PSCredential ($adminUsername, $adminPassword);
7989+
$vmssName = 'VMSS1';
7990+
$imageName = "Canonical:0001-com-ubuntu-server-jammy:22_04-lts:latest";
7991+
7992+
try
7993+
{
7994+
New-AzVmss -ResourceGroupName $resourceGroupName -VMScaleSetName $vmssName -Credential $cred -image $imageName -EnableProxyAgent -AddProxyAgentExtension
7995+
7996+
# Update vmss to add proxy agent extension
7997+
$VMSS = Get-AzVmss -ResourceGroupName $resourceGroupName -VMScaleSetName $vmssName
7998+
$VMSS = Set-AzVmssProxyAgentSetting -VirtualMachineScaleSet $VMSS -AddProxyAgentExtension false
7999+
Update-AzVmss -ResourceGroupName $resourceGroupName -Name $vmssName -VirtualMachineScaleSet $VMSS
8000+
8001+
# Validate
8002+
Assert-AreEqual $VMSS.SecurityProfile.ProxyAgentSettings.Enabled $true
8003+
Assert-AreEqual $VMSS.SecurityProfile.ProxyAgentSettings.AddProxyAgentExtension $false
8004+
}
8005+
finally
8006+
{
8007+
# Cleanup
8008+
Clean-ResourceGroup $resourceGroupName;
8009+
}
79418010
}

src/Compute/Compute/Generated/VirtualMachineScaleSet/Config/SetAzVmssProxyAgentSetting.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public override void ExecuteCmdlet()
102102
})
103103
};
104104

105-
if (this.IsParameterBound(c => c.AddProxyAgentExtension))
105+
if (this.MyInvocation.BoundParameters.ContainsKey(nameof(AddProxyAgentExtension)))
106106
{
107107
this.VirtualMachineScaleSet.VirtualMachineProfile.SecurityProfile.ProxyAgentSettings.AddProxyAgentExtension = this.AddProxyAgentExtension;
108108
}

src/Compute/Compute/Strategies/ComputeRp/VirtualMachineScaleSetStrategy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ internal static ResourceConfig<VirtualMachineScaleSet> CreateVirtualMachineScale
253253
string securityPostureId = null,
254254
string[] securityPostureExcludeExtension = null,
255255
bool? enableProxyAgent = null,
256-
bool? addProxyAgentExtension = null,
256+
bool? addProxyAgentExtension = null
257257
)
258258
=> Strategy.CreateResourceConfig(
259259
resourceGroup: resourceGroup,

src/Compute/Compute/VirtualMachine/Config/SetAzVMProxyAgentSetting.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public override void ExecuteCmdlet()
101101
KeyIncarnationId = this.KeyIncarnationId
102102
};
103103

104-
if (this.IsParameterBound(c => c.AddProxyAgentExtension))
104+
if (this.MyInvocation.BoundParameters.ContainsKey(nameof(AddProxyAgentExtension)))
105105
{
106106
this.VM.SecurityProfile.ProxyAgentSettings.AddProxyAgentExtension = this.AddProxyAgentExtension;
107107
}

0 commit comments

Comments
 (0)