Skip to content

Commit 153f602

Browse files
committed
Merge branch 'dev' of https://github.com/AuxMon/azure-powershell into dev
2 parents f4b7685 + a37c220 commit 153f602

24 files changed

+1457
-149
lines changed

src/Common/Commands.Common/Commands.Common.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
<Reference Include="System.Xml" />
134134
</ItemGroup>
135135
<ItemGroup>
136+
<Compile Include="StringExtensions.cs" />
136137
<Compile Include="AzureDataCmdlet.cs" />
137138
<Compile Include="AzurePSCmdlet.cs" />
138139
<Compile Include="AzurePSDataCollectionProfile.cs" />
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using System.Globalization;
16+
17+
namespace Microsoft.WindowsAzure.Commands.Common
18+
{
19+
/// <summary>
20+
/// Extension methods for strings.
21+
/// </summary>
22+
public static class StringExtensions
23+
{
24+
/// <summary>
25+
/// Formats the string with parameters and invariant culture.
26+
/// </summary>
27+
/// <param name="s">The string</param>
28+
/// <param name="args">The arguments</param>
29+
public static string FormatInvariant(this string s, params object[] args)
30+
{
31+
return string.Format(CultureInfo.InvariantCulture, s, args);
32+
}
33+
}
34+
}

src/ResourceManager/Insights/Commands.Insights.Test/Commands.Insights.Test.csproj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@
175175
<Compile Include="Metrics\GetAzureRmMetricDefinitionTests.cs" />
176176
<Compile Include="Metrics\GetAzureRmMetricTests.cs" />
177177
<Compile Include="Properties\AssemblyInfo.cs" />
178+
<Compile Include="ScenarioTests\AzureRmLogProfileTests.cs" />
178179
<Compile Include="ScenarioTests\AzureRmDiagnosticSettingTests.cs" />
179180
<Compile Include="ScenarioTests\AlertsTests.cs" />
180181
<Compile Include="ScenarioTests\AutoscaleTests.cs" />
@@ -210,6 +211,9 @@
210211
<ItemGroup>
211212
<None Include="MSSharedLibKey.snk" />
212213
<None Include="packages.config" />
214+
<None Include="ScenarioTests\AzureRmLogProfileTests.ps1">
215+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
216+
</None>
213217
<None Include="ScenarioTests\AzureRmDiagnosticSettingTests.ps1">
214218
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
215219
</None>
@@ -231,6 +235,18 @@
231235
<None Include="ScenarioTests\UsageMetricsTests.ps1">
232236
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
233237
</None>
238+
<None Include="SessionRecords\Microsoft.Azure.Commands.Insights.Test.ScenarioTests.AzureRmDiagnosticSettingTests\TestSetAzureRmDiagnosticSettingWithRetention.json">
239+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
240+
</None>
241+
<None Include="SessionRecords\Microsoft.Azure.Commands.Insights.Test.ScenarioTests.AzureRmLogProfileTests\TestAddAzureRmLogProfileWithRetention.json">
242+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
243+
</None>
244+
<None Include="SessionRecords\Microsoft.Azure.Commands.Insights.Test.ScenarioTests.AzureRmLogProfileTests\TestGetAzureRmLogProfile.json">
245+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
246+
</None>
247+
<None Include="SessionRecords\Microsoft.Azure.Commands.Insights.Test.ScenarioTests.AzureRmLogProfileTests\TestAddAzureRmLogProfile.json">
248+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
249+
</None>
234250
<None Include="SessionRecords\Microsoft.Azure.Commands.Insights.Test.ScenarioTests.AlertsTests\TestAddAzureRmLogAlertRule.json">
235251
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
236252
</None>

src/ResourceManager/Insights/Commands.Insights.Test/ScenarioTests/AzureRmDiagnosticSettingTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ public void TestSetAzureRmDiagnosticSetting()
3434
TestsController.NewInstance.RunPsTest("Test-SetAzureRmDiagnosticSetting");
3535
}
3636

37+
[Fact]
38+
[Trait(Category.AcceptanceType, Category.CheckIn)]
39+
public void TestSetAzureRmDiagnosticSettingWithRetention()
40+
{
41+
TestsController.NewInstance.RunPsTest("Test-SetAzureRmDiagnosticSettingWithRetention");
42+
}
43+
3744
[Fact]
3845
[Trait(Category.AcceptanceType, Category.CheckIn)]
3946
public void TestSetAzureRmDiagnosticSettingCategoriesOnly()

src/ResourceManager/Insights/Commands.Insights.Test/ScenarioTests/AzureRmDiagnosticSettingTests.ps1

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,40 @@ function Test-SetAzureRmDiagnosticSetting
6969
}
7070
}
7171

72+
<#
73+
.SYNOPSIS
74+
Tests setting diagnostics
75+
#>
76+
function Test-SetAzureRmDiagnosticSettingWithRetention
77+
{
78+
try
79+
{
80+
$actual = Set-AzureRmDiagnosticSetting -ResourceId /subscriptions/1a66ce04-b633-4a0b-b2bc-a912ec8986a6/resourcegroups/insights-integration/providers/test.shoebox/testresources2/pstest0000eastusR2 -StorageAccountId /subscriptions/1a66ce04-b633-4a0b-b2bc-a912ec8986a6/resourceGroups/montest/providers/Microsoft.Storage/storageAccounts/montest3470 -Enable $true -RetentionEnabled $true -RetentionInDays 90
81+
82+
Assert-AreEqual $actual.StorageAccountId "/subscriptions/1a66ce04-b633-4a0b-b2bc-a912ec8986a6/resourceGroups/montest/providers/Microsoft.Storage/storageAccounts/montest3470"
83+
Assert-AreEqual montest3470 $actual.StorageAccountName
84+
Assert-AreEqual 1 $actual.Metrics.Count
85+
Assert-AreEqual $true $actual.Metrics[0].Enabled
86+
Assert-AreEqual "PT1M" $actual.Metrics[0].Timegrain
87+
Assert-AreEqual $true $actual.Metrics[0].RetentionPolicy.Enabled
88+
Assert-AreEqual 90 $actual.Metrics[0].RetentionPolicy.Days
89+
Assert-AreEqual 2 $actual.Logs.Count
90+
Assert-AreEqual $true $actual.Logs[0].Enabled
91+
Assert-AreEqual "TestLog1" $actual.Logs[0].Category
92+
Assert-AreEqual $true $actual.Logs[0].RetentionPolicy.Enabled
93+
Assert-AreEqual 90 $actual.Logs[0].RetentionPolicy.Days
94+
Assert-AreEqual $true $actual.Logs[1].Enabled
95+
Assert-AreEqual "TestLog2" $actual.Logs[1].Category
96+
Assert-AreEqual $true $actual.Logs[1].RetentionPolicy.Enabled
97+
Assert-AreEqual 90 $actual.Logs[1].RetentionPolicy.Days
98+
}
99+
finally
100+
{
101+
# Cleanup
102+
# No cleanup needed for now
103+
}
104+
}
105+
72106
<#
73107
.SYNOPSIS
74108
Tests setting diagnostics for categories only
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// ----------------------------------------------------------------------------------
2+
//
3+
// Copyright Microsoft Corporation
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
// Unless required by applicable law or agreed to in writing, software
9+
// distributed under the License is distributed on an "AS IS" BASIS,
10+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
// See the License for the specific language governing permissions and
12+
// limitations under the License.
13+
// ----------------------------------------------------------------------------------
14+
15+
using Microsoft.WindowsAzure.Commands.ScenarioTest;
16+
using Microsoft.WindowsAzure.Commands.Test.Utilities.Common;
17+
using Xunit;
18+
19+
namespace Microsoft.Azure.Commands.Insights.Test.ScenarioTests
20+
{
21+
public class AzureRmLogProfileTests : RMTestBase
22+
{
23+
[Fact]
24+
[Trait(Category.AcceptanceType, Category.CheckIn)]
25+
public void TestGetAzureRmLogProfile()
26+
{
27+
TestsController.NewInstance.RunPsTest("Test-GetAzureRmLogProfile");
28+
}
29+
30+
[Fact]
31+
[Trait(Category.AcceptanceType, Category.CheckIn)]
32+
public void TestAddAzureRmLogProfile()
33+
{
34+
TestsController.NewInstance.RunPsTest("Test-AddAzureRmLogProfile");
35+
}
36+
37+
[Fact]
38+
[Trait(Category.AcceptanceType, Category.CheckIn)]
39+
public void TestAddAzureRmLogProfileWithRetention()
40+
{
41+
TestsController.NewInstance.RunPsTest("Test-AddAzureRmLogProfileWithRetention");
42+
}
43+
}
44+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# ----------------------------------------------------------------------------------
2+
#
3+
# Copyright Microsoft Corporation
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
# ----------------------------------------------------------------------------------
14+
15+
<#
16+
.SYNOPSIS
17+
Tests getting log profiles
18+
#>
19+
function Test-GetAzureRmLogProfile
20+
{
21+
try
22+
{
23+
# Test
24+
$actual = Get-AzureRmLogProfile -Name default
25+
26+
Assert-AreEqual /subscriptions/1a66ce04-b633-4a0b-b2bc-a912ec8986a6/providers/microsoft.insights/logprofiles/default $actual.Id
27+
Assert-AreEqual default $actual.Name
28+
Assert-AreEqual "/subscriptions/1a66ce04-b633-4a0b-b2bc-a912ec8986a6/resourceGroups/insights-integration/providers/Microsoft.Storage/storageAccounts/insightsintegration7777" $actual.StorageAccountId
29+
Assert-AreEqual $null $actual.ServiceBusRuleId
30+
Assert-AreEqual 1 $actual.Locations.Count
31+
Assert-AreEqual global $actual.Locations
32+
Assert-AreEqual 3 $actual.Categories.Count
33+
Assert-AreEqual Delete $actual.Categories[0]
34+
Assert-AreEqual Write $actual.Categories[1]
35+
Assert-AreEqual Action $actual.Categories[2]
36+
Assert-AreEqual $false $actual.RetentionPolicy.Enabled
37+
Assert-AreEqual 0 $actual.RetentionPolicy.Days
38+
}
39+
finally
40+
{
41+
# Cleanup
42+
# No cleanup needed for now
43+
}
44+
}
45+
46+
<#
47+
.SYNOPSIS
48+
Tests adding log profile
49+
#>
50+
function Test-AddAzureRmLogProfile
51+
{
52+
try
53+
{
54+
$actual = Add-AzureRmLogProfile -Name default -StorageAccountId /subscriptions/1a66ce04-b633-4a0b-b2bc-a912ec8986a6/resourceGroups/insights-integration/providers/Microsoft.Storage/storageAccounts/insightsintegration7777 -Locations global -Categories Delete,Write,Action
55+
56+
Assert-AreEqual $true $actual
57+
}
58+
finally
59+
{
60+
# Cleanup
61+
# No cleanup needed for now
62+
}
63+
}
64+
65+
<#
66+
.SYNOPSIS
67+
Tests adding log profile
68+
#>
69+
function Test-AddAzureRmLogProfileWithRetention
70+
{
71+
try
72+
{
73+
$actual = Add-AzureRmLogProfile -Name default -StorageAccountId /subscriptions/1a66ce04-b633-4a0b-b2bc-a912ec8986a6/resourceGroups/insights-integration/providers/Microsoft.Storage/storageAccounts/insightsintegration7777 -Locations global -Categories Delete,Write,Action -RetentionInDays 90
74+
75+
Assert-AreEqual $true $actual
76+
}
77+
finally
78+
{
79+
# Cleanup
80+
# No cleanup needed for now
81+
}
82+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
{
2+
"Entries": [
3+
{
4+
"RequestUri": "/%2Fsubscriptions%2F1a66ce04-b633-4a0b-b2bc-a912ec8986a6%2Fresourcegroups%2Finsights-integration%2Fproviders%2Ftest.shoebox%2Ftestresources2%2Fpstest0000eastusR2/providers/microsoft.insights/diagnosticSettings/service?api-version=2015-07-01",
5+
"RequestMethod": "GET",
6+
"RequestBody": "",
7+
"RequestHeaders": {
8+
"Accept": [ "application/json" ],
9+
"User-Agent": [ "User-Agent: Microsoft.Azure.Management.Insights.InsightsManagementClient/0.9.0.0 AzurePowershell/v0.9.9.0" ],
10+
"Connection": [ "Keep-Alive" ]
11+
},
12+
"ResponseBody": "{\"id\":\"/subscriptions/1a66ce04-b633-4a0b-b2bc-a912ec8986a6/resourcegroups/insights-integration/providers/test.shoebox/testresources2/pstest0000eastusr2/diagnosticSettings/service\",\"name\":\"service\",\"location\":null,\"tags\":null,\"properties\":{\"storageAccountName\":\"montest3470\",\"storageAccountId\":\"/subscriptions/1a66ce04-b633-4a0b-b2bc-a912ec8986a6/resourceGroups/montest/providers/Microsoft.Storage/storageAccounts/montest3470\",\"metrics\":[{\"timeGrain\":\"PT1M\",\"enabled\":false,\"retentionPolicy\":{\"days\":0}}],\"logs\":[{\"category\":\"TestLog1\",\"enabled\":false,\"retentionPolicy\":{\"days\":0}},{\"category\":\"TestLog2\",\"enabled\":false,\"retentionPolicy\":{\"days\":0}}]}}",
13+
"ResponseHeaders": {
14+
"Cache-Control": [
15+
"no-cache"
16+
],
17+
"Date": [
18+
"Mon, 03 Mar 2015 00:07:07 GMT"
19+
],
20+
"Expires": [
21+
"-1"
22+
],
23+
"Pragma": [
24+
"no-cache"
25+
],
26+
"Content-Length": [
27+
"441"
28+
],
29+
"Content-Type": [
30+
"application/json; charset=utf-8"
31+
],
32+
"x-ms-ratelimit-remaining-subscription-writes": [
33+
"1199"
34+
],
35+
"x-ms-request-id": [
36+
"47af504c-88a1-49c5-9766-e397d54e490b"
37+
],
38+
"x-ms-correlation-request-id": [
39+
"e223e5fa-7d3c-4d2c-a2e9-aed3011aefb7"
40+
],
41+
"x-ms-routing-request-id": [
42+
"WESTUS:20150303T190828Z:e223e5fa-7d3c-4d2c-a2e9-aed3011aefb7"
43+
],
44+
"Strict-Transport-Security": [
45+
"max-age=31536000; includeSubDomains"
46+
]
47+
},
48+
"StatusCode": 200
49+
},
50+
{
51+
"RequestUri": "/%2Fsubscriptions%2F1a66ce04-b633-4a0b-b2bc-a912ec8986a6%2Fresourcegroups%2Finsights-integration%2Fproviders%2Ftest.shoebox%2Ftestresources2%2Fpstest0000eastusR2/providers/microsoft.insights/diagnosticSettings/service?api-version=2015-07-01",
52+
"RequestMethod": "PUT",
53+
"RequestBody": "{\"properties\": {\"storageAccountId\": \"/subscriptions/1a66ce04-b633-4a0b-b2bc-a912ec8986a6/resourceGroups/montest/providers/Microsoft.Storage/storageAccounts/montest3470\",\"metrics\": [{\"timeGrain\": \"PT1M\",\"enabled\": true,\"retentionPolicy\": {\"enabled\": false,\"days\": 0}}],\"logs\": [{\"category\": \"TestLog1\",\"enabled\": true,\"retentionPolicy\": {\"enabled\": false,\"days\": 0}},{\"category\": \"TestLog2\",\"enabled\": true,\"retentionPolicy\": {\"enabled\": false,\"days\": 0}}]}}",
54+
"RequestHeaders": {
55+
"Accept": [ "application/json" ],
56+
"User-Agent": [ "User-Agent: Microsoft.Azure.Management.Insights.InsightsManagementClient/0.9.0.0 AzurePowershell/v0.9.9.0" ],
57+
"Connection": [ "Keep-Alive" ]
58+
},
59+
"ResponseBody": "{\"id\":\"/subscriptions/1a66ce04-b633-4a0b-b2bc-a912ec8986a6/resourcegroups/insights-integration/providers/test.shoebox/testresources2/pstest0000eastusr2/diagnosticSettings/service\",\"name\":\"service\",\"location\":null,\"tags\":null,\"properties\":{\"storageAccountName\":\"montest3470\",\"storageAccountId\":\"/subscriptions/1a66ce04-b633-4a0b-b2bc-a912ec8986a6/resourceGroups/montest/providers/Microsoft.Storage/storageAccounts/montest3470\",\"metrics\":[{\"timeGrain\":\"PT1M\",\"enabled\":true,\"retentionPolicy\":{\"days\":0}}],\"logs\":[{\"category\":\"TestLog1\",\"enabled\":true,\"retentionPolicy\":{\"days\":0}},{\"category\":\"TestLog2\",\"enabled\":true,\"retentionPolicy\":{\"days\":0, \"enabled\":true}}]}}",
60+
"ResponseHeaders": {
61+
"Cache-Control": [
62+
"no-cache"
63+
],
64+
"Date": [
65+
"Mon, 03 Mar 2015 00:07:07 GMT"
66+
],
67+
"Expires": [
68+
"-1"
69+
],
70+
"Pragma": [
71+
"no-cache"
72+
],
73+
"Content-Length": [
74+
"614"
75+
],
76+
"Content-Type": [
77+
"application/json; charset=utf-8"
78+
],
79+
"x-ms-ratelimit-remaining-subscription-writes": [
80+
"1199"
81+
],
82+
"x-ms-request-id": [
83+
"47af504c-88a1-49c5-9766-e397d54e490b"
84+
],
85+
"x-ms-correlation-request-id": [
86+
"e223e5fa-7d3c-4d2c-a2e9-aed3011aefb7"
87+
],
88+
"x-ms-routing-request-id": [
89+
"WESTUS:20150303T190828Z:e223e5fa-7d3c-4d2c-a2e9-aed3011aefb7"
90+
],
91+
"Strict-Transport-Security": [
92+
"max-age=31536000; includeSubDomains"
93+
]
94+
},
95+
"StatusCode": 200
96+
}
97+
],
98+
"Names": {
99+
"Test-AddAlertRule": [
100+
""
101+
]
102+
},
103+
"Variables": {
104+
"SubscriptionId": "a93fb07c-6c93-40be-bf3b-4f0deba10f4b"
105+
}
106+
}

0 commit comments

Comments
 (0)