-
Notifications
You must be signed in to change notification settings - Fork 4k
Common Code Version of Compute Management Library (Issue #5512) #5709
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
b7cccfe
fdfcacf
91ab984
6bf4e57
f93ffbd
60b64cb
5e3309a
0d20a38
7b18865
fd04b6d
4c885dc
62fd1f7
4caf066
8bdbcb4
88bac37
5fcf1fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should go in the profile tests project - if it does not, you will need to create a lot of test infrastructure to make this execute like the other tests. |
||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Import Project="..\..\packages\xunit.core.2.3.1\build\xunit.core.props" Condition="Exists('..\..\packages\xunit.core.2.3.1\build\xunit.core.props')" /> | ||
<Import Project="..\..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\..\packages\xunit.runner.visualstudio.2.3.1\build\net20\xunit.runner.visualstudio.props')" /> | ||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProjectGuid>{8A4E00AA-5F65-4A95-B9B0-FEC06486555E}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>Microsoft.Azure.Commands.Common.Compute.Tests</RootNamespace> | ||
<AssemblyName>Microsoft.Azure.Commands.Common.Compute.Tests</AssemblyName> | ||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<NuGetPackageImportStamp> | ||
</NuGetPackageImportStamp> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug\</OutputPath> | ||
<DefineConstants>DEBUG;TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>pdbonly</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release\</OutputPath> | ||
<DefineConstants>TRACE</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory"> | ||
<HintPath>..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.28.3\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="Microsoft.Rest.ClientRuntime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> | ||
<SpecificVersion>False</SpecificVersion> | ||
<HintPath>..\..\packages\Microsoft.Rest.ClientRuntime.2.3.9\lib\net452\Microsoft.Rest.ClientRuntime.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="Microsoft.Rest.ClientRuntime.Azure, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> | ||
<SpecificVersion>False</SpecificVersion> | ||
<HintPath>..\..\packages\Microsoft.Rest.ClientRuntime.Azure.3.3.10\lib\net452\Microsoft.Rest.ClientRuntime.Azure.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Net.Http" /> | ||
<Reference Include="xunit.abstractions"> | ||
<HintPath>..\..\packages\xunit.abstractions.2.0.1\lib\net35\xunit.abstractions.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="xunit.assert, Version=2.3.1.3858, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL"> | ||
<SpecificVersion>False</SpecificVersion> | ||
<HintPath>..\..\packages\xunit.assert.2.3.1\lib\netstandard1.1\xunit.assert.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="xunit.core, Version=2.3.1.3858, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL"> | ||
<SpecificVersion>False</SpecificVersion> | ||
<HintPath>..\..\packages\xunit.extensibility.core.2.3.1\lib\netstandard1.1\xunit.core.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
<Reference Include="xunit.execution.desktop"> | ||
<HintPath>..\..\packages\xunit.extensibility.execution.2.3.1\lib\net452\xunit.execution.desktop.dll</HintPath> | ||
<Private>True</Private> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="CredentialManager.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="Version2016-04-preview\ComputeManagementClientShould.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Commands.Common.Compute\Commands.Common.Compute.csproj"> | ||
<Project>{f6d508d1-be2d-475d-aa0f-dfb5c615cc9d}</Project> | ||
<Name>Commands.Common.Compute</Name> | ||
</ProjectReference> | ||
<ProjectReference Include="..\Commands.ScenarioTests.Common\Commands.ScenarioTests.Common.csproj"> | ||
<Project>{C1BDA476-A5CC-4394-914D-48B0EC31A710}</Project> | ||
<Name>Commands.ScenarioTests.Common</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Analyzer Include="..\..\packages\xunit.analyzers.0.7.0\analyzers\dotnet\cs\xunit.analyzers.dll" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<Import Project="..\..\packages\xunit.core.2.3.1\build\xunit.core.targets" Condition="Exists('..\..\packages\xunit.core.2.3.1\build\xunit.core.targets')" /> | ||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> | ||
<PropertyGroup> | ||
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> | ||
</PropertyGroup> | ||
<Error Condition="!Exists('..\..\packages\xunit.core.2.3.1\build\xunit.core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\xunit.core.2.3.1\build\xunit.core.targets'))" /> | ||
</Target> | ||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it. | ||
Other similar extension points exist, see Microsoft.Common.targets. | ||
<Target Name="BeforeBuild"> | ||
</Target> | ||
<Target Name="AfterBuild"> | ||
</Target> | ||
--> | ||
</Project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// Copyright Microsoft Corporation | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// ---------------------------------------------------------------------------------- | ||
|
||
namespace Microsoft.Azure.Commands.Common.Compute.Tests | ||
{ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using Microsoft.IdentityModel.Clients.ActiveDirectory; | ||
using Microsoft.Rest; | ||
|
||
class CredentialManager | ||
{ | ||
protected CredentialManager() { } | ||
|
||
private const string ServicePrincipalEnvVariableName = "AZURE_SERVICE_PRINCIPAL"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already have a test infrastructure that does this -this will make it essentially impossible to run these tests on ci without setting up this environment variable everywhere. Let's dicuss thet best way to bring these tests inline. |
||
|
||
private static readonly string UserId = "UserId".ToLower(); | ||
private static readonly string Password = "Password".ToLower(); | ||
private static readonly string AadTenant = "AADTenant".ToLower(); | ||
private static readonly string Subscription = "SubscriptionId".ToLower(); | ||
private const string AuthUrl = "https://login.microsoftonline.com/"; | ||
private const string BaseUrl = "https://management.azure.com/"; | ||
|
||
public string ApplicationId { get; private set; } | ||
public string ApplicationSecret { get; private set; } | ||
public string TenantId { get; private set; } | ||
public string SubscriptionId { get; private set; } | ||
|
||
public TokenCredentials TokenCredentials | ||
{ | ||
get | ||
{ | ||
var clientCredential = new ClientCredential(ApplicationId, ApplicationSecret); | ||
var context = new AuthenticationContext(Path.Combine(AuthUrl, TenantId)); | ||
var result = context.AcquireTokenAsync(BaseUrl, clientCredential); | ||
|
||
if (result == null) throw new InvalidOperationException("Failed to obtain the token"); | ||
|
||
return new TokenCredentials(result.Result.AccessToken); | ||
} | ||
} | ||
|
||
public static CredentialManager FromServicePrincipalEnvVariable(string envVariableName = ServicePrincipalEnvVariableName) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should likely remove this file. |
||
{ | ||
//AZURE_SERVICE_PRINCIPAL = UserId =< UserGuid >; Password =< Password >; AADTenant =< TenantGuid >; SubscriptionId =< SubscriptionId > | ||
var spString = Environment.GetEnvironmentVariable(envVariableName); | ||
|
||
if (spString == null) throw new ArgumentNullException($"Failed to get environment variable {envVariableName}"); | ||
|
||
var sp = new Dictionary<string, string>(); | ||
var pairs = spString.Trim().Split(';'); | ||
foreach (var pair in pairs) | ||
{ | ||
var keyVal = pair.Trim().Split(new[] { '=' }, 2); | ||
if (keyVal.Length < 2) throw new ArgumentException($"Failed to parse {envVariableName}"); | ||
sp.Add(keyVal[0].Trim().ToLower(), keyVal[1].Trim()); | ||
} | ||
|
||
if (!sp.ContainsKey(UserId.ToLower())) throw new ArgumentException($"Failed to find {UserId} in {envVariableName}"); | ||
if (!sp.ContainsKey(Password.ToLower())) throw new ArgumentException($"Failed to find {Password} in {envVariableName}"); | ||
if (!sp.ContainsKey(AadTenant.ToLower())) throw new ArgumentException($"Failed to find {AadTenant} in {envVariableName}"); | ||
if (!sp.ContainsKey(Subscription.ToLower())) throw new ArgumentException($"Failed to find {Subscription} in {envVariableName}"); | ||
|
||
var credentialManager = new CredentialManager | ||
{ | ||
ApplicationId = sp[UserId], | ||
ApplicationSecret = sp[Password], | ||
TenantId = sp[AadTenant], | ||
SubscriptionId = sp[Subscription] | ||
}; | ||
|
||
return credentialManager; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System.Reflection; | ||
using System.Runtime.CompilerServices; | ||
using System.Runtime.InteropServices; | ||
|
||
// General Information about an assembly is controlled through the following | ||
// set of attributes. Change these attribute values to modify the information | ||
// associated with an assembly. | ||
[assembly: AssemblyTitle("Commands.Common.Compute.Tests")] | ||
[assembly: AssemblyDescription("")] | ||
[assembly: AssemblyConfiguration("")] | ||
[assembly: AssemblyCompany("HP Inc.")] | ||
[assembly: AssemblyProduct("Commands.Common.Compute.Tests")] | ||
[assembly: AssemblyCopyright("Copyright © HP Inc. 2018")] | ||
[assembly: AssemblyTrademark("")] | ||
[assembly: AssemblyCulture("")] | ||
|
||
// Setting ComVisible to false makes the types in this assembly not visible | ||
// to COM components. If you need to access a type in this assembly from | ||
// COM, set the ComVisible attribute to true on that type. | ||
[assembly: ComVisible(false)] | ||
|
||
// The following GUID is for the ID of the typelib if this project is exposed to COM | ||
[assembly: Guid("8a4e00aa-5f65-4a95-b9b0-fec06486555e")] | ||
|
||
// Version information for an assembly consists of the following four values: | ||
// | ||
// Major Version | ||
// Minor Version | ||
// Build Number | ||
// Revision | ||
// | ||
// You can specify all the values or you can default the Build and Revision Numbers | ||
// by using the '*' as shown below: | ||
// [assembly: AssemblyVersion("1.0.*")] | ||
[assembly: AssemblyVersion("1.0.0.0")] | ||
[assembly: AssemblyFileVersion("1.0.0.0")] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// | ||
// Copyright Microsoft Corporation | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// ---------------------------------------------------------------------------------- | ||
|
||
|
||
|
||
namespace Microsoft.Azure.Commands.Common.Compute.Tests | ||
{ | ||
using Compute.Version2016_04_preview; | ||
using Microsoft.WindowsAzure.Commands.ScenarioTest; | ||
using Xunit; | ||
using System.Linq; | ||
|
||
namespace Version2016_04_preview | ||
{ | ||
public class ComputeManagementClientShould | ||
{ | ||
private IComputeManagementClient Client {get;} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These all need to be check-in tests. Let's discuss what to do with this per the above. |
||
|
||
public ComputeManagementClientShould() | ||
{ | ||
var credManager = CredentialManager.FromServicePrincipalEnvVariable(); | ||
Client = new ComputeManagementClient(credManager.TokenCredentials) | ||
{ | ||
SubscriptionId = credManager.SubscriptionId | ||
}; | ||
} | ||
|
||
[Fact] | ||
[Trait(Category.RunType, Category.LiveOnly)] | ||
public void ListVirtualMachine() | ||
{ | ||
var vmClient = Client.VirtualMachines; | ||
var vms = vmClient.ListAll().ToList(); | ||
Assert.True(vms.Count > 0); | ||
} | ||
|
||
[Fact] | ||
[Trait(Category.RunType, Category.LiveOnly)] | ||
public void ListVirtualMachineSizes() | ||
{ | ||
var vmSizeClient = Client.VirtualMachineSizes; | ||
var vmSizes = vmSizeClient.List("WestUs").ToList(); | ||
Assert.True(vmSizes.Count > 0); | ||
} | ||
|
||
[Fact] | ||
[Trait(Category.RunType, Category.LiveOnly)] | ||
public void ListVirtualMachineImagePublishers() | ||
{ | ||
var vmImagesClient = Client.VirtualMachineImages; | ||
var vmImagePublisers = vmImagesClient.ListPublishers("WestUs").ToList(); | ||
Assert.True(vmImagePublisers.Count > 0); | ||
} | ||
|
||
[Fact] | ||
[Trait(Category.RunType, Category.LiveOnly)] | ||
public void ListDisks() | ||
{ | ||
var disksClient = Client.Disks; | ||
var disks = disksClient.List().ToList(); | ||
Assert.True(disks.Count > 0); | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<packages> | ||
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="2.28.3" targetFramework="net452" /> | ||
<package id="xunit" version="2.3.1" targetFramework="net452" /> | ||
<package id="xunit.abstractions" version="2.0.1" targetFramework="net452" /> | ||
<package id="xunit.analyzers" version="0.7.0" targetFramework="net452" /> | ||
<package id="xunit.assert" version="2.3.1" targetFramework="net452" /> | ||
<package id="xunit.core" version="2.3.1" targetFramework="net452" /> | ||
<package id="xunit.extensibility.core" version="2.3.1" targetFramework="net452" /> | ||
<package id="xunit.extensibility.execution" version="2.3.1" targetFramework="net452" /> | ||
</packages> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netcoreapp2.0</TargetFramework> | ||
<AssemblyName>Microsoft.Azure.Commands.Common.Compute</AssemblyName> | ||
<RootNamespace>Microsoft.Azure.Commands.Common.Compute</RootNamespace> | ||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\ResourceManager\Common\Commands.ResourceManager.Common\Common.ResourceManager.Netcore.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cormacpayne
It's not deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vladimir-shcherbakov Commands.Common.Compute.Netcore is being added, but Commands.Compute.Netcore appears to be being removed