Skip to content

Commit af28796

Browse files
author
Ed Munoz
committed
Added scenario tests for attaching NSG to VM and to NIC.
1 parent 80416b4 commit af28796

File tree

5 files changed

+3537
-3
lines changed

5 files changed

+3537
-3
lines changed

src/ServiceManagement/Network/Commands.Network.Test/Commands.Network.Test.csproj

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
33
<Import Project="..\..\..\packages\xunit.runner.visualstudio.2.0.0\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\..\..\packages\xunit.runner.visualstudio.2.0.0\build\net20\xunit.runner.visualstudio.props')" />
44
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
@@ -204,6 +204,12 @@
204204
<None Include="SessionRecords\Microsoft.Azure.Commands.Network.Test.ScenarioTests.IPForwardingScenarioTests\SetIPForwardingOnVMAndUpdateVM.json">
205205
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
206206
</None>
207+
<None Include="SessionRecords\Microsoft.Azure.Commands.Network.Test.ScenarioTests.NSGScenarioTests\SetNSGOnNICAndUpdateVM.json">
208+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
209+
</None>
210+
<None Include="SessionRecords\Microsoft.Azure.Commands.Network.Test.ScenarioTests.NSGScenarioTests\SetNSGOnRoleAndUpdateVM.json">
211+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
212+
</None>
207213
<None Include="SessionRecords\Microsoft.Azure.Commands.Network.Test.ScenarioTests.NSGScenarioTests\TestCreateAndRemoveNSG.json">
208214
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
209215
</None>

src/ServiceManagement/Network/Commands.Network.Test/ScenarioTests/NetworkSecurityGroup/NSGScenarioTests.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,23 @@ public void TestSetNSGToSubnetInDiffRegion()
106106
{
107107
this.RunPowerShellTest("Test-SetNetworkSecurityGroupToSubnetInDifferentRegion");
108108
}
109-
109+
110+
[Fact]
111+
[Trait(Category.Service, Category.Network)]
112+
[Trait(Category.AcceptanceType, Category.CheckIn)]
113+
public void SetNSGOnRoleAndUpdateVM()
114+
{
115+
this.RunPowerShellTest("Test-SetNSGOnRoleAndUpdateVM");
116+
}
117+
118+
[Fact]
119+
[Trait(Category.Service, Category.Network)]
120+
[Trait(Category.AcceptanceType, Category.CheckIn)]
121+
public void SetNSGOnNICAndUpdateVM()
122+
{
123+
this.RunPowerShellTest("Test-SetNSGOnNICAndUpdateVM");
124+
}
125+
110126
#region Test setup
111127
protected void SetupManagementClients()
112128
{

src/ServiceManagement/Network/Commands.Network.Test/ScenarioTests/NetworkSecurityGroup/NetworkSecurityGroupTests.ps1

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ function Test-SetNetworkSecurityGroupToSubnetInDifferentRegion
192192
Assert-Throws { Set-AzureNetworkSecurityGroupToSubnet -Name $securityGroupName -VirtualNetwork $VirtualNetworkName -Subnet $SubnetName -Force } $expectedMessage
193193
}
194194

195-
########################## Remove Network Security Group for Subnet Tests #############################
195+
########################## Remove Network Security Group from Subnet Tests #############################
196196

197197
<#
198198
.SYNOPSIS
@@ -214,3 +214,72 @@ function Test-RemoveNetworkSecurityGroupFromSubnet
214214
$expectedMessage = "ResourceNotFound: The virtual network name $VirtualNetworkName and subnet $SubnetName does not have any network security group assigned."
215215
Assert-Throws { Get-AzureNetworkSecurityGroupForSubnet -VirtualNetwork $VirtualNetworkName -Subnet $SubnetName } $expectedMessage
216216
}
217+
218+
########################## Update-AzureVM keeps NSG on Role and on NIC #############################
219+
220+
<#
221+
.SYNOPSIS
222+
Tests Update-AzureVM after a VM has NSG on Role
223+
#>
224+
function Test-SetNSGOnRoleAndUpdateVM
225+
{
226+
# Setup
227+
Set-AzureVNetConfig ($(Get-Location).Path + "\TestData\SimpleNetworkConfiguration.xml")
228+
$VMName = getAssetName
229+
$image = get-azurevmimage | Where-Object {$_.OS -eq 'Windows'} | Select-Object -First 1 -ExpandProperty ImageName
230+
$image = "b9a55fa61dad4dd88bab1b26ca2ed075__Test-Win2K8R2SP1-Datacenter-201401.01-en.us-127GB.vhd"
231+
232+
# Test
233+
New-AzureVMConfig -ImageName $image -Name $VMName -InstanceSize Small |
234+
Add-AzureProvisioningConfig -Windows -AdminUsername azuretest -Password "Pa@!!w0rd" |
235+
Set-AzureSubnet -SubnetNames $SubnetName |
236+
New-AzureVM -VNetName $VirtualNetworkName -ServiceName $VMName -Location $Location
237+
238+
$securityGroupName = Get-SecurityGroupName
239+
$securityRuleName = Get-SecurityRuleName
240+
$createdSecurityGroup = New-NetworkSecurityGroup $securityGroupName
241+
242+
# Test
243+
Get-AzureVM $VMName | Set-AzureNetworkSecurityGroupAssociation $securityGroupName
244+
Get-AzureVM $VMName |
245+
Add-AzureEndpoint -Name "http" -Protocol tcp -LocalPort 80 -PublicPort 80 |
246+
Update-AzureVM
247+
248+
# Assert
249+
$retrievedNSG = Get-AzureVM $VMName | Get-AzureNetworkSecurityGroupAssociation
250+
Assert-AreEqual $securityGroupName $retrievedNSG.Name
251+
}
252+
<#
253+
.SYNOPSIS
254+
Tests Update-AzureVM after a VM has NSG on Role
255+
#>
256+
function Test-SetNSGOnNICAndUpdateVM
257+
{
258+
# Setup
259+
Set-AzureVNetConfig ($(Get-Location).Path + "\TestData\SimpleNetworkConfiguration.xml")
260+
$VMName = getAssetName
261+
$nicName = getAssetName
262+
$image = get-azurevmimage | Where-Object {$_.OS -eq 'Windows'} | Select-Object -First 1 -ExpandProperty ImageName
263+
$image = "b9a55fa61dad4dd88bab1b26ca2ed075__Test-Win2K8R2SP1-Datacenter-201401.01-en.us-127GB.vhd"
264+
265+
# Test
266+
New-AzureVMConfig -ImageName $image -Name $VMName -InstanceSize Large |
267+
Add-AzureProvisioningConfig -Windows -AdminUsername azuretest -Password "Pa@!!w0rd" |
268+
Set-AzureSubnet -SubnetNames $SubnetName |
269+
Add-AzureNetworkInterfaceConfig -Name $nicName -SubnetName $SubnetName |
270+
New-AzureVM -VNetName $VirtualNetworkName -ServiceName $VMName -Location $Location
271+
272+
$securityGroupName = Get-SecurityGroupName
273+
$securityRuleName = Get-SecurityRuleName
274+
$createdSecurityGroup = New-NetworkSecurityGroup $securityGroupName
275+
276+
# Test
277+
Get-AzureVM $VMName | Set-AzureNetworkSecurityGroupAssociation -Name $securityGroupName -NetworkInterfaceName $nicName
278+
Get-AzureVM $VMName |
279+
Add-AzureEndpoint -Name "http" -Protocol tcp -LocalPort 80 -PublicPort 80 |
280+
Update-AzureVM
281+
282+
# Assert
283+
$retrievedNSG = Get-AzureVM $VMName | Get-AzureNetworkSecurityGroupAssociation -NetworkInterfaceName $nicName
284+
Assert-AreEqual $securityGroupName $retrievedNSG.Name
285+
}

0 commit comments

Comments
 (0)