Skip to content

Commit 3c56e78

Browse files
authored
Merge pull request #3961 from xizhamsft/dev
Switch to swagger generated SDK for operational insights powershell commands
2 parents 2898c3c + d14c810 commit 3c56e78

File tree

52 files changed

+2826
-3916
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2826
-3916
lines changed

src/ResourceManager/OperationalInsights/Commands.OperationalInsights.Test/Commands.OperationalInsights.Test.csproj

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@
5757
<Reference Include="Microsoft.Azure.Gallery">
5858
<HintPath>..\..\..\packages\Microsoft.Azure.Gallery.2.6.2-preview\lib\net40\Microsoft.Azure.Gallery.dll</HintPath>
5959
</Reference>
60-
<Reference Include="Microsoft.Azure.Management.OperationalInsights, Version=0.16.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
61-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.OperationalInsights.0.16.0-preview\lib\net40\Microsoft.Azure.Management.OperationalInsights.dll</HintPath>
60+
<Reference Include="Microsoft.Azure.Management.OperationalInsights, Version=0.18.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
61+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.OperationalInsights.0.18.0-preview\lib\net45\Microsoft.Azure.Management.OperationalInsights.dll</HintPath>
6262
<Private>True</Private>
6363
</Reference>
6464
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
@@ -69,9 +69,9 @@
6969
<SpecificVersion>False</SpecificVersion>
7070
<HintPath>..\..\..\packages\Microsoft.Azure.Test.Framework.1.0.6179.26854-prerelease\lib\net45\Microsoft.Azure.Test.Framework.dll</HintPath>
7171
</Reference>
72-
<Reference Include="Microsoft.Azure.Test.HttpRecorder">
73-
<SpecificVersion>False</SpecificVersion>
74-
<HintPath>..\..\..\packages\Microsoft.Azure.Test.HttpRecorder.1.6.7-preview\lib\net45\Microsoft.Azure.Test.HttpRecorder.dll</HintPath>
72+
<Reference Include="Microsoft.Azure.Test.HttpRecorder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
73+
<HintPath>..\..\..\packages\Microsoft.Azure.Test.HttpRecorder.1.6.8\lib\net45\Microsoft.Azure.Test.HttpRecorder.dll</HintPath>
74+
<Private>True</Private>
7575
</Reference>
7676
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory, Version=2.28.3.860, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
7777
<HintPath>..\..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.28.3\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll</HintPath>
@@ -84,8 +84,16 @@
8484
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.2.3.5\lib\net45\Microsoft.Rest.ClientRuntime.dll</HintPath>
8585
<Private>True</Private>
8686
</Reference>
87+
<Reference Include="Microsoft.Rest.ClientRuntime.Azure, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
88+
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.3.3.5\lib\net45\Microsoft.Rest.ClientRuntime.Azure.dll</HintPath>
89+
<Private>True</Private>
90+
</Reference>
8791
<Reference Include="Microsoft.Rest.ClientRuntime.Azure.Authentication, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
88-
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.Authentication.2.2.9-preview\lib\net45\Microsoft.Rest.ClientRuntime.Azure.Authentication.dll</HintPath>
92+
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.Authentication.2.2.12\lib\net45\Microsoft.Rest.ClientRuntime.Azure.Authentication.dll</HintPath>
93+
<Private>True</Private>
94+
</Reference>
95+
<Reference Include="Microsoft.Rest.ClientRuntime.Azure.TestFramework, Version=1.5.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
96+
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.TestFramework.1.5.1-preview\lib\net45\Microsoft.Rest.ClientRuntime.Azure.TestFramework.dll</HintPath>
8997
<Private>True</Private>
9098
</Reference>
9199
<Reference Include="Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">

src/ResourceManager/OperationalInsights/Commands.OperationalInsights.Test/ScenarioTests/DataSourceTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
using Microsoft.Azure.ServiceManagemenet.Common.Models;
1616
using Microsoft.WindowsAzure.Commands.ScenarioTest;
17+
using System;
1718
using Xunit;
1819
using Xunit.Abstractions;
1920

src/ResourceManager/OperationalInsights/Commands.OperationalInsights.Test/ScenarioTests/DataSourceTests.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ function Test-DataSourceCreateFailsWithoutWorkspace
9797

9898
New-AzureRmResourceGroup -Name $rgname -Location $wslocation -Force
9999

100-
Assert-ThrowsContains { New-AzureRmOperationalInsightsAzureActivityLogDataSource -ResourceGroupName $rgname -WorkspaceName $wsname -Name $dsName -SubscriptionId $subId1 } "ResourceNotFound"
100+
Assert-ThrowsContains { New-AzureRmOperationalInsightsAzureActivityLogDataSource -ResourceGroupName $rgname -WorkspaceName $wsname -Name $dsName -SubscriptionId $subId1 } "NotFound"
101101
}
102102

103103
<#
@@ -151,7 +151,7 @@ function Test-ToggleSingletonDataSourceState
151151
New-AzureRmResourceGroup -Name $rgname -Location $wslocation -Force
152152

153153
# Create a workspace to house the data source
154-
$workspace = New-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname -Name $wsname -Location $wslocation -Force
154+
$workspace = New-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname -Name $wsname -Location $wslocation -Sku premium -Force
155155

156156
# enable/disable iislog collection
157157
Enable-AzureRmOperationalInsightsIISLogCollection -Workspace $workspace

src/ResourceManager/OperationalInsights/Commands.OperationalInsights.Test/ScenarioTests/OperationalInsightsScenarioTestBase.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222
using Microsoft.Azure.Test.HttpRecorder;
2323
using Microsoft.WindowsAzure.Commands.ScenarioTest;
2424
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
25+
using System;
2526
using System.Collections.Generic;
27+
using System.IO;
28+
using RestTestFramework = Microsoft.Rest.ClientRuntime.Azure.TestFramework;
2629

2730
namespace Microsoft.Azure.Commands.OperationalInsights.Test
2831
{
@@ -35,9 +38,9 @@ protected OperationalInsightsScenarioTestBase()
3538
helper = new EnvironmentSetupHelper();
3639
}
3740

38-
protected void SetupManagementClients()
41+
protected void SetupManagementClients(RestTestFramework.MockContext context)
3942
{
40-
var operationalInsightsManagementClient = GetOperationalInsightsManagementClient();
43+
var operationalInsightsManagementClient = GetOperationalInsightsManagementClient(context);
4144
var resourceManagementClient = GetResourceManagementClient();
4245
var subscriptionsClient = GetSubscriptionClient();
4346
var galleryClient = GetGalleryClient();
@@ -60,12 +63,11 @@ protected void RunPowerShellTest(params string[] scripts)
6063
var providersToIgnore = new Dictionary<string, string>();
6164
providersToIgnore.Add("Microsoft.Azure.Management.Resources.ResourceManagementClient", "2016-02-01");
6265
HttpMockServer.Matcher = new PermissiveRecordMatcherWithApiExclusion(true, d, providersToIgnore);
66+
HttpMockServer.RecordsDirectory = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SessionRecords");
6367

64-
using (UndoContext context = UndoContext.Current)
68+
using (RestTestFramework.MockContext context = RestTestFramework.MockContext.Start(TestUtilities.GetCallingClass(2), TestUtilities.GetCurrentMethodName(2)))
6569
{
66-
context.Start(TestUtilities.GetCallingClass(2), TestUtilities.GetCurrentMethodName(2));
67-
68-
SetupManagementClients();
70+
SetupManagementClients(context);
6971

7072
helper.SetupEnvironment(AzureModule.AzureResourceManager);
7173
helper.SetupModules(AzureModule.AzureResourceManager,
@@ -80,9 +82,9 @@ protected void RunPowerShellTest(params string[] scripts)
8082
}
8183
}
8284

83-
protected OperationalInsightsManagementClient GetOperationalInsightsManagementClient()
85+
protected OperationalInsightsManagementClient GetOperationalInsightsManagementClient(RestTestFramework.MockContext context)
8486
{
85-
return TestBase.GetServiceClient<OperationalInsightsManagementClient>(new CSMTestEnvironmentFactory());
87+
return context.GetServiceClient<OperationalInsightsManagementClient>(RestTestFramework.TestEnvironmentFactory.GetTestEnvironment());
8688
}
8789

8890
protected ResourceManagementClient GetResourceManagementClient()

src/ResourceManager/OperationalInsights/Commands.OperationalInsights.Test/ScenarioTests/StorageInsightTests.ps1

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function Test-StorageInsightCreateUpdateDelete
2828
New-AzureRmResourceGroup -Name $rgname -Location $wslocation -Force
2929

3030
# Create a workspace to house the storage insight
31-
$workspace = New-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname -Name $wsname -Location $wslocation -Force
31+
$workspace = New-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname -Name $wsname -Location $wslocation -Sku "STANDARD" -Force
3232

3333
# Create a storage insight
3434
$storageinsight = New-AzureRmOperationalInsightsStorageInsight -ResourceGroupName $rgname -WorkspaceName $wsname -Name $siname -Tables @("WADWindowsEventLogsTable", "LinuxSyslogVer2v0") -Containers @("wad-iis-logfiles") -StorageAccountResourceId $said -StorageAccountKey "fakekey"
@@ -80,7 +80,7 @@ function Test-StorageInsightCreateUpdateDelete
8080
Assert-AreEqualArray @("WADWindowsEventLogsTable") $storageInsight.Tables
8181
Assert-AreEqualArray @() $storageInsight.Containers
8282

83-
$storageinsight = $storageinsight | Set-AzureRmOperationalInsightsStorageInsight -Tables @() -Containers @("wad-iis-logfiles")
83+
$storageinsight = $storageinsight | Set-AzureRmOperationalInsightsStorageInsight -Tables @() -Containers @("wad-iis-logfiles") -StorageAccountKey "anotherfakekey"
8484
Assert-AreEqualArray @() $storageInsight.Tables
8585
Assert-AreEqualArray @("wad-iis-logfiles") $storageInsight.Containers
8686

@@ -110,5 +110,5 @@ function Test-StorageInsightCreateFailsNoWs
110110

111111
New-AzureRmResourceGroup -Name $rgname -Location $wslocation -Force
112112

113-
Assert-ThrowsContains { New-AzureRmOperationalInsightsStorageInsight -ResourceGroupName $rgname -WorkspaceName $wsname -Name $siname -Tables @("WADWindowsEventLogsTable", "LinuxSyslogVer2v0") -StorageAccountResourceId $said -StorageAccountKey "fakekey" } "ResourceNotFound"
113+
Assert-ThrowsContains { New-AzureRmOperationalInsightsStorageInsight -ResourceGroupName $rgname -WorkspaceName $wsname -Name $siname -Tables @("WADWindowsEventLogsTable", "LinuxSyslogVer2v0") -StorageAccountResourceId $said -StorageAccountKey "fakekey" } "NotFound"
114114
}

src/ResourceManager/OperationalInsights/Commands.OperationalInsights.Test/ScenarioTests/WorkspaceTests.ps1

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ function Test-WorkspaceCreateUpdateDelete
2525
New-AzureRmResourceGroup -Name $rgname -Location $wslocation -Force
2626

2727
# Create and get a workspace
28-
$workspace = New-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname -Name $wsname -Location $wslocation -Sku free -Tags @{"tag1" = "val1"} -Force
28+
$workspace = New-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname -Name $wsname -Location $wslocation -Sku "STANDARD" -Tags @{"tag1" = "val1"} -Force
2929
Assert-AreEqual $rgname $workspace.ResourceGroupName
3030
Assert-AreEqual $wsname $workspace.Name
3131
Assert-AreEqual $wslocation $workspace.Location
32-
Assert-AreEqual "free" $workspace.Sku
32+
Assert-AreEqual "STANDARD" $workspace.Sku
33+
# if no value for RetentionInDays is specified, use the default value for the sku. For standard, the default is 30.
34+
Assert-AreEqual 30 $workspace.RetentionInDays
3335
Assert-NotNull $workspace.ResourceId
3436
Assert-AreEqual 1 $workspace.Tags.Count
3537
Assert-NotNull $workspace.CustomerId
@@ -39,33 +41,34 @@ function Test-WorkspaceCreateUpdateDelete
3941
Assert-AreEqual $rgname $workspace.ResourceGroupName
4042
Assert-AreEqual $wsname $workspace.Name
4143
Assert-AreEqual $wslocation $workspace.Location
42-
Assert-AreEqual "free" $workspace.Sku
44+
Assert-AreEqual "STANDARD" $workspace.Sku
45+
Assert-AreEqual 30 $workspace.RetentionInDays
4346
Assert-NotNull $workspace.ResourceId
4447
Assert-AreEqual 1 $workspace.Tags.Count
4548
Assert-NotNull $workspace.CustomerId
4649
Assert-NotNull $workspace.PortalUrl
4750

4851
# Create a second workspace for list testing
4952
$wstwoname = Get-ResourceName
50-
$workspacetwo = New-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname -Name $wstwoname -Location $wslocation -Force
51-
53+
$workspacetwo = New-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname -Name $wstwoname -Location $wslocation -Sku "PerNode" -RetentionInDays 60 -Force
54+
55+
$workspacetwo = Get-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname -Name $wstwoname
56+
Assert-AreEqual 60 $workspacetwo.RetentionInDays
57+
5258
# List the workspaces in the subscription
5359
$workspaces = Get-AzureRmOperationalInsightsWorkspace
54-
Assert-AreEqual 2 $workspaces.Count
5560
Assert-AreEqual 1 ($workspaces | Where {$_.Name -eq $wsname}).Count
5661
Assert-AreEqual 1 ($workspaces | Where {$_.Name -eq $wstwoname}).Count
5762

5863
# List the workspaces in the resource group
5964
$workspaces = Get-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname
60-
Assert-AreEqual 2 $workspaces.Count
6165
Assert-AreEqual 1 ($workspaces | Where {$_.Name -eq $wsname}).Count
6266
Assert-AreEqual 1 ($workspaces | Where {$_.Name -eq $wstwoname}).Count
6367

6468
# Delete the second workspace
6569
Remove-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgName -Name $wstwoname -Force
66-
Assert-ThrowsContains { Get-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname -Name $wstwoname } "ResourceNotFound"
70+
Assert-ThrowsContains { Get-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname -Name $wstwoname } "NotFound"
6771
$workspaces = Get-AzureRmOperationalInsightsWorkspace
68-
Assert-AreEqual 1 $workspaces.Count
6972
Assert-AreEqual 1 ($workspaces | Where {$_.Name -eq $wsname}).Count
7073
Assert-AreEqual 0 ($workspaces | Where {$_.Name -eq $wstwoname}).Count
7174

@@ -76,17 +79,18 @@ function Test-WorkspaceCreateUpdateDelete
7679
$workspace = $workspace | New-AzureRmOperationalInsightsWorkspace -Tags @{"foo" = "bar"} -Force
7780
Assert-AreEqual 1 $workspace.Tags.Count
7881

79-
# Clear the tags and update the sku via piping
80-
$workspace | Set-AzureRmOperationalInsightsWorkspace -Tags @{} -Sku standard
82+
# Clear the tags and update the sku, RetentionInDays via piping
83+
$workspace | Set-AzureRmOperationalInsightsWorkspace -Tags @{} -Sku standalone -RetentionInDays 123
8184
$workspace = Get-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname -Name $wsname
8285
Assert-AreEqual 0 $workspace.Tags.Count
83-
Assert-AreEqual standard $workspace.Sku
86+
Assert-AreEqual standalone $workspace.Sku
87+
Assert-AreEqual 123 $workspace.RetentionInDays
8488

8589
# Delete the original workspace via piping
8690
$workspace | Remove-AzureRmOperationalInsightsWorkspace -Force
8791
$workspaces = Get-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname
8892
Assert-AreEqual 0 $workspaces.Count
89-
Assert-ThrowsContains { Get-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname -Name wsname } "ResourceNotFound"
93+
Assert-ThrowsContains { Get-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname -Name wsname } "NotFound"
9094
}
9195

9296
<#
@@ -106,7 +110,7 @@ function Test-WorkspaceActions
106110
Assert-AreEqual 0 $accounts.Count
107111

108112
# Attempt to link a workspace to an invalid account
109-
Assert-ThrowsContains { New-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname -Name $wsname -Location $wslocation -CustomerId ([guid]::NewGuid()) } "not a valid link target"
113+
Assert-ThrowsContains { New-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname -Name $wsname -Location $wslocation -Sku "STANDARD" -CustomerId ([guid]::NewGuid()) } "BadRequest"
110114

111115
# Create a real workspace for use in the rest of the test
112116
$workspace = New-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname -Name $wsname -Location $wslocation -Sku "STANDARD" -Tags @{"tag1" = "val1"} -Force
@@ -159,11 +163,11 @@ function Test-WorkspaceEnableDisableListIntelligencePacks
159163
New-AzureRmResourceGroup -Name $rgname -Location $wslocation -Force
160164

161165
# Create and get a workspace
162-
$workspace = New-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname -Name $wsname -Location $wslocation -Sku free -Tags @{"tag1" = "val1"} -Force
166+
$workspace = New-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname -Name $wsname -Location $wslocation -Sku "STANDARD" -Tags @{"tag1" = "val1"} -Force
163167
Assert-AreEqual $rgname $workspace.ResourceGroupName
164168
Assert-AreEqual $wsname $workspace.Name
165169
Assert-AreEqual $wslocation $workspace.Location
166-
Assert-AreEqual "free" $workspace.Sku
170+
Assert-AreEqual "STANDARD" $workspace.Sku
167171
Assert-NotNull $workspace.ResourceId
168172
Assert-AreEqual 1 $workspace.Tags.Count
169173
Assert-NotNull $workspace.CustomerId
@@ -209,5 +213,5 @@ function Test-WorkspaceEnableDisableListIntelligencePacks
209213
$workspace | Remove-AzureRmOperationalInsightsWorkspace -Force
210214
$workspaces = Get-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname
211215
Assert-AreEqual 0 $workspaces.Count
212-
Assert-ThrowsContains { Get-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname -Name wsname } "ResourceNotFound"
216+
Assert-ThrowsContains { Get-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname -Name wsname } "NotFound"
213217
}

0 commit comments

Comments
 (0)