Skip to content

Commit aa06da2

Browse files
authored
Merge pull request #1 from aygoya/1-sev-resType-closeTkt
new severity, update ticket and other model updates
2 parents bbaa2f5 + b18267d commit aa06da2

File tree

14 files changed

+671
-523
lines changed

14 files changed

+671
-523
lines changed

src/Resources/ResourceManager/Implementation/ResourceGroups/GetAzureResourceGroupCmdlet.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,7 @@ public class GetAzureResourceGroupCmdlet : ResourceManagerCmdletBase
6666
public override void ExecuteCmdlet()
6767
{
6868
Name = Name ?? ResourceIdentifier.FromResourceGroupIdentifier(this.Id).ResourceGroupName;
69-
70-
this.WriteObject(
71-
ResourceManagerSdkClient.FilterResourceGroups(name: this.Name, tag: this.Tag, detailed: false, location: this.Location),
72-
true);
69+
this.WriteObject(ResourceManagerSdkClient.FilterResourceGroups(name: this.Name, tag: this.Tag, detailed: false, location: this.Location), true);
7370
}
7471

7572
}

src/Resources/ResourceManager/SdkClient/ResourceManagerSdkClient.cs

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
using Microsoft.Azure.Management.ResourceManager;
3636
using Microsoft.Azure.Management.ResourceManager.Models;
3737
using Microsoft.Rest.Azure;
38+
using Microsoft.Rest.Azure.OData;
3839
using Microsoft.WindowsAzure.Commands.Common;
3940
using Microsoft.WindowsAzure.Commands.Utilities.Common;
4041
using Newtonsoft.Json;
@@ -905,11 +906,26 @@ public virtual List<PSResourceGroup> FilterResourceGroups(string name, Hashtable
905906
{
906907
List<PSResourceGroup> result = new List<PSResourceGroup>();
907908

909+
ODataQuery<ResourceGroupFilter> resourceGroupFilter = null;
910+
911+
if (tag != null && tag.Count >= 1)
912+
{
913+
PSTagValuePair tagValuePair = TagsConversionHelper.Create(tag);
914+
if (tagValuePair == null || tag.Count > 1)
915+
{
916+
throw new ArgumentException(ProjectResources.InvalidTagFormat);
917+
}
918+
919+
resourceGroupFilter = string.IsNullOrEmpty(tagValuePair.Value)
920+
? new ODataQuery<ResourceGroupFilter>(rgFilter => rgFilter.TagName == tagValuePair.Name)
921+
: new ODataQuery<ResourceGroupFilter>(rgFilter => rgFilter.TagName == tagValuePair.Name && rgFilter.TagValue == tagValuePair.Value);
922+
}
923+
908924
if (string.IsNullOrEmpty(name) || WildcardPattern.ContainsWildcardCharacters(name))
909925
{
910926
List<ResourceGroup> resourceGroups = new List<ResourceGroup>();
911927

912-
var listResult = ResourceManagementClient.ResourceGroups.List(null);
928+
var listResult = ResourceManagementClient.ResourceGroups.List(odataQuery: resourceGroupFilter);
913929
resourceGroups.AddRange(listResult);
914930

915931
while (!string.IsNullOrEmpty(listResult.NextPageLink))
@@ -928,32 +944,6 @@ public virtual List<PSResourceGroup> FilterResourceGroups(string name, Hashtable
928944
? resourceGroups.Where(resourceGroup => resourceGroup.Location.EqualsAsLocation(location)).ToList()
929945
: resourceGroups;
930946

931-
// TODO: Replace with server side filtering when available
932-
if (tag != null && tag.Count >= 1)
933-
{
934-
PSTagValuePair tagValuePair = TagsConversionHelper.Create(tag);
935-
if (tagValuePair == null)
936-
{
937-
throw new ArgumentException(ProjectResources.InvalidTagFormat);
938-
}
939-
if (string.IsNullOrEmpty(tagValuePair.Value))
940-
{
941-
resourceGroups =
942-
resourceGroups.Where(rg => rg.Tags != null
943-
&& rg.Tags.Keys.Contains(tagValuePair.Name,
944-
StringComparer.OrdinalIgnoreCase))
945-
.Select(rg => rg).ToList();
946-
}
947-
else
948-
{
949-
resourceGroups =
950-
resourceGroups.Where(rg => rg.Tags != null && rg.Tags.Keys.Contains(tagValuePair.Name,
951-
StringComparer.OrdinalIgnoreCase))
952-
.Where(rg => rg.Tags.Values.Contains(tagValuePair.Value,
953-
StringComparer.OrdinalIgnoreCase))
954-
.Select(rg => rg).ToList();
955-
}
956-
}
957947
result.AddRange(resourceGroups.Select(rg => rg.ToPSResourceGroup()));
958948
}
959949
else

src/Resources/Resources.Test/Models.ResourceGroups/ResourceClientTests.cs

Lines changed: 0 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
using System.IO;
2020
using System.Linq;
2121
using System.Net;
22-
using System.Runtime.Serialization.Formatters;
2322
using System.Text.RegularExpressions;
2423
using System.Threading;
2524
using System.Threading.Tasks;
@@ -1153,108 +1152,6 @@ public void GetsAllResourceGroupsWithDetails()
11531152
Assert.Equal(resourceGroup4.Name, actual[3].ResourceGroupName);
11541153
}
11551154

1156-
[Fact]
1157-
[Trait(Category.AcceptanceType, Category.CheckIn)]
1158-
public void GetsResourceGroupsFilteredByTags()
1159-
{
1160-
Dictionary<string, string> tag1 = new Dictionary<string, string> { { "tag1", "val1" }, { "tag2", "val2" } };
1161-
Dictionary<string, string> tag2 = new Dictionary<string, string> { { "tag1", "valx" } };
1162-
Dictionary<string, string> tag3 = new Dictionary<string, string> { { "tag2", "" } };
1163-
1164-
ResourceGroup resourceGroup1 = new ResourceGroup(location: resourceGroupLocation, name: resourceGroupName + 1, tags: tag1);
1165-
ResourceGroup resourceGroup2 = new ResourceGroup(location: resourceGroupLocation, name: resourceGroupName + 2, tags: tag2);
1166-
ResourceGroup resourceGroup3 = new ResourceGroup(location: resourceGroupLocation, name: resourceGroupName + 3, tags: tag3);
1167-
ResourceGroup resourceGroup4 = new ResourceGroup(location: resourceGroupLocation, name: resourceGroupName + 4);
1168-
var listResult = new List<ResourceGroup>() { resourceGroup1, resourceGroup2, resourceGroup3, resourceGroup4 };
1169-
var pagableResult = new Page<ResourceGroup>();
1170-
pagableResult.SetItemValue(listResult);
1171-
resourceGroupMock.Setup(f => f.ListWithHttpMessagesAsync(null, null, new CancellationToken()))
1172-
.Returns(Task.Factory.StartNew(() =>
1173-
new AzureOperationResponse<IPage<ResourceGroup>>()
1174-
{
1175-
Body = pagableResult
1176-
}));
1177-
SetupListForResourceGroupAsync(resourceGroup1.Name, new List<GenericResource>() { CreateGenericResource(null, null, "resource") });
1178-
SetupListForResourceGroupAsync(resourceGroup2.Name, new List<GenericResource>() { CreateGenericResource(null, null, "resource") });
1179-
SetupListForResourceGroupAsync(resourceGroup3.Name, new List<GenericResource>() { CreateGenericResource(null, null, "resource") });
1180-
SetupListForResourceGroupAsync(resourceGroup4.Name, new List<GenericResource>() { CreateGenericResource(null, null, "resource") });
1181-
1182-
List<PSResourceGroup> groups1 = resourcesClient.FilterResourceGroups(null,
1183-
new Hashtable(new Dictionary<string, string> { { "tag1", "val1" } }), false);
1184-
1185-
Assert.Single(groups1);
1186-
Assert.Equal(resourceGroup1.Name, groups1[0].ResourceGroupName);
1187-
1188-
List<PSResourceGroup> groups2 = resourcesClient.FilterResourceGroups(null,
1189-
new Hashtable(new Dictionary<string, string> { { "tag2", "" } }), false);
1190-
1191-
Assert.Equal(2, groups2.Count);
1192-
Assert.Equal(resourceGroup1.Name, groups2[0].ResourceGroupName);
1193-
Assert.Equal(resourceGroup3.Name, groups2[1].ResourceGroupName);
1194-
1195-
List<PSResourceGroup> groups3 = resourcesClient.FilterResourceGroups(null,
1196-
new Hashtable(new Dictionary<string, string> { { "Name", "tag3" } }), false);
1197-
1198-
Assert.Empty(groups3);
1199-
1200-
List<PSResourceGroup> groups4 = resourcesClient.FilterResourceGroups(null,
1201-
new Hashtable(new Dictionary<string, string> { { "TAG1", "val1" } }), false);
1202-
1203-
Assert.Single(groups4);
1204-
Assert.Equal(resourceGroup1.Name, groups4[0].ResourceGroupName);
1205-
}
1206-
1207-
[Fact]
1208-
[Trait(Category.AcceptanceType, Category.CheckIn)]
1209-
public void GetsResourceGroupsFilteredByTagsWithDetails()
1210-
{
1211-
Dictionary<string, string> tag1 = new Dictionary<string, string> { { "tag1", "val1" }, { "tag2", "val2" } };
1212-
Dictionary<string, string> tag2 = new Dictionary<string, string> { { "tag1", "valx" } };
1213-
Dictionary<string, string> tag3 = new Dictionary<string, string> { { "tag2", "" } };
1214-
1215-
ResourceGroup resourceGroup1 = new ResourceGroup(location: resourceGroupLocation, name: resourceGroupName + 1, tags: tag1);
1216-
ResourceGroup resourceGroup2 = new ResourceGroup(location: resourceGroupLocation, name: resourceGroupName + 2, tags: tag2);
1217-
ResourceGroup resourceGroup3 = new ResourceGroup(location: resourceGroupLocation, name: resourceGroupName + 3, tags: tag3);
1218-
ResourceGroup resourceGroup4 = new ResourceGroup(location: resourceGroupLocation, name: resourceGroupName + 4);
1219-
var listResult = new List<ResourceGroup>() { resourceGroup1, resourceGroup2, resourceGroup3, resourceGroup4 };
1220-
var pagableResult = new Page<ResourceGroup>();
1221-
pagableResult.SetItemValue(listResult);
1222-
resourceGroupMock.Setup(f => f.ListWithHttpMessagesAsync(null, null, new CancellationToken()))
1223-
.Returns(Task.Factory.StartNew(() =>
1224-
new AzureOperationResponse<IPage<ResourceGroup>>()
1225-
{
1226-
Body = pagableResult
1227-
}));
1228-
SetupListForResourceGroupAsync(resourceGroup1.Name, new List<GenericResource>() { CreateGenericResource(null, null, "resource") });
1229-
SetupListForResourceGroupAsync(resourceGroup2.Name, new List<GenericResource>() { CreateGenericResource(null, null, "resource") });
1230-
SetupListForResourceGroupAsync(resourceGroup3.Name, new List<GenericResource>() { CreateGenericResource(null, null, "resource") });
1231-
SetupListForResourceGroupAsync(resourceGroup4.Name, new List<GenericResource>() { CreateGenericResource(null, null, "resource") });
1232-
1233-
List<PSResourceGroup> groups1 = resourcesClient.FilterResourceGroups(null,
1234-
new Hashtable(new Dictionary<string, string> { { "tag1", "val1" } }), true);
1235-
1236-
Assert.Single(groups1);
1237-
Assert.Equal(resourceGroup1.Name, groups1[0].ResourceGroupName);
1238-
1239-
List<PSResourceGroup> groups2 = resourcesClient.FilterResourceGroups(null,
1240-
new Hashtable(new Dictionary<string, string> { { "tag2", "" } }), true);
1241-
1242-
Assert.Equal(2, groups2.Count);
1243-
Assert.Equal(resourceGroup1.Name, groups2[0].ResourceGroupName);
1244-
Assert.Equal(resourceGroup3.Name, groups2[1].ResourceGroupName);
1245-
1246-
List<PSResourceGroup> groups3 = resourcesClient.FilterResourceGroups(null,
1247-
new Hashtable(new Dictionary<string, string> { { "tag3", "" } }), true);
1248-
1249-
Assert.Empty(groups3);
1250-
1251-
List<PSResourceGroup> groups4 = resourcesClient.FilterResourceGroups(null,
1252-
new Hashtable(new Dictionary<string, string> { { "TAG1", "val1" }}), true);
1253-
1254-
Assert.Single(groups4);
1255-
Assert.Equal(resourceGroup1.Name, groups4[0].ResourceGroupName);
1256-
}
1257-
12581155
[Fact]
12591156
[Trait(Category.AcceptanceType, Category.CheckIn)]
12601157
public void DeletesResourcesGroup()

src/Resources/Resources.Test/ScenarioTests/ResourceGroupTests.ps1

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ function Test-FindResourceGroup
279279
{
280280
# Test
281281
$actual = New-AzResourceGroup -Name $rgname -Location $location -Tag @{ testtag = "testval" }
282-
$actual2 = New-AzResourceGroup -Name $rgname2 -Location $location -Tag @{ testtag = "testval2" }
282+
$actual2 = New-AzResourceGroup -Name $rgname2 -Location $location -Tag @{ testtag2 = "testval2"; testtag = "test_val" }
283283

284284
$expected1 = Get-AzResourceGroup -Name $rgname
285285
# Assert
@@ -316,7 +316,19 @@ function Test-FindResourceGroup
316316

317317
$expected6 = Get-AzResourceGroup -Tag @{ testtag2 = $null }
318318
# Assert
319-
Assert-AreEqual @($expected6).Count 0
319+
Assert-AreEqual @($expected6).Count 1
320+
321+
$expected7 = Get-AzResourceGroup -Tag @{ testtag2 = "testval" }
322+
# Assert
323+
Assert-AreEqual @($expected7).Count 0
324+
325+
$expected8 = Get-AzResourceGroup -Tag @{ testtagX = $null }
326+
# Assert
327+
Assert-AreEqual @($expected8).Count 0
328+
329+
$expected9 = Get-AzResourceGroup -Tag @{ testtagY = "testval" }
330+
# Assert
331+
Assert-AreEqual @($expected9).Count 0
320332
}
321333
finally
322334
{
@@ -357,7 +369,7 @@ function Test-ExportResourceGroup
357369
# Test
358370
New-AzResourceGroup -Name $rgname -Location $rglocation
359371
#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine")]
360-
$r = New-AzResource -Name $rname -Location "centralus" -Tags @{ testtag = "testval"} -ResourceGroupName $rgname -ResourceType $resourceType -PropertyObject @{"administratorLogin" = "adminuser"; "administratorLoginPassword" = "P@ssword1"} -SkuObject @{ Name = "A0" } -ApiVersion $apiversion -Force
372+
$r = New-AzResource -Name $rname -Location "centralus" -Tags @{ testtag = "testval" } -ResourceGroupName $rgname -ResourceType $resourceType -PropertyObject @{"administratorLogin" = "adminuser"; "administratorLoginPassword" = "P@ssword1"} -SkuObject @{ Name = "A0" } -ApiVersion $apiversion -Force
361373
Assert-AreEqual $r.ResourceGroupName $rgname
362374

363375
$exportOutput = Export-AzResourceGroup -ResourceGroupName $rgname -Force
@@ -393,11 +405,11 @@ function Test-ExportResourceGroupWithFiltering
393405
New-AzResourceGroup -Name $rgname -Location $rglocation
394406

395407
#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine")]
396-
$r1 = New-AzResource -Name $rname1 -Location "centralus" -Tags @{ testtag = "testval"} -ResourceGroupName $rgname -ResourceType $resourceType -PropertyObject @{"administratorLogin" = "adminuser"; "administratorLoginPassword" = "P@ssword1"} -SkuObject @{ Name = "A0" } -ApiVersion $apiversion -Force
408+
$r1 = New-AzResource -Name $rname1 -Location "centralus" -Tags @{ testtag = "testval" } -ResourceGroupName $rgname -ResourceType $resourceType -PropertyObject @{"administratorLogin" = "adminuser"; "administratorLoginPassword" = "P@ssword1"} -SkuObject @{ Name = "A0" } -ApiVersion $apiversion -Force
397409
Assert-NotNull $r1.ResourceId
398410

399411
#[SuppressMessage("Microsoft.Security", "CS002:SecretInNextLine")]
400-
$r2 = New-AzResource -Name $rname2 -Location "centralus" -Tags @{ testtag = "testval"} -ResourceGroupName $rgname -ResourceType $resourceType -PropertyObject @{"administratorLogin" = "adminuser"; "administratorLoginPassword" = "P@ssword1"} -SkuObject @{ Name = "A0" } -ApiVersion $apiversion -Force
412+
$r2 = New-AzResource -Name $rname2 -Location "centralus" -Tags @{ testtag = "testval" } -ResourceGroupName $rgname -ResourceType $resourceType -PropertyObject @{"administratorLogin" = "adminuser"; "administratorLoginPassword" = "P@ssword1"} -SkuObject @{ Name = "A0" } -ApiVersion $apiversion -Force
401413
Assert-NotNull $r2.ResourceId
402414

403415
$exportOutput = Export-AzResourceGroup -ResourceGroupName $rgname -Force -Resource @($r2.ResourceId) -IncludeParameterDefaultValue -IncludeComments

src/Resources/Resources.Test/SessionRecords/Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ResourceGroupTests/TestFindResourceGroup.json

Lines changed: 528 additions & 339 deletions
Large diffs are not rendered by default.

src/Resources/Resources/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-->
2020
## Upcoming Release
2121
* Fix for null reference bug in GetAzureRoleAssignmentCommand
22+
* Updated `Get-AzResourceGroup` to perform resource group tag filtering on server-side
2223

2324
## Version 1.11.0
2425
* Refactored template deployment cmdlets

src/Support/Support.Test/ScenarioTests/ServiceTests.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Gets complete list of services.
1818
#>
1919
function Get-AzSupportServiceNoParameter
2020
{
21-
$propertiesCount = 4
21+
$propertiesCount = 5
2222
$cmdletReturnType = "Microsoft.Azure.Commands.Support.Models.PSSupportService"
2323

2424
$queryResult = Get-AzSupportService
@@ -38,7 +38,7 @@ Get service by name
3838
#>
3939
function Get-AzSupportServiceByNameParameterSetUsingNameAlias
4040
{
41-
$propertiesCount = 4
41+
$propertiesCount = 5
4242
$cmdletReturnType = "Microsoft.Azure.Commands.Support.Models.PSSupportService"
4343

4444
$queryResult = Get-AzSupportService
@@ -58,7 +58,7 @@ Get service by name
5858
#>
5959
function Get-AzSupportServiceByNameParameterSetUsingId
6060
{
61-
$propertiesCount = 4
61+
$propertiesCount = 5
6262
$cmdletReturnType = "Microsoft.Azure.Commands.Support.Models.PSSupportService"
6363

6464
$queryResult = Get-AzSupportService
@@ -78,7 +78,7 @@ Get service by name
7878
#>
7979
function Get-AzSupportServiceByNameParameterSetUsingCompleteResourceId
8080
{
81-
$propertiesCount = 4
81+
$propertiesCount = 5
8282
$cmdletReturnType = "Microsoft.Azure.Commands.Support.Models.PSSupportService"
8383

8484
$queryResult = Get-AzSupportService

src/Support/Support.Test/ScenarioTests/SupportTicketTests.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,8 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using Microsoft.Azure.Commands.ScenarioTest;
16-
using Microsoft.Azure.Management.Internal.Resources;
17-
using Microsoft.Azure.Management.Internal.Resources.Models;
1816
using Microsoft.Azure.ServiceManagement.Common.Models;
19-
using Microsoft.Rest.Azure.OData;
2017
using Microsoft.WindowsAzure.Commands.ScenarioTest;
21-
using System.Linq;
2218
using Xunit;
2319

2420
namespace Microsoft.Azure.Commands.Support.Test.ScenarioTests
@@ -124,5 +120,19 @@ public void UpdateAzSupportTicketNameParameterSetWithContactDetail()
124120
{
125121
TestController.NewInstance.RunPowerShellTest(_logger, "Update-AzSupportTicketNameParameterSetWithContactDetail");
126122
}
123+
124+
[Fact]
125+
[Trait(Category.AcceptanceType, Category.CheckIn)]
126+
public void UpdateAzSupportTicketParentObjectParameterSetUpdateSeverity()
127+
{
128+
TestController.NewInstance.RunPowerShellTest(_logger, "Update-AzSupportTicketParentObjectParameterSetUpdateSeverity");
129+
}
130+
131+
[Fact]
132+
[Trait(Category.AcceptanceType, Category.CheckIn)]
133+
public void UpdateAzSupportTicketParentObjectParameterSetUpdateStatus()
134+
{
135+
TestController.NewInstance.RunPowerShellTest(_logger, "Update-AzSupportTicketParentObjectParameterSetUpdateSeverity");
136+
}
127137
}
128138
}

0 commit comments

Comments
 (0)