Skip to content

Commit 7546816

Browse files
committed
add support for premium managed disks
1 parent d5b0d69 commit 7546816

File tree

9 files changed

+7460
-6524
lines changed

9 files changed

+7460
-6524
lines changed

src/ResourceManager/Common/Commands.ScenarioTests.ResourceManager.Common/EnvironmentSetupHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ public virtual Collection<PSObject> RunPowerShellTest(params string[] scripts)
395395
private void SetupPowerShellModules(System.Management.Automation.PowerShell powershell)
396396
{
397397
powershell.AddScript("$error.clear()");
398+
powershell.AddScript("Set-ExecutionPolicy Bypass -Scope Process");
398399
powershell.AddScript(string.Format("Write-Debug \"current directory: {0}\"", AppDomain.CurrentDomain.BaseDirectory));
399400
powershell.AddScript(string.Format("Write-Debug \"current executing assembly: {0}\"", Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)));
400401
powershell.AddScript(string.Format("cd \"{0}\"", AppDomain.CurrentDomain.BaseDirectory));

src/ResourceManager/Compute/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
-->
2020
## Current Release
2121

22+
* Updated Set-AzureRmVMAEMExtension and Test-AzureRmVMAEMExtension cmdlets to support Premium managed disks
23+
2224
## Version 2.9.0
2325

2426
* Fix bug in Get-* cmdlets, to allow retrieving multiple pages of data (more than 120 items)

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/AEMExtensionTests.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,5 +76,11 @@ public void TestAEMExtensionAdvancedWindowsMD()
7676
{
7777
ComputeTestController.NewInstance.RunPsTest("Test-AEMExtensionAdvancedWindowsMD");
7878
}
79+
80+
[Fact]
81+
public void TestAEMExtensionAdvancedLinuxMD()
82+
{
83+
ComputeTestController.NewInstance.RunPsTest("Test-AEMExtensionAdvancedLinuxMD");
84+
}
7985
}
80-
}
86+
}

src/ResourceManager/Compute/Commands.Compute.Test/ScenarioTests/AEMExtensionTests.ps1

Lines changed: 86 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -250,31 +250,31 @@ function Test-AEMExtensionAdvancedWindowsMD
250250

251251
try
252252
{
253-
Write-Verbose "Start the test Test-AEMExtensionAdvancedWindows"
253+
Write-Verbose "Start the test Test-AEMExtensionAdvancedWindowsMD"
254254
# Setup
255255
$vm = Create-AdvancedVM -rgname $rgname -loc $loc -vmsize 'Standard_DS2' -stotype 'Premium_LRS' -nicCount 2 -useMD
256256
$vmname = $vm.Name
257-
Write-Verbose "Test-AEMExtensionAdvancedWindows: VM created"
257+
Write-Verbose "Test-AEMExtensionAdvancedWindowsMD: VM created"
258258

259259
# Get with not extension
260-
Write-Verbose "Test-AEMExtensionAdvancedWindows: Get with no extension"
260+
Write-Verbose "Test-AEMExtensionAdvancedWindowsMD: Get with no extension"
261261
$extension = Get-AzureRmVMAEMExtension -ResourceGroupName $rgname -VMName $vmname
262262
Assert-Null $extension
263263

264264
# Test with not extension
265-
Write-Verbose "Test-AEMExtensionAdvancedWindows: Test with no extension"
265+
Write-Verbose "Test-AEMExtensionAdvancedWindowsMD: Test with no extension"
266266
$res = Test-AzureRmVMAEMExtension -ResourceGroupName $rgname -VMName $vmname -SkipStorageCheck
267267
Assert-False { $res.Result }
268-
Write-Verbose "Test-AEMExtensionAdvancedWindows: Test done"
268+
Write-Verbose "Test-AEMExtensionAdvancedWindowsMD: Test done"
269269

270270
$stoname = 'sto' + $rgname + "2";
271271
New-AzureRmStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type 'Standard_LRS';
272272

273273
# Set and Get command.
274-
Write-Verbose "Test-AEMExtensionAdvancedWindows: Set with no extension"
274+
Write-Verbose "Test-AEMExtensionAdvancedWindowsMD: Set with no extension"
275275
Set-AzureRmVMAEMExtension -ResourceGroupName $rgname -VMName $vmname -WADStorageAccountName $stoname -SkipStorage
276-
Write-Verbose "Test-AEMExtensionAdvancedWindows: Set done"
277-
Write-Verbose "Test-AEMExtensionAdvancedWindows: Get with extension"
276+
Write-Verbose "Test-AEMExtensionAdvancedWindowsMD: Set done"
277+
Write-Verbose "Test-AEMExtensionAdvancedWindowsMD: Get with extension"
278278
$extension = Get-AzureRmVMAEMExtension -ResourceGroupName $rgname -VMName $vmname
279279

280280

@@ -284,24 +284,95 @@ function Test-AEMExtensionAdvancedWindowsMD
284284
Assert-AreEqual $extension.Name 'AzureCATExtensionHandler'
285285
$settings = $extension.PublicSettings | ConvertFrom-Json
286286
Assert-NotNull $settings.cfg
287-
Write-Verbose "Test-AEMExtensionAdvancedWindows: Get done"
287+
Write-Verbose "Test-AEMExtensionAdvancedWindowsMD: Get done"
288288

289289
# Test command.
290-
Write-Verbose "Test-AEMExtensionAdvancedWindows: Test with extension"
290+
Write-Verbose "Test-AEMExtensionAdvancedWindowsMD: Test with extension"
291291
$res = Test-AzureRmVMAEMExtension -ResourceGroupName $rgname -VMName $vmname -SkipStorageCheck
292292
Assert-True { $res.Result }
293293
Assert-True { ($res.PartialResults.Count -gt 0) }
294-
Write-Verbose "Test-AEMExtensionAdvancedWindows: Test done"
294+
Write-Verbose "Test-AEMExtensionAdvancedWindowsMD: Test done"
295295

296296
# Remove command.
297-
Write-Verbose "Test-AEMExtensionAdvancedWindows: Remove with extension"
297+
Write-Verbose "Test-AEMExtensionAdvancedWindowsMD: Remove with extension"
298298
Remove-AzureRmVMAEMExtension -ResourceGroupName $rgname -VMName $vmname
299-
Write-Verbose "Test-AEMExtensionAdvancedWindows: Remove done"
299+
Write-Verbose "Test-AEMExtensionAdvancedWindowsMD: Remove done"
300300

301-
Write-Verbose "Test-AEMExtensionAdvancedWindows: Get after remove"
301+
Write-Verbose "Test-AEMExtensionAdvancedWindowsMD: Get after remove"
302302
$extension = Get-AzureRmVMAEMExtension -ResourceGroupName $rgname -VMName $vmname
303303
Assert-Null $extension
304-
Write-Verbose "Test-AEMExtensionAdvancedWindows: Get after remove done"
304+
Write-Verbose "Test-AEMExtensionAdvancedWindowsMD: Get after remove done"
305+
}
306+
finally
307+
{
308+
# Cleanup
309+
Clean-ResourceGroup $rgname
310+
}
311+
}
312+
313+
function Test-AEMExtensionAdvancedLinuxMD
314+
{
315+
$rgname = Get-ComputeTestResourceName
316+
$loc = Get-ComputeVMLocation
317+
318+
try
319+
{
320+
Write-Host "Start the test Test-AEMExtensionAdvancedLinuxMD"
321+
# Setup
322+
$vm = Create-AdvancedVM -rgname $rgname -loc $loc -vmsize 'Standard_DS2' -stotype 'Premium_LRS' -nicCount 2 -useMD -linux
323+
$vmname = $vm.Name
324+
$vm = Get-AzureRmVM -ResourceGroupName $rgname -Name $vmname
325+
Add-AzureRmVMDataDisk -VM $vm -StorageAccountType StandardLRS -Lun (($vm.StorageProfile.DataDisks | select -ExpandProperty Lun | Measure-Object -Maximum).Maximum + 1) -CreateOption Empty -DiskSizeInGB 10 | Update-AzureRmVM
326+
327+
328+
Write-Verbose "Test-AEMExtensionAdvancedLinuxMD: VM created"
329+
330+
# Get with not extension
331+
Write-Verbose "Test-AEMExtensionAdvancedLinuxMD: Get with no extension"
332+
$extension = Get-AzureRmVMAEMExtension -ResourceGroupName $rgname -VMName $vmname
333+
Assert-Null $extension
334+
335+
# Test with not extension
336+
Write-Verbose "Test-AEMExtensionAdvancedLinuxMD: Test with no extension"
337+
$res = Test-AzureRmVMAEMExtension -ResourceGroupName $rgname -VMName $vmname -SkipStorageCheck
338+
Assert-False { $res.Result }
339+
Write-Verbose "Test-AEMExtensionAdvancedLinuxMD: Test done"
340+
341+
$stoname = 'sto' + $rgname + "2";
342+
New-AzureRmStorageAccount -ResourceGroupName $rgname -Name $stoname -Location $loc -Type 'Standard_LRS';
343+
344+
# Set and Get command.
345+
Write-Verbose "Test-AEMExtensionAdvancedLinuxMD: Set with no extension"
346+
Set-AzureRmVMAEMExtension -ResourceGroupName $rgname -VMName $vmname -WADStorageAccountName $stoname -SkipStorage
347+
Write-Verbose "Test-AEMExtensionAdvancedLinuxMD: Set done"
348+
Write-Verbose "Test-AEMExtensionAdvancedLinuxMD: Get with extension"
349+
$extension = Get-AzureRmVMAEMExtension -ResourceGroupName $rgname -VMName $vmname
350+
351+
352+
Assert-NotNull $extension
353+
Assert-AreEqual $extension.Publisher 'Microsoft.OSTCExtensions'
354+
Assert-AreEqual $extension.ExtensionType 'AzureEnhancedMonitorForLinux'
355+
Assert-AreEqual $extension.Name 'AzureEnhancedMonitorForLinux'
356+
$settings = $extension.PublicSettings | ConvertFrom-Json
357+
Assert-NotNull $settings.cfg
358+
Write-Verbose "Test-AEMExtensionAdvancedLinuxMD: Get done"
359+
360+
# Test command.
361+
Write-Verbose "Test-AEMExtensionAdvancedLinuxMD: Test with extension"
362+
$res = Test-AzureRmVMAEMExtension -ResourceGroupName $rgname -VMName $vmname -SkipStorageCheck
363+
Assert-True { $res.Result }
364+
Assert-True { ($res.PartialResults.Count -gt 0) }
365+
Write-Verbose "Test-AEMExtensionAdvancedLinuxMD: Test done"
366+
367+
# Remove command.
368+
Write-Verbose "Test-AEMExtensionAdvancedLinuxMD: Remove with extension"
369+
Remove-AzureRmVMAEMExtension -ResourceGroupName $rgname -VMName $vmname
370+
Write-Verbose "Test-AEMExtensionAdvancedLinuxMD: Remove done"
371+
372+
Write-Verbose "Test-AEMExtensionAdvancedLinuxMD: Get after remove"
373+
$extension = Get-AzureRmVMAEMExtension -ResourceGroupName $rgname -VMName $vmname
374+
Assert-Null $extension
375+
Write-Verbose "Test-AEMExtensionAdvancedLinuxMD: Get after remove done"
305376
}
306377
finally
307378
{

src/ResourceManager/Compute/Commands.Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.AEMExtensionTests/TestAEMExtensionAdvancedLinuxMD.json

Lines changed: 5927 additions & 0 deletions
Large diffs are not rendered by default.

src/ResourceManager/Compute/Commands.Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.AEMExtensionTests/TestAEMExtensionAdvancedWindowsMD.json

Lines changed: 1355 additions & 6476 deletions
Large diffs are not rendered by default.

src/ResourceManager/Compute/Commands.Compute/Extension/AEM/AEMHelper.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,18 @@ internal string GetResourceGroupFromId(string id)
9797
return result.Groups[2].Value;
9898
}
9999

100+
internal string GetResourceNameFromId(string id)
101+
{
102+
var matcher = new Regex("/subscriptions/([^/]+)/resourceGroups/([^/]+)/providers/([^/]+)/([^/]+)/([^/]+)(/\\w+)?");
103+
var result = matcher.Match(id);
104+
if (!result.Success || result.Groups == null || result.Groups.Count < 3)
105+
{
106+
throw new InvalidOperationException(string.Format("Cannot find resource group name and storage account name from resource identity {0}", id));
107+
}
108+
109+
return result.Groups[5].Value;
110+
}
111+
100112
internal bool IsPremiumStorageAccount(string accountName)
101113
{
102114
return IsPremiumStorageAccount(this.GetStorageAccountFromCache(accountName));
@@ -817,4 +829,4 @@ internal bool CheckDiagnosticsTable(string storageAccountName, string resId, str
817829
return tableExists;
818830
}
819831
}
820-
}
832+
}

src/ResourceManager/Compute/Commands.Compute/Extension/AEM/SetAzureRmVMAEMExtension.cs

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -207,36 +207,47 @@ public override void ExecuteCmdlet()
207207
sapmonPublicConfig.Add(new KeyValuePair() { Key = "osdisk.connhour", Value = (accountName + ".hour") });
208208
}
209209
}
210-
else if (osdisk.ManagedDisk.StorageAccountType == StorageAccountTypes.PremiumLRS)
211-
{
212-
WriteVerbose("OS Disk Storage Account is a premium account - adding SLAs for OS disk");
213-
var sla = this._Helper.GetDiskSLA(osdisk);
214-
sapmonPublicConfig.Add(new KeyValuePair() { Key = "osdisk.type", Value = AEMExtensionConstants.DISK_TYPE_PREMIUM_MD });
215-
sapmonPublicConfig.Add(new KeyValuePair() { Key = "osdisk.sla.throughput", Value = sla.TP });
216-
sapmonPublicConfig.Add(new KeyValuePair() { Key = "osdisk.sla.iops", Value = sla.IOPS });
217-
}
218210
else
219211
{
220-
this._Helper.WriteWarning("[WARN] Standard Managed Disks are not supported. Extension will be installed but no disk metrics will be available.");
212+
var osDiskMD = ComputeClient.ComputeManagementClient.Disks.Get(this._Helper.GetResourceGroupFromId(osdisk.ManagedDisk.Id),
213+
this._Helper.GetResourceNameFromId(osdisk.ManagedDisk.Id));
214+
if (osDiskMD.AccountType == StorageAccountTypes.PremiumLRS)
215+
{
216+
WriteVerbose("OS Disk Storage Account is a premium account - adding SLAs for OS disk");
217+
var sla = this._Helper.GetDiskSLA(osDiskMD.DiskSizeGB, null);
218+
sapmonPublicConfig.Add(new KeyValuePair() { Key = "osdisk.type", Value = AEMExtensionConstants.DISK_TYPE_PREMIUM_MD });
219+
sapmonPublicConfig.Add(new KeyValuePair() { Key = "osdisk.sla.throughput", Value = sla.TP });
220+
sapmonPublicConfig.Add(new KeyValuePair() { Key = "osdisk.sla.iops", Value = sla.IOPS });
221+
}
222+
else
223+
{
224+
this._Helper.WriteWarning("[WARN] Standard Managed Disks are not supported. Extension will be installed but no disk metrics will be available.");
225+
}
221226
}
222227

223228
// Get Storage accounts from disks
224229
var diskNumber = 1;
225230
foreach (var disk in disks)
226231
{
227-
228-
if (disk.ManagedDisk != null && disk.ManagedDisk.StorageAccountType == StorageAccountTypes.PremiumLRS)
232+
if (disk.ManagedDisk != null)
229233
{
230-
this._Helper.WriteVerbose("Data Disk {0} is a Premium Managed Disk - adding SLAs for disk", diskNumber.ToString());
231-
var sla = this._Helper.GetDiskSLA(disk);
232-
sapmonPublicConfig.Add(new KeyValuePair() { Key = "disk.type." + diskNumber, Value = AEMExtensionConstants.DISK_TYPE_PREMIUM_MD });
233-
sapmonPublicConfig.Add(new KeyValuePair() { Key = "disk.sla.throughput." + diskNumber, Value = sla.TP });
234-
sapmonPublicConfig.Add(new KeyValuePair() { Key = "disk.sla.iops." + diskNumber, Value = sla.IOPS });
235-
this._Helper.WriteVerbose("Done - Data Disk {0} is a Premium Managed Disk - adding SLAs for disk", diskNumber.ToString());
236-
}
237-
else if (disk.ManagedDisk != null)
238-
{
239-
this._Helper.WriteWarning("[WARN] Standard Managed Disks are not supported. Extension will be installed but no disk metrics will be available.");
234+
var diskMD = ComputeClient.ComputeManagementClient.Disks.Get(this._Helper.GetResourceGroupFromId(disk.ManagedDisk.Id),
235+
this._Helper.GetResourceNameFromId(disk.ManagedDisk.Id));
236+
237+
if (diskMD.AccountType == StorageAccountTypes.PremiumLRS)
238+
{
239+
this._Helper.WriteVerbose("Data Disk {0} is a Premium Managed Disk - adding SLAs for disk", diskNumber.ToString());
240+
var sla = this._Helper.GetDiskSLA(diskMD.DiskSizeGB, null);
241+
sapmonPublicConfig.Add(new KeyValuePair() { Key = "disk.type." + diskNumber, Value = AEMExtensionConstants.DISK_TYPE_PREMIUM_MD });
242+
sapmonPublicConfig.Add(new KeyValuePair() { Key = "disk.sla.throughput." + diskNumber, Value = sla.TP });
243+
sapmonPublicConfig.Add(new KeyValuePair() { Key = "disk.sla.iops." + diskNumber, Value = sla.IOPS });
244+
this._Helper.WriteVerbose("Done - Data Disk {0} is a Premium Managed Disk - adding SLAs for disk", diskNumber.ToString());
245+
}
246+
else
247+
{
248+
this._Helper.WriteWarning("[WARN] Standard Managed Disks are not supported. Extension will be installed but no disk metrics will be available.");
249+
250+
}
240251
continue;
241252
}
242253

0 commit comments

Comments
 (0)