Skip to content

Commit c86c954

Browse files
committed
Merge pull request #1500 from huangpf/clu
AzureRT PR - CLU Compute Cmdlets (alpha)
2 parents 240c89e + cf66893 commit c86c954

File tree

109 files changed

+26249
-2
lines changed

Some content is hidden

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

109 files changed

+26249
-2
lines changed

src/CLU/CLUCoreCLR.sln

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.CLU", "Microsoft.
3939
EndProject
4040
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.CLU.Test", "Microsoft.CLU.Test\Microsoft.CLU.Test.xproj", "{91422B55-28A5-48DE-BCA0-30C3E30FFB1C}"
4141
EndProject
42+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Azure.Commands.Compute", "Microsoft.Azure.Commands.Compute\Microsoft.Azure.Commands.Compute.xproj", "{04F9968A-5662-4508-BEE2-31F56848FCBA}"
43+
ProjectSection(ProjectDependencies) = postProject
44+
{99B1290D-A073-4907-8018-51C714431778} = {99B1290D-A073-4907-8018-51C714431778}
45+
{3910613E-4ED2-49E2-8CCF-966D586665AC} = {3910613E-4ED2-49E2-8CCF-966D586665AC}
46+
{81A48E48-89A7-4B93-8207-4F8FA6DC251B} = {81A48E48-89A7-4B93-8207-4F8FA6DC251B}
47+
{45B05B68-516F-4D74-897F-56D12894946C} = {45B05B68-516F-4D74-897F-56D12894946C}
48+
EndProjectSection
49+
EndProject
50+
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.Azure.Commands.Compute.Test", "Microsoft.Azure.Commands.Compute.Test\Microsoft.Azure.Commands.Compute.Test.xproj", "{13C34370-51A4-4726-81B8-BE0996FC9CFF}"
51+
ProjectSection(ProjectDependencies) = postProject
52+
{3910613E-4ED2-49E2-8CCF-966D586665AC} = {3910613E-4ED2-49E2-8CCF-966D586665AC}
53+
{81A48E48-89A7-4B93-8207-4F8FA6DC251B} = {81A48E48-89A7-4B93-8207-4F8FA6DC251B}
54+
{A9CC2879-D45D-4DCB-A405-6EEDB749B15F} = {A9CC2879-D45D-4DCB-A405-6EEDB749B15F}
55+
{04F9968A-5662-4508-BEE2-31F56848FCBA} = {04F9968A-5662-4508-BEE2-31F56848FCBA}
56+
EndProjectSection
57+
EndProject
4258
Global
4359
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4460
Debug|Any CPU = Debug|Any CPU
@@ -117,6 +133,14 @@ Global
117133
{91422B55-28A5-48DE-BCA0-30C3E30FFB1C}.Debug|Any CPU.Build.0 = Debug|Any CPU
118134
{91422B55-28A5-48DE-BCA0-30C3E30FFB1C}.Release|Any CPU.ActiveCfg = Release|Any CPU
119135
{91422B55-28A5-48DE-BCA0-30C3E30FFB1C}.Release|Any CPU.Build.0 = Release|Any CPU
136+
{04F9968A-5662-4508-BEE2-31F56848FCBA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
137+
{04F9968A-5662-4508-BEE2-31F56848FCBA}.Debug|Any CPU.Build.0 = Debug|Any CPU
138+
{04F9968A-5662-4508-BEE2-31F56848FCBA}.Release|Any CPU.ActiveCfg = Release|Any CPU
139+
{04F9968A-5662-4508-BEE2-31F56848FCBA}.Release|Any CPU.Build.0 = Release|Any CPU
140+
{13C34370-51A4-4726-81B8-BE0996FC9CFF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
141+
{13C34370-51A4-4726-81B8-BE0996FC9CFF}.Debug|Any CPU.Build.0 = Debug|Any CPU
142+
{13C34370-51A4-4726-81B8-BE0996FC9CFF}.Release|Any CPU.ActiveCfg = Release|Any CPU
143+
{13C34370-51A4-4726-81B8-BE0996FC9CFF}.Release|Any CPU.Build.0 = Release|Any CPU
120144
EndGlobalSection
121145
GlobalSection(SolutionProperties) = preSolution
122146
HideSolutionNode = FALSE

src/CLU/Commands.ScenarioTests.ResourceManager.Common/PSCmdletExtensions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,11 @@ public static void SetCommandRuntimeMock(this PSCmdlet cmdlet, ICommandRuntime v
5353
var property = GetInternalProperty("CommandRuntime", typeof (ICommandRuntime));
5454
property.SetValue(cmdlet, value);
5555
}
56+
57+
public static ICommandRuntime GetCommandRuntimeMock(this PSCmdlet cmdlet)
58+
{
59+
var property = GetInternalProperty("CommandRuntime", typeof(ICommandRuntime));
60+
return (ICommandRuntime)property.GetValue(cmdlet);
61+
}
5662
}
5763
}
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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.Commands.Compute;
16+
using Microsoft.Azure.Commands.ScenarioTest;
17+
using Microsoft.Azure.Commands.Compute.ScenarioTest;
18+
using Microsoft.Azure.Management.Authorization;
19+
using Microsoft.Azure.Management.Compute;
20+
using Microsoft.Azure.Management.Compute.Models;
21+
using Microsoft.Rest.Azure;
22+
using Moq;
23+
using Newtonsoft.Json;
24+
using System;
25+
using System.Collections.Generic;
26+
using System.Linq;
27+
using System.Management.Automation;
28+
using System.Threading;
29+
using System.Threading.Tasks;
30+
using Xunit;
31+
using Microsoft.Azure.Commands.Common.Test.Mocks;
32+
using Microsoft.Azure.Commands.Common.Authentication.Models;
33+
using Microsoft.Azure.Commands.Utilities.Common;
34+
35+
namespace Microsoft.Azure.Commands.Compute.Test
36+
{
37+
public class GetAzureVMSizeCommandTests
38+
{
39+
private MemoryDataStore _dataStore;
40+
private MockCommandRuntime _commandRuntimeMock;
41+
42+
private Mock<IVirtualMachineSizesOperations> vmSizesMock;
43+
44+
public GetAzureVMSizeCommandTests()
45+
{
46+
_dataStore = new MemoryDataStore();
47+
_commandRuntimeMock = new MockCommandRuntime();
48+
}
49+
private IPage<T> GetPagableType<T>(List<T> collection)
50+
{
51+
var pagableResult = new Page<T>();
52+
pagableResult.SetItemValue<T>(collection);
53+
return pagableResult;
54+
}
55+
56+
private void SetupListForVirtualMachineSizeAsync(string name, List<VirtualMachineSize> result)
57+
{
58+
vmSizesMock.Setup(f => f.ListWithHttpMessagesAsync(name, null, new CancellationToken()))
59+
.Returns(Task.Factory.StartNew(() =>
60+
new AzureOperationResponse<IPage<VirtualMachineSize>>
61+
{
62+
Body = GetPagableType(result)
63+
}));
64+
}
65+
66+
[Fact]
67+
[Trait(Category.AcceptanceType, Category.CheckIn)]
68+
public void GetVirtualMachineSizesFromLocation()
69+
{
70+
var computeManagementClientMock = new Mock<IComputeManagementClient>();
71+
vmSizesMock = new Mock<IVirtualMachineSizesOperations>();
72+
computeManagementClientMock.Setup(f => f.VirtualMachineSizes).Returns(vmSizesMock.Object);
73+
var vmSizeList = new List<VirtualMachineSize>
74+
{
75+
new VirtualMachineSize
76+
{
77+
Name = "1",
78+
MaxDataDiskCount = 1,
79+
MemoryInMB = 1,
80+
NumberOfCores = 1,
81+
OsDiskSizeInMB = 1,
82+
ResourceDiskSizeInMB = 1
83+
},
84+
new VirtualMachineSize
85+
{
86+
Name = "2",
87+
MaxDataDiskCount = 2,
88+
MemoryInMB = 2,
89+
NumberOfCores = 2,
90+
OsDiskSizeInMB = 2,
91+
ResourceDiskSizeInMB = 2
92+
}
93+
};
94+
SetupListForVirtualMachineSizeAsync("westus", vmSizeList);
95+
96+
var progressLoggerMock = new Mock<Action<string>>();
97+
var errorLoggerMock = new Mock<Action<string>>();
98+
var computeClient = new ComputeClient(computeManagementClientMock.Object)
99+
{
100+
VerboseLogger = progressLoggerMock.Object,
101+
ErrorLogger = errorLoggerMock.Object
102+
};
103+
104+
var profile = new AzureRMProfile(_dataStore);
105+
profile.Environments.Add("foo", AzureEnvironment.PublicEnvironments.Values.FirstOrDefault());
106+
profile.Context = new AzureContext(new AzureSubscription(), new AzureAccount(), profile.Environments["foo"]);
107+
GetAzureVMSizeCommand cmdlet = new GetAzureVMSizeCommand
108+
{
109+
ComputeClient = computeClient,
110+
Location = "westus"
111+
};
112+
cmdlet.DataStore = _dataStore;
113+
cmdlet.SetCommandRuntimeMock(_commandRuntimeMock);
114+
cmdlet.DefaultProfile = profile;
115+
116+
// Act
117+
cmdlet.InvokeBeginProcessing();
118+
cmdlet.ExecuteCmdlet();
119+
cmdlet.InvokeEndProcessing();
120+
121+
var runtime = cmdlet.GetCommandRuntimeMock() as MockCommandRuntime;
122+
Assert.True(runtime.OutputPipeline.Count == vmSizeList.Count);
123+
for (int i = 0; i < runtime.OutputPipeline.Count; i++)
124+
{
125+
var item = runtime.OutputPipeline[i] as VirtualMachineSize;
126+
Assert.True(item.Name == vmSizeList[i].Name);
127+
Assert.True(item.MaxDataDiskCount == vmSizeList[i].MaxDataDiskCount);
128+
Assert.True(item.MemoryInMB == vmSizeList[i].MemoryInMB);
129+
Assert.True(item.NumberOfCores == vmSizeList[i].NumberOfCores);
130+
Assert.True(item.OsDiskSizeInMB == vmSizeList[i].OsDiskSizeInMB);
131+
Assert.True(item.ResourceDiskSizeInMB == vmSizeList[i].ResourceDiskSizeInMB);
132+
}
133+
134+
return;
135+
}
136+
}
137+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0.23107" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0.23107</VisualStudioVersion>
5+
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
6+
</PropertyGroup>
7+
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
8+
<PropertyGroup Label="Globals">
9+
<ProjectGuid>13c34370-51a4-4726-81b8-be0996fc9cff</ProjectGuid>
10+
<RootNamespace>Microsoft.Azure.Commands.Compute.Test</RootNamespace>
11+
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
12+
<OutputPath Condition="'$(OutputPath)'=='' ">..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
13+
</PropertyGroup>
14+
<PropertyGroup>
15+
<SchemaVersion>2.0</SchemaVersion>
16+
</PropertyGroup>
17+
<ItemGroup>
18+
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
19+
</ItemGroup>
20+
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
21+
</Project>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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.Management.Compute.Models;
16+
using System.Collections.Generic;
17+
using System.Reflection;
18+
19+
namespace Microsoft.Azure.Commands.Compute.ScenarioTest
20+
{
21+
public static class PageExtensions
22+
{
23+
public static void SetItemValue<T> (this Page<T> pagableObj, List<T> collection) {
24+
var property = typeof(Page<T>).GetProperty("Items", BindingFlags.Instance | BindingFlags.NonPublic);
25+
property.SetValue(pagableObj, collection);
26+
}
27+
}
28+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{
2+
"version": "1.0.0-*",
3+
"description": "Tests for Compute Resource Provider Cmdlets",
4+
"authors": [ "huangpf", "markcowl", "hovsepm" ],
5+
"tags": [ "" ],
6+
"projectUrl": "",
7+
"licenseUrl": "",
8+
"frameworks": {
9+
"dnxcore50": {
10+
"dependencies": {
11+
"Microsoft.NETCore": "5.0.1-beta-23516",
12+
"Microsoft.NETCore.Platforms": "1.0.1-beta-23516",
13+
"Microsoft.CSharp": "4.0.1-beta-23516"
14+
}
15+
}
16+
},
17+
"dependencies": {
18+
"AutoMapper": "4.1.1",
19+
"Commands.Common": "",
20+
"Commands.Common.Authentication": "",
21+
"Commands.Common.Storage": "",
22+
"Commands.ResourceManager.Common": "",
23+
"Commands.ResourceManager.Cmdlets": "",
24+
"Commands.ScenarioTests.ResourceManager.Common": "",
25+
"Microsoft.Azure.Commands.Profile": "",
26+
"Microsoft.Azure.Commands.Resources": "",
27+
"Microsoft.Azure.Management.Compute": "11.0.0-prerelease",
28+
"Microsoft.Azure.Management.Network": "3.0.3-preview",
29+
"Microsoft.Azure.Management.Storage": "4.0.0-preview",
30+
"Microsoft.IdentityModel.Clients.ActiveDirectory": "3.6.212041202-alpha",
31+
"Microsoft.Rest.ClientRuntime": "1.8.0",
32+
"Newtonsoft.Json": "7.0.1",
33+
"System.Collections": "4.0.11-beta-23516",
34+
"System.Collections.Concurrent": "4.0.11-beta-23516",
35+
"System.Diagnostics.Tools": "4.0.1-beta-23516",
36+
"System.Diagnostics.TraceSource": "4.0.0-beta-23516",
37+
"System.Diagnostics.Tracing": "4.0.21-beta-23516",
38+
"System.IO": "4.0.11-beta-23516",
39+
"System.IO.FileSystem": "4.0.1-beta-23516",
40+
"System.Net.Http": "4.0.1-beta-23516",
41+
"System.Net.WebHeaderCollection": "4.0.1-beta-23516",
42+
"System.Reflection": "4.1.0-beta-23516",
43+
"System.Reflection.Extensions": "4.0.1-beta-23516",
44+
"System.Reflection.Primitives": "4.0.1-beta-23516",
45+
"System.Reflection.TypeExtensions": "4.1.0-beta-23516",
46+
"System.Runtime": "4.0.21-beta-23516",
47+
"System.Runtime.Extensions": "4.0.11-beta-23516",
48+
"System.Runtime.Serialization.Json": "4.0.1-beta-23516",
49+
"System.Runtime.Serialization.Primitives": "4.1.0-beta-23516",
50+
"System.Runtime.Serialization.Xml": "4.1.0-beta-23516",
51+
"System.Security.Cryptography.Algorithms": "4.0.0-beta-23516",
52+
"System.Security.Cryptography.X509Certificates": "4.0.0-beta-23516",
53+
"System.Text.Encoding": "4.0.11-beta-23516",
54+
"System.Text.Encoding.Extensions": "4.0.11-beta-23516",
55+
"System.Threading": "4.0.11-beta-23516",
56+
"System.Threading.Tasks": "4.0.11-beta-23516",
57+
"System.Threading.Thread": "4.0.0-beta-23516",
58+
"System.Xml.ReaderWriter": "4.0.11-beta-23516",
59+
"xunit": "2.1.0",
60+
"xunit.assert": "2.1.0",
61+
"xunit.runner.dnx": "2.1.0-rc1-build204",
62+
"moq.netcore": "4.4.0-beta8",
63+
"Microsoft.CLU": "1.0.0",
64+
"System.Linq": "4.0.1-beta-23409",
65+
"System.Xml.XmlDocument": "4.0.1-beta-23516",
66+
"System.Xml.XPath.XmlDocument": "4.0.1-beta-23516",
67+
"WindowsAzure.Storage": "6.1.1-preview",
68+
"Microsoft.Azure.Commands.Compute": "1.0.0-*"
69+
},
70+
"commands": {
71+
"test": "xunit.runner.dnx"
72+
}
73+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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.Management.Compute;
16+
17+
namespace Microsoft.Azure.Commands.Compute
18+
{
19+
public abstract class AvailabilitySetBaseCmdlet : ComputeClientBaseCmdlet
20+
{
21+
public IAvailabilitySetsOperations AvailabilitySetClient
22+
{
23+
get
24+
{
25+
return ComputeClient.ComputeManagementClient.AvailabilitySets;
26+
}
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)