-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Container instances/groups management client #3580
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
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,107 @@ | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using Microsoft.Azure.Management.ContainerInstance; | ||
| using Microsoft.Azure.Management.ContainerInstance.Models; | ||
| using Microsoft.Azure.Management.ResourceManager.Models; | ||
| using Microsoft.Rest.Azure; | ||
| using Xunit; | ||
|
|
||
| namespace ContainerInstance.Tests | ||
| { | ||
| public class ContainerGroupScenarioTests | ||
| { | ||
| [Fact] | ||
| public void ContainerGroupCreateGetDeleteTests() | ||
| { | ||
| using (TestContext context = new TestContext(this)) | ||
| { | ||
| string containerInstanceLocation = "westus"; | ||
|
|
||
| ResourceGroup resourceGroup = context.CreateResourceGroup("containergroupcrd-", containerInstanceLocation); | ||
| ContainerInstanceManagementClient containerClient = context.GetClient<ContainerInstanceManagementClient>(); | ||
|
|
||
| string containerGroupName = context.GenerateName("containergroup"); | ||
| string containerOsType = "Linux"; | ||
|
Contributor
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.
Use |
||
|
|
||
| string containerName = "test1"; | ||
|
Contributor
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.
Can you also use |
||
| string containerImage = "nginx"; | ||
| int containerPort = 80; | ||
| double containerCpu = 1; | ||
| double containerMemoryInGB = 1.5; | ||
|
|
||
| // Add a containergroup with a container | ||
| ContainerGroup createdContainerGroup = containerClient.ContainerGroups.CreateOrUpdate(resourceGroup.Name, containerGroupName, new ContainerGroup | ||
| { | ||
| Location = resourceGroup.Location, | ||
| OsType = containerOsType, | ||
| Containers = new List<Container> | ||
| { | ||
| new Container | ||
| { | ||
| Name = containerName, | ||
| Image = containerImage, | ||
| Ports = new List<ContainerPort> | ||
| { | ||
| new ContainerPort(containerPort) | ||
| }, | ||
| Resources = new ResourceRequirements | ||
| { | ||
| Requests = new ResourceRequests | ||
| { | ||
| Cpu = containerCpu, | ||
| MemoryInGB = containerMemoryInGB | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }); | ||
| Assert.NotNull(createdContainerGroup); | ||
| Assert.Equal(containerGroupName, createdContainerGroup.Name); | ||
| Assert.Equal(containerOsType, createdContainerGroup.OsType); | ||
| Assert.Equal(1, createdContainerGroup.Containers.Count); | ||
|
Contributor
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. Also verify the there is public IP address assigned. |
||
|
|
||
| Container createdContainer = createdContainerGroup.Containers.First(); | ||
| Assert.Equal(containerName, createdContainer.Name); | ||
| Assert.Equal(containerImage, createdContainer.Image); | ||
| Assert.Equal(1, createdContainer.Ports.Count); | ||
| Assert.Equal(containerPort, createdContainer.Ports.First().Port); | ||
| Assert.Equal(containerCpu, createdContainer.Resources.Requests.Cpu); | ||
| Assert.Equal(containerMemoryInGB, createdContainer.Resources.Requests.MemoryInGB); | ||
|
|
||
| // Wait till the container group is ready before proceeding | ||
| ContainerGroupUtilities.WaitTillProvisioningStateSucceeded(containerClient, resourceGroup.Name, containerGroupName); | ||
|
Contributor
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. Not really necessary. You can call get or list before reach succeeded provisioning state. |
||
|
|
||
| string containerGroupID = createdContainerGroup.Id; | ||
|
|
||
| // Get the container group | ||
| ContainerGroup getContainerGroup = containerClient.ContainerGroups.Get(resourceGroup.Name, containerGroupName); | ||
| Assert.NotNull(createdContainerGroup); | ||
| Assert.Equal(containerGroupName, getContainerGroup.Name); | ||
| Assert.Equal(containerOsType, getContainerGroup.OsType); | ||
|
|
||
| Container getContainer = getContainerGroup.Containers.First(); | ||
| Assert.Equal(containerName, getContainer.Name); | ||
| Assert.Equal(containerImage, getContainer.Image); | ||
| Assert.Equal(1, getContainer.Ports.Count); | ||
| Assert.Equal(containerPort, getContainer.Ports.First().Port); | ||
| Assert.Equal(containerCpu, getContainer.Resources.Requests.Cpu); | ||
| Assert.Equal(containerMemoryInGB, getContainer.Resources.Requests.MemoryInGB); | ||
|
Contributor
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. Wrap all the assertion into a helper method. |
||
|
|
||
| // List the container group within the resource group | ||
| IPage<ContainerGroup> listRgContainerGroup = containerClient.ContainerGroups.ListByResourceGroup(resourceGroup.Name); | ||
| Assert.NotNull(listRgContainerGroup); | ||
| Assert.Equal(1, listRgContainerGroup.Count()); | ||
| Assert.Equal(containerGroupName, listRgContainerGroup.First().Name); | ||
|
|
||
| // List the container group within the subscription | ||
| IPage<ContainerGroup> listSubContainerGroup = containerClient.ContainerGroups.List(); | ||
| Assert.NotNull(listRgContainerGroup); | ||
| Assert.True(listRgContainerGroup.Count() >= 1); | ||
| Assert.True(listRgContainerGroup.Any(x => containerGroupID.Equals(x?.Id))); | ||
|
Contributor
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. Create a test case in which you create 2 container group. When listing all, you should get both. When listing by resource group, you should only get one. |
||
|
|
||
| // Delete the container group | ||
| containerClient.ContainerGroups.Delete(resourceGroup.Name, containerGroupName); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <Import Project="$([MSBuild]::GetPathOfFileAbove('AzSdk.test.reference.props'))" /> | ||
| <PropertyGroup> | ||
| <PackageId>ContainerInstance.Tests</PackageId> | ||
| <AssemblyName>ContainerInstance.Tests</AssemblyName> | ||
| <VersionPrefix>1.0.0-preview</VersionPrefix> | ||
| </PropertyGroup> | ||
| <PropertyGroup> | ||
| <TargetFrameworks>netcoreapp1.1</TargetFrameworks> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <Compile Remove="Utilities\ContainerInstanceTestUtilities.cs" /> | ||
|
Contributor
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. @ScottHolden this is not needed. I know VS might have added it, can you remove it. VS will include code files by default in all sub directories. |
||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.Azure.KeyVault" Version="2.0.6" /> | ||
| <PackageReference Include="Microsoft.Azure.Management.KeyVault" Version="2.2.0-preview" /> | ||
| <PackageReference Include="Microsoft.Azure.Management.Network" Version="11.1.0-preview" /> | ||
| <PackageReference Include="Microsoft.Azure.Management.RecoveryServices" Version="4.2.0-preview" /> | ||
| <PackageReference Include="Microsoft.Azure.Management.RecoveryServices.Backup" Version="1.2.0-preview" /> | ||
| <PackageReference Include="Microsoft.Azure.Management.ResourceManager" Version="1.6.0-preview" /> | ||
| <PackageReference Include="Microsoft.Azure.Management.Storage" Version="6.5.0-preview" /> | ||
| <PackageReference Include="Microsoft.Extensions.Configuration" Version="1.1.2" /> | ||
| <PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="1.1.2" /> | ||
| <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.2" /> | ||
| <PackageReference Include="WindowsAzure.Storage" Version="8.1.4" /> | ||
| </ItemGroup> | ||
|
Contributor
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. Remove. All not needed. |
||
| <ItemGroup> | ||
| <ProjectReference Include="..\Management.ContainerInstance\Microsoft.Azure.Management.ContainerInstance.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <None Update="SessionRecords\**\*.json"> | ||
| <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| </None> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Folder Include="SessionRecords\" /> | ||
|
Contributor
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. @ScottHolden can you clean up these itemgroup, you do not need a separate directory itemgroup for SessionRecords |
||
| </ItemGroup> | ||
| </Project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| using System.Collections.Generic; | ||
| using System.Threading; | ||
| using Microsoft.Azure.Management.ContainerInstance; | ||
| using Microsoft.Azure.Management.ContainerInstance.Models; | ||
| using Microsoft.Azure.Management.ResourceManager.Models; | ||
| using Xunit; | ||
|
|
||
| namespace ContainerInstance.Tests | ||
| { | ||
| public class ContainerLogScenarioTests | ||
| { | ||
| [Fact] | ||
| public void ContainerLogGetTest() | ||
| { | ||
| using (TestContext context = new TestContext(this)) | ||
| { | ||
| string containerInstanceLocation = "westus"; | ||
|
|
||
| ResourceGroup resourceGroup = context.CreateResourceGroup("containerlogget-", containerInstanceLocation); | ||
| ContainerInstanceManagementClient containerClient = context.GetClient<ContainerInstanceManagementClient>(); | ||
|
|
||
| string containerGroupName = context.GenerateName("containergroup"); | ||
| string containerOsType = "Linux"; | ||
| string containerName = "test1"; | ||
|
Contributor
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. Similar to the other scenario tests. Use built in function to generate name. |
||
| string containerImage = "nginx"; | ||
| int containerPort = 80; | ||
| double containerCpu = 1; | ||
| double containerMemoryInGB = 1.5; | ||
|
|
||
| // Create an empty container group | ||
| ContainerGroup createdContainerGroup = containerClient.ContainerGroups.CreateOrUpdate(resourceGroup.Name, containerGroupName, new ContainerGroup | ||
| { | ||
| Location = resourceGroup.Location, | ||
| OsType = containerOsType, | ||
| Containers = new List<Container> | ||
| { | ||
| new Container | ||
| { | ||
| Name = containerName, | ||
| Image = containerImage, | ||
| Ports = new List<ContainerPort> | ||
| { | ||
| new ContainerPort(containerPort) | ||
| }, | ||
| Resources = new ResourceRequirements | ||
| { | ||
| Requests = new ResourceRequests | ||
| { | ||
| Cpu = containerCpu, | ||
| MemoryInGB = containerMemoryInGB | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }); | ||
| Assert.NotNull(createdContainerGroup); | ||
|
|
||
| // Wait till ready | ||
| ContainerGroupUtilities.WaitTillProvisioningStateSucceeded(containerClient, resourceGroup.Name, containerGroupName); | ||
|
|
||
| // Check that we can list the logs | ||
| Logs logs = containerClient.ContainerLogs.List(resourceGroup.Name, containerName, containerGroupName); | ||
| Assert.NotNull(logs); | ||
| Assert.NotNull(logs.Content); | ||
|
|
||
| // Delete the container group | ||
| containerClient.ContainerGroups.Delete(resourceGroup.Name, containerGroupName); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| using System.Reflection; | ||
| using System.Runtime.InteropServices; | ||
| using Xunit; | ||
|
|
||
| // 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: AssemblyConfiguration("")] | ||
| [assembly: AssemblyCompany("")] | ||
| [assembly: AssemblyProduct("ContainerInstance.Tests")] | ||
| [assembly: AssemblyTrademark("")] | ||
|
|
||
| // 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("ef989c56-f585-40a2-8af6-18789546f5bf")] |
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.
Just use
TestUtilities.GenerateName