Skip to content

Commit 395ab26

Browse files
Merge branch 'dev' of https://github.com/Azure/azure-powershell into dev
2 parents c466552 + 910d7db commit 395ab26

36 files changed

+4284
-280
lines changed

src/Common/Commands.ScenarioTest/Commands.ScenarioTest.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@
105105
<Reference Include="Microsoft.WindowsAzure.Management.Compute">
106106
<HintPath>..\..\packages\Microsoft.WindowsAzure.Management.Compute.12.2.0-preview\lib\net40\Microsoft.WindowsAzure.Management.Compute.dll</HintPath>
107107
</Reference>
108+
<Reference Include="Microsoft.WindowsAzure.Management.Network, Version=7.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
109+
<HintPath>..\..\packages\Microsoft.WindowsAzure.Management.Network.7.0.0\lib\net40\Microsoft.WindowsAzure.Management.Network.dll</HintPath>
110+
<Private>True</Private>
111+
</Reference>
108112
<Reference Include="Microsoft.WindowsAzure.Management.Storage">
109113
<HintPath>..\..\packages\Microsoft.WindowsAzure.Management.Storage.5.1.1\lib\net40\Microsoft.WindowsAzure.Management.Storage.dll</HintPath>
110114
</Reference>
@@ -205,6 +209,9 @@
205209
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.ServiceManagementTests\RunServiceManagementCloudExceptionTests.json">
206210
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
207211
</None>
212+
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.ServiceManagementTests\RunStartAndStopMultipleVirtualMachinesTest.json">
213+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
214+
</None>
208215
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.ServiceManagementTests\TestGetAzureLocation.json">
209216
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
210217
</None>

src/Common/Commands.ScenarioTest/Resources/ServiceManagement/ServiceManagementTests.ps1

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,68 @@ function Run-ServiceManagementCloudExceptionTests
6969
Assert-ThrowsLike { $st = Get-AzureService -ServiceName '*' } $compare;
7070
Assert-ThrowsLike { $st = Get-AzureVM -ServiceName '*' } $compare;
7171
Assert-ThrowsLike { $st = Get-AzureAffinityGroup -Name '*' } $compare;
72+
}
73+
74+
# Test Start/Stop-AzureVM for Multiple VMs
75+
function Run-StartAndStopMultipleVirtualMachinesTest
76+
{
77+
# Setup
78+
$location = Get-DefaultLocation;
79+
$imgName = Get-DefaultImage $location;
80+
81+
$storageName = 'pstest' + (getAssetName);
82+
New-AzureStorageAccount -StorageAccountName $storageName -Location $location;
83+
84+
# Associate the new storage account with the current subscription
85+
Set-CurrentStorageAccountName $storageName;
86+
87+
$vmNameList = @("vm01", "vm02", "test04");
88+
$svcName = 'pstest' + (Get-CloudServiceName);
89+
$userName = "pstestuser";
90+
$password = "p@ssw0rd";
91+
92+
# Test
93+
New-AzureService -ServiceName $svcName -Location $location;
94+
95+
try
96+
{
97+
foreach ($vmName in $vmNameList)
98+
{
99+
New-AzureQuickVM -Windows -ImageName $imgName -Name $vmName -ServiceName $svcName -AdminUsername $userName -Password $password;
100+
}
101+
102+
# Get VM List
103+
$vmList = Get-AzureVM -ServiceName $svcName;
104+
105+
# Test Stop
106+
Stop-AzureVM -Force -ServiceName $svcName -Name $vmNameList[0];
107+
Stop-AzureVM -Force -ServiceName $svcName -Name $vmNameList[0],$vmNameList[1];
108+
Stop-AzureVM -Force -ServiceName $svcName -Name $vmNameList;
109+
Stop-AzureVM -Force -ServiceName $svcName -Name '*';
110+
Stop-AzureVM -Force -ServiceName $svcName -Name 'vm*';
111+
Stop-AzureVM -Force -ServiceName $svcName -Name 'vm*','test*';
112+
Stop-AzureVM -Force -ServiceName $svcName -VM $vmList[0];
113+
Stop-AzureVM -Force -ServiceName $svcName -VM $vmList[0],$vmList[1];
114+
Stop-AzureVM -Force -ServiceName $svcName -VM $vmList;
115+
116+
# Test Start
117+
Start-AzureVM -ServiceName $svcName -Name $vmNameList[0];
118+
Start-AzureVM -ServiceName $svcName -Name $vmNameList[0],$vmNameList[1];
119+
Start-AzureVM -ServiceName $svcName -Name $vmNameList;
120+
Start-AzureVM -ServiceName $svcName -Name '*';
121+
Start-AzureVM -ServiceName $svcName -Name 'vm*';
122+
Start-AzureVM -ServiceName $svcName -Name 'vm*','test*';
123+
Start-AzureVM -ServiceName $svcName -VM $vmList[0];
124+
Start-AzureVM -ServiceName $svcName -VM $vmList[0],$vmList[1];
125+
Start-AzureVM -ServiceName $svcName -VM $vmList;
126+
}
127+
catch
128+
{
129+
130+
}
131+
finally
132+
{
133+
# Cleanup
134+
Cleanup-CloudService $svcName;
135+
}
72136
}

src/Common/Commands.ScenarioTest/ServiceManagement/ScenarioTests.cs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,21 @@
1212
// limitations under the License.
1313
// ----------------------------------------------------------------------------------
1414

15-
using Microsoft.Azure.Common.Authentication;
16-
using Microsoft.Azure.Test;
17-
using System.Collections.Generic;
18-
using System.IO;
19-
using System.Linq;
2015
using Xunit;
2116

2217
namespace Microsoft.WindowsAzure.Commands.ScenarioTest
2318
{
2419
public partial class ServiceManagementTests
2520
{
21+
[Fact]
22+
[Trait(Category.Service, Category.ServiceManagement)]
23+
[Trait(Category.AcceptanceType, Category.CheckIn)]
24+
[Trait(Category.AcceptanceType, Category.BVT)]
25+
public void TestGetAzureVM()
26+
{
27+
this.RunPowerShellTest("Test-GetAzureVM");
28+
}
29+
2630
[Fact]
2731
[Trait(Category.Service, Category.ServiceManagement)]
2832
[Trait(Category.AcceptanceType, Category.CheckIn)]
@@ -40,5 +44,14 @@ public void RunServiceManagementCloudExceptionTests()
4044
{
4145
this.RunPowerShellTest("Run-ServiceManagementCloudExceptionTests");
4246
}
47+
48+
[Fact]
49+
[Trait(Category.Service, Category.ServiceManagement)]
50+
[Trait(Category.AcceptanceType, Category.CheckIn)]
51+
[Trait(Category.AcceptanceType, Category.BVT)]
52+
public void RunStartAndStopMultipleVirtualMachinesTest()
53+
{
54+
this.RunPowerShellTest("Run-StartAndStopMultipleVirtualMachinesTest");
55+
}
4356
}
4457
}

src/Common/Commands.ScenarioTest/ServiceManagement/ServiceManagementTests.cs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,33 @@
1414

1515
using Microsoft.Azure.Common.Authentication;
1616
using Microsoft.Azure.Test;
17+
using Microsoft.WindowsAzure.Management;
18+
using Microsoft.WindowsAzure.Management.Compute;
19+
using Microsoft.WindowsAzure.Management.Network;
20+
using Microsoft.WindowsAzure.Management.Storage;
1721
using System.Collections.Generic;
1822
using System.IO;
1923
using System.Linq;
20-
using Xunit;
2124

2225
namespace Microsoft.WindowsAzure.Commands.ScenarioTest
2326
{
2427
public partial class ServiceManagementTests
2528
{
2629
private EnvironmentSetupHelper helper = new EnvironmentSetupHelper();
2730

28-
[Fact]
29-
[Trait(Category.AcceptanceType, Category.CheckIn)]
30-
public void TestGetAzureVM()
31-
{
32-
this.RunPowerShellTest("Test-GetAzureVM");
33-
}
34-
3531
protected void SetupManagementClients()
3632
{
37-
helper.SetupSomeOfManagementClients();
33+
var rdfeTestFactory = new RDFETestEnvironmentFactory();
34+
var managementClient = TestBase.GetServiceClient<ManagementClient>(rdfeTestFactory);
35+
var computeClient = TestBase.GetServiceClient<ComputeManagementClient>(rdfeTestFactory);
36+
var networkClient = TestBase.GetServiceClient<NetworkManagementClient>(rdfeTestFactory);
37+
var storageClient = TestBase.GetServiceClient<StorageManagementClient>(rdfeTestFactory);
38+
39+
helper.SetupSomeOfManagementClients(
40+
managementClient,
41+
computeClient,
42+
networkClient,
43+
storageClient);
3844
}
3945

4046
protected void RunPowerShellTest(params string[] scripts)

src/Common/Commands.ScenarioTest/SessionRecords/Microsoft.WindowsAzure.Commands.ScenarioTest.ServiceManagementTests/RunStartAndStopMultipleVirtualMachinesTest.json

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

src/Common/Commands.ScenarioTest/packages.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<package id="Microsoft.WindowsAzure.ConfigurationManager" version="2.0.3" targetFramework="net45" />
1919
<package id="Microsoft.WindowsAzure.Management" version="4.1.1" targetFramework="net45" />
2020
<package id="Microsoft.WindowsAzure.Management.Compute" version="12.2.0-preview" targetFramework="net45" />
21+
<package id="Microsoft.WindowsAzure.Management.Network" version="7.0.0" targetFramework="net45" />
2122
<package id="Microsoft.WindowsAzure.Management.Storage" version="5.1.1" targetFramework="net45" />
2223
<package id="Microsoft.WindowsAzure.Management.WebSites" version="4.4.2-prerelease" targetFramework="net45" />
2324
<package id="Newtonsoft.Json" version="6.0.4" targetFramework="net45" />

src/ResourceManager/Compute/Commands.Compute/Common/ComputeClient.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919

2020
namespace Microsoft.Azure.Commands.Compute
2121
{
22-
public partial class ComputeClient
22+
public class ComputeClient
2323
{
24-
public IComputeManagementClient ComputeManagementClient { get; set; }
25-
24+
public IComputeManagementClient ComputeManagementClient { get; private set; }
25+
2626
public Action<string> VerboseLogger { get; set; }
2727

2828
public Action<string> ErrorLogger { get; set; }
@@ -32,9 +32,9 @@ public ComputeClient(AzureContext context)
3232
{
3333
}
3434

35-
public ComputeClient(IComputeManagementClient resourceManagementClient)
35+
public ComputeClient(IComputeManagementClient computeManagementClient)
3636
{
37-
ComputeManagementClient = resourceManagementClient;
37+
ComputeManagementClient = computeManagementClient;
3838
}
3939
}
4040
}

src/ResourceManager/ResourceManager/Commands.ResourceManager/Cmdlets/Components/LongRunningOperationHelper.cs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ internal LongRunningOperationHelper(string activityName, Func<ResourceManagerRes
7676
/// Waits for the operation to complete.
7777
/// </summary>
7878
/// <param name="operationResult">The operation result.</param>
79-
internal JToken WaitOnOperation(OperationResult operationResult)
79+
internal string WaitOnOperation(OperationResult operationResult)
8080
{
8181
// TODO: Re-factor this mess.
8282
this.ProgressTrackerObject.UpdateProgress("Starting", 0);
8383

8484
var trackingResult = this.HandleOperationResponse(operationResult, this.IsResourceCreateOrUpdate ? operationResult.OperationUri : operationResult.LocationUri);
8585

86-
while (trackingResult.ShouldWait)
86+
while (trackingResult != null && trackingResult.ShouldWait)
8787
{
8888
operationResult =
8989
this.GetResourcesClient()
@@ -161,10 +161,11 @@ private TrackingOperationResult HandleOperationResponse(OperationResult operatio
161161
/// <param name="operationResult">The result of the operation.</param>
162162
private TrackingOperationResult HandleCreateOrUpdateResponse(OperationResult operationResult)
163163
{
164-
var resource = operationResult.Value == null
165-
? null
166-
: operationResult.Value
167-
.ToObject<Resource<InsensitiveDictionary<JToken>>>(JsonExtensions.JsonObjectTypeSerializer);
164+
Resource<InsensitiveDictionary<JToken>> resource;
165+
if (!operationResult.Value.TryConvertTo<Resource<InsensitiveDictionary<JToken>>>(out resource))
166+
{
167+
return null;
168+
}
168169

169170
if(resource == null && operationResult.HttpStatusCode == HttpStatusCode.Created)
170171
{
@@ -444,11 +445,12 @@ private string GetAzureAsyncOperationState(OperationResult operationResult)
444445
/// <param name="operationResult">The operation result.</param>
445446
private static string GetResourceState(OperationResult operationResult)
446447
{
447-
var resource = operationResult.Value == null
448-
? null
449-
: operationResult.Value
450-
.ToObject<Resource<InsensitiveDictionary<JToken>>>(JsonExtensions.JsonObjectTypeSerializer);
451-
448+
Resource<InsensitiveDictionary<JToken>> resource;
449+
if (!operationResult.Value.TryConvertTo<Resource<InsensitiveDictionary<JToken>>>(out resource))
450+
{
451+
return null;
452+
}
453+
452454
if (resource == null)
453455
{
454456
return null;

src/ResourceManager/ResourceManager/Commands.ResourceManager/Cmdlets/Components/OperationResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,6 @@ public class OperationResult
5656
/// <summary>
5757
/// Gets or sets the value.
5858
/// </summary>
59-
public JObject Value { get; set; }
59+
public string Value { get; set; }
6060
}
6161
}

src/ResourceManager/ResourceManager/Commands.ResourceManager/Cmdlets/Components/ResourceIdUtility.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static string GetResourceId(string resourceId, string extensionResourceTy
4040
resourceIdBuilder.Append(ResourceIdUtility.ProcessResourceTypeAndName(resourceType: extensionResourceType, resourceName: extensionResourceName));
4141
}
4242

43-
return resourceId.ToString();
43+
return resourceIdBuilder.ToString();
4444
}
4545

4646
/// <summary>

src/ResourceManager/ResourceManager/Commands.ResourceManager/Cmdlets/Extensions/ErrorResponseMessageExceptionExtensions.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Extensions
1616
{
17+
using System;
1718
using System.Management.Automation;
1819
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Entities.ErrorResponses;
1920

@@ -31,5 +32,25 @@ internal static ErrorRecord ToErrorRecord(this ErrorResponseMessageException exc
3132
// TODO: Improve this.
3233
return new ErrorRecord(exception, exception.ErrorResponseMessage == null ? exception.HttpStatus.ToString() : exception.ErrorResponseMessage.Error.Code, ErrorCategory.CloseError, null);
3334
}
35+
36+
/// <summary>
37+
/// Converts <see cref="Exception"/> objects into <see cref="ErrorRecord"/>
38+
/// </summary>
39+
/// <param name="exception">The exception</param>
40+
internal static ErrorRecord ToErrorRecord(this Exception exception)
41+
{
42+
// TODO: Improve this.
43+
return new ErrorRecord(exception, exception.Message, ErrorCategory.CloseError, null);
44+
}
45+
46+
/// <summary>
47+
/// Converts <see cref="AggregateException"/> objects into <see cref="ErrorRecord"/>
48+
/// </summary>
49+
/// <param name="exception">The exception</param>
50+
internal static ErrorRecord ToErrorRecord(this AggregateException aggregateException)
51+
{
52+
// TODO: Improve this.
53+
return new ErrorRecord(aggregateException, aggregateException.ToString(), ErrorCategory.CloseError, null);
54+
}
3455
}
3556
}

src/ResourceManager/ResourceManager/Commands.ResourceManager/Cmdlets/Extensions/HttpMessageExtensions.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,35 @@ public static async Task<T> ReadContentAsJsonAsync<T>(this HttpResponseMessage m
5050
}
5151
}
5252
}
53+
54+
/// <summary>
55+
/// Reads the JSON content from the http response message.
56+
/// </summary>
57+
/// <typeparam name="T">The type of object contained in the JSON.</typeparam>
58+
/// <param name="message">The response message to be read.</param>
59+
/// <param name="rewindContentStream">Rewind content stream if set to true.</param>
60+
/// <returns>An object of type T instantiated from the response message's body.</returns>
61+
public static async Task<string> ReadContentAsStringAsync(this HttpResponseMessage message, bool rewindContentStream = false)
62+
{
63+
using (var stream = await message.Content
64+
.ReadAsStreamAsync()
65+
.ConfigureAwait(continueOnCapturedContext: false))
66+
using (var streamReader = new StreamReader(stream))
67+
{
68+
var streamPosition = stream.Position;
69+
try
70+
{
71+
72+
return streamReader.ReadToEnd();
73+
}
74+
finally
75+
{
76+
if (stream.CanSeek && streamPosition != stream.Position && rewindContentStream)
77+
{
78+
stream.Seek(streamPosition, SeekOrigin.Begin);
79+
}
80+
}
81+
}
82+
}
5383
}
5484
}

src/ResourceManager/ResourceManager/Commands.ResourceManager/Cmdlets/Extensions/JsonExtensions.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,39 @@ public static bool CanConvertTo<TType>(this JToken jobject)
147147
return jobject.TryConvertTo(out ignored);
148148
}
149149

150+
/// <summary>
151+
/// Checks if a conversion from the supplied <see cref="JToken"/> to a <typeparamref name="TType"/> can be made.
152+
/// </summary>
153+
/// <typeparam name="TType">The type to convert to.</typeparam>
154+
/// <param name="str">The string.</param>
155+
/// <param name="result">The result.</param>
156+
public static bool TryConvertTo<TType>(this string str, out TType result)
157+
{
158+
if (string.IsNullOrWhiteSpace(str))
159+
{
160+
result = default(TType);
161+
return true;
162+
}
163+
164+
try
165+
{
166+
result = str.FromJson<TType>();
167+
return !object.Equals(result, default(TType));
168+
}
169+
catch (FormatException)
170+
{
171+
}
172+
catch (ArgumentException)
173+
{
174+
}
175+
catch (JsonException)
176+
{
177+
}
178+
179+
result = default(TType);
180+
return false;
181+
}
182+
150183
/// <summary>
151184
/// Checks if a conversion from the supplied <see cref="JToken"/> to a <typeparamref name="TType"/> can be made.
152185
/// </summary>

0 commit comments

Comments
 (0)