Skip to content

Fix issue with Properties property of PSResource #6218

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 4 commits into from
May 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ResourceManager/Resources/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Additional information about change #1
-->
## Current Release
* Fix issue with `Properties` property of `PSResource` object(s) returned from `Get-AzureRmResource`

## Version 6.0.0
* Set minimum dependency of module to PowerShell 5.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Components;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Extensions;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkExtensions;
using Microsoft.Azure.Management.ResourceManager.Models;
using Newtonsoft.Json.Linq;
using System.Collections;
using System.Collections.Generic;
using System.Management.Automation;

namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels
{
Expand All @@ -40,7 +43,7 @@ public class PSResource

public Plan Plan { get; set; }

public object Properties { get; set; }
public PSObject Properties { get; set; }

public string ResourceGroupName { get; set; }

Expand All @@ -62,7 +65,7 @@ public PSResource(GenericResource resource)
this.ManagedBy = resource.ManagedBy;
this.Name = resource.Name;
this.Plan = resource.Plan;
this.Properties = resource.Properties;
this.Properties = ((JToken)resource.Properties).ToPsObject();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice.

Also, argh PowerShell, haha.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, is it ever possible for resource.Properties to not be convertible to JToken?

this.ResourceType = resource.Type;
this.Sku = resource.Sku;
this.Tags = resource.Tags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,12 @@
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ResourceTests\TestFindAResourceTest.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ResourceTests\TestGetResourceByComponentsAndProperties.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ResourceTests\TestGetResourceByIdAndProperties.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Resources.Test.ScenarioTests.ResourceTests\TestGetResourceForNonExisingResource.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,14 @@ public void TestMoveResourceFailed()
ResourcesController.NewInstance.RunPsTest("Test-MoveResourceFailed");
}

[Fact(Skip = "Successfully re-recorded, but still failing in playback")]
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestSetAResourceTest()
{
ResourcesController.NewInstance.RunPsTest("Test-SetAResource");
}

[Fact(Skip = "Successfully re-recorded, but still failing in playback")]
[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestSetAResourceWithPatchTest()
{
Expand Down Expand Up @@ -133,6 +133,20 @@ public void TestGetResourceWithExpandProperties()
ResourcesController.NewInstance.RunPsTest("Test-GetResourceExpandProperties");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestGetResourceByIdAndProperties()
{
ResourcesController.NewInstance.RunPsTest("Test-GetResourceByIdAndProperties");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestGetResourceByComponentsAndProperties()
{
ResourcesController.NewInstance.RunPsTest("Test-GetResourceByComponentsAndProperties");
}

[Fact(Skip = "Zones are disabled for now.")]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestManageResourceWithZones()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,78 @@ function Test-GetResourceExpandProperties
}
}

<#
.SYNOPSIS
Tests getting a resource by id and its properties
#>
function Test-GetResourceByIdAndProperties
{
# Setup
$rgname = Get-ResourceGroupName
$rname = Get-ResourceName
$rglocation = Get-Location "Microsoft.Resources" "resourceGroups" "West US"
$apiversion = "2014-04-01"
$resourceType = "Providers.Test/statefulResources"

try
{
# Test
New-AzureRmResourceGroup -Name $rgname -Location $rglocation
$resource = New-AzureRmResource -Name $rname -Location $rglocation -Tags @{testtag = "testval"} -ResourceGroupName $rgname -ResourceType $resourceType -PropertyObject @{"key" = "value"} -SkuObject @{ Name = "A0" } -ApiVersion $apiversion -Force
$resourceGet = Get-AzureRmResource -ResourceId $resource.ResourceId

# Assert
Assert-NotNull $resourceGet
Assert-AreEqual $resourceGet.Name $rname
Assert-AreEqual $resourceGet.ResourceGroupName $rgname
Assert-AreEqual $resourceGet.ResourceType $resourceType
$properties = $resourceGet.Properties
Assert-NotNull $properties
Assert-NotNull $properties.key
Assert-AreEqual $properties.key "value"
}
finally
{
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
Tests getting a resource by its components and its properties
#>
function Test-GetResourceByComponentsAndProperties
{
# Setup
$rgname = Get-ResourceGroupName
$rname = Get-ResourceName
$rglocation = Get-Location "Microsoft.Resources" "resourceGroups" "West US"
$apiversion = "2014-04-01"
$resourceType = "Providers.Test/statefulResources"

try
{
# Test
New-AzureRmResourceGroup -Name $rgname -Location $rglocation
$resource = New-AzureRmResource -Name $rname -Location $rglocation -Tags @{testtag = "testval"} -ResourceGroupName $rgname -ResourceType $resourceType -PropertyObject @{"key" = "value"} -SkuObject @{ Name = "A0" } -ApiVersion $apiversion -Force
$resourceGet = Get-AzureRmResource -Name $rname -ResourceGroupName $rgname -ResourceType $resourceType

# Assert
Assert-NotNull $resourceGet
Assert-AreEqual $resourceGet.Name $rname
Assert-AreEqual $resourceGet.ResourceGroupName $rgname
Assert-AreEqual $resourceGet.ResourceType $resourceType
$properties = $resourceGet.Properties
Assert-NotNull $properties
Assert-NotNull $properties.key
Assert-AreEqual $properties.key "value"
}
finally
{
Clean-ResourceGroup $rgname
}
}

<#
.SYNOPSIS
Tests managing resource with zones.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void RunPsTest(params string[] scripts)
() => scripts,
// no custom initializer
null,
// no custom cleanup
// no custom cleanup
null,
callingClassType,
mockName);
Expand Down Expand Up @@ -121,6 +121,7 @@ public void RunPsTestWorkflow(
d.Add("Microsoft.Resources", null);
d.Add("Microsoft.Features", null);
d.Add("Microsoft.Authorization", null);
d.Add("Providers.Test", null);
var providersToIgnore = new Dictionary<string, string>();
providersToIgnore.Add("Microsoft.Azure.Management.ResourceManager.ResourceManagementClient", "2016-07-01");
providersToIgnore.Add("Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01");
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tools/StaticAnalysis/Exceptions/BreakingChangeIssues.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"AssemblyFileName","ClassName","Target","Severity","ProblemId","Description","Remediation"
"Microsoft.Azure.Commands.ResourceManager.Cmdlets.dll","Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.GetAzureResourceCmdlet","Get-AzureRmResource","0","3000","The type of property 'Properties' of type 'Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.PSResource' has changed from 'System.Object' to 'System.Management.Automation.PSObject'.","Change the type of property 'Properties' back to 'System.Object'."
"Microsoft.Azure.Commands.ServiceFabric.dll","Microsoft.Azure.Commands.ServiceFabric.Commands.NewAzureRmServiceFabricCluster","New-AzureRmServiceFabricCluster","0","3000","The type of property 'Properties' of type 'Microsoft.Azure.Commands.ServiceFabric.Models.PSDeploymentExtended' has changed from 'Microsoft.Azure.Management.ResourceManager.Models.DeploymentPropertiesExtended' to 'Microsoft.Azure.Management.Internal.Resources.Models.DeploymentPropertiesExtended'.","Change the type of property 'Properties' back to 'Microsoft.Azure.Management.ResourceManager.Models.DeploymentPropertiesExtended'."
"Microsoft.Azure.Commands.Sql.dll","Microsoft.Azure.Commands.Sql.FailoverGroup.Cmdlet.AddAzureSqlDatabaseToFailoverGroup","Add-AzureRmSqlDatabaseToFailoverGroup","0","3000","The type of property 'Edition' of type 'Microsoft.Azure.Commands.Sql.Database.Model.AzureSqlDatabaseModel' has changed from 'Microsoft.Azure.Commands.Sql.Database.Model.DatabaseEdition' to 'System.String'.","Change the type of property 'Edition' back to 'Microsoft.Azure.Commands.Sql.Database.Model.DatabaseEdition'."
"Microsoft.Azure.Commands.Sql.dll","Microsoft.Azure.Commands.Sql.ElasticPool.Cmdlet.NewAzureSqlElasticPool","New-AzureRmSqlElasticPool","0","2020","The cmdlet 'New-AzureRmSqlElasticPool' no longer supports the type 'Microsoft.Azure.Commands.Sql.Database.Model.DatabaseEdition' for parameter 'Edition'.","Change the type for parameter 'Edition' back to 'Microsoft.Azure.Commands.Sql.Database.Model.DatabaseEdition'."
Expand Down