Skip to content

Commit 65ca805

Browse files
committed
Format Image Cmdlet Output
1 parent d5ebd4c commit 65ca805

File tree

8 files changed

+1120
-8
lines changed

8 files changed

+1120
-8
lines changed

src/ResourceManager/Compute/Commands.Compute.Test/Commands.Compute.Test.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,9 @@
289289
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineTests\TestVirtualMachineWithVMAgentAutoUpdate.json">
290290
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
291291
</None>
292+
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VirtualMachineTests\TestVMImageCmdletOutputFormat.json">
293+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
294+
</None>
292295
<None Include="SessionRecords\Microsoft.Azure.Commands.Compute.Test.ScenarioTests.VMDynamicTests\RunVMDynamicTests.json">
293296
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
294297
</None>

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

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function Get-ComputeTestMode
8989
}
9090

9191
# Get Compute Test Location
92-
function Get-ComputTestLocation
92+
function Get-ComputeTestLocation
9393
{
9494
return $env:AZURE_COMPUTE_TEST_LOCATION;
9595
}
@@ -293,9 +293,37 @@ function Get-DefaultVMConfig
293293

294294
# VM Profile & Hardware
295295
$vmsize = Get-DefaultVMSize $location;
296-
$vmname = Get-RandomItemName 'pstestvm';
296+
$vmname = Get-RandomItemName 'crptestps';
297297

298298
$vm = New-AzureVMConfig -VMName $vmname -VMSize $vmsize;
299299

300300
return $vm;
301-
}
301+
}
302+
303+
# Assert Output Contains
304+
function Assert-OutputContains
305+
{
306+
param([string] $cmd, [string[]] $sstr)
307+
308+
$st = Write-Verbose ('Running Command : ' + $cmd);
309+
$output = Invoke-Expression $cmd | Out-String;
310+
311+
$max_output_len = 1500;
312+
if ($output.Length -gt $max_output_len)
313+
{
314+
# Truncate Long Output in Logs
315+
$st = Write-Verbose ('Output String : ' + $output.Substring(0, $max_output_len) + '...');
316+
}
317+
else
318+
{
319+
$st = Write-Verbose ('Output String : ' + $output);
320+
}
321+
322+
$index = 1;
323+
foreach ($str in $sstr)
324+
{
325+
$st = Write-Verbose ('Search String ' + $index++ + " : `'" + $str + "`'");
326+
Assert-True { $output.Contains($str) }
327+
$st = Write-Verbose "Found.";
328+
}
329+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ function Run-VMDynamicTests
259259
{
260260
param ([int] $num_total_generated_tests = 3, [string] $base_folder = '.\ScenarioTests\Generated')
261261

262-
$target_location = Get-ComputTestLocation;
262+
$target_location = Get-ComputeTestLocation;
263263

264264
$st = Write-Verbose 'Running VM Dynamic Tests - Start';
265265

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,5 +102,12 @@ public void TestVirtualMachineTags()
102102
{
103103
ComputeTestController.NewInstance.RunPsTest("Test-VirtualMachineTags");
104104
}
105+
106+
[Fact]
107+
[Trait(Category.AcceptanceType, Category.CheckIn)]
108+
public void TestVMImageCmdletOutputFormat()
109+
{
110+
ComputeTestController.NewInstance.RunPsTest("Test-VMImageCmdletOutputFormat");
111+
}
105112
}
106113
}

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,3 +1281,27 @@ function Test-LinuxVirtualMachine
12811281
Clean-ResourceGroup $rgname
12821282
}
12831283
}
1284+
1285+
# Test Image Cmdlet Output Format
1286+
function Test-VMImageCmdletOutputFormat
1287+
{
1288+
$locStr = 'westus';
1289+
$publisher = 'MicrosoftWindowsServer';
1290+
$offer = 'WindowsServer';
1291+
$sku = '2008-R2-SP1';
1292+
$ver = '2.0.201503';
1293+
1294+
Assert-OutputContains " Get-AzureVMImagePublisher -Location $locStr" @('Id', 'Location', 'PublisherName');
1295+
1296+
Assert-OutputContains " Get-AzureVMImagePublisher -Location $locStr | ? { `$_.PublisherName -eq `'$publisher`' } " @('Id', 'Location', 'PublisherName');
1297+
1298+
Assert-OutputContains " Get-AzureVMImagePublisher -Location $locStr | ? { `$_.PublisherName -eq `'$publisher`' } | Get-AzureVMImageOffer " @('Id', 'Location', 'PublisherName', 'Offer');
1299+
1300+
Assert-OutputContains " Get-AzureVMImagePublisher -Location $locStr | ? { `$_.PublisherName -eq `'$publisher`' } | Get-AzureVMImageOffer | Get-AzureVMImageSku " @('Id', 'Location', 'PublisherName', 'Offer', 'Sku');
1301+
1302+
Assert-OutputContains " Get-AzureVMImagePublisher -Location $locStr | ? { `$_.PublisherName -eq `'$publisher`' } | Get-AzureVMImageOffer | Get-AzureVMImageSku | Get-AzureVMImage " @('Id', 'Location', 'PublisherName', 'Offer', 'Sku', 'Version', 'FilterExpression');
1303+
1304+
Assert-OutputContains " Get-AzureVMImage -Location $locStr -PublisherName $publisher -Offer $offer -Skus $sku -Version $ver " @('Id', 'Location', 'PublisherName', 'Offer', 'Sku', 'Version', 'FilterExpression', 'Name', 'DataDiskImages', 'OSDiskImage', 'PurchasePlan');
1305+
1306+
Assert-OutputContains " Get-AzureVMImageDetail -Location $locStr -PublisherName $publisher -Offer $offer -Skus $sku -Version $ver " @('Id', 'Location', 'PublisherName', 'Offer', 'Sku', 'Version', 'FilterExpression', 'Name', 'DataDiskImages', 'OSDiskImage', 'PurchasePlan');
1307+
}

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

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

src/ResourceManager/Compute/Commands.Compute/Microsoft.Azure.Commands.Compute.format.ps1xml

Lines changed: 193 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,34 @@
111111
</ListEntries>
112112
</ListControl>
113113
</View>-->
114+
114115
<View>
115-
<Name>Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineExtensionImageType</Name>
116+
<Name>Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineImageBase</Name>
116117
<ViewSelectedBy>
117-
<TypeName>Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineExtensionImageType</TypeName>
118+
<TypeName>Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineImageBase</TypeName>
119+
</ViewSelectedBy>
120+
<ListControl>
121+
<ListEntries>
122+
<ListEntry>
123+
<ListItems>
124+
<ListItem>
125+
<Label>Id</Label>
126+
<PropertyName>Id</PropertyName>
127+
</ListItem>
128+
<ListItem>
129+
<Label>Location</Label>
130+
<PropertyName>Location</PropertyName>
131+
</ListItem>
132+
</ListItems>
133+
</ListEntry>
134+
</ListEntries>
135+
</ListControl>
136+
</View>
137+
138+
<View>
139+
<Name>Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineImagePublisher</Name>
140+
<ViewSelectedBy>
141+
<TypeName>Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineImagePublisher</TypeName>
118142
</ViewSelectedBy>
119143
<ListControl>
120144
<ListEntries>
@@ -132,15 +156,180 @@
132156
<Label>PublisherName</Label>
133157
<PropertyName>PublisherName</PropertyName>
134158
</ListItem>
159+
</ListItems>
160+
</ListEntry>
161+
</ListEntries>
162+
</ListControl>
163+
</View>
164+
165+
<View>
166+
<Name>Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineImageOffer</Name>
167+
<ViewSelectedBy>
168+
<TypeName>Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineImageOffer</TypeName>
169+
</ViewSelectedBy>
170+
<ListControl>
171+
<ListEntries>
172+
<ListEntry>
173+
<ListItems>
135174
<ListItem>
136-
<Label>Type</Label>
137-
<PropertyName>Type</PropertyName>
175+
<Label>Id</Label>
176+
<PropertyName>Id</PropertyName>
177+
</ListItem>
178+
<ListItem>
179+
<Label>Location</Label>
180+
<PropertyName>Location</PropertyName>
181+
</ListItem>
182+
<ListItem>
183+
<Label>PublisherName</Label>
184+
<PropertyName>PublisherName</PropertyName>
185+
</ListItem>
186+
<ListItem>
187+
<Label>Offer</Label>
188+
<PropertyName>Offer</PropertyName>
189+
</ListItem>
190+
</ListItems>
191+
</ListEntry>
192+
</ListEntries>
193+
</ListControl>
194+
</View>
195+
196+
<View>
197+
<Name>Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineImageSku</Name>
198+
<ViewSelectedBy>
199+
<TypeName>Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineImageSku</TypeName>
200+
</ViewSelectedBy>
201+
<ListControl>
202+
<ListEntries>
203+
<ListEntry>
204+
<ListItems>
205+
<ListItem>
206+
<Label>Id</Label>
207+
<PropertyName>Id</PropertyName>
208+
</ListItem>
209+
<ListItem>
210+
<Label>Location</Label>
211+
<PropertyName>Location</PropertyName>
212+
</ListItem>
213+
<ListItem>
214+
<Label>PublisherName</Label>
215+
<PropertyName>PublisherName</PropertyName>
216+
</ListItem>
217+
<ListItem>
218+
<Label>Offer</Label>
219+
<PropertyName>Offer</PropertyName>
220+
</ListItem>
221+
<ListItem>
222+
<Label>Skus</Label>
223+
<PropertyName>Skus</PropertyName>
224+
</ListItem>
225+
</ListItems>
226+
</ListEntry>
227+
</ListEntries>
228+
</ListControl>
229+
</View>
230+
231+
<View>
232+
<Name>Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineImage</Name>
233+
<ViewSelectedBy>
234+
<TypeName>Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineImage</TypeName>
235+
</ViewSelectedBy>
236+
<ListControl>
237+
<ListEntries>
238+
<ListEntry>
239+
<ListItems>
240+
<ListItem>
241+
<Label>Id</Label>
242+
<PropertyName>Id</PropertyName>
243+
</ListItem>
244+
<ListItem>
245+
<Label>Location</Label>
246+
<PropertyName>Location</PropertyName>
247+
</ListItem>
248+
<ListItem>
249+
<Label>PublisherName</Label>
250+
<PropertyName>PublisherName</PropertyName>
251+
</ListItem>
252+
<ListItem>
253+
<Label>Offer</Label>
254+
<PropertyName>Offer</PropertyName>
255+
</ListItem>
256+
<ListItem>
257+
<Label>Skus</Label>
258+
<PropertyName>Skus</PropertyName>
259+
</ListItem>
260+
<ListItem>
261+
<Label>Version</Label>
262+
<PropertyName>Version</PropertyName>
263+
</ListItem>
264+
<ListItem>
265+
<Label>FilterExpression</Label>
266+
<PropertyName>FilterExpression</PropertyName>
267+
</ListItem>
268+
</ListItems>
269+
</ListEntry>
270+
</ListEntries>
271+
</ListControl>
272+
</View>
273+
274+
<View>
275+
<Name>Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineImageDetail</Name>
276+
<ViewSelectedBy>
277+
<TypeName>Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineImageDetail</TypeName>
278+
</ViewSelectedBy>
279+
<ListControl>
280+
<ListEntries>
281+
<ListEntry>
282+
<ListItems>
283+
<ListItem>
284+
<Label>Id</Label>
285+
<PropertyName>Id</PropertyName>
286+
</ListItem>
287+
<ListItem>
288+
<Label>Location</Label>
289+
<PropertyName>Location</PropertyName>
290+
</ListItem>
291+
<ListItem>
292+
<Label>PublisherName</Label>
293+
<PropertyName>PublisherName</PropertyName>
294+
</ListItem>
295+
<ListItem>
296+
<Label>Offer</Label>
297+
<PropertyName>Offer</PropertyName>
298+
</ListItem>
299+
<ListItem>
300+
<Label>Skus</Label>
301+
<PropertyName>Skus</PropertyName>
302+
</ListItem>
303+
<ListItem>
304+
<Label>Version</Label>
305+
<PropertyName>Version</PropertyName>
306+
</ListItem>
307+
<ListItem>
308+
<Label>FilterExpression</Label>
309+
<PropertyName>FilterExpression</PropertyName>
310+
</ListItem>
311+
<ListItem>
312+
<Label>Name</Label>
313+
<PropertyName>Name</PropertyName>
314+
</ListItem>
315+
<ListItem>
316+
<Label>OSDiskImage</Label>
317+
<PropertyName>OSDiskImageText</PropertyName>
318+
</ListItem>
319+
<ListItem>
320+
<Label>PurchasePlan</Label>
321+
<PropertyName>PurchasePlanText</PropertyName>
322+
</ListItem>
323+
<ListItem>
324+
<Label>DataDiskImages</Label>
325+
<PropertyName>DataDiskImagesText</PropertyName>
138326
</ListItem>
139327
</ListItems>
140328
</ListEntry>
141329
</ListEntries>
142330
</ListControl>
143331
</View>
332+
144333
<View>
145334
<Name>Microsoft.Azure.Commands.Compute.Models.PSVirtualMachineExtensionImage</Name>
146335
<ViewSelectedBy>

src/ResourceManager/Compute/Commands.Compute/Models/PSVirtualMachineImage.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// ----------------------------------------------------------------------------------
1414

1515
using Microsoft.Azure.Management.Compute.Models;
16+
using Newtonsoft.Json;
1617
using System.Collections.Generic;
1718

1819
namespace Microsoft.Azure.Commands.Compute.Models
@@ -53,8 +54,26 @@ public class PSVirtualMachineImageDetail : PSVirtualMachineImage
5354

5455
public OSDiskImage OSDiskImage { get; set; }
5556

57+
[JsonIgnore]
58+
public string OSDiskImageText
59+
{
60+
get { return JsonConvert.SerializeObject(OSDiskImage, Formatting.Indented); }
61+
}
62+
5663
public PurchasePlan PurchasePlan { get; set; }
5764

65+
[JsonIgnore]
66+
public string PurchasePlanText
67+
{
68+
get { return JsonConvert.SerializeObject(PurchasePlan, Formatting.Indented); }
69+
}
70+
5871
public IList<DataDiskImage> DataDiskImages { get; set; }
72+
73+
[JsonIgnore]
74+
public string DataDiskImagesText
75+
{
76+
get { return JsonConvert.SerializeObject(DataDiskImages, Formatting.Indented); }
77+
}
5978
}
6079
}

0 commit comments

Comments
 (0)