Skip to content

Show OperationID from CloudException thrown by Compute Cmdlets #546

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 29 commits into from
Jul 1, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7a280cf
Merge pull request #27 from Azure/dev
huangpf Jun 20, 2015
7d4cfda
Merge pull request #28 from Azure/dev
huangpf Jun 21, 2015
c59fb5f
Fix VHD Link Creation in Update-AzureVM
huangpf Jun 22, 2015
285f13b
Ex. Handle
huangpf Jun 23, 2015
bdb3985
Merge pull request #29 from Azure/release-0.9.4
huangpf Jun 23, 2015
b686007
WriteCloudExceptionError
huangpf Jun 23, 2015
e5b1ae3
Add ComputeCloudException
huangpf Jun 24, 2015
b1693f5
ExecuteCmdlet Update
huangpf Jun 24, 2015
4fc5a79
Merge branch 'dev' of https://github.com/huangpf/azure-powershell int…
huangpf Jun 24, 2015
0b02e14
Add ComputeCloudException to Service Management cmdlets
huangpf Jun 24, 2015
f33010d
Merge pull request #30 from Azure/release-0.9.4
huangpf Jun 24, 2015
8564936
Merge pull request #30 from Azure/release-0.9.4
AzureRT Jun 24, 2015
6df726d
Update Test
huangpf Jun 25, 2015
97b0d36
Update Test
huangpf Jun 25, 2015
17fa11b
Merge branch 'dev' of https://github.com/huangpf/azure-powershell int…
huangpf Jun 25, 2015
7385b7d
Merge pull request #31 from Azure/release-0.9.4
huangpf Jun 25, 2015
6d9910d
Merge branch 'dev' of https://github.com/huangpf/azure-powershell int…
huangpf Jun 25, 2015
e016ebd
Address CRs
huangpf Jun 25, 2015
ff2a772
Accept a list of Name/VMs in Start/Stop-AzureVM
huangpf Jun 25, 2015
e7d36d8
Merge branch 'dev' of https://github.com/huangpf/azure-powershell int…
huangpf Jun 25, 2015
1eb17b6
Merge branch 'dev' of https://github.com/huangpf/azure-powershell int…
huangpf Jun 26, 2015
5b31531
Merge pull request #32 from Azure/dev
huangpf Jun 26, 2015
607100d
Merge branch 'dev' of https://github.com/huangpf/azure-powershell int…
huangpf Jun 26, 2015
8dcfc83
Merge pull request #31 from huangpf/dev
AzureRT Jun 26, 2015
bd3fd32
Merge pull request #29 from huangpf/d0622
AzureRT Jun 26, 2015
e68d101
Merge pull request #33 from AzureRT/dev
huangpf Jun 26, 2015
422520e
Merge pull request #34 from Azure/dev
huangpf Jun 30, 2015
23a4517
Address CRs
huangpf Jun 30, 2015
b25048a
Address CRs
huangpf Jun 30, 2015
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
1 change: 1 addition & 0 deletions src/Common/Commands.Common/Commands.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AzurePowerShell.cs" />
<Compile Include="ComputeCloudException.cs" />
<Compile Include="Constants.cs" />
<Compile Include="SecureStringExtensions.cs" />
<Compile Include="ConversionUtilities.cs" />
Expand Down
60 changes: 60 additions & 0 deletions src/Common/Commands.Common/ComputeCloudException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Hyak.Common;
using System;
using System.Linq;
using System.Text;

namespace Microsoft.WindowsAzure.Commands.Common
{
public class ComputeCloudException : CloudException
{
protected const string RequestIdHeaderInResponse = "x-ms-request-id";

public ComputeCloudException(CloudException ex)
: base(GetErrorMessageWithRequestIdInfo(ex), ex)
{
}

protected static string GetErrorMessageWithRequestIdInfo(CloudException cloudException)
{
if (cloudException == null)
{
throw new ArgumentNullException("cloudException");
}

var sb = new StringBuilder();

if (!string.IsNullOrEmpty(cloudException.Message))
{
sb.Append(cloudException.Message);
}

if (cloudException.Response != null &&
cloudException.Response.Headers != null)
{
var headers = cloudException.Response.Headers;
if (headers.ContainsKey(RequestIdHeaderInResponse))
{
sb.AppendLine().AppendFormat(
Properties.Resources.ComputeCloudExceptionOperationIdMessage,
headers[RequestIdHeaderInResponse].FirstOrDefault());
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit. you can do the same thing with a little bit less code:

var sb = new StringBuilder();

if(!string.IsNullOrEmpty(cloudException.Message))
{
    sb.AppendLine(cloudException.Message);
}

if (cloudException.Response != null && 
    cloudException.Response.Headers != null)
{
    var headers = cloudException.Response.Headers;
    if (headers.ContainsKey(RequestIdHeaderInResponse))
    {
        sb.AppendFormat(
            Properties.Resources.ComputeCloudExceptionOperationIdMessage,
            headers[RequestIdHeaderInResponse].FirstOrDefault());
    }
} 

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Thanks!


return sb.ToString();
}
}
}
11 changes: 10 additions & 1 deletion src/Common/Commands.Common/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/Common/Commands.Common/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1361,4 +1361,7 @@ use and privacy statement at &lt;url&gt; and (c) agree to sharing my contact inf
<data name="SwitchAzureModeDeprecated" xml:space="preserve">
<value>The Switch-AzureMode cmdlet is deprecated and will be removed in a future release.</value>
</data>
<data name="ComputeCloudExceptionOperationIdMessage" xml:space="preserve">
<value>OperationID : '{0}'</value>
</data>
</root>
13 changes: 8 additions & 5 deletions src/Common/Commands.ScenarioTest/Commands.ScenarioTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,13 @@
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.AutomationTests\TestAutomationSuspendAndResumeJob.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.AzureVMTests\TestGetAzureLocation.json">
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.ServiceManagementTests\RunServiceManagementCloudExceptionTests.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.AzureVMTests\TestGetAzureVM.json">
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.ServiceManagementTests\TestGetAzureLocation.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.ServiceManagementTests\TestGetAzureVM.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.WindowsAzure.Commands.ScenarioTest.SchedulerTests\TestSchedulerEndToEnd.json">
Expand Down Expand Up @@ -289,8 +292,8 @@
<Compile Include="Resources\ResourceLocator.cs" />
<Compile Include="Scheduler\SchedulerTests.cs" />
<Compile Include="ServiceBusTests\ServiceBusAuthorizationRuleTests.cs" />
<Compile Include="ServiceManagement\GetLocationTests.cs" />
<Compile Include="ServiceManagement\GetVMTests.cs" />
<Compile Include="ServiceManagement\ScenarioTests.cs" />
<Compile Include="ServiceManagement\ServiceManagementTests.cs" />
<Compile Include="StorageTests\StorageContainerTest.cs" />
<Compile Include="StorageTests\StorageContextTest.cs" />
<Compile Include="StoreTests\StoreTests.cs" />
Expand Down Expand Up @@ -414,7 +417,7 @@
<None Include="Resources\CloudService\Cache\mc.tgz">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Resources\ServiceManagement\AzureVMTests.ps1">
<None Include="Resources\ServiceManagement\ServiceManagementTests.ps1">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Resources\ServiceManagement\Common.ps1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,4 @@ function Cleanup-Storage
Write-Warning "Cannot Remove the Storage Account"
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,12 @@ function Test-GetAzureLocation
Cleanup-CloudService $svcName
}
}

# Test Service Management Cloud Exception
function Run-ServiceManagementCloudExceptionTests
{
$compare = "*OperationID : `'*`'";
Assert-ThrowsLike { $st = Get-AzureService -ServiceName '*' } $compare;
Assert-ThrowsLike { $st = Get-AzureVM -ServiceName '*' } $compare;
Assert-ThrowsLike { $st = Get-AzureAffinityGroup -Name '*' } $compare;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.WindowsAzure.Commands.ScenarioTest.Common;
using Microsoft.Azure.Common.Authentication;
using Microsoft.Azure.Test;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Xunit;

namespace Microsoft.WindowsAzure.Commands.ScenarioTest
{
public partial class AzureVMTests
public partial class ServiceManagementTests
{
[Fact]
[Trait(Category.Service, Category.ServiceManagement)]
Expand All @@ -27,5 +31,14 @@ public void TestGetAzureLocation()
{
this.RunPowerShellTest("Test-GetAzureLocation");
}

[Fact]
[Trait(Category.Service, Category.ServiceManagement)]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.AcceptanceType, Category.BVT)]
public void RunServiceManagementCloudExceptionTests()
{
this.RunPowerShellTest("Run-ServiceManagementCloudExceptionTests");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,16 @@

namespace Microsoft.WindowsAzure.Commands.ScenarioTest
{
public partial class AzureVMTests
public partial class ServiceManagementTests
{
private EnvironmentSetupHelper helper = new EnvironmentSetupHelper();

#region Get-AzureVM Scenario Tests

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test takes 151.519s which is too much. since you are working with these tests, could you take a look why it is soo long? Consider removing it from CheckIn category if it is too complex and there is no way to make it run shorter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests related to VM usually take some time. Can we create a separate items to track and fix it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

~3 minutes it too much for recorded tests but I'm ok to track it as a separate item.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is not run in the PR test, but in the post-check-in test, right?

public void TestGetAzureVM()
{
this.RunPowerShellTest("Test-GetAzureVM");
}
#endregion

protected void SetupManagementClients()
{
Expand All @@ -48,7 +45,7 @@ protected void RunPowerShellTest(params string[] scripts)

SetupManagementClients();

List<string> modules = Directory.GetFiles("Resources\\ServiceManagement", "*.ps1").ToList();
List<string> modules = Directory.GetFiles(@"Resources\ServiceManagement", "*.ps1").ToList();
modules.Add("Common.ps1");
modules.Add(@"..\..\..\..\Package\Debug\ServiceManagement\Azure\Azure.psd1");

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
{
"Entries": [
{
"RequestUri": "/4d368445-cbb1-42a7-97a6-6850ab99f48e/services/hostedservices/*",
"EncodedRequestUri": "LzRkMzY4NDQ1LWNiYjEtNDJhNy05N2E2LTY4NTBhYjk5ZjQ4ZS9zZXJ2aWNlcy9ob3N0ZWRzZXJ2aWNlcy8lMkE=",
"RequestMethod": "GET",
"RequestBody": "",
"RequestHeaders": {
"x-ms-version": [
"2015-04-01"
],
"User-Agent": [
"Microsoft.WindowsAzure.Management.Compute.ComputeManagementClient/12.0.0.0"
]
},
"ResponseBody": "<Error xmlns=\"http://schemas.microsoft.com/windowsazure\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n <Code>BadRequest</Code>\r\n <Message>The hosted service name is invalid.</Message>\r\n</Error>",
"ResponseHeaders": {
"Content-Length": [
"194"
],
"Content-Type": [
"application/xml; charset=utf-8"
],
"x-ms-servedbyregion": [
"ussouth3"
],
"Strict-Transport-Security": [
"max-age=31536000; includeSubDomains"
],
"x-ms-request-id": [
"8fbc1c1bfd26be549be7ac6edfe8fd67"
],
"Cache-Control": [
"no-cache"
],
"Date": [
"Wed, 24 Jun 2015 21:52:37 GMT"
],
"Server": [
"1.0.6198.243",
"(rd_rdfe_stable.150618-1025)",
"Microsoft-HTTPAPI/2.0"
]
},
"StatusCode": 400
},
{
"RequestUri": "/4d368445-cbb1-42a7-97a6-6850ab99f48e/services/hostedservices/*/deploymentslots/Production",
"EncodedRequestUri": "LzRkMzY4NDQ1LWNiYjEtNDJhNy05N2E2LTY4NTBhYjk5ZjQ4ZS9zZXJ2aWNlcy9ob3N0ZWRzZXJ2aWNlcy8lMkEvZGVwbG95bWVudHNsb3RzL1Byb2R1Y3Rpb24=",
"RequestMethod": "GET",
"RequestBody": "",
"RequestHeaders": {
"x-ms-version": [
"2015-04-01"
],
"User-Agent": [
"Microsoft.WindowsAzure.Management.Compute.ComputeManagementClient/12.0.0.0"
]
},
"ResponseBody": "<Error xmlns=\"http://schemas.microsoft.com/windowsazure\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n <Code>BadRequest</Code>\r\n <Message>The hosted service name is invalid.</Message>\r\n</Error>",
"ResponseHeaders": {
"Content-Length": [
"194"
],
"Content-Type": [
"application/xml; charset=utf-8"
],
"x-ms-servedbyregion": [
"ussouth3"
],
"Strict-Transport-Security": [
"max-age=31536000; includeSubDomains"
],
"x-ms-request-id": [
"235043d87cdfbdbea385a799a177dbeb"
],
"Cache-Control": [
"no-cache"
],
"Date": [
"Wed, 24 Jun 2015 21:52:37 GMT"
],
"Server": [
"1.0.6198.243",
"(rd_rdfe_stable.150618-1025)",
"Microsoft-HTTPAPI/2.0"
]
},
"StatusCode": 400
},
{
"RequestUri": "/4d368445-cbb1-42a7-97a6-6850ab99f48e/affinitygroups/*",
"EncodedRequestUri": "LzRkMzY4NDQ1LWNiYjEtNDJhNy05N2E2LTY4NTBhYjk5ZjQ4ZS9hZmZpbml0eWdyb3Vwcy8lMkE=",
"RequestMethod": "GET",
"RequestBody": "",
"RequestHeaders": {
"x-ms-version": [
"2014-10-01"
],
"User-Agent": [
"Microsoft.WindowsAzure.Management.ManagementClient/4.0.0.0"
]
},
"ResponseBody": "<Error xmlns=\"http://schemas.microsoft.com/windowsazure\" xmlns:i=\"http://www.w3.org/2001/XMLSchema-instance\">\r\n <Code>ResourceNotFound</Code>\r\n <Message>The affinity group does not exist.</Message>\r\n</Error>",
"ResponseHeaders": {
"Content-Length": [
"199"
],
"Content-Type": [
"application/xml; charset=utf-8"
],
"x-ms-servedbyregion": [
"ussouth3"
],
"x-ms-request-id": [
"e7eb6116c17abe61b27520096b982601"
],
"Cache-Control": [
"no-cache"
],
"Date": [
"Wed, 24 Jun 2015 21:52:38 GMT"
],
"Server": [
"1.0.6198.243",
"(rd_rdfe_stable.150618-1025)",
"Microsoft-HTTPAPI/2.0"
]
},
"StatusCode": 404
}
],
"Names": {},
"Variables": {
"SubscriptionId": "4d368445-cbb1-42a7-97a6-6850ab99f48e"
}
}
Loading