Skip to content

Commit 85e6b5f

Browse files
committed
Fix snapshot cmdlets
1 parent d902ce1 commit 85e6b5f

10 files changed

+136
-14
lines changed

src/Resources/ResourceManager/Implementation/DeploymentStacks/GetAzResourceGroupDeploymentStackSnapshot.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,24 @@ public class GetAzResourceGroupDeploymentStackSnapshot : DeploymentStacksCmdletB
4848
[ValidateNotNullOrEmpty]
4949
public string StackName { get; set; }
5050

51-
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = GetByResourceIdParameterSetName)]
5251
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, ParameterSetName = GetByDeploymentStackName)]
5352
[ValidateNotNullOrEmpty]
5453
public string SnapshotName { get; set; }
5554

55+
#endregion
5656

57+
#region Cmdlet Overrides
5758
public override void ExecuteCmdlet()
5859
{
5960
try
6061
{
6162
switch (ParameterSetName)
6263
{
6364
case GetByResourceIdParameterSetName:
64-
WriteObject(DeploymentStacksSdkClient.GetResourceGroupDeploymentStackSnapshot(ResourceIdUtility.GetResourceGroupName(ResourceId), ResourceIdUtility.GetDeploymentName(ResourceId), SnapshotName));
65+
ResourceIdentifier resourceIdentifier = new ResourceIdentifier(ResourceId);
66+
StackName = ResourceIdUtility.GetResourceName(ResourceId).Split('/')[0];
67+
SnapshotName = resourceIdentifier.ResourceName;
68+
WriteObject(DeploymentStacksSdkClient.GetResourceGroupDeploymentStackSnapshot(ResourceIdUtility.GetResourceGroupName(ResourceId), StackName, SnapshotName));
6569
break;
6670
case GetByResourceGroupNameParameterSetName:
6771
WriteObject(DeploymentStacksSdkClient.ListResourceGroupDeploymentStackSnapshot(ResourceGroupName, StackName));

src/Resources/ResourceManager/Implementation/DeploymentStacks/GetAzSubscriptionDeploymentStack.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
99
{
10-
[Cmdlet("Get", Common.AzureRMConstants.AzureRMPrefix + "DeploymentStack",
10+
[Cmdlet("Get", Common.AzureRMConstants.AzureRMPrefix + "SubscriptionDeploymentStack",
1111
DefaultParameterSetName = GetAzSubscriptionDeploymentStack.ListParameterSetname), OutputType(typeof(PSDeploymentStack))]
12-
[Alias("Get-AzSubscriptionDeploymentStack")]
12+
[Alias("Get-AzDeploymentStack")]
1313
class GetAzSubscriptionDeploymentStack : DeploymentStacksCmdletBase
1414
{
1515
#region Cmdlet Parameters and Parameter Set Definitions

src/Resources/ResourceManager/Implementation/DeploymentStacks/GetAzSubscriptionDeploymentStackSnapshot.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ public override void ExecuteCmdlet()
5050
WriteObject(DeploymentStacksSdkClient.GetSubscriptionDeploymentStackSnapshot(Name, SnapshotName));
5151
break;
5252
case GetByResourceIdParameterSetName:
53-
WriteObject(DeploymentStacksSdkClient.GetSubscriptionDeploymentStackSnapshot(ResourceIdUtility.GetResourceName(ResourceId), SnapshotName));
53+
ResourceIdentifier resourceIdentifier = new ResourceIdentifier(ResourceId);
54+
Name = ResourceIdUtility.GetResourceName(ResourceId).Split('/')[0];
55+
SnapshotName = resourceIdentifier.ResourceName;
56+
WriteObject(DeploymentStacksSdkClient.GetSubscriptionDeploymentStackSnapshot(Name, SnapshotName));
5457
break;
5558
case ListParameterSetname:
5659
WriteObject(DeploymentStacksSdkClient.ListSubscriptionDeploymentStackSnapshot(Name));

src/Resources/ResourceManager/Implementation/DeploymentStacks/RemoveAzResourceGroupDeploymentStackSnapshot.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ public override void ExecuteCmdlet()
5454

5555
ResourceGroupName = ResourceGroupName ?? resourceIdentifier.ResourceGroupName;
5656
Name = Name ?? ResourceIdUtility.GetResourceName(ResourceId);
57-
SnapshotName = SnapshotName ?? resourceIdentifier.ResourceName;
57+
58+
if(ResourceId != null && SnapshotName == null)
59+
{
60+
Name = Name.Split('/')[0];
61+
SnapshotName = resourceIdentifier.ResourceName;
62+
}
5863

5964
string confirmationMessage = $"Are you sure you want to remove snapshot '{SnapshotName}' of DeploymentStack '{Name}'";
6065

src/Resources/ResourceManager/Implementation/DeploymentStacks/RemoveAzSubscriptionDeploymentStackSnapshot.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,12 @@ public override void ExecuteCmdlet()
4848
: null;
4949

5050
Name = Name ?? ResourceIdUtility.GetResourceName(ResourceId);
51-
SnapshotName = SnapshotName ?? resourceIdentifier.ResourceName;
51+
52+
if (ResourceId != null && SnapshotName == null)
53+
{
54+
Name = Name.Split('/')[0];
55+
SnapshotName = resourceIdentifier.ResourceName;
56+
}
5257

5358
string confirmationMessage = $"Are you sure you want to remove snapshot '{SnapshotName}' of DeploymentStack '{Name}'";
5459

src/Resources/ResourceManager/Implementation/DeploymentStacks/SetAzResourceGroupDeploymentStack.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ public override void ExecuteCmdlet()
109109
throw new PSInvalidOperationException(
110110
string.Format(ProjectResources.InvalidFilePath, TemplateFile));
111111
}
112+
TemplateUri = TemplateFile;
112113
break;
113114
case ParameterFileTemplateSpecParameterSetName:
114115
case ParameterFileTemplateUriParameterSetName:
@@ -122,10 +123,12 @@ public override void ExecuteCmdlet()
122123
string.Format(ProjectResources.InvalidFilePath, TemplateFile));
123124
}
124125
parameters = this.GetParameterObject(ParameterFile);
126+
TemplateUri = TemplateFile;
125127
break;
126128
}
127129

128-
if (DeploymentStacksSdkClient.GetSubscriptionDeploymentStack(
130+
if (DeploymentStacksSdkClient.GetResourceGroupDeploymentStack(
131+
ResourceGroupName,
129132
Name,
130133
throwIfNotExists: false) == null)
131134
throw new DeploymentStacksErrorException($"The stack '{Name}' you're trying to modify does not exist in '{ResourceGroupName}'. Please Use New-AzResourceGroupDeploymentStack to create it");

src/Resources/Resources.Test/Providers/RegisterResourceProviderCmdletTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ public void RegisterResourceProviderTests()
110110
var registrationResult = provider;
111111

112112
this.providerOperationsMock
113-
.Setup(client => client.RegisterWithHttpMessagesAsync(It.IsAny<string>(), null, null, It.IsAny<CancellationToken>()))
114-
.Callback((string providerName, Dictionary<string, List<string>> customHeaders, CancellationToken ignored) =>
113+
.Setup(client => client.RegisterWithHttpMessagesAsync(It.IsAny<string>(), default(ProviderRegistrationRequest), null, It.IsAny<CancellationToken>()))
114+
.Callback((string providerName, ProviderRegistrationRequest properties, Dictionary<string, List<string>> customHeaders, CancellationToken ignored) =>
115115
Assert.Equal(ProviderName, providerName, StringComparer.OrdinalIgnoreCase))
116116
.Returns(() => Task.FromResult(new AzureOperationResponse<Provider>() {
117117
Body = registrationResult
@@ -161,7 +161,7 @@ public void RegisterResourceProviderTests()
161161
/// </summary>
162162
private void VerifyCallPatternAndReset(bool succeeded)
163163
{
164-
this.providerOperationsMock.Verify(f => f.RegisterWithHttpMessagesAsync(It.IsAny<string>(), null, null, It.IsAny<CancellationToken>()), Times.Once());
164+
this.providerOperationsMock.Verify(f => f.RegisterWithHttpMessagesAsync(It.IsAny<string>(), default(ProviderRegistrationRequest), null, It.IsAny<CancellationToken>()), Times.Once());
165165
this.commandRuntimeMock.Verify(f => f.WriteObject(It.IsAny<object>()), succeeded ? Times.Once() : Times.Never());
166166

167167
this.providerOperationsMock.ResetCalls();

src/Resources/Resources.Test/ScenarioTests/DeploymentStackTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ public DeploymentStackTests(ITestOutputHelper output) : base(output)
2626

2727
[Fact()]
2828
[Trait(Category.AcceptanceType, Category.CheckIn)]
29-
public void TestResourceGroupDeploymentStackGetWithResourceName()
29+
public void TestResourceGroupDeploymentStackGet()
3030
{
31-
TestRunner.RunTestScript("");
31+
TestRunner.RunTestScript("Test-GetResourceGroupDeploymentStack");
3232
}
3333

3434
[Fact()]
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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+
<#
16+
.SYNOPSIS
17+
Tests GET operation on deploymentStacks at the RG scope
18+
#>
19+
function Test-GetResourceGroupDeploymentStack
20+
{
21+
# Setup
22+
$rgname = Get-ResourceGroupName
23+
$rname = Get-ResourceName
24+
$rglocation = "West US 2"
25+
$subId = (Get-AzContext).Subscription.SubscriptionId
26+
27+
try
28+
{
29+
# Prepare
30+
New-AzResourceGroup -Name $rgname -Location $rglocation
31+
32+
$deployment = New-AzResourceGroupDeploymentStack -Name $rname -ResourceGroupName $rgname -TemplateFile simpleTemplate.json -ParameterFile simpleTemplateParams.json
33+
$resourceId = "/subscriptions/$subId/resourcegroups/$rgname/providers/Microsoft.Resources/deploymentStacks/$rname"
34+
35+
# Test - GetByNameAndResourceGroup
36+
$getByNameAndResourceGroup = Get-AzResourceGroupDeploymentStack -ResourceGroupName $rgname -Name $rname
37+
38+
# Assert
39+
Assert-NotNull $getByNameAndResourceGroup
40+
41+
# Test - GetByResourceId
42+
$getByResourceId = Get-AzResourceGroupDeploymentStack -ResourceId $resourceId
43+
44+
#Assert
45+
Assert-NotNull $getByResourceId
46+
47+
#Test - ListByResourceGroupName
48+
$listByResourceGroup = Get-AzResourceGroupDeploymentStack -ResourceGroupName $rgname
49+
50+
# Assert
51+
Assert-AreNotEqual 0 $listByResourceGroup.Count
52+
Assert-True { $listByResourceGroup.name.contains($rname) }
53+
}
54+
finally
55+
{
56+
# Cleanup
57+
Clean-ResourceGroup $rgname
58+
}
59+
}
60+
61+
<#
62+
.SYNOPSIS
63+
Tests GET operation on deploymentStacks at the Subscription scope
64+
#>
65+
function Test-GetSubscriptionDeploymentStack
66+
{
67+
# Setup
68+
$rgname = Get-ResourceGroupName
69+
$rname = Get-ResourceName
70+
$rglocation = "West US 2"
71+
72+
try
73+
{
74+
# Prepare
75+
$deployment = New-AzSubscriptionDeploymentStack -Name $rname -TemplateFile simpleTemplate.json -ParameterFile simpleTemplateParams.json
76+
$resourceId = "/subscriptions/$subId/providers/Microsoft.Resources/deploymentStacks/$rname"
77+
78+
# Test - GetByName
79+
$getByName = Get-AzSubscriptionDeploymentStack -Name $rname
80+
81+
# Assert
82+
Assert-NotNull $getByName
83+
84+
# Test - GetByResourceId
85+
$getByResourceId = Get-AzSubscriptionDeploymentStack -ResourceId $resourceId
86+
87+
#Assert
88+
Assert-NotNull $getByResourceId
89+
90+
#Test - ListByResourceGroupName
91+
$list = Get-AzSubscriptionDeploymentStack
92+
93+
# Assert
94+
Assert-AreNotEqual 0 $list.Count
95+
Assert-True { $list.name.contains($rname) }
96+
}
97+
finally
98+
{
99+
# Cleanup
100+
Clean-DeploymentAtSubscription $rname
101+
}
102+
}

src/Resources/Resources/Az.Resources.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ CmdletsToExport = 'Get-AzProviderOperation', 'Remove-AzRoleAssignment',
153153
'Get-AzTenantDeploymentWhatIfResult', 'Get-AzTemplateSpec',
154154
'New-AzTemplateSpec', 'Set-AzTemplateSpec', 'Export-AzTemplateSpec',
155155
'Remove-AzTemplateSpec', 'Get-AzResourceGroupDeploymentStack',
156-
'Get-AzResourceGroupDeploymentStackSnapshot', 'Get-AzDeploymentStack',
156+
'Get-AzResourceGroupDeploymentStackSnapshot', 'Get-AzSubscriptionDeploymentStack',
157157
'Get-AzSubscriptionDeploymentStackSnapshot', 'New-AzResourceGroupDeploymentStack',
158158
'New-AzSubscriptionDeploymentStack', 'Remove-AzResourceGroupDeploymentStack',
159159
'Remove-AzResourceGroupDeploymentStackSnapshot', 'Remove-AzSubscriptionDeploymentStack',

0 commit comments

Comments
 (0)