-
Notifications
You must be signed in to change notification settings - Fork 4k
Adding VirtualCluster related cmdlets and corresponding tests... #8932
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ee44471
Adding VirtualCluster related cmdlets and corresponding tests and hel…
0dc8943
Updating change log.
1f3b0d4
Addressing comments.
fd18400
Merge pull request #1 from Azure/master
milostod d7df235
Modifying Az.Sql.psd1 after the merge from orig.
d592aa8
Modifying tests not to require any prepared resources. Addressing com…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/Sql/Sql.Test/ScenarioTests/VirtualClusterCrudScenarioTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// Copyright Microsoft Corporation | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using Microsoft.Azure.Commands.ScenarioTest.SqlTests; | ||
using Microsoft.Azure.ServiceManagement.Common.Models; | ||
using Microsoft.WindowsAzure.Commands.ScenarioTest; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
using RestTestFramework = Microsoft.Rest.ClientRuntime.Azure.TestFramework; | ||
|
||
namespace Microsoft.Azure.Commands.Sql.Test.ScenarioTests | ||
{ | ||
public class VirtualClusterCrudScenarioTests : SqlTestsBase | ||
{ | ||
protected override void SetupManagementClients(RestTestFramework.MockContext context) | ||
{ | ||
var sqlClient = GetSqlClient(context); | ||
var newResourcesClient = GetResourcesClient(context); | ||
var networkClient = GetNetworkClient(context); | ||
Helper.SetupSomeOfManagementClients(sqlClient, newResourcesClient, networkClient); | ||
} | ||
|
||
public VirtualClusterCrudScenarioTests(ITestOutputHelper output) : base(output) | ||
{ | ||
} | ||
|
||
[Fact] | ||
[Trait(Category.AcceptanceType, Category.CheckIn)] | ||
public void TestGetVirtualCluster() | ||
{ | ||
RunPowerShellTest("Test-GetVirtualCluster"); | ||
} | ||
|
||
[Fact] | ||
[Trait(Category.AcceptanceType, Category.CheckIn)] | ||
public void TestRemoveVirtualCluster() | ||
{ | ||
RunPowerShellTest("Test-RemoveVirtualCluster"); | ||
} | ||
} | ||
} |
103 changes: 103 additions & 0 deletions
103
src/Sql/Sql.Test/ScenarioTests/VirtualClusterCrudScenarioTests.ps1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# ---------------------------------------------------------------------------------- | ||
# | ||
# Copyright Microsoft Corporation | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# ---------------------------------------------------------------------------------- | ||
|
||
<# | ||
.SYNOPSIS | ||
Tests Getting a VirtualCluster | ||
.DESCRIPTION | ||
SmokeTest | ||
#> | ||
function Test-GetVirtualCluster | ||
{ | ||
# Setup | ||
$location = Get-ProviderLocation "Microsoft.Sql/virtualclusters" | ||
$rg = Create-ResourceGroupForTest $location | ||
|
||
$rgName = $rg.ResourceGroupName | ||
$vnetName = "cl_initial" | ||
$subnetName = "Cool" | ||
|
||
# Setup VNET | ||
$virtualNetwork = CreateAndGetVirtualNetworkForManagedInstance $vnetName $subnetName $location $rgName | ||
$subnetId = $virtualNetwork.Subnets.where({ $_.Name -eq $subnetName })[0].Id | ||
|
||
$managedInstance = Create-ManagedInstanceForTest $rg $subnetId | ||
|
||
try | ||
{ | ||
# Test using all parameters | ||
$virtualClusterList = Get-AzSqlVirtualCluster | ||
$virtualCluster = $virtualClusterList.where({$_.SubnetId -eq $subnetId}) | ||
Assert-AreEqual $rgName $virtualCluster.ResourceGroupName | ||
$virtualClusterName = $virtualCluster.VirtualClusterName | ||
|
||
$virtualClusterList = Get-AzSqlVirtualCluster -ResourceGroupName $rgName | ||
$virtualCluster = $virtualClusterList.where({$_.SubnetId -eq $subnetId}) | ||
Assert-AreEqual $rgName $virtualCluster.ResourceGroupName | ||
Assert-AreEqual $virtualClusterName $virtualCluster.VirtualClusterName | ||
|
||
$virtualCluster = Get-AzSqlVirtualCluster -ResourceGroupName $rgName -Name $virtualClusterName | ||
Assert-AreEqual $rgName $virtualCluster.ResourceGroupName | ||
Assert-AreEqual $virtualClusterName $virtualCluster.VirtualClusterName | ||
Assert-AreEqual $subnetId $virtualCluster.SubnetId | ||
} | ||
finally | ||
{ | ||
Remove-ResourceGroupForTest $rg | ||
} | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Tests Removing a VirtualCluster | ||
.DESCRIPTION | ||
SmokeTest | ||
#> | ||
function Test-RemoveVirtualCluster | ||
{ | ||
# Setup | ||
$location = Get-ProviderLocation "Microsoft.Sql/virtualclusters" | ||
$rg = Create-ResourceGroupForTest $location | ||
|
||
$rgName = $rg.ResourceGroupName | ||
$vnetName = "cl_initial" | ||
$subnetName = "Cool" | ||
|
||
# Setup VNET | ||
$virtualNetwork = CreateAndGetVirtualNetworkForManagedInstance $vnetName $subnetName $location $rgName | ||
$subnetId = $virtualNetwork.Subnets.where({ $_.Name -eq $subnetName })[0].Id | ||
|
||
$managedInstance = Create-ManagedInstanceForTest $rg $subnetId | ||
|
||
try | ||
{ | ||
$virtualClusterList = Get-AzSqlVirtualCluster -ResourceGroupName $rgName | ||
$virtualCluster = $virtualClusterList.where({$_.SubnetId -eq $subnetId}) | ||
$virtualClusterName = $virtualCluster.VirtualClusterName | ||
|
||
# Remove the managed instance first | ||
$managedInstance | Remove-AzSqlInstance -Force | ||
|
||
# Remove virtual cluster | ||
$virtualCluster | Remove-AzSqlVirtualCluster | ||
|
||
$all = Get-AzSqlVirtualCluster -ResourceGroupName $rgName | ||
$virtualCluster = $all.where({$_.VirtualClusterName -eq $virtualClusterName}) | ||
Assert-AreEqual $virtualCluster.Count 0 | ||
} | ||
finally | ||
{ | ||
Remove-ResourceGroupForTest $rg | ||
} | ||
} |
25,864 changes: 25,864 additions & 0 deletions
25,864
...ommands.Sql.Test.ScenarioTests.VirtualClusterCrudScenarioTests/TestGetVirtualCluster.json
Large diffs are not rendered by default.
Oops, something went wrong.
29,556 changes: 29,556 additions & 0 deletions
29,556
...ands.Sql.Test.ScenarioTests.VirtualClusterCrudScenarioTests/TestRemoveVirtualCluster.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
src/Sql/Sql/VirtualCluster/Cmdlet/GetAzureSqlVirtualCluster.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// Copyright Microsoft Corporation | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// ---------------------------------------------------------------------------------- | ||
|
||
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters; | ||
using Microsoft.Azure.Commands.Sql.VirtualCluster.Model; | ||
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models; | ||
using System.Collections.Generic; | ||
using System.Management.Automation; | ||
|
||
namespace Microsoft.Azure.Commands.Sql.VirtualCluster.Cmdlet | ||
{ | ||
[Cmdlet(VerbsCommon.Get, ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "SqlVirtualCluster", DefaultParameterSetName = GetByResourceGroupParameterSet)] | ||
[OutputType(typeof(AzureSqlVirtualClusterModel))] | ||
public class GetAzureSqlVirtualCluster : VirtualClusterCmdletBase | ||
{ | ||
protected const string GetByNameAndResourceGroupParameterSet = | ||
"GetVirtualClusterByNameAndResourceGroup"; | ||
|
||
protected const string GetByResourceGroupParameterSet = | ||
"GetVirtualClusterByResourceGroup"; | ||
|
||
protected const string GetByResourceIdParameterSet = | ||
"GetVirtualClusterByResourceId"; | ||
|
||
/// <summary> | ||
/// Gets or sets the name of the virtual cluster. | ||
/// </summary> | ||
[Parameter(ParameterSetName = GetByNameAndResourceGroupParameterSet, | ||
Mandatory = true, | ||
Position = 0, | ||
HelpMessage = "The name of the virtual cluster.")] | ||
[Alias("VirtualClusterName")] | ||
[ResourceNameCompleter("Microsoft.Sql/virtualClusters", "ResourceGroupName")] | ||
[ValidateNotNullOrEmpty] | ||
public string Name { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the name of the resource group. | ||
/// </summary> | ||
[Parameter(ParameterSetName = GetByNameAndResourceGroupParameterSet, | ||
Mandatory = true, | ||
Position = 1, | ||
HelpMessage = "The name of the resource group.")] | ||
[Parameter(ParameterSetName = GetByResourceGroupParameterSet, | ||
Mandatory = false, | ||
HelpMessage = "The name of the resource group.")] | ||
[ResourceGroupCompleter] | ||
[ValidateNotNullOrEmpty] | ||
public override string ResourceGroupName { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or sets the resource id of the virtual cluster | ||
/// </summary> | ||
[Parameter(ParameterSetName = GetByResourceIdParameterSet, | ||
Mandatory = true, | ||
Position = 0, | ||
ValueFromPipelineByPropertyName = true, | ||
HelpMessage = "The resource id of instance object to get")] | ||
[ValidateNotNullOrEmpty] | ||
public string ResourceId { get; set; } | ||
|
||
/// <summary> | ||
/// Gets virtual cluster from the service. | ||
/// </summary> | ||
/// <returns>A single virtual cluster</returns> | ||
protected override IEnumerable<AzureSqlVirtualClusterModel> GetEntity() | ||
{ | ||
ICollection<AzureSqlVirtualClusterModel> results = null; | ||
|
||
if (string.Equals(this.ParameterSetName, GetByResourceIdParameterSet, System.StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
var resourceInfo = new ResourceIdentifier(ResourceId); | ||
|
||
ResourceGroupName = resourceInfo.ResourceGroupName; | ||
Name = resourceInfo.ResourceName; | ||
|
||
results = new List<AzureSqlVirtualClusterModel>(); | ||
results.Add(ModelAdapter.GetVirtualCluster(this.ResourceGroupName, this.Name)); | ||
} | ||
else if (string.Equals(this.ParameterSetName, GetByNameAndResourceGroupParameterSet, System.StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
results = new List<AzureSqlVirtualClusterModel>(); | ||
results.Add(ModelAdapter.GetVirtualCluster(this.ResourceGroupName, this.Name)); | ||
} | ||
else if (string.Equals(this.ParameterSetName, GetByResourceGroupParameterSet, System.StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
if (MyInvocation.BoundParameters.ContainsKey("ResourceGroupName")) | ||
{ | ||
results = ModelAdapter.ListVirtualClustersByResourceGroup(this.ResourceGroupName); | ||
} | ||
else | ||
{ | ||
results = ModelAdapter.ListVirtualClusters(); | ||
} | ||
} | ||
|
||
return results; | ||
} | ||
|
||
/// <summary> | ||
/// No changes, thus nothing to persist. | ||
/// </summary> | ||
/// <param name="entity">The entity retrieved</param> | ||
/// <returns>The unchanged entity</returns> | ||
protected override IEnumerable<AzureSqlVirtualClusterModel> PersistChanges(IEnumerable<AzureSqlVirtualClusterModel> entity) | ||
{ | ||
return entity; | ||
} | ||
|
||
/// <summary> | ||
/// No user input to apply to model. | ||
/// </summary> | ||
/// <param name="model">The model to modify</param> | ||
/// <returns>The input model</returns> | ||
protected override IEnumerable<AzureSqlVirtualClusterModel> ApplyUserInputToModel(IEnumerable<AzureSqlVirtualClusterModel> model) | ||
{ | ||
return model; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: New NuGet package has been published from the Azure SDK for .NET repository