Skip to content

Commit d07d228

Browse files
committed
Fix AutoMapper issue of Zones property when it is null.
1 parent ebd20ac commit d07d228

File tree

5 files changed

+52
-23
lines changed

5 files changed

+52
-23
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ function Test-Disk
6060

6161
# Get disk test
6262
$disk = Get-AzureRmDisk -ResourceGroupName $rgname -DiskName $diskname;
63+
Assert-AreEqual $null $disk.Zones;
6364
Assert-AreEqual 5 $disk.DiskSizeGB;
6465
Assert-AreEqual StandardLRS $disk.Sku.Name;
6566
Assert-AreEqual Windows $disk.OsType;

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,10 @@ function Test-VirtualMachineScaleSetReimageUpdate
372372
Assert-AreEqual "ProvisioningState/succeeded" $vmssInstanceViewResult.VirtualMachine.StatusesSummary[0].Code;
373373

374374
# Manual Upgrade operation
375-
$st = Get-AzureRmVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName | Update-AzureRmVmss -ResourceGroupName $rgname -Name $vmssName;
375+
$vmss = Get-AzureRmVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName;
376+
Assert-AreEqual $null $vmss.Zones;
377+
378+
Update-AzureRmVmss -ResourceGroupName $rgname -Name $vmssName -VirtualMachineScaleSet $vmss;
376379
$vmssResult = Get-AzureRmVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName;
377380
$vmssInstanceViewResult = Get-AzureRmVmss -ResourceGroupName $rgname -VMScaleSetName $vmssName -InstanceView;
378381
Assert-AreEqual "ProvisioningState/succeeded" $vmssInstanceViewResult.VirtualMachine.StatusesSummary[0].Code;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ function Test-VirtualMachine
169169
Update-AzureRmVM -ResourceGroupName $rgname -VM $p;
170170

171171
$vm2 = Get-AzureRmVM -Name $vmname -ResourceGroupName $rgname;
172+
Assert-AreEqual $null $vm2.Zones;
173+
172174
Assert-AreEqual $vm2.NetworkProfile.NetworkInterfaces.Count 1;
173175
Assert-AreEqual $vm2.NetworkProfile.NetworkInterfaces[0].Id $nicId;
174176

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public static void Initialize()
161161
.ForMember(c => c.AvailabilitySetReference, o => o.MapFrom(r => r.AvailabilitySet))
162162
.ForMember(c => c.Extensions, o => o.MapFrom(r => r.Resources))
163163
.ForMember(c => c.OSProfile, o => o.MapFrom(r => r.OsProfile))
164-
.ForMember(c => c.Zones, o => o.MapFrom(r => r.Zones));
164+
.ForMember(c => c.Zones, o => o.Condition(r => (r.Zones != null)));
165165

166166
cfg.CreateMap<AzureOperationResponse<FROM.VirtualMachine>, TO.PSVirtualMachine>()
167167
.ForMember(c => c.StatusCode, o => o.MapFrom(r => r.Response.StatusCode));
@@ -176,7 +176,8 @@ public static void Initialize()
176176
cfg.CreateMap<FROM.VirtualMachine, TO.PSVirtualMachineListStatus>()
177177
.ForMember(c => c.AvailabilitySetReference, o => o.MapFrom(r => r.AvailabilitySet))
178178
.ForMember(c => c.Extensions, o => o.MapFrom(r => r.Resources))
179-
.ForMember(c => c.OSProfile, o => o.MapFrom(r => r.OsProfile));
179+
.ForMember(c => c.OSProfile, o => o.MapFrom(r => r.OsProfile))
180+
.ForMember(c => c.Zones, o => o.Condition(r => (r.Zones != null)));
180181

181182
cfg.CreateMap<AzureOperationResponse<FROM.VirtualMachine>, TO.PSVirtualMachineListStatus>()
182183
.ForMember(c => c.StatusCode, o => o.MapFrom(r => r.Response.StatusCode));
@@ -208,9 +209,13 @@ public static void Initialize()
208209
cfg.CreateMap<AzureOperationResponse<IPage<FROM.Usage>>, TO.PSUsage>()
209210
.ForMember(c => c.StatusCode, o => o.MapFrom(r => r.Response.StatusCode));
210211

211-
cfg.CreateMap<TO.PSVirtualMachine, TO.PSVirtualMachineList>();
212-
cfg.CreateMap<TO.PSVirtualMachineList, TO.PSVirtualMachine>();
212+
// PSVirtualMachine <=> PSVirtualMachineList
213+
cfg.CreateMap<TO.PSVirtualMachine, TO.PSVirtualMachineList>()
214+
.ForMember(c => c.Zones, o => o.Condition(r => (r.Zones != null)));
215+
cfg.CreateMap<TO.PSVirtualMachineList, TO.PSVirtualMachine>()
216+
.ForMember(c => c.Zones, o => o.Condition(r => (r.Zones != null)));
213217

218+
// PSVmssDiskEncryptionStatusContext <=> PSVmssDiskEncryptionStatusContextList
214219
cfg.CreateMap<TO.PSVmssDiskEncryptionStatusContext, TO.PSVmssDiskEncryptionStatusContextList>();
215220
cfg.CreateMap<TO.PSVmssVMDiskEncryptionStatusContext, TO.PSVmssVMDiskEncryptionStatusContextList>();
216221
});

src/ResourceManager/Compute/Commands.Compute/Generated/Models/ComputeAutoMapperProfile.cs

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -66,21 +66,33 @@ protected override void Configure()
6666
Mapper.CreateMap<FROM.Snapshot, TO.PSSnapshotList>();
6767
Mapper.CreateMap<TO.PSSnapshotList, TO.PSSnapshot>();
6868
Mapper.CreateMap<TO.PSSnapshot, TO.PSSnapshotList>();
69-
Mapper.CreateMap<FROM.VirtualMachineScaleSet, TO.PSVirtualMachineScaleSetList>();
70-
Mapper.CreateMap<TO.PSVirtualMachineScaleSetList, TO.PSVirtualMachineScaleSet>();
71-
Mapper.CreateMap<TO.PSVirtualMachineScaleSet, TO.PSVirtualMachineScaleSetList>();
72-
Mapper.CreateMap<FROM.VirtualMachineScaleSet, TO.PSVirtualMachineScaleSetList>();
73-
Mapper.CreateMap<TO.PSVirtualMachineScaleSetList, TO.PSVirtualMachineScaleSet>();
74-
Mapper.CreateMap<TO.PSVirtualMachineScaleSet, TO.PSVirtualMachineScaleSetList>();
69+
Mapper.CreateMap<FROM.VirtualMachineScaleSet, TO.PSVirtualMachineScaleSetList>()
70+
.ForMember(c => c.Zones, o => o.Condition(r => (r.Zones != null)));
71+
Mapper.CreateMap<TO.PSVirtualMachineScaleSetList, TO.PSVirtualMachineScaleSet>()
72+
.ForMember(c => c.Zones, o => o.Condition(r => (r.Zones != null)));
73+
Mapper.CreateMap<TO.PSVirtualMachineScaleSet, TO.PSVirtualMachineScaleSetList>()
74+
.ForMember(c => c.Zones, o => o.Condition(r => (r.Zones != null)));
75+
Mapper.CreateMap<FROM.VirtualMachineScaleSet, TO.PSVirtualMachineScaleSetList>()
76+
.ForMember(c => c.Zones, o => o.Condition(r => (r.Zones != null)));
77+
Mapper.CreateMap<TO.PSVirtualMachineScaleSetList, TO.PSVirtualMachineScaleSet>()
78+
.ForMember(c => c.Zones, o => o.Condition(r => (r.Zones != null)));
79+
Mapper.CreateMap<TO.PSVirtualMachineScaleSet, TO.PSVirtualMachineScaleSetList>()
80+
.ForMember(c => c.Zones, o => o.Condition(r => (r.Zones != null)));
7581
Mapper.CreateMap<FROM.VirtualMachineScaleSetVM, TO.PSVirtualMachineScaleSetVMList>();
7682
Mapper.CreateMap<TO.PSVirtualMachineScaleSetVMList, TO.PSVirtualMachineScaleSetVM>();
7783
Mapper.CreateMap<TO.PSVirtualMachineScaleSetVM, TO.PSVirtualMachineScaleSetVMList>();
78-
Mapper.CreateMap<FROM.VirtualMachine, TO.PSVirtualMachineList>();
79-
Mapper.CreateMap<TO.PSVirtualMachineList, TO.PSVirtualMachine>();
80-
Mapper.CreateMap<TO.PSVirtualMachine, TO.PSVirtualMachineList>();
81-
Mapper.CreateMap<FROM.VirtualMachine, TO.PSVirtualMachineList>();
82-
Mapper.CreateMap<TO.PSVirtualMachineList, TO.PSVirtualMachine>();
83-
Mapper.CreateMap<TO.PSVirtualMachine, TO.PSVirtualMachineList>();
84+
Mapper.CreateMap<FROM.VirtualMachine, TO.PSVirtualMachineList>()
85+
.ForMember(c => c.Zones, o => o.Condition(r => (r.Zones != null)));
86+
Mapper.CreateMap<TO.PSVirtualMachineList, TO.PSVirtualMachine>()
87+
.ForMember(c => c.Zones, o => o.Condition(r => (r.Zones != null)));
88+
Mapper.CreateMap<TO.PSVirtualMachine, TO.PSVirtualMachineList>()
89+
.ForMember(c => c.Zones, o => o.Condition(r => (r.Zones != null)));
90+
Mapper.CreateMap<FROM.VirtualMachine, TO.PSVirtualMachineList>()
91+
.ForMember(c => c.Zones, o => o.Condition(r => (r.Zones != null)));
92+
Mapper.CreateMap<TO.PSVirtualMachineList, TO.PSVirtualMachine>()
93+
.ForMember(c => c.Zones, o => o.Condition(r => (r.Zones != null)));
94+
Mapper.CreateMap<TO.PSVirtualMachine, TO.PSVirtualMachineList>()
95+
.ForMember(c => c.Zones, o => o.Condition(r => (r.Zones != null)));
8496
Mapper.CreateMap<FROM.Disk, FROM.DiskUpdate>();
8597
Mapper.CreateMap<FROM.DiskUpdate, FROM.Disk>();
8698
Mapper.CreateMap<FROM.DiskUpdate, TO.PSDiskUpdate>();
@@ -97,8 +109,10 @@ protected override void Configure()
97109
Mapper.CreateMap<TO.PSVirtualMachineSize, FROM.VirtualMachineSize>();
98110
Mapper.CreateMap<FROM.ContainerService, TO.PSContainerService>();
99111
Mapper.CreateMap<TO.PSContainerService, FROM.ContainerService>();
100-
Mapper.CreateMap<FROM.Disk, TO.PSDisk>();
101-
Mapper.CreateMap<TO.PSDisk, FROM.Disk>();
112+
Mapper.CreateMap<FROM.Disk, TO.PSDisk>()
113+
.ForMember(c => c.Zones, o => o.Condition(r => (r.Zones != null)));
114+
Mapper.CreateMap<TO.PSDisk, FROM.Disk>()
115+
.ForMember(c => c.Zones, o => o.Condition(r => (r.Zones != null)));
102116
Mapper.CreateMap<FROM.AccessUri, TO.PSAccessUri>();
103117
Mapper.CreateMap<TO.PSAccessUri, FROM.AccessUri>();
104118
Mapper.CreateMap<FROM.Image, TO.PSImage>();
@@ -113,8 +127,10 @@ protected override void Configure()
113127
Mapper.CreateMap<TO.PSRunCommandDocumentBase, FROM.RunCommandDocumentBase>();
114128
Mapper.CreateMap<FROM.RollingUpgradeStatusInfo, TO.PSRollingUpgradeStatusInfo>();
115129
Mapper.CreateMap<TO.PSRollingUpgradeStatusInfo, FROM.RollingUpgradeStatusInfo>();
116-
Mapper.CreateMap<FROM.VirtualMachineScaleSet, TO.PSVirtualMachineScaleSet>();
117-
Mapper.CreateMap<TO.PSVirtualMachineScaleSet, FROM.VirtualMachineScaleSet>();
130+
Mapper.CreateMap<FROM.VirtualMachineScaleSet, TO.PSVirtualMachineScaleSet>()
131+
.ForMember(c => c.Zones, o => o.Condition(r => (r.Zones != null)));
132+
Mapper.CreateMap<TO.PSVirtualMachineScaleSet, FROM.VirtualMachineScaleSet>()
133+
.ForMember(c => c.Zones, o => o.Condition(r => (r.Zones != null)));
118134
Mapper.CreateMap<FROM.VirtualMachineScaleSetInstanceView, TO.PSVirtualMachineScaleSetInstanceView>();
119135
Mapper.CreateMap<TO.PSVirtualMachineScaleSetInstanceView, FROM.VirtualMachineScaleSetInstanceView>();
120136
Mapper.CreateMap<FROM.VirtualMachineScaleSetSku, TO.PSVirtualMachineScaleSetSku>();
@@ -125,8 +141,10 @@ protected override void Configure()
125141
Mapper.CreateMap<TO.PSVirtualMachineScaleSetVMInstanceView, FROM.VirtualMachineScaleSetVMInstanceView>();
126142
Mapper.CreateMap<FROM.VirtualMachineCaptureResult, TO.PSVirtualMachineCaptureResult>();
127143
Mapper.CreateMap<TO.PSVirtualMachineCaptureResult, FROM.VirtualMachineCaptureResult>();
128-
Mapper.CreateMap<FROM.VirtualMachine, TO.PSVirtualMachine>();
129-
Mapper.CreateMap<TO.PSVirtualMachine, FROM.VirtualMachine>();
144+
Mapper.CreateMap<FROM.VirtualMachine, TO.PSVirtualMachine>()
145+
.ForMember(c => c.Zones, o => o.Condition(r => (r.Zones != null)));
146+
Mapper.CreateMap<TO.PSVirtualMachine, FROM.VirtualMachine>()
147+
.ForMember(c => c.Zones, o => o.Condition(r => (r.Zones != null)));
130148
Mapper.CreateMap<FROM.VirtualMachineInstanceView, TO.PSVirtualMachineInstanceView>();
131149
Mapper.CreateMap<TO.PSVirtualMachineInstanceView, FROM.VirtualMachineInstanceView>();
132150
Mapper.CreateMap<FROM.RunCommandResult, TO.PSRunCommandResult>();

0 commit comments

Comments
 (0)