Skip to content

Switch to swagger generated SDK for operational insights powershell commands #3961

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
<Reference Include="Microsoft.Azure.Gallery">
<HintPath>..\..\..\packages\Microsoft.Azure.Gallery.2.6.2-preview\lib\net40\Microsoft.Azure.Gallery.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Management.OperationalInsights, Version=0.16.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Azure.Management.OperationalInsights.0.16.0-preview\lib\net40\Microsoft.Azure.Management.OperationalInsights.dll</HintPath>
<Reference Include="Microsoft.Azure.Management.OperationalInsights, Version=0.18.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Azure.Management.OperationalInsights.0.18.0-preview\lib\net45\Microsoft.Azure.Management.OperationalInsights.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Azure.ResourceManager, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
Expand All @@ -69,9 +69,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.Test.Framework.1.0.6179.26854-prerelease\lib\net45\Microsoft.Azure.Test.Framework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Azure.Test.HttpRecorder">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\packages\Microsoft.Azure.Test.HttpRecorder.1.6.7-preview\lib\net45\Microsoft.Azure.Test.HttpRecorder.dll</HintPath>
<Reference Include="Microsoft.Azure.Test.HttpRecorder, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Azure.Test.HttpRecorder.1.6.8\lib\net45\Microsoft.Azure.Test.HttpRecorder.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.IdentityModel.Clients.ActiveDirectory, Version=2.28.3.860, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.IdentityModel.Clients.ActiveDirectory.2.28.3\lib\net45\Microsoft.IdentityModel.Clients.ActiveDirectory.dll</HintPath>
Expand All @@ -84,8 +84,16 @@
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.2.3.5\lib\net45\Microsoft.Rest.ClientRuntime.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Rest.ClientRuntime.Azure, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.3.3.5\lib\net45\Microsoft.Rest.ClientRuntime.Azure.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Rest.ClientRuntime.Azure.Authentication, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.Authentication.2.2.9-preview\lib\net45\Microsoft.Rest.ClientRuntime.Azure.Authentication.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.Authentication.2.2.12\lib\net45\Microsoft.Rest.ClientRuntime.Azure.Authentication.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Rest.ClientRuntime.Azure.TestFramework, Version=1.5.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.TestFramework.1.5.1-preview\lib\net45\Microsoft.Rest.ClientRuntime.Azure.TestFramework.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Threading.Tasks, Version=1.0.12.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

using Microsoft.Azure.ServiceManagemenet.Common.Models;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using System;
using Xunit;
using Xunit.Abstractions;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function Test-DataSourceCreateFailsWithoutWorkspace

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

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

<#
Expand Down Expand Up @@ -151,7 +151,7 @@ function Test-ToggleSingletonDataSourceState
New-AzureRmResourceGroup -Name $rgname -Location $wslocation -Force

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

# enable/disable iislog collection
Enable-AzureRmOperationalInsightsIISLogCollection -Workspace $workspace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
using Microsoft.Azure.Test.HttpRecorder;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
using System;
using System.Collections.Generic;
using System.IO;
using RestTestFramework = Microsoft.Rest.ClientRuntime.Azure.TestFramework;

namespace Microsoft.Azure.Commands.OperationalInsights.Test
{
Expand All @@ -35,9 +38,9 @@ protected OperationalInsightsScenarioTestBase()
helper = new EnvironmentSetupHelper();
}

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

using (UndoContext context = UndoContext.Current)
using (RestTestFramework.MockContext context = RestTestFramework.MockContext.Start(TestUtilities.GetCallingClass(2), TestUtilities.GetCurrentMethodName(2)))
{
context.Start(TestUtilities.GetCallingClass(2), TestUtilities.GetCurrentMethodName(2));

SetupManagementClients();
SetupManagementClients(context);

helper.SetupEnvironment(AzureModule.AzureResourceManager);
helper.SetupModules(AzureModule.AzureResourceManager,
Expand All @@ -80,9 +82,9 @@ protected void RunPowerShellTest(params string[] scripts)
}
}

protected OperationalInsightsManagementClient GetOperationalInsightsManagementClient()
protected OperationalInsightsManagementClient GetOperationalInsightsManagementClient(RestTestFramework.MockContext context)
{
return TestBase.GetServiceClient<OperationalInsightsManagementClient>(new CSMTestEnvironmentFactory());
return context.GetServiceClient<OperationalInsightsManagementClient>(RestTestFramework.TestEnvironmentFactory.GetTestEnvironment());
}

protected ResourceManagementClient GetResourceManagementClient()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function Test-StorageInsightCreateUpdateDelete
New-AzureRmResourceGroup -Name $rgname -Location $wslocation -Force

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

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

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

Expand Down Expand Up @@ -110,5 +110,5 @@ function Test-StorageInsightCreateFailsNoWs

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

Assert-ThrowsContains { New-AzureRmOperationalInsightsStorageInsight -ResourceGroupName $rgname -WorkspaceName $wsname -Name $siname -Tables @("WADWindowsEventLogsTable", "LinuxSyslogVer2v0") -StorageAccountResourceId $said -StorageAccountKey "fakekey" } "ResourceNotFound"
Assert-ThrowsContains { New-AzureRmOperationalInsightsStorageInsight -ResourceGroupName $rgname -WorkspaceName $wsname -Name $siname -Tables @("WADWindowsEventLogsTable", "LinuxSyslogVer2v0") -StorageAccountResourceId $said -StorageAccountKey "fakekey" } "NotFound"
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ function Test-WorkspaceCreateUpdateDelete
New-AzureRmResourceGroup -Name $rgname -Location $wslocation -Force

# Create and get a workspace
$workspace = New-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname -Name $wsname -Location $wslocation -Sku free -Tags @{"tag1" = "val1"} -Force
$workspace = New-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname -Name $wsname -Location $wslocation -Sku "STANDARD" -Tags @{"tag1" = "val1"} -Force
Assert-AreEqual $rgname $workspace.ResourceGroupName
Assert-AreEqual $wsname $workspace.Name
Assert-AreEqual $wslocation $workspace.Location
Assert-AreEqual "free" $workspace.Sku
Assert-AreEqual "STANDARD" $workspace.Sku
# if no value for RetentionInDays is specified, use the default value for the sku. For standard, the default is 30.
Assert-AreEqual 30 $workspace.RetentionInDays
Assert-NotNull $workspace.ResourceId
Assert-AreEqual 1 $workspace.Tags.Count
Assert-NotNull $workspace.CustomerId
Expand All @@ -39,33 +41,34 @@ function Test-WorkspaceCreateUpdateDelete
Assert-AreEqual $rgname $workspace.ResourceGroupName
Assert-AreEqual $wsname $workspace.Name
Assert-AreEqual $wslocation $workspace.Location
Assert-AreEqual "free" $workspace.Sku
Assert-AreEqual "STANDARD" $workspace.Sku
Assert-AreEqual 30 $workspace.RetentionInDays
Assert-NotNull $workspace.ResourceId
Assert-AreEqual 1 $workspace.Tags.Count
Assert-NotNull $workspace.CustomerId
Assert-NotNull $workspace.PortalUrl

# Create a second workspace for list testing
$wstwoname = Get-ResourceName
$workspacetwo = New-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname -Name $wstwoname -Location $wslocation -Force

$workspacetwo = New-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname -Name $wstwoname -Location $wslocation -Sku "PerNode" -RetentionInDays 60 -Force

$workspacetwo = Get-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname -Name $wstwoname
Assert-AreEqual 60 $workspacetwo.RetentionInDays

# List the workspaces in the subscription
$workspaces = Get-AzureRmOperationalInsightsWorkspace
Assert-AreEqual 2 $workspaces.Count
Assert-AreEqual 1 ($workspaces | Where {$_.Name -eq $wsname}).Count
Assert-AreEqual 1 ($workspaces | Where {$_.Name -eq $wstwoname}).Count

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

# Delete the second workspace
Remove-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgName -Name $wstwoname -Force
Assert-ThrowsContains { Get-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname -Name $wstwoname } "ResourceNotFound"
Assert-ThrowsContains { Get-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname -Name $wstwoname } "NotFound"
$workspaces = Get-AzureRmOperationalInsightsWorkspace
Assert-AreEqual 1 $workspaces.Count
Assert-AreEqual 1 ($workspaces | Where {$_.Name -eq $wsname}).Count
Assert-AreEqual 0 ($workspaces | Where {$_.Name -eq $wstwoname}).Count

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

# Clear the tags and update the sku via piping
$workspace | Set-AzureRmOperationalInsightsWorkspace -Tags @{} -Sku standard
# Clear the tags and update the sku, RetentionInDays via piping
$workspace | Set-AzureRmOperationalInsightsWorkspace -Tags @{} -Sku standalone -RetentionInDays 123
$workspace = Get-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname -Name $wsname
Assert-AreEqual 0 $workspace.Tags.Count
Assert-AreEqual standard $workspace.Sku
Assert-AreEqual standalone $workspace.Sku
Assert-AreEqual 123 $workspace.RetentionInDays

# Delete the original workspace via piping
$workspace | Remove-AzureRmOperationalInsightsWorkspace -Force
$workspaces = Get-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname
Assert-AreEqual 0 $workspaces.Count
Assert-ThrowsContains { Get-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname -Name wsname } "ResourceNotFound"
Assert-ThrowsContains { Get-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname -Name wsname } "NotFound"
}

<#
Expand All @@ -106,7 +110,7 @@ function Test-WorkspaceActions
Assert-AreEqual 0 $accounts.Count

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

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

# Create and get a workspace
$workspace = New-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname -Name $wsname -Location $wslocation -Sku free -Tags @{"tag1" = "val1"} -Force
$workspace = New-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname -Name $wsname -Location $wslocation -Sku "STANDARD" -Tags @{"tag1" = "val1"} -Force
Assert-AreEqual $rgname $workspace.ResourceGroupName
Assert-AreEqual $wsname $workspace.Name
Assert-AreEqual $wslocation $workspace.Location
Assert-AreEqual "free" $workspace.Sku
Assert-AreEqual "STANDARD" $workspace.Sku
Assert-NotNull $workspace.ResourceId
Assert-AreEqual 1 $workspace.Tags.Count
Assert-NotNull $workspace.CustomerId
Expand Down Expand Up @@ -209,5 +213,5 @@ function Test-WorkspaceEnableDisableListIntelligencePacks
$workspace | Remove-AzureRmOperationalInsightsWorkspace -Force
$workspaces = Get-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname
Assert-AreEqual 0 $workspaces.Count
Assert-ThrowsContains { Get-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname -Name wsname } "ResourceNotFound"
Assert-ThrowsContains { Get-AzureRmOperationalInsightsWorkspace -ResourceGroupName $rgname -Name wsname } "NotFound"
}
Loading