-
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
Changes from 5 commits
ee44471
0dc8943
1f3b0d4
fd18400
d7df235
d592aa8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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"); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# ---------------------------------------------------------------------------------- | ||
# | ||
# 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 = "eastus" | ||
$rg = Create-ResourceGroupForTest $location | ||
|
||
$rgName = "RG_MIPlayground" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please have all resource name be randomly generated using getAssetName: https://github.com/Azure/azure-powershell/blob/master/tools/ScenarioTest.ResourceManager/Common.ps1#L371 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. rgName is created in Create-ResourceGroupForTest using getAssetName. I kept hardcoded names for vnet and subnet as it seems that calling getAssetName multiple times in short period produces "queue is empty" error. I see multiple tests are keeping hardcoded values for vnet and subnet, probably for the same reason. |
||
$vnetName = "VNET_MIPlayground" | ||
$subnetName = "VCReservedSubnet" | ||
|
||
# Setup VNET | ||
$virtualNetwork = CreateAndGetVirtualNetworkForManagedInstance $vnetName $subnetName $location $rgName | ||
$subnetId = $virtualNetwork.Subnets.where({ $_.Name -eq $subnetName }).Id | ||
|
||
$managedInstance = Create-ManagedInstanceForTest $rg $subnetId | ||
|
||
try | ||
{ | ||
# Test using all parameters | ||
$virtualClusterList = Get-AzSqlVirtualCluster | ||
$virtualCluster = $virtualClusterList.where({$_.SubnetId -eq $subnetId}) | ||
Assert-AreEqual $location $virtualCluster.Location | ||
Assert-AreEqual $rgName $virtualCluster.ResourceGroupName | ||
$virtualClusterName = $virtualCluster.VirtualClusterName | ||
|
||
$virtualClusterList = Get-AzSqlVirtualCluster -ResourceGroupName $rgName | ||
$virtualCluster = $virtualClusterList.where({$_.SubnetId -eq $subnetId}) | ||
Assert-AreEqual $location $virtualCluster.Location | ||
Assert-AreEqual $rgName $virtualCluster.ResourceGroupName | ||
Assert-AreEqual $virtualClusterName $virtualCluster.VirtualClusterName | ||
|
||
$virtualCluster = Get-AzSqlVirtualCluster -ResourceGroupName $rgName -Name $virtualClusterName | ||
Assert-AreEqual $location $virtualCluster.Location | ||
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 = "eastus" | ||
$rg = Create-ResourceGroupForTest $location | ||
|
||
$rgName = "RG_MIPlayground" | ||
$vnetName = "VNET_MIPlayground" | ||
$subnetName = "VCReservedSubnet" | ||
|
||
# Setup VNET | ||
$virtualNetwork = CreateAndGetVirtualNetworkForManagedInstance $vnetName $subnetName $location $rgName | ||
$subnetId = $virtualNetwork.Subnets.where({ $_.Name -eq $subnetName }).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 | ||
} | ||
} |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.Azure.Management.Sql" Version="1.28.0-preview" /> | ||
<PackageReference Include="Microsoft.Azure.Management.Sql" Version="1.29.0-preview" /> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
<PackageReference Include="Microsoft.Azure.Management.EventHub" Version="2.3.0" /> | ||
<PackageReference Include="Microsoft.Azure.Management.Network" Version="19.10.0-preview" /> | ||
<PackageReference Include="Microsoft.Azure.Graph.RBAC" Version="3.2.0-preview" /> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -217,7 +217,8 @@ CmdletsToExport = 'Get-AzSqlDatabaseTransparentDataEncryption', | |
'Remove-AzSqlDatabaseSensitivityClassification', | ||
'Remove-AzSqlInstanceDatabaseSensitivityClassification', | ||
'Get-AzSqlDatabaseSensitivityRecommendation', | ||
'Get-AzSqlInstanceDatabaseSensitivityRecommendation' | ||
'Get-AzSqlInstanceDatabaseSensitivityRecommendation', | ||
'Get-AzSqlVirtualCluster', 'Remove-AzSqlVirtualCluster' | ||
|
||
# Variables to export from this module | ||
# VariablesToExport = @() | ||
|
@@ -271,7 +272,7 @@ PrivateData = @{ | |
# IconUri = '' | ||
|
||
# ReleaseNotes of this module | ||
ReleaseNotes = '* Support Database Data Classification.' | ||
ReleaseNotes = '* Add Virtual Cluster cmdlets' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please revert this change, we will update during versioning. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, thanks. |
||
|
||
# Prerelease string of this module | ||
# Prerelease = '' | ||
|
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; | ||
} | ||
} | ||
} |
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.
Please get location using Get-Location to ensure this will work on all clouds: https://github.com/Azure/azure-powershell/blob/master/tools/ScenarioTest.ResourceManager/Common.ps1#L583
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.
Hi @maddieclayton , I used some pre-made resources to speed up the test because provisioning of a new virtual cluster takes several hours. I've made the changes to create everything in the test, however, each test takes almost 4 hours to execute. If this is not a problem, I'll commit the change. Please let me know.
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.
@milostod It is fine to take 4 hours to record this test - because the SDK calls will be instantaneous in playback mode, it will not affect our CI, and having a test take 4 hours to record is much better than having to do manual set up that takes the same amount of time.
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.
@maddieclayton I agree. I've made the changes, tests are now creating everything from scratch, including ResourceGroup, VNet and Subnet. Total running time was 7hrs:30min for two tests. I used Get-ProviderLocation since it uses Get-AzResourceProvider instead of Get-AzureRmResourceProvider command for which I had some trouble running locally.