Skip to content

Commit cf4e9a1

Browse files
authored
Merge pull request Azure#9051 from niander/nowait
NoWait Support for Compute LRO Cmdlets that supports some sort of OperationResult
2 parents 673d2c2 + 982d9c1 commit cf4e9a1

File tree

72 files changed

+4261
-318
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+4261
-318
lines changed

src/Accounts/Authentication.Test/LongRunningCmdletTests.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,21 @@ public void JobCopiesCmdletParameterSet()
208208
}
209209

210210

211+
[Fact]
212+
[Trait(Category.AcceptanceType, Category.CheckIn)]
213+
public void NoWaitWithAsJob()
214+
{
215+
var mock = new Mock<ICommandRuntime>();
216+
var cmdlet = new AzureStreamTestCmdlet();
217+
cmdlet.MyInvocation.BoundParameters["AsJob"] = true;
218+
cmdlet.MyInvocation.BoundParameters["NoWait"] = true;
219+
220+
mock.Setup(m => m.WriteObject(It.IsAny<object>())).Throws(new InvalidOperationException("Should not execute as job"));
221+
222+
cmdlet.CommandRuntime = mock.Object;
223+
cmdlet.ExecuteSynchronouslyOrAsJob();
224+
}
225+
211226
AzureStreamTestCmdlet SetupCmdlet(bool CallShouldProcess, bool CallShouldContinue, out Mock<ICommandRuntime> mockRuntime)
212227
{
213228
var cmdlet = new AzureStreamTestCmdlet();
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
16+
using Xunit;
17+
18+
namespace Microsoft.Azure.Commands.Compute.Test.ScenarioTests
19+
{
20+
public class NoWaitTests : ComputeTestRunner
21+
{
22+
public NoWaitTests(Xunit.Abstractions.ITestOutputHelper output) : base(output)
23+
{
24+
}
25+
26+
[Fact]
27+
[Trait(Category.AcceptanceType, Category.CheckIn)]
28+
public void TestNoWaitParameter()
29+
{
30+
TestRunner.RunTestScript("Test-NoWaitParameter");
31+
}
32+
33+
}
34+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
Test NoWait Switch Parameter
18+
#>
19+
function Test-NoWaitParameter
20+
{
21+
# Setup
22+
$rgname = Get-ComputeTestResourceName
23+
24+
try
25+
{
26+
# Common
27+
$loc = Get-ComputeVMLocation;
28+
New-AzResourceGroup -Name $rgname -Location $loc -Force;
29+
30+
$vmname = 'vm' + $rgname;
31+
$user = "Foo12";
32+
$password = $PLACEHOLDER;
33+
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force;
34+
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);
35+
[string]$domainNameLabel = "$vmname-$vmname".tolower();
36+
$vmobject = New-AzVm -Name $vmname -ResourceGroupName $rgname -Credential $cred -DomainNameLabel $domainNameLabel;
37+
38+
$response = Start-AzVm -ResourceGroupName $rgname -Name $vmname -NoWait
39+
Assert-NotNull $response.RequestId
40+
}
41+
finally
42+
{
43+
# Cleanup
44+
Clean-ResourceGroup $rgname;
45+
}
46+
}

src/Compute/Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.NoWaitTests/TestNoWaitParameter.json

Lines changed: 3056 additions & 0 deletions
Large diffs are not rendered by default.

src/Compute/Compute/Extension/ADDomain/SetAzureVMADDomainExtensionCommand.cs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,28 @@ public override void ExecuteCmdlet()
115115
ProtectedSettings = privateSettings
116116
};
117117

118-
var op = this.VirtualMachineExtensionClient.CreateOrUpdateWithHttpMessagesAsync(
119-
this.ResourceGroupName,
120-
this.VMName,
121-
this.Name ?? VirtualMachineADDomainExtensionContext.ExtensionDefaultName,
122-
parameters).GetAwaiter().GetResult();
123-
124-
var result = ComputeAutoMapperProfile.Mapper.Map<PSAzureOperationResponse>(op);
125-
WriteObject(result);
118+
if (NoWait.IsPresent)
119+
{
120+
var op = this.VirtualMachineExtensionClient.BeginCreateOrUpdateWithHttpMessagesAsync(
121+
this.ResourceGroupName,
122+
this.VMName,
123+
this.Name ?? VirtualMachineADDomainExtensionContext.ExtensionDefaultName,
124+
parameters).GetAwaiter().GetResult();
125+
126+
var result = ComputeAutoMapperProfile.Mapper.Map<PSAzureOperationResponse>(op);
127+
WriteObject(result);
128+
}
129+
else
130+
{
131+
var op = this.VirtualMachineExtensionClient.CreateOrUpdateWithHttpMessagesAsync(
132+
this.ResourceGroupName,
133+
this.VMName,
134+
this.Name ?? VirtualMachineADDomainExtensionContext.ExtensionDefaultName,
135+
parameters).GetAwaiter().GetResult();
136+
137+
var result = ComputeAutoMapperProfile.Mapper.Map<PSAzureOperationResponse>(op);
138+
WriteObject(result);
139+
}
126140
});
127141
}
128142
}

src/Compute/Compute/Extension/AEM/RemoveAzureRmVMAEMExtension.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ public class RemoveAzureRmVMAEMExtension : VirtualMachineExtensionBaseCmdlet
7171
HelpMessage = "Operating System Type of the virtual machines. Possible values: Windows | Linux")]
7272
public string OSType { get; set; }
7373

74+
[Parameter(Mandatory = false, HelpMessage = "Starts the operation and returns immediately, before the operation is completed. In order to determine if the operation has sucessufuly been completed, use some other mechanism.")]
75+
public SwitchParameter NoWait { get; set; }
76+
7477
public override void ExecuteCmdlet()
7578
{
7679
this._Helper = new AEMHelper((err) => this.WriteError(err), (msg) => this.WriteVerbose(msg), (msg) => this.WriteWarning(msg),
@@ -115,9 +118,17 @@ public override void ExecuteCmdlet()
115118
}
116119
}
117120

118-
var op = this.VirtualMachineExtensionClient.DeleteWithHttpMessagesAsync(this.ResourceGroupName, this.VMName, this.Name).GetAwaiter().GetResult();
119-
var result = ComputeAutoMapperProfile.Mapper.Map<PSAzureOperationResponse>(op);
120-
WriteObject(result);
121+
if (NoWait.IsPresent)
122+
{
123+
var op = this.VirtualMachineExtensionClient.BeginDeleteWithHttpMessagesAsync(this.ResourceGroupName, this.VMName, this.Name).GetAwaiter().GetResult();
124+
WriteObject(ComputeAutoMapperProfile.Mapper.Map<PSAzureOperationResponse>(op));
125+
}
126+
else
127+
{
128+
var op = this.VirtualMachineExtensionClient.DeleteWithHttpMessagesAsync(this.ResourceGroupName, this.VMName, this.Name).GetAwaiter().GetResult();
129+
var result = ComputeAutoMapperProfile.Mapper.Map<PSAzureOperationResponse>(op);
130+
WriteObject(result);
131+
}
121132
});
122133
}
123134
}

src/Compute/Compute/Extension/AEM/SetAzureRmVMAEMExtension.cs

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ public class SetAzureRmVMAEMExtension : VirtualMachineExtensionBaseCmdlet
8888
HelpMessage = "Disables the settings for table content")]
8989
public SwitchParameter SkipStorage { get; set; }
9090

91+
[Parameter(Mandatory = false, HelpMessage = "Starts the operation and returns immediately, before the operation is completed. In order to determine if the operation has sucessufuly been completed, use some other mechanism.")]
92+
public SwitchParameter NoWait { get; set; }
93+
9194
public SetAzureRmVMAEMExtension()
9295
{
9396
}
@@ -403,25 +406,50 @@ public override void ExecuteCmdlet()
403406

404407
Version aemVersion = this._Helper.GetExtensionVersion(selectedVM, selectedVMStatus, OSType, AEMExtensionConstants.AEMExtensionType[OSType], AEMExtensionConstants.AEMExtensionPublisher[OSType]);
405408

406-
var op = this.VirtualMachineExtensionClient.CreateOrUpdateWithHttpMessagesAsync(
407-
this.ResourceGroupName, this.VMName, AEMExtensionConstants.AEMExtensionDefaultName[OSType],
408-
new VirtualMachineExtension()
409-
{
410-
Publisher = AEMExtensionConstants.AEMExtensionPublisher[OSType],
411-
VirtualMachineExtensionType = AEMExtensionConstants.AEMExtensionType[OSType],
412-
TypeHandlerVersion = aemVersion.ToString(2),
413-
Settings = jsonPublicConfig,
414-
ProtectedSettings = jsonPrivateConfig,
415-
Location = selectedVM.Location,
416-
AutoUpgradeMinorVersion = true,
417-
ForceUpdateTag = DateTime.Now.Ticks.ToString()
418-
}).GetAwaiter().GetResult();
419-
420-
this._Helper.WriteHost("[INFO] Azure Enhanced Monitoring Extension for SAP configuration updated. It can take up to 15 Minutes for the monitoring data to appear in the SAP system.");
421-
this._Helper.WriteHost("[INFO] You can check the configuration of a virtual machine by calling the Test-AzVMAEMExtension commandlet.");
422-
423-
var result = ComputeAutoMapperProfile.Mapper.Map<PSAzureOperationResponse>(op);
424-
WriteObject(result);
409+
if (NoWait.IsPresent)
410+
{
411+
var op = this.VirtualMachineExtensionClient.BeginCreateOrUpdateWithHttpMessagesAsync(
412+
this.ResourceGroupName, this.VMName, AEMExtensionConstants.AEMExtensionDefaultName[OSType],
413+
new VirtualMachineExtension()
414+
{
415+
Publisher = AEMExtensionConstants.AEMExtensionPublisher[OSType],
416+
VirtualMachineExtensionType = AEMExtensionConstants.AEMExtensionType[OSType],
417+
TypeHandlerVersion = aemVersion.ToString(2),
418+
Settings = jsonPublicConfig,
419+
ProtectedSettings = jsonPrivateConfig,
420+
Location = selectedVM.Location,
421+
AutoUpgradeMinorVersion = true,
422+
ForceUpdateTag = DateTime.Now.Ticks.ToString()
423+
}).GetAwaiter().GetResult();
424+
425+
this._Helper.WriteHost("[INFO] Azure Enhanced Monitoring Extension for SAP configuration updated. It can take up to 15 Minutes for the monitoring data to appear in the SAP system.");
426+
this._Helper.WriteHost("[INFO] You can check the configuration of a virtual machine by calling the Test-AzVMAEMExtension commandlet.");
427+
428+
var result = ComputeAutoMapperProfile.Mapper.Map<PSAzureOperationResponse>(op);
429+
WriteObject(result);
430+
}
431+
else
432+
{
433+
var op = this.VirtualMachineExtensionClient.CreateOrUpdateWithHttpMessagesAsync(
434+
this.ResourceGroupName, this.VMName, AEMExtensionConstants.AEMExtensionDefaultName[OSType],
435+
new VirtualMachineExtension()
436+
{
437+
Publisher = AEMExtensionConstants.AEMExtensionPublisher[OSType],
438+
VirtualMachineExtensionType = AEMExtensionConstants.AEMExtensionType[OSType],
439+
TypeHandlerVersion = aemVersion.ToString(2),
440+
Settings = jsonPublicConfig,
441+
ProtectedSettings = jsonPrivateConfig,
442+
Location = selectedVM.Location,
443+
AutoUpgradeMinorVersion = true,
444+
ForceUpdateTag = DateTime.Now.Ticks.ToString()
445+
}).GetAwaiter().GetResult();
446+
447+
this._Helper.WriteHost("[INFO] Azure Enhanced Monitoring Extension for SAP configuration updated. It can take up to 15 Minutes for the monitoring data to appear in the SAP system.");
448+
this._Helper.WriteHost("[INFO] You can check the configuration of a virtual machine by calling the Test-AzVMAEMExtension commandlet.");
449+
450+
var result = ComputeAutoMapperProfile.Mapper.Map<PSAzureOperationResponse>(op);
451+
WriteObject(result);
452+
}
425453
});
426454
}
427455

src/Compute/Compute/Extension/AzureDiskEncryption/DisableAzureDiskEncryption.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
namespace Microsoft.Azure.Commands.Compute.Extension.AzureDiskEncryption
2828
{
29-
[Cmdlet("Disable", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VMDiskEncryption",SupportsShouldProcess = true)]
29+
[Cmdlet("Disable", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VMDiskEncryption", SupportsShouldProcess = true)]
3030
[OutputType(typeof(PSAzureOperationResponse))]
3131
public class DisableAzureDiskEncryptionCommand : VirtualMachineExtensionBaseCmdlet
3232
{

src/Compute/Compute/Extension/AzureDiskEncryption/RemoveAzureDiskEncryptionExtension.cs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ public class RemoveAzureDiskEncryptionExtensionCommand : VirtualMachineExtension
5959
[ValidateNotNullOrEmpty]
6060
public SwitchParameter Force { get; set; }
6161

62+
[Parameter(Mandatory = false, HelpMessage = "Starts the operation and returns immediately, before the operation is completed. In order to determine if the operation has sucessufuly been completed, use some other mechanism.")]
63+
public SwitchParameter NoWait { get; set; }
64+
6265
public override void ExecuteCmdlet()
6366
{
6467
base.ExecuteCmdlet();
@@ -81,12 +84,24 @@ public override void ExecuteCmdlet()
8184
&& (this.Force.IsPresent
8285
|| this.ShouldContinue(Properties.Resources.VirtualMachineExtensionRemovalConfirmation, Properties.Resources.VirtualMachineExtensionRemovalCaption)))
8386
{
84-
var op = this.VirtualMachineExtensionClient.DeleteWithHttpMessagesAsync(
85-
this.ResourceGroupName,
86-
this.VMName,
87-
this.Name).GetAwaiter().GetResult();
88-
var result = ComputeAutoMapperProfile.Mapper.Map<PSAzureOperationResponse>(op);
89-
WriteObject(result);
87+
if (NoWait.IsPresent)
88+
{
89+
var op = this.VirtualMachineExtensionClient.BeginDeleteWithHttpMessagesAsync(
90+
this.ResourceGroupName,
91+
this.VMName,
92+
this.Name).GetAwaiter().GetResult();
93+
var result = ComputeAutoMapperProfile.Mapper.Map<PSAzureOperationResponse>(op);
94+
WriteObject(result);
95+
}
96+
else
97+
{
98+
var op = this.VirtualMachineExtensionClient.DeleteWithHttpMessagesAsync(
99+
this.ResourceGroupName,
100+
this.VMName,
101+
this.Name).GetAwaiter().GetResult();
102+
var result = ComputeAutoMapperProfile.Mapper.Map<PSAzureOperationResponse>(op);
103+
WriteObject(result);
104+
}
90105
}
91106
});
92107
}

src/Compute/Compute/Extension/AzureDiskEncryption/SetAzureDiskEncryptionExtension.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
namespace Microsoft.Azure.Commands.Compute.Extension.AzureDiskEncryption
2929
{
30-
[Cmdlet("Set", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VMDiskEncryptionExtension",SupportsShouldProcess = true,DefaultParameterSetName = AzureDiskEncryptionExtensionConstants.singlePassParameterSet)]
30+
[Cmdlet("Set", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VMDiskEncryptionExtension", SupportsShouldProcess = true, DefaultParameterSetName = AzureDiskEncryptionExtensionConstants.singlePassParameterSet)]
3131
[OutputType(typeof(PSAzureOperationResponse))]
3232
public class SetAzureDiskEncryptionExtensionCommand : VirtualMachineExtensionBaseCmdlet
3333
{
@@ -357,7 +357,7 @@ private AzureOperationResponse<VirtualMachine> UpdateVmEncryptionSettings(DiskEn
357357
this.ComputeClient.ComputeManagementClient.VirtualMachines
358358
.DeallocateWithHttpMessagesAsync(this.ResourceGroupName, this.VMName).GetAwaiter()
359359
.GetResult();
360-
360+
361361
// update vm
362362
vmParameters = (this.ComputeClient.ComputeManagementClient.VirtualMachines.Get(
363363
this.ResourceGroupName, this.VMName));
@@ -412,7 +412,7 @@ private Hashtable GetExtensionPublicSettings()
412412
string keyEncryptAlgorithm = string.Empty;
413413
if (!string.IsNullOrEmpty(this.KeyEncryptionKeyUrl))
414414
{
415-
if(!string.IsNullOrEmpty(KeyEncryptionAlgorithm))
415+
if (!string.IsNullOrEmpty(KeyEncryptionAlgorithm))
416416
{
417417
keyEncryptAlgorithm = KeyEncryptionAlgorithm;
418418
}

src/Compute/Compute/Extension/BGInfo/SetAzureVMBGInfoExtension.cs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,28 @@ protected override void ProcessRecord()
4747
ForceUpdateTag = this.ForceRerun
4848
};
4949

50-
var op = this.VirtualMachineExtensionClient.CreateOrUpdateWithHttpMessagesAsync(
51-
this.ResourceGroupName,
52-
this.VMName,
53-
this.Name ?? VirtualMachineBGInfoExtensionContext.ExtensionDefaultName,
54-
parameters).GetAwaiter().GetResult();
50+
if (NoWait.IsPresent)
51+
{
52+
var op = this.VirtualMachineExtensionClient.BeginCreateOrUpdateWithHttpMessagesAsync(
53+
this.ResourceGroupName,
54+
this.VMName,
55+
this.Name ?? VirtualMachineBGInfoExtensionContext.ExtensionDefaultName,
56+
parameters).GetAwaiter().GetResult();
5557

56-
var result = ComputeAutoMapperProfile.Mapper.Map<PSAzureOperationResponse>(op);
57-
WriteObject(result);
58+
var result = ComputeAutoMapperProfile.Mapper.Map<PSAzureOperationResponse>(op);
59+
WriteObject(result);
60+
}
61+
else
62+
{
63+
var op = this.VirtualMachineExtensionClient.CreateOrUpdateWithHttpMessagesAsync(
64+
this.ResourceGroupName,
65+
this.VMName,
66+
this.Name ?? VirtualMachineBGInfoExtensionContext.ExtensionDefaultName,
67+
parameters).GetAwaiter().GetResult();
68+
69+
var result = ComputeAutoMapperProfile.Mapper.Map<PSAzureOperationResponse>(op);
70+
WriteObject(result);
71+
}
5872
});
5973
}
6074
}

0 commit comments

Comments
 (0)