Skip to content

Commit 54851b4

Browse files
authored
[Synapse]-Add Firewall Rule management cmdlets (Azure#12014)
* Add firewall rule related cmdlet. * Fix comments. * Update parameterset. * Change startip/endip optional in update cmdlet. * Update session record. * Fix CI error.
1 parent acf07dc commit 54851b4

24 files changed

+2567
-42
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
namespace Microsoft.Azure.Commands.Synapse.Test.ScenarioTests
16+
{
17+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
18+
using ServiceManagement.Common.Models;
19+
using Xunit;
20+
21+
public class FirewallTests : SynapseTestBase
22+
{
23+
public XunitTracingInterceptor _logger;
24+
25+
public FirewallTests(Xunit.Abstractions.ITestOutputHelper output)
26+
{
27+
_logger = new XunitTracingInterceptor(output);
28+
XunitTracingInterceptor.AddToContext(_logger);
29+
}
30+
31+
[Fact]
32+
[Trait(Category.AcceptanceType, Category.CheckIn)]
33+
public void TestSynapseFirewall()
34+
{
35+
string testResourceGroupName = SynapseTestBase.TestResourceGroupName;
36+
if (string.IsNullOrEmpty(testResourceGroupName))
37+
{
38+
testResourceGroupName = nameof(TestResourceGroupName);
39+
}
40+
41+
string testWorkspaceName = SynapseTestBase.TestWorkspaceName;
42+
if (string.IsNullOrEmpty(testWorkspaceName))
43+
{
44+
testWorkspaceName = nameof(TestWorkspaceName);
45+
}
46+
47+
SynapseTestBase.NewInstance.RunPsTest(
48+
_logger,
49+
string.Format(
50+
"Test-SynapseFirewall -resourceGroupName '{0}' -workspaceName '{1}'",
51+
"testResourceGroupName",
52+
"testWorkspaceName"
53+
));
54+
}
55+
}
56+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<#
2+
.SYNOPSIS
3+
Tests Synapse Firewall Lifecycle (Create, Update, Get, List, Delete).
4+
#>
5+
function Test-SynapseFirewall
6+
{
7+
param
8+
(
9+
$resourceGroupName = (Get-ResourceGroupName),
10+
$workspaceName = (Get-SynapseWorkspaceName)
11+
)
12+
13+
try
14+
{
15+
$resourceGroupName = [Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::GetVariable("resourceGroupName", $resourceGroupName)
16+
$workspaceName = [Microsoft.Azure.Test.HttpRecorder.HttpMockServer]::GetVariable("workspaceName", $workspaceName)
17+
$workspace = Get-AzSynapseWorkspace -resourceGroupName $resourceGroupName -Name $workspaceName
18+
$firewallRuleName = "originRuleName"
19+
$StartIpAddress = "0.0.0.0"
20+
$NewStartIpAddress = "10.0.0.0"
21+
$EndIpAddress = "255.255.255.255"
22+
$NewEndIpAddress = "255.0.0.0"
23+
$SucessState = "Succeeded"
24+
25+
# create firewall
26+
$firewallCreated = New-AzSynapseFirewallRule -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $firewallRuleName -StartIpAddress $StartIpAddress -EndIpAddress $EndIpAddress
27+
28+
Assert-AreEqual $StartIpAddress $firewallCreated.StartIpAddress
29+
Assert-AreEqual $EndIpAddress $firewallCreated.EndIpAddress
30+
31+
# Wait for 10 seconds for the create completion
32+
[Microsoft.Rest.ClientRuntime.Azure.TestFramework.TestUtilities]::Wait(10000)
33+
34+
# List firewall
35+
$firewallList = Get-AzSynapseFirewallRule -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName
36+
Assert-NotNull $firewallList
37+
38+
# Get firewall
39+
$firewallGet = Get-AzSynapseFirewallRule -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $firewallRuleName
40+
Assert-AreEqual $SucessState $firewallGet.ProvisioningState
41+
Assert-AreEqual $StartIpAddress $firewallGet.StartIpAddress
42+
Assert-AreEqual $EndIpAddress $firewallGet.EndIpAddress
43+
44+
# Update firewall
45+
$firewallUpdate = Update-AzSynapseFirewallRule -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $firewallRuleName -StartIpAddress $NewStartIpAddress -EndIpAddress $NewEndIpAddress
46+
Assert-AreEqual $NewStartIpAddress $firewallUpdate.StartIpAddress
47+
Assert-AreEqual $NewEndIpAddress $firewallUpdate.EndIpAddress
48+
49+
# Delete firewall
50+
Assert-True {Remove-AzSynapseFirewallRule -ResourceGroupName $resourceGroupName -WorkspaceName $workspaceName -Name $firewallRuleName -PassThru} "Remove firewall rule failed"
51+
}
52+
finally
53+
{
54+
# cleanup the firewallRuleName created by test code.
55+
}
56+
}

src/Synapse/Synapse.Test/ScenarioTests/SparkJobTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public void TestSynapseSparkJob()
4646
_logger,
4747
string.Format(
4848
"Test-SynapseSparkJob -resourceGroupname '{0}' -workspaceName '{1}' -sparkPoolName {2}",
49+
resourceGroupName,
4950
testWorkspaceName,
5051
testSparkPoolName));
5152
}

0 commit comments

Comments
 (0)