Skip to content

Commit 2db74e2

Browse files
authored
Merge pull request #278 from kisantia/preview
Adding basic SQL virtual network rules functionality
2 parents f17c3e1 + 32e5971 commit 2db74e2

33 files changed

+53255
-52
lines changed

src/ResourceManager/Common/Commands.ScenarioTests.ResourceManager.Common/EnvironmentSetupHelper.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public EnvironmentSetupHelper()
6565
TestExecutionHelpers.SetUpSessionAndProfile();
6666
var datastore = new MemoryDataStore();
6767
AzureSession.Instance.DataStore = datastore;
68-
var rmprofile = new AzureRmProfile(Path.Combine(AzureSession.Instance.ARMProfileDirectory, AzureSession.Instance.ARMProfileFile));
68+
var rmprofile = new AzureRmProfile(Path.Combine(AzureSession.Instance.ProfileDirectory, AzureSession.Instance.ProfileFile));
6969
rmprofile.EnvironmentTable.Add("foo", new AzureEnvironment(AzureEnvironment.PublicEnvironments.Values.FirstOrDefault()));
7070
rmprofile.DefaultContext = new AzureContext(new AzureSubscription(), new AzureAccount(), rmprofile.EnvironmentTable["foo"], new AzureTenant());
7171
rmprofile.DefaultContext.Subscription.SetEnvironment("foo");
@@ -135,6 +135,15 @@ public string RMStorageDataPlaneModule
135135
}
136136
}
137137

138+
public string RMNetworkModule
139+
{
140+
get
141+
{
142+
return Path.Combine(this.PackageDirectory,
143+
@"ResourceManager\AzureResourceManager\AzureRM.Network\AzureRM.Network.psd1");
144+
}
145+
}
146+
138147
public string GetRMModulePath(string psd1FileName)
139148
{
140149
string basename = Path.GetFileNameWithoutExtension(psd1FileName);
@@ -256,12 +265,12 @@ private void SetupAzureEnvironmentFromEnvironmentVariables(AzureModule mode)
256265
private void SetAuthenticationFactory(AzureModule mode, TestEnvironment environment)
257266
{
258267
#if !NETSTANDARD
259-
if(environment.AuthorizationContext.Certificate != null)
268+
if (environment.AuthorizationContext.Certificate != null)
260269
{
261270
AzureSession.Instance.AuthenticationFactory = new MockCertificateAuthenticationFactory(environment.UserName,
262271
environment.AuthorizationContext.Certificate);
263272
}
264-
else if(environment.AuthorizationContext.TokenCredentials.ContainsKey(TokenAudience.Management))
273+
else if (environment.AuthorizationContext.TokenCredentials.ContainsKey(TokenAudience.Management))
265274
{
266275
var httpMessage = new HttpRequestMessage();
267276
environment.AuthorizationContext.TokenCredentials[TokenAudience.Management]
@@ -430,4 +439,4 @@ private void SetupPowerShellModules(System.Management.Automation.PowerShell powe
430439
}
431440

432441
}
433-
}
442+
}

src/ResourceManager/Sql/AzureRM.Sql.psd1

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,11 @@ CmdletsToExport = 'Get-AzureRmSqlDatabaseTransparentDataEncryption',
177177
'Get-AzureRmSqlSyncMember', 'Remove-AzureRmSqlSyncMember',
178178
'New-AzureRmSqlSyncAgent', 'Get-AzureRmSqlSyncAgent',
179179
'Remove-AzureRmSqlSyncAgent', 'New-AzureRmSqlSyncAgentKey',
180-
'Get-AzureRmSqlSyncAgentLinkedDatabase'
180+
'Get-AzureRmSqlSyncAgentLinkedDatabase',
181+
'New-AzureRmSqlServerVirtualNetworkRule',
182+
'Set-AzureRmSqlServerVirtualNetworkRule',
183+
'Get-AzureRmSqlServerVirtualNetworkRule',
184+
'Remove-AzureRmSqlServerVirtualNetworkRule'
181185

182186
# Variables to export from this module
183187
# VariablesToExport = @()

src/ResourceManager/Sql/ChangeLog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
- Additional information about change #1
1919
-->
2020
## Current Release
21+
* Adding support for Virtual Network Rules
22+
- Adding Get-AzureRmSqlServerVirtualNetworkRule cmdlet which gets the virtual network rules by a specific rule name or a list of virtual network rules in an Azure Sql server.
23+
- Adding Set-AzureRmSqlServerVirtualNetworkRule cmdlet which changes the virtual network that the rule points to.
24+
- Adding Remove-AzureRmSqlServerVirtualNetworkRule cmdlet which removes a virtual network rule for an Azure Sql server.
25+
- Adding New-AzureRmSqlServerVirtualNetworkRule cmdlet which creates a new virtual network rule for an Azure Sql server.
2126

2227
## Version 3.3.1
2328

src/ResourceManager/Sql/Commands.Sql.Test/Commands.Sql.Test.csproj

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,11 @@
7777
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Authorization.2.0.0\lib\net40\Microsoft.Azure.Management.Authorization.dll</HintPath>
7878
<Private>True</Private>
7979
</Reference>
80+
<Reference Include="Microsoft.Azure.Management.Network">
81+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Network.14.0.0-preview\lib\net452\Microsoft.Azure.Management.Network.dll</HintPath>
82+
</Reference>
8083
<Reference Include="Microsoft.Azure.Management.Sql, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
81-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Sql.1.5.0-preview\lib\net452\Microsoft.Azure.Management.Sql.dll</HintPath>
84+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Sql.1.6.0-preview\lib\net452\Microsoft.Azure.Management.Sql.dll</HintPath>
8285
<Private>True</Private>
8386
</Reference>
8487
<Reference Include="Microsoft.Azure.Management.Storage">
@@ -310,6 +313,7 @@
310313
<Compile Include="ScenarioTests\SqlTestsBase.cs" />
311314
<Compile Include="ScenarioTests\TransparentDataEncryptionCrudTests.cs" />
312315
<Compile Include="ScenarioTests\ServerKeyVaultKeyTests.cs" />
316+
<Compile Include="ScenarioTests\VirtualNetworkRuleTest.cs" />
313317
<Compile Include="ScenarioTests\IndexRecommendationTests.cs" />
314318
<Compile Include="ScenarioTests\ImportExportTests.cs" />
315319
<Compile Include="UnitTests\AzureSqlDatabaseImportExportTests.cs" />
@@ -396,6 +400,9 @@
396400
<None Include="ScenarioTests\ServerKeyVaultKeyTests.ps1">
397401
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
398402
</None>
403+
<None Include="ScenarioTests\VirtualNetworkRuleTest.ps1">
404+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
405+
</None>
399406
<None Include="SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.AdvisorTests\TestGetElasticPoolAdvisor.json">
400407
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
401408
</None>
@@ -942,6 +949,15 @@
942949
<None Include=".\SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.ServerUpgradeTests\TestServerUpgradeWithUpgradeHint.json">
943950
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
944951
</None>
952+
<None Include=".\SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.VirtualNetworkRuleTest\TestVirtualNetworkRuleCreateAndUpdate.json">
953+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
954+
</None>
955+
<None Include=".\SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.VirtualNetworkRuleTest\TestVirtualNetworkRuleGet.json">
956+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
957+
</None>
958+
<None Include=".\SessionRecords\Microsoft.Azure.Commands.Sql.Test.ScenarioTests.VirtualNetworkRuleTest\TestVirtualNetworkRuleRemove.json">
959+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
960+
</None>
945961
</ItemGroup>
946962
<ItemGroup>
947963
<EmbeddedResource Include="Properties\Resources.resx">

src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/Common.ps1

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,15 @@ function Get-FailoverGroupName
337337
return getAssetName
338338
}
339339

340+
<#
341+
.SYNOPSIS
342+
Gets valid virtual network rule name
343+
#>
344+
function Get-VirtualNetworkRuleName
345+
{
346+
return getAssetName
347+
}
348+
340349
<#
341350
.SYNOPSIS
342351
Gets the location for a provider, if not found return East US
@@ -388,18 +397,6 @@ function Remove-ResourceGroupForTest ($rg)
388397
Remove-AzureRmResourceGroup -Name $rg.ResourceGroupName -Force
389398
}
390399

391-
<#
392-
.SYNOPSIS
393-
Gets the server credential
394-
#>
395-
function Create-ServerForTest ($resourceGroup, $location = "westcentralus")
396-
{
397-
$serverLogin = "testusername"
398-
$serverPassword = "t357ingP@s5w0rd!"
399-
$credentials = new-object System.Management.Automation.PSCredential($serverLogin, ($serverPassword | ConvertTo-SecureString -asPlainText -Force))
400-
return $credentials
401-
}
402-
403400
<#
404401
.SYNOPSIS
405402
Gets the server credential

src/ResourceManager/Sql/Commands.Sql.Test/ScenarioTests/SqlTestsBase.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using Microsoft.Azure.Commands.Common.Authentication;
1616
using Microsoft.Azure.Commands.ScenarioTest.Mocks;
1717
using Microsoft.Azure.Management.Authorization;
18+
using Microsoft.Azure.Management.Network;
1819
using Microsoft.Azure.Management.Resources;
1920
using Microsoft.Azure.Test;
2021
using Microsoft.Azure.Test.HttpRecorder;
@@ -62,7 +63,7 @@ protected virtual void SetupManagementClients(RestTestFramework.MockContext cont
6263
var newResourcesClient = GetResourcesClient(context);
6364
helper.SetupSomeOfManagementClients(sqlClient, sqlLegacyClient, resourcesClient, newResourcesClient);
6465
}
65-
66+
6667
protected void RunPowerShellTest(params string[] scripts)
6768
{
6869
TestExecutionHelpers.SetUpSessionAndProfile();
@@ -95,7 +96,8 @@ protected void RunPowerShellTest(params string[] scripts)
9596
helper.GetRMModulePath(@"AzureRM.Insights.psd1"),
9697
helper.GetRMModulePath(@"AzureRM.Sql.psd1"),
9798
"AzureRM.Storage.ps1",
98-
"AzureRM.Resources.ps1");
99+
"AzureRM.Resources.ps1",
100+
helper.RMNetworkModule);
99101
helper.RunPowerShellTest(scripts);
100102
}
101103
}
@@ -114,7 +116,7 @@ protected Management.Sql.SqlManagementClient GetSqlClient(RestTestFramework.Mock
114116

115117
protected Management.Sql.LegacySdk.SqlManagementClient GetLegacySqlClient()
116118
{
117-
Management.Sql.LegacySdk.SqlManagementClient client =
119+
Management.Sql.LegacySdk.SqlManagementClient client =
118120
TestBase.GetServiceClient<Management.Sql.LegacySdk.SqlManagementClient>(
119121
new CSMTestEnvironmentFactory());
120122
if (HttpMockServer.Mode == HttpRecorderMode.Playback)
@@ -149,7 +151,7 @@ protected ResourceManagementClient GetResourcesClient()
149151

150152
protected Management.Internal.Resources.ResourceManagementClient GetResourcesClient(RestTestFramework.MockContext context)
151153
{
152-
Management.Internal.Resources.ResourceManagementClient client =
154+
Management.Internal.Resources.ResourceManagementClient client =
153155
context.GetServiceClient<Management.Internal.Resources.ResourceManagementClient>(RestTestFramework.TestEnvironmentFactory.GetTestEnvironment());
154156
if (HttpMockServer.Mode == HttpRecorderMode.Playback)
155157
{
@@ -169,6 +171,18 @@ protected AuthorizationManagementClient GetAuthorizationManagementClient()
169171
return client;
170172
}
171173

174+
protected Management.Network.NetworkManagementClient GetNetworkClient(RestTestFramework.MockContext context)
175+
{
176+
Management.Network.NetworkManagementClient client =
177+
context.GetServiceClient<Management.Network.NetworkManagementClient>(
178+
RestTestFramework.TestEnvironmentFactory.GetTestEnvironment());
179+
if (HttpMockServer.Mode == HttpRecorderMode.Playback)
180+
{
181+
client.LongRunningOperationRetryTimeout = 0;
182+
}
183+
return client;
184+
}
185+
172186
protected GraphRbacManagementClient GetGraphClient(RestTestFramework.MockContext context)
173187
{
174188
var environment = RestTestFramework.TestEnvironmentFactory.GetTestEnvironment();
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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.ScenarioTest.SqlTests;
16+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17+
using Xunit;
18+
using Xunit.Abstractions;
19+
using RestTestFramework = Microsoft.Rest.ClientRuntime.Azure.TestFramework;
20+
21+
namespace Microsoft.Azure.Commands.Sql.Test.ScenarioTests
22+
{
23+
public class VirtualNetworkRuleTest : SqlTestsBase
24+
{
25+
protected override void SetupManagementClients(RestTestFramework.MockContext context)
26+
{
27+
var sqlClient = GetSqlClient(context);
28+
var sqlLegacyClient = GetLegacySqlClient();
29+
var resourcesClient = GetResourcesClient();
30+
var newResourcesClient = GetResourcesClient(context);
31+
var networkClient = GetNetworkClient(context);
32+
helper.SetupSomeOfManagementClients(sqlClient, sqlLegacyClient, resourcesClient, newResourcesClient, networkClient);
33+
}
34+
public VirtualNetworkRuleTest(ITestOutputHelper output) : base(output)
35+
{
36+
}
37+
38+
[Fact]
39+
[Trait(Category.AcceptanceType, Category.CheckIn)]
40+
public void TestVirtualNetworkRuleCreateAndUpdate()
41+
{
42+
RunPowerShellTest("Test-CreateAndUpdateVirtualNetworkRule");
43+
}
44+
45+
[Fact]
46+
[Trait(Category.AcceptanceType, Category.CheckIn)]
47+
public void TestVirtualNetworkRuleGet()
48+
{
49+
RunPowerShellTest("Test-GetVirtualNetworkRule");
50+
}
51+
52+
[Fact]
53+
[Trait(Category.AcceptanceType, Category.CheckIn)]
54+
public void TestVirtualNetworkRuleRemove()
55+
{
56+
RunPowerShellTest("Test-RemoveVirtualNetworkRule");
57+
}
58+
}
59+
}

0 commit comments

Comments
 (0)