Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/AzureStack/Admin/ComputeAdmin/AzSdk.RP.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--This file and it's contents are updated at build time moving or editing might result in build failure. Take due deligence while editing this file-->
<PropertyGroup>
<AzureApiTag>Compute.Admin_2015-12-01-preview;Compute.Admin_2018-02-09;</AzureApiTag>
<AzureApiTag>Compute.Admin_2018-07-30-preview;Compute.Admin_2015-12-01-preview;Compute.Admin_2018-02-09;</AzureApiTag>
<PackageTags>$(PackageTags);$(CommonTags);$(AzureApiTag);</PackageTags>
</PropertyGroup>
</Project>

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"Entries": [
{
"RequestUri": "/subscriptions/c69f350f-01b9-417d-bb90-08a397934964/providers/Microsoft.Compute.Admin/locations/local/disks/454E5E28-8D5E-41F9-929E-BFF6A7E1A253?api-version=2018-07-30-preview",
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvYzY5ZjM1MGYtMDFiOS00MTdkLWJiOTAtMDhhMzk3OTM0OTY0L3Byb3ZpZGVycy9NaWNyb3NvZnQuQ29tcHV0ZS5BZG1pbi9sb2NhdGlvbnMvbG9jYWwvZGlza3MvNDU0RTVFMjgtOEQ1RS00MUY5LTkyOUUtQkZGNkE3RTFBMjUzP2FwaS12ZXJzaW9uPTIwMTgtMDctMzAtcHJldmlldw==",
"RequestMethod": "GET",
"RequestBody": "",
"RequestHeaders": {
"x-ms-client-request-id": [
"4e863a57-76fb-452d-88a0-0f02536482c4"
],
"accept-language": [
"en-US"
],
"User-Agent": [
"FxVersion/4.6.26020.03",
"Microsoft.AzureStack.Management.Compute.Admin.ComputeAdminClient/0.3.0.0"
]
},
"ResponseHeaders": {
"Cache-Control": [
"no-cache"
],
"Date": [
"Thu, 09 Aug 2018 06:05:35 GMT"
],
"Pragma": [
"no-cache"
],
"Server": [
"Microsoft-HTTPAPI/2.0"
],
"WWW-Authenticate": [
"oYG3MIG0oAMKAQChCwYJKoZIgvcSAQICooGfBIGcYIGZBgkqhkiG9xIBAgICAG+BiTCBhqADAgEFoQMCAQ+iejB4oAMCARKicQRvjIutUf86si1PznOxO46jZQoJpHzmbKpfCyvgxna+bM0QZeMSLg3+oXjDYvFcH4XZZO7xel4mEqfwVL014pnxwvP4Wbw7Y76vkIsHL5yXg+zw12stsD3/bGcayVkZVHeb1psmHvCI7swotWiODA3x"
],
"Strict-Transport-Security": [
"max-age=31536000; includeSubDomains"
],
"x-ms-served-by": [
"00000000-0000-0000-0000-000000000000_0"
],
"x-ms-correlation-request-id": [
"cbe90dad-de09-4f3d-8266-9c494514767e"
],
"x-ms-ratelimit-remaining-subscription-reads": [
"14972"
],
"x-ms-request-id": [
"cbe90dad-de09-4f3d-8266-9c494514767e"
],
"x-ms-routing-request-id": [
"LOCAL:20180809T060536Z:cbe90dad-de09-4f3d-8266-9c494514767e"
],
"X-Content-Type-Options": [
"nosniff"
],
"Content-Length": [
"92"
],
"Content-Type": [
"application/json; charset=utf-8"
],
"Expires": [
"-1"
]
},
"ResponseBody": "{\r\n \"error\": {\r\n \"code\": \"NotFound\",\r\n \"message\": \"The entity was not found.\"\r\n }\r\n}",
"StatusCode": 404
}
],
"Names": {},
"Variables": {
"SubscriptionId": "c69f350f-01b9-417d-bb90-08a397934964"
}
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you do tests that should fail? For instance try to migrate to a share that doesn't exist or with a disk that is invalid?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try Assert.False or Assert.Exception constructs.
If you wish to add the tests but enable them at a later time, you could always skip the tests, hope this helps

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added more tests.

using Microsoft.AzureStack.Management.Compute.Admin;
using Microsoft.AzureStack.Management.Compute.Admin.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading;
using Xunit;

namespace Compute.Tests
{
public class DiskMigrationJobTests : ComputeTestBase
{
private void ValidateDiskMigration(DiskMigrationJob diskMigration)
{
Assert.NotNull(diskMigration);
Assert.NotNull(diskMigration.CreationTime);
Assert.NotNull(diskMigration.Id);
Assert.NotNull(diskMigration.Location);
Assert.NotNull(diskMigration.Name);
Assert.NotNull(diskMigration.Status);
Assert.NotNull(diskMigration.TargetShare);
Assert.NotNull(diskMigration.Type);
Assert.NotNull(diskMigration.MigrationId);
}

[Fact]
public void TestDiskMigration()
{
string targetShare = @"\\SU1FileServer.azurestack.local\SU1_ObjStore\";
RunTest((client) => {
var disks = client.Disks.List(Location);
List<Disk> toMigrationDisks = new List<Disk>();
foreach(var disk in disks)
{
if (toMigrationDisks.Count < 3)
{
toMigrationDisks.Add(disk);
}
else
{
break;
}
}

var migrationId = "ba0644a4-c2ed-4e3c-a167-089a32865297";// This guid should be the same as the ones in sessionRecord

var migration = client.DiskMigrationJobs.Create(Location, migrationId, targetShare, toMigrationDisks);
ValidateDiskMigration(migration);

migration = client.DiskMigrationJobs.Cancel(Location, migrationId);
ValidateDiskMigration(migration);

var migrationFromGet = client.DiskMigrationJobs.Get(Location, migrationId);
ValidateDiskMigration(migrationFromGet);

var migrationList = client.DiskMigrationJobs.List(Location);
migrationList.ForEach(ValidateDiskMigration);

var migrationSucceededList = client.DiskMigrationJobs.List(Location, status: "Succeeded");
migrationSucceededList.ForEach(ValidateDiskMigration);
});
}

[Fact]
public void TestDiskMigrationInvalidInput()
{
string targetShare = @"\\SU1FileServer.azurestack.local\SU1_ObjStore_Invalid\";
RunTest((client) => {
var disks = client.Disks.List(Location);
List<Disk> toMigrationDisks = new List<Disk>();
if (disks.Count() > 0)
{
toMigrationDisks.Add(disks.First());

var migrationId = "A50E9E6B-CFC2-4BC7-956B-0F7C35035DF2";// This guid should be the same as the ones in sessionRecord

ValidateExpectedReturnCode(
() => client.DiskMigrationJobs.Create(Location, migrationId, targetShare, toMigrationDisks),
HttpStatusCode.BadRequest
);

ValidateExpectedReturnCode(
() => client.DiskMigrationJobs.Get(Location, migrationId),
HttpStatusCode.NotFound
);

toMigrationDisks[0].DiskId = "454E5E28-8D5E-41F9-929E-BFF6A7E1A253"; //Use some not exist disk
targetShare = @"\\SU1FileServer.azurestack.local\SU1_ObjStore\";

var migration = client.DiskMigrationJobs.Create(Location, migrationId, targetShare, toMigrationDisks);
int times = 0;
do
{
Thread.Sleep(3);
migration = client.DiskMigrationJobs.Get(Location, migrationId);
if (migration.Subtasks[0].MigrationSubtaskStatus.Equals("Skipped"))
{
break;
}
times++;
Thread.Sleep(3);
}
while (times < 50);

if(!migration.Subtasks[0].MigrationSubtaskStatus.Equals("Skipped"))
{
throw new Exception("Migration Status is not expected");
}
}
});
}
}
}
109 changes: 109 additions & 0 deletions src/AzureStack/Admin/ComputeAdmin/Compute.Admin.Tests/src/DiskTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@

using Microsoft.AzureStack.Management.Compute.Admin;
using Microsoft.AzureStack.Management.Compute.Admin.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using Xunit;

namespace Compute.Tests
{
public class DiskTests : ComputeTestBase
{
private void ValidateDisk(Disk disk)
{
Assert.NotNull(disk);
Assert.NotNull(disk.ActualSizeGB);
Assert.NotNull(disk.ProvisionSizeGB);
Assert.NotNull(disk.DiskSku);
Assert.NotNull(disk.DiskType);
Assert.NotNull(disk.SharePath);
Assert.NotNull(disk.Status);
Assert.NotNull(disk.UserResourceId);
Assert.NotNull(disk.Type);
Assert.NotNull(disk.Id);
Assert.NotNull(disk.Name);
Assert.NotNull(disk.Location);
Assert.NotNull(disk.DiskId);
}

private void ValidateDiskTheSame(Disk diskRight, Disk diskLeft)
{
Assert.NotNull(diskRight);
Assert.NotNull(diskLeft);

Assert.True(diskRight.Id == diskLeft.Id);
}

private void ValidateDisksTheSame(IEnumerable<Disk> disksRight, IEnumerable<Disk> disksLeft)
{
Assert.NotNull(disksRight);
Assert.NotNull(disksLeft);
Assert.Equal(disksRight.Count(), disksLeft.Count());

disksRight.ForEach(disk => Assert.True(IsDiskExistsInCollection(disk, disksLeft)));
}

private bool IsDiskExistsInCollection(Disk disk, IEnumerable<Disk> disks)
{
return disks.Any(diskInCollection => diskInCollection.UserResourceId.Equals(disk.UserResourceId, StringComparison.OrdinalIgnoreCase));
}

[Fact]
public void TestListDisks()
{
RunTest((client) => {
var disks = client.Disks.List(Location);
disks.ForEach(ValidateDisk);

if(disks.Count()>0)
{
var firstDisk = disks.First();
var tenantSubscriptionId = firstDisk.UserResourceId.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries)[1];

var disksForSubscription = client.Disks.List(Location, userSubscriptionId: tenantSubscriptionId);
ValidateDisksTheSame(disks.Where(disk => disk.UserResourceId.Contains(tenantSubscriptionId)), disksForSubscription);

var disksForStatus = client.Disks.List(Location, status: firstDisk.Status);
ValidateDisksTheSame(disks.Where(disk => disk.Status.Equals(firstDisk.Status, StringComparison.OrdinalIgnoreCase)), disksForStatus);

var disksForShare = client.Disks.List(Location, sharePath: firstDisk.SharePath);
ValidateDisksTheSame(disks.Where(disk => disk.SharePath.Equals(firstDisk.SharePath, StringComparison.OrdinalIgnoreCase)), disksForShare);

if (disks.Count() >= 2)
{
var disksWithCountAndStart = client.Disks.List(Location, count: 1, start: 1);
ValidateDisksTheSame(new List<Disk>() { disks.ElementAt(1) }, disksWithCountAndStart);
}
}
});
}

[Fact]
public void TestGetDisk()
{
RunTest((client) => {
var disks = client.Disks.List(Location);
disks.ForEach(ValidateDisk);

if (disks.Count() > 0)
{
var firstDisk = disks.First();
var diskFromServer = client.Disks.Get(Location, firstDisk.DiskId);
ValidateDiskTheSame(firstDisk, diskFromServer);
}
});
}

[Fact]
public void TestGetDiskInvalid()
{
RunTest((client) => {
ValidateExpectedReturnCode(
() => client.Disks.Get(Location, "454E5E28-8D5E-41F9-929E-BFF6A7E1A253"),
HttpStatusCode.NotFound);
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Net;
using Microsoft.Rest.Azure;
using Microsoft.Rest.ClientRuntime.Azure.TestFramework;
using Xunit;

namespace Compute.Tests
{
Expand Down Expand Up @@ -85,18 +86,25 @@ public void IgnoreExceptions(Action action) {

public void ValidateExpectedReturnCode(Action action, HttpStatusCode httpResponseCode)
{
try { action.Invoke(); }
catch (CloudException ex)
Assert.Throws<CloudException>(() =>
{
if (ex.Response.StatusCode == httpResponseCode)
try
{
// Expected exception received.
action.Invoke();
}
else
catch (CloudException ex)
{
throw ex;
if (ex.Response.StatusCode == httpResponseCode)
{
// Expected exception received.
throw;
}
else
{
throw new Exception($"Test failed: CloudException with wrong StatusCode {ex.Response.StatusCode}.");
}
}
}
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,16 @@ public partial class ComputeAdminClient : ServiceClient<ComputeAdminClient>, ICo
/// </summary>
public virtual IVMExtensionsOperations VMExtensions { get; private set; }

/// <summary>
/// Gets the IDisksOperations.
/// </summary>
public virtual IDisksOperations Disks { get; private set; }

/// <summary>
/// Gets the IDiskMigrationJobsOperations.
/// </summary>
public virtual IDiskMigrationJobsOperations DiskMigrationJobs { get; private set; }

/// <summary>
/// Initializes a new instance of the ComputeAdminClient class.
/// </summary>
Expand Down Expand Up @@ -296,6 +306,8 @@ private void Initialize()
PlatformImages = new PlatformImagesOperations(this);
Quotas = new QuotasOperations(this);
VMExtensions = new VMExtensionsOperations(this);
Disks = new DisksOperations(this);
DiskMigrationJobs = new DiskMigrationJobsOperations(this);
BaseUri = new System.Uri("https://adminmanagement.local.azurestack.external");
AcceptLanguage = "en-US";
LongRunningOperationRetryTimeout = 30;
Expand Down
Loading