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 " `n Resiliency 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 " `n Test 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 " `n Route 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 " `n Test 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 " `n Failover 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 " `n Stop 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 " `n All 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 " `n Single 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 " `n Combined Failover Test completed successfully."
217+ }
0 commit comments