Skip to content

Commit 1f78e44

Browse files
authored
Merge pull request #6962 from hyonholee/enumfix
[Compute] Fix storage account type issue
2 parents 78aad2a + fbdd2f5 commit 1f78e44

File tree

10 files changed

+18781
-32
lines changed

10 files changed

+18781
-32
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ function Test-VirtualMachineProfile
133133
Assert-AreEqual $p.StorageProfile.OSDisk.Name $osDiskName;
134134
Assert-AreEqual $p.StorageProfile.OSDisk.Vhd.Uri $osDiskVhdUri;
135135
Assert-AreEqual $managedOsDiskId_1 $p.StorageProfile.OSDisk.ManagedDisk.Id;
136-
Assert-AreEqual "Standard_LRS" $p.StorageProfile.OSDisk.ManagedDisk.StorageAccountType;
136+
Assert-Null $p.StorageProfile.OSDisk.ManagedDisk.StorageAccountType;
137137
Assert-AreEqual $false $p.StorageProfile.OSDisk.WriteAcceleratorEnabled;
138138

139139
# Windows OS

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,5 +384,17 @@ public void TestVirtualMachineWriteAcceleratorUpdate()
384384
{
385385
ComputeTestController.NewInstance.RunPsTest(_logger, "Test-VirtualMachineWriteAcceleratorUpdate");
386386
}
387+
388+
#if NETSTANDARD
389+
[Fact(Skip = "Updated Storage, needs re-recorded")]
390+
[Trait(Category.RunType, Category.DesktopOnly)]
391+
#else
392+
[Fact]
393+
#endif
394+
[Trait(Category.AcceptanceType, Category.CheckIn)]
395+
public void TestVirtualMachineManagedDisk()
396+
{
397+
ComputeTestController.NewInstance.RunPsTest(_logger, "Test-VirtualMachineManagedDisk");
398+
}
387399
}
388400
}

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

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3315,4 +3315,132 @@ function Test-VirtualMachineWriteAcceleratorUpdate
33153315
# Cleanup
33163316
Clean-ResourceGroup $rgname
33173317
}
3318+
}
3319+
3320+
function Test-VirtualMachineManagedDisk
3321+
{
3322+
# Setup
3323+
$rgname = Get-ComputeTestResourceName
3324+
3325+
try
3326+
{
3327+
$loc = Get-ComputeVMLocation;
3328+
New-AzureRmResourceGroup -Name $rgname -Location $loc -Force;
3329+
3330+
# VM Profile & Hardware
3331+
$vmsize = 'Standard_DS1';
3332+
$vmname = 'vm' + $rgname;
3333+
3334+
$p = New-AzureRmVMConfig -VMName $vmname -VMSize $vmsize;
3335+
3336+
# NRP
3337+
$subnet = New-AzureRmVirtualNetworkSubnetConfig -Name ('subnet' + $rgname) -AddressPrefix "10.0.0.0/24";
3338+
$vnet = New-AzureRmVirtualNetwork -Force -Name ('vnet' + $rgname) -ResourceGroupName $rgname -Location $loc -AddressPrefix "10.0.0.0/16" -Subnet $subnet;
3339+
$vnet = Get-AzureRmVirtualNetwork -Name ('vnet' + $rgname) -ResourceGroupName $rgname;
3340+
$subnetId = $vnet.Subnets[0].Id;
3341+
$pubip = New-AzureRmPublicIpAddress -Force -Name ('pubip' + $rgname) -ResourceGroupName $rgname -Location $loc -AllocationMethod Dynamic -DomainNameLabel ('pubip' + $rgname);
3342+
$pubip = Get-AzureRmPublicIpAddress -Name ('pubip' + $rgname) -ResourceGroupName $rgname;
3343+
$pubipId = $pubip.Id;
3344+
$nic = New-AzureRmNetworkInterface -Force -Name ('nic' + $rgname) -ResourceGroupName $rgname -Location $loc -SubnetId $subnetId -PublicIpAddressId $pubip.Id;
3345+
$nic = Get-AzureRmNetworkInterface -Name ('nic' + $rgname) -ResourceGroupName $rgname;
3346+
$nicId = $nic.Id;
3347+
3348+
$p = Add-AzureRmVMNetworkInterface -VM $p -Id $nicId;
3349+
3350+
# OS & Image
3351+
$user = "Foo2";
3352+
$password = $PLACEHOLDER;
3353+
$securePassword = ConvertTo-SecureString $password -AsPlainText -Force;
3354+
$cred = New-Object System.Management.Automation.PSCredential ($user, $securePassword);
3355+
$computerName = 'test';
3356+
3357+
$p = Set-AzureRmVMOperatingSystem -VM $p -Windows -ComputerName $computerName -Credential $cred;
3358+
3359+
$imgRef = Get-DefaultCRPImage -loc $loc;
3360+
$p = ($imgRef | Set-AzureRmVMSourceImage -VM $p);
3361+
3362+
# Virtual Machine
3363+
New-AzureRmVM -ResourceGroupName $rgname -Location $loc -VM $p;
3364+
3365+
# Get VM
3366+
$vm = Get-AzureRmVM -Name $vmname -ResourceGroupName $rgname;
3367+
3368+
Assert-NotNull $vm.StorageProfile.OsDisk.ManagedDisk.Id;
3369+
Assert-AreEqual 'Premium_LRS' $vm.StorageProfile.OsDisk.ManagedDisk.StorageAccountType;
3370+
3371+
# Create OS snapshot from the VM
3372+
$snapshotConfig = New-AzureRmSnapshotConfig -SourceUri $vm.Storageprofile.OsDisk.ManagedDisk.Id -Location $loc -CreateOption Copy;
3373+
$snapshotname = "ossnapshot";
3374+
New-AzureRmSnapshot -Snapshot $snapshotConfig -SnapshotName $snapshotname -ResourceGroupName $rgname;
3375+
$snapshot = Get-AzureRmSnapshot -SnapshotName $snapshotname -ResourceGroupName $rgname;
3376+
3377+
Assert-NotNull $snapshot.Id;
3378+
Assert-AreEqual $snapshotname $snapshot.Name;
3379+
Assert-AreEqual 'Standard_LRS' $snapshot.Sku.Name;
3380+
3381+
# Create an OS disk from the snapshot
3382+
$osdiskConfig = New-AzureRmDiskConfig -Location $loc -CreateOption Copy -SourceUri $snapshot.Id;
3383+
$osdiskname = "osdisk";
3384+
New-AzureRmDisk -ResourceGroupName $rgname -DiskName $osdiskname -Disk $osdiskConfig;
3385+
$osdisk = Get-AzureRmDisk -ResourceGroupName $rgname -DiskName $osdiskname;
3386+
3387+
Assert-NotNull $osdisk.Id;
3388+
Assert-AreEqual $osdiskname $osdisk.Name;
3389+
Assert-AreEqual 'Standard_LRS' $osdisk.Sku.Name;
3390+
3391+
# Stop the VM
3392+
Stop-AzureRmVM -ResourceGroupName $rgname -Name $vmname -Force;
3393+
3394+
# Change the OS disk of the VM
3395+
$vm = Set-AzureRmVMOSDisk -VM $vm -Name $osdiskname -ManagedDiskId $osdisk.Id;
3396+
3397+
# Create an empty disk
3398+
$datadiskconfig = New-AzureRmDiskConfig -Location $loc -CreateOption Empty -AccountType 'Standard_LRS' -DiskSizeGB 10;
3399+
$datadiskname = "datadisk";
3400+
New-AzureRmDisk -ResourceGroupName $rgname -DiskName $datadiskname -Disk $datadiskconfig;
3401+
$datadisk = Get-AzureRmDisk -ResourceGroupName $rgname -DiskName $datadiskname;
3402+
3403+
Assert-NotNull $datadisk.Id;
3404+
Assert-AreEqual $datadiskname $datadisk.Name;
3405+
Assert-AreEqual 'Standard_LRS' $datadisk.Sku.Name;
3406+
3407+
# Add the disk to the VM
3408+
$vm = Add-AzureRmVMDataDisk -VM $vm -Name $datadiskname -ManagedDiskId $dataDisk.Id -Lun 2 -CreateOption Attach -Caching 'ReadWrite';
3409+
3410+
# Update and start the VM
3411+
Update-AzureRmVM -ResourceGroupName $rgname -VM $vm;
3412+
Start-AzureRmVM -ResourceGroupName $rgname -Name $vmname;
3413+
3414+
# Get the updated VM
3415+
$vm = Get-AzureRmVM -ResourceGroupName $rgname -Name $vmname;
3416+
3417+
Assert-NotNull $vm.VmId;
3418+
Assert-AreEqual $vmname $vm.Name ;
3419+
Assert-AreEqual 1 $vm.NetworkProfile.NetworkInterfaces.Count;
3420+
Assert-AreEqual $nicId $vm.NetworkProfile.NetworkInterfaces[0].Id;
3421+
3422+
Assert-AreEqual $imgRef.Offer $vm.StorageProfile.ImageReference.Offer;
3423+
Assert-AreEqual $imgRef.PublisherName $vm.StorageProfile.ImageReference.Publisher;
3424+
Assert-AreEqual $imgRef.Skus $vm.StorageProfile.ImageReference.Sku;
3425+
Assert-AreEqual $imgRef.Version $vm.StorageProfile.ImageReference.Version;
3426+
3427+
Assert-AreEqual $user $vm.OSProfile.AdminUsername;
3428+
Assert-AreEqual $computerName $vm.OSProfile.ComputerName;
3429+
Assert-AreEqual $vmsize $vm.HardwareProfile.VmSize;
3430+
3431+
Assert-True {$vm.DiagnosticsProfile.BootDiagnostics.Enabled;};
3432+
3433+
Assert-AreEqual "BGInfo" $vm.Extensions[0].VirtualMachineExtensionType;
3434+
Assert-AreEqual "Microsoft.Compute" $vm.Extensions[0].Publisher;
3435+
3436+
Assert-AreEqual $osdisk.Id $vm.StorageProfile.OsDisk.ManagedDisk.Id;
3437+
Assert-AreEqual 'Standard_LRS' $vm.StorageProfile.OsDisk.ManagedDisk.StorageAccountType;
3438+
Assert-AreEqual $datadisk.Id $vm.StorageProfile.DataDisks[0].ManagedDisk.Id;
3439+
Assert-AreEqual 'Standard_LRS' $vm.StorageProfile.DataDisks[0].ManagedDisk.StorageAccountType;
3440+
}
3441+
finally
3442+
{
3443+
# Cleanup
3444+
Clean-ResourceGroup $rgname
3445+
}
33183446
}

src/ResourceManager/Compute/Commands.Compute.Test/SessionRecords/Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineTests/TestVirtualMachineManagedDisk.json

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

src/ResourceManager/Compute/Commands.Compute/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- Additional information about change #1
2020
-->
2121
## Current Release
22+
* Fixed issue with storage account type for VM with managed disk
2223
* Fixed issue with default resource groups not being set.
2324
* Fix AEM Extension cmdlets for other environments, for example Azure China
2425

src/ResourceManager/Compute/Commands.Compute/Common/ComputeClientBaseCmdlet.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
using System.Text.RegularExpressions;
1919
using Microsoft.Azure.Commands.Compute.Common;
2020
using Microsoft.Azure.Commands.ResourceManager.Common;
21+
using Microsoft.Azure.Management.Compute.Models;
2122

2223
namespace Microsoft.Azure.Commands.Compute
2324
{
@@ -96,6 +97,28 @@ public static string GetOperationIdFromUrlString(string Url)
9697
Match m = r.Match(Url);
9798
return m.Success ? m.Groups["id"].Value : null;
9899
}
100+
101+
public static ManagedDiskParameters SetManagedDisk(string managedDiskId, string storageAccountType, ManagedDiskParameters managedDisk = null)
102+
{
103+
if (string.IsNullOrWhiteSpace(managedDiskId) && string.IsNullOrWhiteSpace(storageAccountType))
104+
{
105+
return managedDisk;
106+
}
107+
108+
managedDisk = new ManagedDiskParameters();
109+
110+
if (!string.IsNullOrWhiteSpace(managedDiskId))
111+
{
112+
managedDisk.Id = managedDiskId;
113+
}
114+
115+
if (!string.IsNullOrWhiteSpace(storageAccountType))
116+
{
117+
managedDisk.StorageAccountType = storageAccountType;
118+
}
119+
120+
return managedDisk;
121+
}
99122
}
100123
}
101124

src/ResourceManager/Compute/Commands.Compute/Generated/Image/Config/AddAzureRmImageDataDiskCommand.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ private void Run()
110110
vDataDisks.BlobUri = this.MyInvocation.BoundParameters.ContainsKey("BlobUri") ? this.BlobUri : null;
111111
vDataDisks.Caching = this.MyInvocation.BoundParameters.ContainsKey("Caching") ? this.Caching : (CachingTypes?) null;
112112
vDataDisks.DiskSizeGB = this.MyInvocation.BoundParameters.ContainsKey("DiskSizeGB") ? this.DiskSizeGB : (int?) null;
113-
vDataDisks.StorageAccountType = this.MyInvocation.BoundParameters.ContainsKey("StorageAccountType") ? (StorageAccountTypes ?) this.StorageAccountType : null;
113+
if (this.MyInvocation.BoundParameters.ContainsKey("StorageAccountType"))
114+
{
115+
vDataDisks.StorageAccountType = (StorageAccountTypes?) this.StorageAccountType;
116+
}
114117
if (this.MyInvocation.BoundParameters.ContainsKey("SnapshotId"))
115118
{
116119
// Snapshot

src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/AddAzureVMDataDiskCommand.cs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,7 @@ public override void ExecuteCmdlet()
224224
DiskSizeGB = this.DiskSizeInGB,
225225
Lun = this.Lun.GetValueOrDefault(),
226226
CreateOption = this.CreateOption,
227-
ManagedDisk = (this.ManagedDiskId == null && this.StorageAccountType == null)
228-
? null
229-
: new ManagedDiskParameters
230-
{
231-
Id = this.ManagedDiskId,
232-
StorageAccountType = this.StorageAccountType
233-
},
227+
ManagedDisk = SetManagedDisk(this.ManagedDiskId, this.StorageAccountType),
234228
WriteAcceleratorEnabled = this.WriteAccelerator.IsPresent
235229
});
236230

@@ -258,11 +252,7 @@ public override void ExecuteCmdlet()
258252
DiskSizeGB = this.DiskSizeInGB,
259253
Lun = this.Lun.GetValueOrDefault(),
260254
CreateOption = this.CreateOption,
261-
ManagedDisk = new ManagedDiskParameters
262-
{
263-
Id = this.ManagedDiskId,
264-
StorageAccountType = this.StorageAccountType
265-
},
255+
ManagedDisk = SetManagedDisk(this.ManagedDiskId, this.StorageAccountType),
266256
WriteAcceleratorEnabled = this.WriteAccelerator.IsPresent
267257
});
268258

src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/NewAzureVMDataDiskCommand.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,7 @@ public override void ExecuteCmdlet()
132132
DiskSizeGB = this.DiskSizeInGB,
133133
Lun = this.Lun,
134134
CreateOption = this.CreateOption,
135-
ManagedDisk = (this.ManagedDiskId == null && this.StorageAccountType == null)
136-
? null
137-
: new ManagedDiskParameters
138-
{
139-
Id = this.ManagedDiskId,
140-
StorageAccountType = this.StorageAccountType
141-
},
135+
ManagedDisk = SetManagedDisk(this.ManagedDiskId, this.StorageAccountType),
142136
WriteAcceleratorEnabled = this.WriteAccelerator.IsPresent
143137
};
144138

src/ResourceManager/Compute/Commands.Compute/VirtualMachine/Config/SetAzureVMOSDiskCommand.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
namespace Microsoft.Azure.Commands.Compute
2323
{
2424
[Cmdlet("Set", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "VMOSDisk",DefaultParameterSetName = DefaultParamSet),OutputType(typeof(PSVirtualMachine))]
25-
public class SetAzureVMOSDiskCommand : Microsoft.Azure.Commands.ResourceManager.Common.AzureRMCmdlet
25+
public class SetAzureVMOSDiskCommand : ComputeClientBaseCmdlet
2626
{
2727
protected const string DefaultParamSet = "DefaultParamSet";
2828
protected const string WindowsParamSet = "WindowsParamSet";
@@ -244,16 +244,7 @@ public override void ExecuteCmdlet()
244244
};
245245
}
246246

247-
if (!string.IsNullOrEmpty(this.ManagedDiskId) || this.StorageAccountType != null)
248-
{
249-
if (this.VM.StorageProfile.OsDisk.ManagedDisk == null)
250-
{
251-
this.VM.StorageProfile.OsDisk.ManagedDisk = new ManagedDiskParameters();
252-
}
253-
254-
this.VM.StorageProfile.OsDisk.ManagedDisk.Id = this.ManagedDiskId ?? this.VM.StorageProfile.OsDisk.ManagedDisk.Id;
255-
this.VM.StorageProfile.OsDisk.ManagedDisk.StorageAccountType = this.StorageAccountType ?? this.VM.StorageProfile.OsDisk.ManagedDisk.StorageAccountType;
256-
}
247+
this.VM.StorageProfile.OsDisk.ManagedDisk = SetManagedDisk(this.ManagedDiskId, this.StorageAccountType, this.VM.StorageProfile.OsDisk.ManagedDisk);
257248

258249
this.VM.StorageProfile.OsDisk.WriteAcceleratorEnabled = this.WriteAccelerator.IsPresent;
259250

0 commit comments

Comments
 (0)