Skip to content

Commit 207a359

Browse files
Vnet gateway failover and insights (#28517)
1 parent cd400de commit 207a359

File tree

39 files changed

+5438
-2
lines changed

39 files changed

+5438
-2
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.Azure.Commands.Network.Test.ScenarioTests;
16+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17+
using Xunit;
18+
using Xunit.Abstractions;
19+
20+
namespace Commands.Network.Test.ScenarioTests
21+
{
22+
public class VirtualNetworkGatewayFailoverTests : NetworkTestRunner
23+
{
24+
public VirtualNetworkGatewayFailoverTests(ITestOutputHelper output)
25+
: base(output)
26+
{
27+
}
28+
29+
[Fact(Skip = "Requires pre-created virtual network gateway resources")]
30+
[Trait(Category.AcceptanceType, Category.CheckIn)]
31+
[Trait(Category.Owner, NrpTeamAlias.exrdev)]
32+
public void TestVirtualNetworkGatewayResiliencyInformation()
33+
{
34+
TestRunner.RunTestScript("Test-VirtualNetworkGatewayResiliencyInformation");
35+
}
36+
37+
[Fact(Skip = "Requires pre-created virtual network gateway resources")]
38+
[Trait(Category.AcceptanceType, Category.CheckIn)]
39+
[Trait(Category.Owner, NrpTeamAlias.exrdev)]
40+
public void TestVirtualNetworkGatewayRoutesInformation()
41+
{
42+
TestRunner.RunTestScript("Test-VirtualNetworkGatewayRoutesInformation");
43+
}
44+
45+
[Fact(Skip = "Requires pre-created virtual network gateway resources")]
46+
[Trait(Category.AcceptanceType, Category.CheckIn)]
47+
[Trait(Category.Owner, NrpTeamAlias.exrdev)]
48+
public void TestStartVirtualNetworkGatewaySiteFailoverTest()
49+
{
50+
TestRunner.RunTestScript("Test-StartAzureVirtualNetworkGatewaySiteFailoverTest");
51+
}
52+
53+
// Test for StopAzureVirtualNetworkGatewaySiteFailoverTest cmdlet
54+
[Fact(Skip = "Requires pre-created virtual network gateway resources")]
55+
[Trait(Category.AcceptanceType, Category.CheckIn)]
56+
[Trait(Category.Owner, NrpTeamAlias.exrdev)]
57+
public void TestStopVirtualNetworkGatewaySiteFailoverTest()
58+
{
59+
TestRunner.RunTestScript("Test-StopAzureVirtualNetworkGatewaySiteFailoverTest");
60+
}
61+
62+
[Fact(Skip = "Requires pre-created virtual network gateway resources")]
63+
[Trait(Category.AcceptanceType, Category.CheckIn)]
64+
[Trait(Category.Owner, NrpTeamAlias.exrdev)]
65+
public void TestCombinedVirtualNetworkGatewayFailoverTestDetails()
66+
{
67+
TestRunner.RunTestScript("Test-CombinedAzureVirtualNetworkGatewayFailoverTestDetails");
68+
}
69+
}
70+
}
Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
<#
2+
.SYNOPSIS
3+
Tests the retrieval of resiliency information for a virtual network gateway.
4+
.DESCRIPTION
5+
This test assumes the virtual network gateway already exists and is properly configured.
6+
#>
7+
function Test-VirtualNetworkGatewayResiliencyInformation
8+
{
9+
$rgName = "shubhati_failover" # <-- Replace with actual resource group
10+
$vnetGatewayName = "shubhati_failoverGw" # <-- Replace with actual gateway name
11+
12+
#Safeguard: Skip test if the resource doesn't exist
13+
if (-not (Get-AzVirtualNetworkGateway -ResourceGroupName $rgName -Name $vnetGatewayName -ErrorAction SilentlyContinue)) {
14+
Write-Warning "Test skipped: Virtual Network Gateway '$vnetGatewayName' not found in RG '$rgName'."
15+
return
16+
}
17+
18+
Write-Debug "Fetching resiliency information for Virtual Network Gateway: $vnetGatewayName in RG: $rgName"
19+
20+
$resultJson = Get-AzVirtualNetworkGatewayResiliencyInformation `
21+
-ResourceGroupName $rgName `
22+
-VirtualNetworkGatewayName $vnetGatewayName `
23+
-AttemptRefresh:$true
24+
25+
Write-Debug "`nResiliency Info JSON:"
26+
Write-Debug $resultJson
27+
28+
# Assert that the result is not null
29+
Assert-NotNull $resultJson "The resiliency information result is null."
30+
31+
Write-Debug "`nTest completed successfully."
32+
}
33+
34+
<#
35+
.SYNOPSIS
36+
Tests the retrieval of route information for a virtual network gateway.
37+
.DESCRIPTION
38+
This test assumes the virtual network gateway already exists and is properly configured.
39+
#>
40+
function Test-VirtualNetworkGatewayRoutesInformation
41+
{
42+
$rgName = "shubhati_failover" # <-- Replace with actual resource group
43+
$vnetGatewayName = "shubhati_failoverGw" # <-- Replace with actual gateway name
44+
45+
# Safeguard: Skip test if the resource doesn't exist
46+
if (-not (Get-AzVirtualNetworkGateway -ResourceGroupName $rgName -Name $vnetGatewayName -ErrorAction SilentlyContinue)) {
47+
Write-Warning "Test skipped: Virtual Network Gateway '$vnetGatewayName' not found in RG '$rgName'."
48+
return
49+
}
50+
51+
Write-Host "Fetching route information for Virtual Network Gateway: $vnetGatewayName in RG: $rgName"
52+
53+
# Fetch route information
54+
$resultJson = Get-AzVirtualNetworkGatewayRoutesInformation `
55+
-ResourceGroupName $rgName `
56+
-VirtualNetworkGatewayName $vnetGatewayName
57+
58+
Write-Debug "`nRoute Information JSON:"
59+
Write-Debug $resultJson
60+
61+
# Assert that the result is not null
62+
Assert-NotNull $resultJson "The route information result is null."
63+
64+
Write-Debug "`nTest completed successfully."
65+
}
66+
67+
<#
68+
.SYNOPSIS
69+
Tests the start of the virtual network gateway site failover.
70+
.DESCRIPTION
71+
This test triggers the start of a site failover on a virtual network gateway. It assumes the resources are pre-created.
72+
#>
73+
function Test-StartAzureVirtualNetworkGatewaySiteFailoverTest
74+
{
75+
$rgName = "shubhati_failover" # <-- Replace with actual resource group
76+
$vnetGatewayName = "shubhati_failoverGw" # <-- Replace with actual gateway name
77+
$peeringLocation = "London2" # <-- Replace with actual peering location
78+
79+
# Safeguard: Skip test if the resource doesn't exist
80+
if (-not (Get-AzVirtualNetworkGateway -ResourceGroupName $rgName -Name $vnetGatewayName -ErrorAction SilentlyContinue)) {
81+
Write-Warning "Test skipped: Virtual Network Gateway '$vnetGatewayName' not found in RG '$rgName'."
82+
return
83+
}
84+
85+
Write-Debug "Starting failover test for Virtual Network Gateway: $vnetGatewayName in RG: $rgName"
86+
87+
try {
88+
# Start failover test
89+
$resultFailover = Start-AzVirtualNetworkGatewaySiteFailoverTest `
90+
-ResourceGroupName $rgName `
91+
-VirtualNetworkGatewayName $vnetGatewayName `
92+
-PeeringLocation $peeringLocation `
93+
-Type "SingleSiteFailover"
94+
95+
Write-Debug "`nFailover Test started successfully."
96+
}
97+
catch {
98+
$errorMessage = $_.Exception.Message
99+
Write-Error "An error occurred while starting the failover test: $errorMessage"
100+
throw "Test failed due to exception: $errorMessage"
101+
}
102+
}
103+
104+
<#
105+
.SYNOPSIS
106+
Tests the stop of the virtual network gateway site failover.
107+
.DESCRIPTION
108+
This test triggers the stop of a site failover on a virtual network gateway. It assumes the resources are pre-created.
109+
#>
110+
function Test-StopAzureVirtualNetworkGatewaySiteFailoverTest
111+
{
112+
$rgName = "shubhati_failover" # <-- Replace with actual resource group
113+
$vnetGatewayName = "shubhati_failoverGw" # <-- Replace with actual gateway name
114+
$peeringLocation = "London2" # <-- Replace with actual peering location
115+
116+
# Safeguard: Skip test if the resource doesn't exist
117+
if (-not (Get-AzVirtualNetworkGateway -ResourceGroupName $rgName -Name $vnetGatewayName -ErrorAction SilentlyContinue)) {
118+
Write-Warning "Test skipped: Virtual Network Gateway '$vnetGatewayName' not found in RG '$rgName'."
119+
return
120+
}
121+
122+
Write-Debug "Waiting for 5 minutes before stopping the failover test for Virtual Network Gateway: $vnetGatewayName in RG: $rgName"
123+
124+
# Sleep for 5 minutes (300 seconds)
125+
Start-Sleep -Seconds 300
126+
127+
Write-Debug "Starting the process of stopping the failover test"
128+
129+
try{
130+
# Define failover connection details
131+
$detail = @(
132+
[Microsoft.Azure.Management.Network.Models.FailoverConnectionDetails]@{
133+
FailoverConnectionName = "shubhati_ER_Arista--conn--shubhati_failoverGw"
134+
FailoverLocation = "eastus2euap"
135+
IsVerified = $true
136+
}
137+
)
138+
139+
# Stop the failover test
140+
$resultStopFailover = Stop-AzVirtualNetworkGatewaySiteFailoverTest `
141+
-ResourceGroupName $rgName `
142+
-VirtualNetworkGatewayName $vnetGatewayName `
143+
-PeeringLocation $peeringLocation `
144+
-Detail $detail `
145+
-WasSimulationSuccessful $true
146+
147+
Write-Debug "`nStop Failover Test completed successfully."
148+
}
149+
catch {
150+
$errorMessage = $_.Exception.Message
151+
Write-Error "An error occurred while stopping the failover test: $errorMessage"
152+
throw "Test failed due to exception: $errorMessage"
153+
}
154+
}
155+
156+
<#
157+
.SYNOPSIS
158+
Tests the retrieval of failover test details for a virtual network gateway.
159+
.DESCRIPTION
160+
This test first retrieves a list of all failover tests for a virtual network gateway, then fetches details of a specific failover test based on the first test's results.
161+
#>
162+
function Test-CombinedAzureVirtualNetworkGatewayFailoverTestDetails
163+
{
164+
$rgName = "shubhati_failover" # <-- Replace with actual resource group
165+
$vnetGatewayName = "shubhati_failoverGw" # <-- Replace with actual gateway name
166+
167+
# Safeguard: Skip test if the resource doesn't exist
168+
if (-not (Get-AzVirtualNetworkGateway -ResourceGroupName $rgName -Name $vnetGatewayName -ErrorAction SilentlyContinue)) {
169+
Write-Warning "Test skipped: Virtual Network Gateway '$vnetGatewayName' not found in RG '$rgName'."
170+
return
171+
}
172+
173+
Write-Debug "Fetching all failover tests for Virtual Network Gateway: $vnetGatewayName in RG: $rgName"
174+
175+
# Fetch all failover tests
176+
$resultAllTests = Get-AzVirtualNetworkGatewayFailoverAllTestsDetail `
177+
-ResourceGroupName $rgName `
178+
-VirtualNetworkGatewayName $vnetGatewayName `
179+
-Type "SingleSiteFailover" `
180+
-FetchLatest $true
181+
182+
Write-Debug "`nAll Failover Tests:"
183+
Write-Debug $resultAllTests
184+
185+
# Assert that the result is not null or empty
186+
Assert-NotNull $resultAllTests "The failover all test details are null or empty."
187+
188+
# Check if there is at least one result and fetch the details of the first test
189+
if ($resultAllTests.value.Count -gt 0) {
190+
$firstTest = $resultAllTests.value[0]
191+
$testGuid = $firstTest.TestGuid
192+
$peeringLocation = $firstTest.PeeringLocation
193+
194+
Write-Debug "Fetching details for Failover Test ID: $testGuid at Peering Location: $peeringLocation"
195+
196+
# Fetch details for a specific failover test using the TestGuid from the previous step
197+
$resultSingleTest = Get-AzVirtualNetworkGatewayFailoverSingleTestDetail `
198+
-ResourceGroupName $rgName `
199+
-VirtualNetworkGatewayName $vnetGatewayName `
200+
-PeeringLocation $peeringLocation `
201+
-FailoverTestId $testGuid
202+
203+
Write-Debug "`nSingle Failover Test Details:"
204+
Write-Debug $resultSingleTest
205+
206+
# Assert that the result is not null or empty
207+
Assert-NotNull $resultSingleTest "The failover single test details for specific test are null or empty."
208+
209+
# Further assertions can be made depending on the specifics of the test data
210+
Assert-True ($resultSingleTest.value.Count -gt 0) "No details found for the failover test."
211+
}
212+
else {
213+
Write-Warning "No failover tests were found for Virtual Network Gateway '$vnetGatewayName'."
214+
}
215+
216+
Write-Debug "`nCombined Failover Test completed successfully."
217+
}

0 commit comments

Comments
 (0)