Skip to content

Commit 84596b9

Browse files
committed
Merge pull request #306 from Azure/dev
.
2 parents 07fc93b + 12bfe67 commit 84596b9

File tree

15 files changed

+2443
-115
lines changed

15 files changed

+2443
-115
lines changed

ChangeLog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* New-AzureRmWebAppSSLBinding
99
* Get-AzureRmWebAppSSLBinding
1010
* Remove-AzureRmWebAppSSLBinding
11-
* Azure Websites: Added AseName and AseResourceGroupName parameters in New-AzureRmAppServicePlan cmdlet
11+
* Azure Websites: Added AseName and AseResourceGroupName parameters in New-AzureRmWebApp and New-AzureRmAppServicePlan cmdlet
1212

1313
## 2015.12.14 version 1.0.2
1414
* Azure Compute (ARM):

src/ResourceManager/Profile/Commands.Profile/Models/RMProfileClient.cs

Lines changed: 33 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public AzureRMProfile Login(
6868
var token = AcquireAccessToken(account, environment, tenantId, password, promptBehavior);
6969
if(TryGetTenantSubscription(token, account, environment, tenantId, subscriptionId, subscriptionName, out newSubscription, out newTenant))
7070
{
71-
account.SetProperty(AzureAccount.Property.Tenants, new[] { newTenant.Id.ToString() });
71+
account.SetOrAppendProperty(AzureAccount.Property.Tenants, new[] { newTenant.Id.ToString() });
7272
}
7373
}
7474
// (tenant is not provided and subscription is present) OR
@@ -240,7 +240,7 @@ private void SwitchSubscription(AzureSubscription subscription)
240240

241241
public List<AzureTenant> ListTenants(string tenant)
242242
{
243-
return ListAccountTenants(_profile.Context.Account, _profile.Context.Environment, null, ShowDialog.Auto)
243+
return ListAccountTenants(_profile.Context.Account, _profile.Context.Environment, null, ShowDialog.Never)
244244
.Where(t => tenant == null ||
245245
tenant.Equals(t.Id.ToString(), StringComparison.OrdinalIgnoreCase) ||
246246
tenant.Equals(t.Domain, StringComparison.OrdinalIgnoreCase))
@@ -380,7 +380,9 @@ public IEnumerable<AzureSubscription> ListSubscriptions()
380380
{
381381
try
382382
{
383-
subscriptions.AddRange(ListSubscriptions(tenant.Id.ToString()));
383+
subscriptions.AddRange(
384+
ListSubscriptions(
385+
(tenant.Id == Guid.Empty) ? tenant.Domain:tenant.Id.ToString()));
384386
}
385387
catch (AadAuthenticationException)
386388
{
@@ -481,19 +483,24 @@ private bool TryGetTenantSubscription(IAccessToken accessToken,
481483
}
482484
else
483485
{
484-
var subscriptions = subscriptionClient.Subscriptions.List().Subscriptions;
485-
if (subscriptions != null && subscriptions.Any())
486+
var subscriptions = (subscriptionClient.Subscriptions.List().Subscriptions ??
487+
new List<Microsoft.Azure.Subscriptions.Models.Subscription>())
488+
.Where(s => "enabled".Equals(s.State, StringComparison.OrdinalIgnoreCase) ||
489+
"warned".Equals(s.State, StringComparison.OrdinalIgnoreCase));
490+
491+
if (subscriptions.Any())
486492
{
487493
if (subscriptionName != null)
488494
{
489-
subscriptionFromServer = subscriptions.FirstOrDefault(s => s.DisplayName.Equals(subscriptionName, StringComparison.OrdinalIgnoreCase));
495+
subscriptionFromServer = subscriptions.FirstOrDefault(
496+
s => s.DisplayName.Equals(subscriptionName, StringComparison.OrdinalIgnoreCase));
490497
}
491498
else
492499
{
493-
if (subscriptions.Count > 1)
500+
if (subscriptions.Count() > 1)
494501
{
495502
WriteWarningMessage(string.Format(
496-
"TenantId '{0}' contains more than one subscription. First one will be selected for further use. " +
503+
"TenantId '{0}' contains more than one active subscription. First one will be selected for further use. " +
497504
"To select another subscription, use Set-AzureRmContext.",
498505
tenantId));
499506
}
@@ -569,10 +576,21 @@ private List<AzureTenant> ListAccountTenants(AzureAccount account, AzureEnvironm
569576
{
570577
result =
571578
account.GetPropertyAsArray(AzureAccount.Property.Tenants)
572-
.Select( ti => new AzureTenant()
573-
{
574-
Id = new Guid(ti),
575-
Domain = AccessTokenExtensions.GetDomain(account.Id)
579+
.Select( ti => {
580+
var tenant = new AzureTenant();
581+
582+
Guid guid;
583+
if(Guid.TryParse(ti, out guid))
584+
{
585+
tenant.Id = guid;
586+
tenant.Domain = AccessTokenExtensions.GetDomain(account.Id);
587+
}
588+
else
589+
{
590+
tenant.Domain = ti;
591+
}
592+
593+
return tenant;
576594
}).ToList();
577595
}
578596

@@ -608,7 +626,7 @@ private IEnumerable<AzureSubscription> ListSubscriptionsForTenant(AzureAccount a
608626
subscriptions.Subscriptions.Select(
609627
(s) =>
610628
s.ToAzureSubscription(new AzureContext(_profile.Context.Subscription, account,
611-
environment, CreateTenantFromString(tenantId))));
629+
environment, CreateTenantFromString(tenantId, accessToken.TenantId))));
612630
}
613631

614632
return new List<AzureSubscription>();
@@ -623,7 +641,7 @@ private void WriteWarningMessage(string message)
623641
}
624642
}
625643

626-
private static AzureTenant CreateTenantFromString(string tenantOrDomain)
644+
private static AzureTenant CreateTenantFromString(string tenantOrDomain, string accessTokenTenantId)
627645
{
628646
AzureTenant result = new AzureTenant();
629647
Guid id;
@@ -633,6 +651,7 @@ private static AzureTenant CreateTenantFromString(string tenantOrDomain)
633651
}
634652
else
635653
{
654+
result.Id = Guid.Parse(accessTokenTenantId);
636655
result.Domain = tenantOrDomain;
637656
}
638657

src/ResourceManager/Websites/Commands.Websites.Test/Commands.Websites.Test.csproj

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
<Private>True</Private>
6565
</Reference>
6666
<Reference Include="Microsoft.Azure.Management.Websites, Version=1.0.0.2, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
67+
<SpecificVersion>False</SpecificVersion>
6768
<HintPath>..\..\..\packages\Microsoft.Azure.Management.Websites.1.0.2-preview\lib\net45\Microsoft.Azure.Management.Websites.dll</HintPath>
6869
<Private>True</Private>
6970
</Reference>
@@ -129,6 +130,7 @@
129130
</Reference>
130131
<Reference Include="System.Net.Http.WebRequest" />
131132
<Reference Include="System.Runtime.Serialization" />
133+
<Reference Include="System.Xml" />
132134
<Reference Include="xunit, Version=1.9.2.1705, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
133135
<HintPath>..\..\..\packages\xunit.1.9.2\lib\net20\xunit.dll</HintPath>
134136
<Private>True</Private>
@@ -139,13 +141,11 @@
139141
</Reference>
140142
</ItemGroup>
141143
<ItemGroup>
142-
<Compile Include="NewAzureWebsitesCommandTests.cs" />
143144
<Compile Include="ScenarioTests\AppServicePlanTests.cs" />
144145
<Compile Include="ScenarioTests\SSLBindingTests.cs" />
145146
<Compile Include="ScenarioTests\WebAppSlotTests.cs" />
146147
<Compile Include="ScenarioTests\WebsitesController.cs" />
147148
<Compile Include="ScenarioTests\WebAppTests.cs" />
148-
<Compile Include="WebsitesTestHelpers.cs" />
149149
<Compile Include="Properties\AssemblyInfo.cs" />
150150
</ItemGroup>
151151
<ItemGroup>
@@ -210,6 +210,9 @@
210210
<None Include="SessionRecords\Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppSlotTests\TestCreateNewWebAppSlot.json">
211211
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
212212
</None>
213+
<None Include="SessionRecords\Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppSlotTests\TestCreateNewWebAppSlotOnAse.json">
214+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
215+
</None>
213216
<None Include="SessionRecords\Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppSlotTests\TestGetWebAppSlot.json">
214217
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
215218
</None>
@@ -231,6 +234,9 @@
231234
<None Include="SessionRecords\Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppTests\TestCloneNewWebAppWithNewTrafficManager.json">
232235
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
233236
</None>
237+
<None Include="SessionRecords\Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppTests\TestCreateNewAppOnAse.json">
238+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
239+
</None>
234240
<None Include="SessionRecords\Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppTests\TestCreateNewWebApp.json">
235241
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
236242
</None>

src/ResourceManager/Websites/Commands.Websites.Test/NewAzureWebsitesCommandTests.cs

Lines changed: 0 additions & 62 deletions
This file was deleted.

src/ResourceManager/Websites/Commands.Websites.Test/ScenarioTests/Common.ps1

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ function Get-ResourceGroupName
4848
return getAssetName
4949
}
5050

51+
<#
52+
.SYNOPSIS
53+
Gets an aseName for testing.
54+
#>
55+
function Get-AseName
56+
{
57+
return getAssetName
58+
}
59+
5160
<#
5261
.SYNOPSIS
5362
Gets the location for the Website. Default to West US if none found.

src/ResourceManager/Websites/Commands.Websites.Test/ScenarioTests/WebAppSlotTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ public void TestCreateNewWebAppSlot()
2828
WebsitesController.NewInstance.RunPsTest("Test-CreateNewWebAppSlot");
2929
}
3030

31+
[Fact]
32+
[Trait(Category.AcceptanceType, Category.CheckIn)]
33+
public void TestCreateNewWebAppSlotOnAse()
34+
{
35+
WebsitesController.NewInstance.RunPsTest("Test-CreateNewWebAppSlotOnAse");
36+
}
37+
3138
[Fact]
3239
[Trait(Category.AcceptanceType, Category.CheckIn)]
3340
public void TestGetWebAppSlot()

src/ResourceManager/Websites/Commands.Websites.Test/ScenarioTests/WebAppSlotTests.ps1

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,65 @@ function Test-CreateNewWebAppSlot
430430
}
431431
}
432432

433+
<#
434+
.SYNOPSIS
435+
Tests creating a new web app slot on ASE.
436+
#>
437+
function Test-CreateNewWebAppSlotOnAse
438+
{
439+
# Setup
440+
$rgname = "appdemorg"
441+
$appname = Get-WebsiteName
442+
$slotname = "staging"
443+
$location = "West US"
444+
$planName = "travel_production_plan"
445+
$aseName = "asedemo"
446+
447+
$apiversion = "2015-08-01"
448+
$resourceType = "Microsoft.Web/sites"
449+
try
450+
{
451+
#Setup
452+
$serverFarm = Get-AzureRmAppServicePlan -ResourceGroupName $rgname -Name $planName
453+
454+
# Create new web app
455+
$actual = New-AzureRmWebApp -ResourceGroupName $rgname -Name $appname -Location $location -AppServicePlan $planName -AseName $aseName
456+
457+
# Assert
458+
Assert-AreEqual $appname $actual.Name
459+
Assert-AreEqual $serverFarm.Id $actual.ServerFarmId
460+
461+
# Get new web app
462+
$result = Get-AzureRmWebApp -ResourceGroupName $rgname -Name $appname
463+
464+
# Assert
465+
Assert-AreEqual $appname $result.Name
466+
Assert-AreEqual $serverFarm.Id $result.ServerFarmId
467+
468+
# Create deployment slot
469+
$slot1 = New-AzureRmWebAppSlot -ResourceGroupName $rgname -Name $appname -Slot $slotname -AppServicePlan $planName -AseName $aseName
470+
$appWithSlotName = "$appname/$slotname"
471+
472+
# Assert
473+
Assert-AreEqual $appWithSlotName $slot1.Name
474+
Assert-AreEqual $serverFarm.Id $slot1.ServerFarmId
475+
476+
# Get new web app slot
477+
$slot1 = Get-AzureRmWebAppSlot -ResourceGroupName $rgname -Name $appname -Slot $slotname
478+
479+
# Assert
480+
Assert-AreEqual $appWithSlotName $slot1.Name
481+
Assert-AreEqual $serverFarm.Id $slot1.ServerFarmId
482+
483+
}
484+
finally
485+
{
486+
# Cleanup
487+
Remove-AzureRmWebAppSlot -ResourceGroupName $rgname -Name $appname -Slot $slotname -Force
488+
Remove-AzureRmWebApp -ResourceGroupName $rgname -Name $appname -Force
489+
}
490+
}
491+
433492
<#
434493
.SYNOPSIS
435494
Tests retrieving web app slots

src/ResourceManager/Websites/Commands.Websites.Test/ScenarioTests/WebAppTests.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ public void TestCreateNewWebApp()
2828
WebsitesController.NewInstance.RunPsTest("Test-CreateNewWebApp");
2929
}
3030

31+
[Fact]
32+
[Trait(Category.AcceptanceType, Category.CheckIn)]
33+
public void TestCreateNewAppOnAse()
34+
{
35+
WebsitesController.NewInstance.RunPsTest("Test-CreateNewWebAppOnAse");
36+
}
37+
3138
[Fact(Skip = "Needs investigation. Fails running playback")]
3239
[Trait(Category.AcceptanceType, Category.CheckIn)]
3340
public void TestGetWebApp()

src/ResourceManager/Websites/Commands.Websites.Test/ScenarioTests/WebAppTests.ps1

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,46 @@ function Test-CreateNewWebApp
408408
}
409409
}
410410

411+
<#
412+
.SYNOPSIS
413+
Tests creating a new website on an ase
414+
#>
415+
function Test-CreateNewWebAppOnAse
416+
{
417+
# Setup
418+
$rgname = "appdemorg"
419+
$wname = Get-WebsiteName
420+
$location = "West US"
421+
$whpName = "travel_production_plan"
422+
$aseName = "asedemo"
423+
$apiversion = "2015-08-01"
424+
$resourceType = "Microsoft.Web/sites"
425+
try
426+
{
427+
#Setup
428+
$serverFarm = Get-AzureRmAppServicePlan -ResourceGroupName $rgname -Name $whpName
429+
430+
# Create new web app
431+
$actual = New-AzureRmWebApp -ResourceGroupName $rgname -Name $wname -Location $location -AppServicePlan $whpName -AseName $aseName
432+
433+
# Assert
434+
Assert-AreEqual $wname $actual.Name
435+
Assert-AreEqual $serverFarm.Id $actual.ServerFarmId
436+
437+
# Get new web app
438+
$result = Get-AzureRmWebApp -ResourceGroupName $rgname -Name $wname
439+
440+
# Assert
441+
Assert-AreEqual $wname $result.Name
442+
Assert-AreEqual $serverFarm.Id $result.ServerFarmId
443+
}
444+
finally
445+
{
446+
# Cleanup
447+
Remove-AzureRmWebApp -ResourceGroupName $rgname -Name $wname -Force
448+
}
449+
}
450+
411451
<#
412452
.SYNOPSIS
413453
Tests retrieving websites

0 commit comments

Comments
 (0)