Skip to content

Commit

Permalink
Merge pull request #33 from AzureRT/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
huangpf committed Jun 26, 2015
2 parents 5b31531 + bd3fd32 commit e68d101
Show file tree
Hide file tree
Showing 55 changed files with 1,831 additions and 695 deletions.
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(cloudException.Message);

if (cloudException.Response != null)
{
var headers = cloudException.Response.Headers;
if (headers != null && headers.ContainsKey(RequestIdHeaderInResponse))
{
if (sb.Length > 0)
{
// If the original exception message is not empty, append a new line here.
sb.Append(Environment.NewLine);
}

sb.AppendFormat(
Properties.Resources.ComputeCloudExceptionOperationIdMessage,
headers[RequestIdHeaderInResponse].FirstOrDefault());
}
}

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)]
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

0 comments on commit e68d101

Please sign in to comment.