Skip to content

Commit ffafda6

Browse files
rytruongREDMOND\rytruong
andauthored
added test for DiskRestorePoint and AcceleratedNetwork (#25591)
* added test for DiskRestorePoint and AcceleratedNetwork * added recorded tests Co-authored-by: REDMOND\rytruong <[email protected]>
1 parent 44c4a29 commit ffafda6

File tree

5 files changed

+4691
-1373
lines changed

5 files changed

+4691
-1373
lines changed

sdk/compute/Microsoft.Azure.Management.Compute/tests/DiskRPTests/DiskRPScenarioTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ public void Snapshot_CRUD_WithSecurityType()
7474
Snapshot_CRUD_WithSecurityType_Execute("Snapshot_CRUD_WithSecurityType", location: "eastus2");
7575
}
7676

77+
[Fact]
78+
public void Snapshot_CRUD_WithAcceleratedNetwork()
79+
{
80+
Snapshot_CRUD_WithAcceleratedNetwork_Execute(DiskCreateOption.Empty, "Snapshot_CRUD_WithAcceleratedNetwork", diskSizeGB: 5, location: "eastus2");
81+
}
82+
7783
[Fact]
7884
public void Disk_List_EmptyDisk()
7985
{

sdk/compute/Microsoft.Azure.Management.Compute/tests/DiskRPTests/DiskRPTestsBase.cs

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,50 @@ protected void Snapshot_CRUD_WithSecurityType_Execute(string methodName, string
392392
}
393393
}
394394

395+
protected void Snapshot_CRUD_WithAcceleratedNetwork_Execute(string diskCreateOption, string methodName, int? diskSizeGB = null, string location = null)
396+
{
397+
using (MockContext context = MockContext.Start(this.GetType(), methodName))
398+
{
399+
EnsureClientsInitialized(context);
400+
DiskRPLocation = location ?? DiskRPLocation;
401+
402+
var rgName = TestUtilities.GenerateName(TestPrefix);
403+
var diskName = TestUtilities.GenerateName(DiskNamePrefix);
404+
var snapshotName = TestUtilities.GenerateName(DiskNamePrefix);
405+
406+
Disk disk = GenerateDefaultDisk(diskCreateOption, rgName, diskSizeGB);
407+
disk.SupportedCapabilities = new SupportedCapabilities { AcceleratedNetwork = true };
408+
409+
try
410+
{
411+
m_ResourcesClient.ResourceGroups.CreateOrUpdate(rgName, new ResourceGroup { Location = DiskRPLocation });
412+
413+
//put disk
414+
m_CrpClient.Disks.CreateOrUpdate(rgName, diskName, disk);
415+
Disk diskOut = m_CrpClient.Disks.Get(rgName, diskName);
416+
417+
Validate(disk, diskOut, disk.Location);
418+
419+
// Generate snapshot using disk info
420+
Snapshot snapshot = GenerateDefaultSnapshot(diskOut.Id, location: location);
421+
422+
// **********
423+
// TEST
424+
// **********
425+
426+
Snapshot snapshotOut = m_CrpClient.Snapshots.CreateOrUpdate(rgName, snapshotName, snapshot);
427+
Validate(snapshot, snapshotOut);
428+
Assert.NotNull(snapshotOut.SupportedCapabilities.AcceleratedNetwork);
429+
Assert.Equal(disk.SupportedCapabilities.AcceleratedNetwork, snapshotOut.SupportedCapabilities.AcceleratedNetwork);
430+
OperateSnapshot(snapshot, rgName, snapshotName);
431+
}
432+
finally
433+
{
434+
m_ResourcesClient.ResourceGroups.Delete(rgName);
435+
}
436+
}
437+
}
438+
395439
protected void DiskEncryptionSet_CRUD_Execute(string methodName, string encryptionType, string location = null)
396440
{
397441
using (MockContext context = MockContext.Start(this.GetType(), methodName))
@@ -1474,13 +1518,11 @@ protected void Disk_CRUD_WithPurchasePlan_Execute(string diskCreateOption, strin
14741518
m_ResourcesClient.ResourceGroups.Delete(rgName);
14751519
}
14761520
}
1477-
14781521
}
14791522

1480-
14811523
#endregion
14821524

1483-
#region Generation
1525+
#region Generation
14841526
public static readonly GrantAccessData AccessDataDefault = new GrantAccessData { Access = AccessLevel.Read, DurationInSeconds = 1000 };
14851527

14861528
protected Disk GenerateDefaultDisk(string diskCreateOption, string rgName, int? diskSizeGB = null, IList<string> zones = null, string location = null)

sdk/compute/Microsoft.Azure.Management.Compute/tests/ScenarioTests/RestorePointTests.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,9 @@ public void CreateRpcAndRestorePoints()
9393
VerifyRestorePointDetails(createdRP, rpName, osDisk, 1,
9494
excludeDiskId: dataDiskId, vmSize: vmSize);
9595
RestorePoint getRP = GetRP(rgName, rpcName, rpName);
96-
VerifyRestorePointDetails(createdRP, rpName, osDisk, 1,
96+
VerifyRestorePointDetails(getRP, rpName, osDisk, 1,
9797
excludeDiskId: dataDiskId, vmSize: vmSize);
98+
VerifyDiskRestorePoint(rgName, rpcName, rpName);
9899

99100
// get RPC without $expand=restorePoints
100101
RestorePointCollection returnedRpc = GetRpc(rgName, rpcName);
@@ -110,6 +111,7 @@ public void CreateRpcAndRestorePoints()
110111
RestorePoint rpInRpc = returnedRpc.RestorePoints[0];
111112
VerifyRestorePointDetails(rpInRpc, rpName, osDisk, 1,
112113
excludeDiskId: dataDiskId, vmSize: vmSize);
114+
VerifyDiskRestorePoint(rgName, rpcName, rpName);
113115

114116
// delete the restore point
115117
DeleteRP(rgName, rpcName, rpName);
@@ -271,5 +273,32 @@ private RestorePointCollection CreateRpc(string sourceVMId, string rpcName,
271273
inputRpc);
272274
return restorePointCollection;
273275
}
276+
277+
// Verify disk restore points.
278+
private void VerifyDiskRestorePoint(string rgName, string rpcName, string rpName)
279+
{
280+
IPage<DiskRestorePoint> listDiskRestorePoint = m_CrpClient.DiskRestorePoint.ListByRestorePoint(rgName, rpcName, rpName);
281+
GrantAccessData accessData = new GrantAccessData { Access = AccessLevel.Read, DurationInSeconds = 1000 };
282+
foreach (DiskRestorePoint drp in listDiskRestorePoint)
283+
{
284+
var getDrp = m_CrpClient.DiskRestorePoint.Get(rgName, rpcName, rpName, drp.Name);
285+
ValidateDiskRestorePoint(getDrp, drp.Name);
286+
287+
AccessUri accessUri = m_CrpClient.DiskRestorePoint.GrantAccess(rgName, rpcName, rpName, getDrp.Name, accessData);
288+
Assert.NotNull(accessUri.AccessSAS);
289+
290+
getDrp = m_CrpClient.DiskRestorePoint.Get(rgName, rpcName, rpName, drp.Name);
291+
ValidateDiskRestorePoint(getDrp, drp.Name);
292+
293+
m_CrpClient.DiskRestorePoint.RevokeAccess(rgName, rpcName, rpName, drp.Name);
294+
}
295+
}
296+
297+
private void ValidateDiskRestorePoint(DiskRestorePoint drp, string rpName)
298+
{
299+
Assert.NotNull(drp);
300+
Assert.NotNull(drp.Id);
301+
Assert.Equal(rpName, drp.Name);
302+
}
274303
}
275304
}

0 commit comments

Comments
 (0)