Skip to content

Commit 69990a9

Browse files
author
Qinyuan Wan
committed
Merge branch 'dev' of https://github.com/Azure/azure-powershell into dev
2 parents 8348987 + 0c5eea9 commit 69990a9

File tree

157 files changed

+4144
-1944
lines changed

Some content is hidden

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

157 files changed

+4144
-1944
lines changed

src/Common/Commands.Common/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Common/Commands.Common/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,4 +1544,7 @@ Select Y to enable data collection [Y/N]:</value>
15441544
<data name="NoCurrentContextForDataCmdlet" xml:space="preserve">
15451545
<value>"There is no current context, please log in using Login-AzureRmAccount for Azure Resource Manager or Add-AzureAccount for Azure Service Management."</value>
15461546
</data>
1547+
<data name="NoSubscriptionFoundForTenant" xml:space="preserve">
1548+
<value>No subscriptions are associated with the logged in account in Azure Service Management (RDFE). This means that the logged in user is not an administrator or co-administrator for any account.\r\nDid you mean to execute Login-AzureRmAccount?</value>
1549+
</data>
15471550
</root>

src/ResourceManager/AzureBatch/Commands.Batch.Test/BatchTestHelpers.cs

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,90 @@ public static RequestInterceptor CreateFakeGetFileAndPropertiesFromComputeNodeRe
391391
return response;
392392
}
393393

394+
/// <summary>
395+
/// Builds a CloudPoolUsageMetricsResponse object. Note: The lengths of all three lists must be the same.
396+
/// </summary>
397+
public static AzureOperationResponse<IPage<ProxyModels.PoolUsageMetrics>, ProxyModels.PoolListPoolUsageMetricsHeaders> CreatePoolListUsageMetricsResponse(
398+
IEnumerable<string> poolIds,
399+
IEnumerable<DateTime> startTimes,
400+
IEnumerable<DateTime> endTimes)
401+
{
402+
var poolUsageList = new List<ProxyModels.PoolUsageMetrics>();
403+
404+
// Validate the lengths of the lists are equal
405+
if (!(poolIds.Count() == startTimes.Count() && startTimes.Count() == endTimes.Count()))
406+
{
407+
throw new ArgumentException("The lists length are not equal.");
408+
}
409+
410+
using (var startTimeEnumerator = startTimes.GetEnumerator())
411+
using (var endTimeEnumerator = endTimes.GetEnumerator())
412+
using (var poolIdEnumerator = poolIds.GetEnumerator())
413+
{
414+
while (startTimeEnumerator.MoveNext() && endTimeEnumerator.MoveNext() && poolIdEnumerator.MoveNext())
415+
{
416+
poolUsageList.Add(new ProxyModels.PoolUsageMetrics()
417+
{
418+
PoolId = poolIdEnumerator.Current,
419+
StartTime = startTimeEnumerator.Current,
420+
EndTime = endTimeEnumerator.Current
421+
});
422+
}
423+
}
424+
425+
var response = new AzureOperationResponse
426+
<IPage<ProxyModels.PoolUsageMetrics>, ProxyModels.PoolListPoolUsageMetricsHeaders>()
427+
{
428+
Response = new HttpResponseMessage(HttpStatusCode.OK),
429+
Body = new MockPagedEnumerable<ProxyModels.PoolUsageMetrics>(poolUsageList)
430+
};
431+
432+
return response;
433+
}
434+
435+
/// <summary>
436+
/// Builds a CloudPoolStatisticsResponse object. Note: Using avgCPUPercentage and startTime for validating if the pipeline return the correct values
437+
/// </summary>
438+
public static AzureOperationResponse<ProxyModels.PoolStatistics, ProxyModels.PoolGetAllPoolsLifetimeStatisticsHeaders> CreatePoolStatisticsResponse(
439+
double avgCPUPercentage,
440+
DateTime startTime)
441+
{
442+
var stats = new ProxyModels.PoolStatistics()
443+
{
444+
ResourceStats = new ProxyModels.ResourceStatistics() { AvgCPUPercentage = avgCPUPercentage },
445+
UsageStats = new ProxyModels.UsageStatistics() { StartTime = startTime }
446+
};
447+
448+
var response = new AzureOperationResponse
449+
<ProxyModels.PoolStatistics, ProxyModels.PoolGetAllPoolsLifetimeStatisticsHeaders>()
450+
{
451+
Body = stats,
452+
Response = new HttpResponseMessage(HttpStatusCode.Accepted)
453+
};
454+
455+
return response;
456+
}
457+
458+
/// <summary>
459+
/// Builds a CloudJobStatisticsResponse object.Note: Using startTime for validating if the pipeline return the correct values
460+
/// </summary>
461+
public static AzureOperationResponse<ProxyModels.JobStatistics, ProxyModels.JobGetAllJobsLifetimeStatisticsHeaders> CreateJobStatisticsResponse(DateTime startTime)
462+
{
463+
var stats = new ProxyModels.JobStatistics()
464+
{
465+
StartTime = startTime
466+
};
467+
468+
var response = new AzureOperationResponse
469+
<ProxyModels.JobStatistics, ProxyModels.JobGetAllJobsLifetimeStatisticsHeaders>()
470+
{
471+
Body = stats,
472+
Response = new HttpResponseMessage(HttpStatusCode.Accepted)
473+
};
474+
475+
return response;
476+
}
477+
394478
/// <summary>
395479
/// Builds a GetRemoteLoginSettingsResponse object
396480
/// </summary>

src/ResourceManager/AzureBatch/Commands.Batch.Test/Commands.Batch.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@
225225
<Compile Include="Jobs\DisableBatchJobCommandTests.cs" />
226226
<Compile Include="Jobs\EnableBatchJobCommandTests.cs" />
227227
<Compile Include="Jobs\GetBatchJobCommandTests.cs" />
228+
<Compile Include="Jobs\GetBatchJobStatisticsCommandTests.cs" />
228229
<Compile Include="Jobs\NewBatchJobCommandTests.cs" />
229230
<Compile Include="Jobs\RemoveBatchJobCommandTests.cs" />
230231
<Compile Include="Jobs\SetBatchJobCommandTests.cs" />
@@ -234,6 +235,8 @@
234235
<Compile Include="Pools\DisableBatchAutoScaleCommandTests.cs" />
235236
<Compile Include="Pools\EnableBatchAutoScaleCommandTests.cs" />
236237
<Compile Include="Pools\GetBatchPoolCommandTests.cs" />
238+
<Compile Include="Pools\GetBatchPoolStatisticsCommandTests.cs" />
239+
<Compile Include="Pools\GetBatchPoolUsageMetricsCommandTests.cs" />
237240
<Compile Include="Pools\NewBatchPoolCommandTests.cs" />
238241
<Compile Include="Pools\RemoveBatchPoolCommandTests.cs" />
239242
<Compile Include="Pools\SetBatchPoolCommandTests.cs" />
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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.Azure.Batch;
16+
using Microsoft.Azure.Batch.Protocol;
17+
using Microsoft.Azure.Commands.Batch.Models;
18+
using Microsoft.Rest.Azure;
19+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
20+
using Moq;
21+
using System;
22+
using System.Collections.Generic;
23+
using System.Linq;
24+
using System.Management.Automation;
25+
using System.Threading.Tasks;
26+
using Xunit;
27+
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;
28+
using ProxyModels = Microsoft.Azure.Batch.Protocol.Models;
29+
30+
namespace Microsoft.Azure.Commands.Batch.Test.Jobs
31+
{
32+
public class GetBatchJobStatisticsCommandTests : WindowsAzure.Commands.Test.Utilities.Common.RMTestBase
33+
{
34+
private GetBatchJobStatisticsCommand cmdlet;
35+
private Mock<BatchClient> batchClientMock;
36+
private Mock<ICommandRuntime> commandRuntimeMock;
37+
38+
public GetBatchJobStatisticsCommandTests(Xunit.Abstractions.ITestOutputHelper output)
39+
{
40+
ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output));
41+
batchClientMock = new Mock<BatchClient>();
42+
commandRuntimeMock = new Mock<ICommandRuntime>();
43+
cmdlet = new GetBatchJobStatisticsCommand()
44+
{
45+
CommandRuntime = commandRuntimeMock.Object,
46+
BatchClient = batchClientMock.Object,
47+
};
48+
}
49+
50+
[Fact]
51+
[Trait(Category.AcceptanceType, Category.CheckIn)]
52+
public void GetBatchJobStatisticsTest()
53+
{
54+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
55+
cmdlet.BatchContext = context;
56+
57+
DateTime startTime = DateTime.UtcNow;
58+
59+
AzureOperationResponse<
60+
ProxyModels.JobStatistics,
61+
ProxyModels.JobGetAllJobsLifetimeStatisticsHeaders> response =
62+
BatchTestHelpers.CreateJobStatisticsResponse(startTime);
63+
64+
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<
65+
ProxyModels.JobGetAllJobsLifetimeStatisticsOptions,
66+
AzureOperationResponse<ProxyModels.JobStatistics, ProxyModels.JobGetAllJobsLifetimeStatisticsHeaders>>(responseToUse: response);
67+
68+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
69+
70+
// Setup the cmdlet to write pipeline output to a variable that can be examined later
71+
PSJobStatistics statistics = null;
72+
commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny<PSJobStatistics>())).Callback<object>(c => statistics = (PSJobStatistics)c);
73+
74+
cmdlet.ExecuteCmdlet();
75+
76+
Assert.Equal(startTime, statistics.StartTime);
77+
}
78+
}
79+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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.Azure.Batch;
16+
using Microsoft.Azure.Batch.Protocol;
17+
using Microsoft.Azure.Commands.Batch.Models;
18+
using Microsoft.Rest.Azure;
19+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
20+
using Moq;
21+
using System;
22+
using System.Collections.Generic;
23+
using System.Linq;
24+
using System.Management.Automation;
25+
using System.Threading.Tasks;
26+
using Xunit;
27+
using BatchClient = Microsoft.Azure.Commands.Batch.Models.BatchClient;
28+
using ProxyModels = Microsoft.Azure.Batch.Protocol.Models;
29+
30+
namespace Microsoft.Azure.Commands.Batch.Test.Pools
31+
{
32+
public class GetBatchPoolStatisticsCommandTests : WindowsAzure.Commands.Test.Utilities.Common.RMTestBase
33+
{
34+
private GetBatchPoolStatisticsCommand cmdlet;
35+
private Mock<BatchClient> batchClientMock;
36+
private Mock<ICommandRuntime> commandRuntimeMock;
37+
38+
public GetBatchPoolStatisticsCommandTests(Xunit.Abstractions.ITestOutputHelper output)
39+
{
40+
ServiceManagemenet.Common.Models.XunitTracingInterceptor.AddToContext(new ServiceManagemenet.Common.Models.XunitTracingInterceptor(output));
41+
batchClientMock = new Mock<BatchClient>();
42+
commandRuntimeMock = new Mock<ICommandRuntime>();
43+
cmdlet = new GetBatchPoolStatisticsCommand()
44+
{
45+
CommandRuntime = commandRuntimeMock.Object,
46+
BatchClient = batchClientMock.Object,
47+
};
48+
}
49+
50+
[Fact]
51+
[Trait(Category.AcceptanceType, Category.CheckIn)]
52+
public void GetBatchPoolStatisticsTest()
53+
{
54+
BatchAccountContext context = BatchTestHelpers.CreateBatchContextWithKeys();
55+
cmdlet.BatchContext = context;
56+
57+
double avgCPUPercentage = 10;
58+
DateTime startTime = DateTime.UtcNow;
59+
60+
AzureOperationResponse<
61+
ProxyModels.PoolStatistics,
62+
ProxyModels.PoolGetAllPoolsLifetimeStatisticsHeaders> response =
63+
BatchTestHelpers.CreatePoolStatisticsResponse(avgCPUPercentage, startTime);
64+
65+
RequestInterceptor interceptor = BatchTestHelpers.CreateFakeServiceResponseInterceptor<
66+
ProxyModels.PoolGetAllPoolsLifetimeStatisticsOptions,
67+
AzureOperationResponse<ProxyModels.PoolStatistics, ProxyModels.PoolGetAllPoolsLifetimeStatisticsHeaders>>(responseToUse: response);
68+
69+
cmdlet.AdditionalBehaviors = new List<BatchClientBehavior>() { interceptor };
70+
71+
// Setup the cmdlet to write pipeline output to a variable that can be examined later
72+
PSPoolStatistics statistics = null;
73+
commandRuntimeMock.Setup(r => r.WriteObject(It.IsAny<PSPoolStatistics>())).Callback<object>(c => statistics = (PSPoolStatistics)c);
74+
75+
cmdlet.ExecuteCmdlet();
76+
77+
Assert.NotNull(statistics);
78+
Assert.Equal(startTime, statistics.UsageStatistics.StartTime);
79+
Assert.Equal(avgCPUPercentage, statistics.ResourceStatistics.AverageCpuPercentage);
80+
}
81+
}
82+
}

0 commit comments

Comments
 (0)