Skip to content

Commit 5546669

Browse files
committed
Second Commit#9895,Azure#10422,#Azure#10482
1 parent b8504f6 commit 5546669

File tree

11 files changed

+7427
-2752
lines changed

11 files changed

+7427
-2752
lines changed

src/Websites/Websites.Test/ScenarioTests/AppServicePlanTests.ps1

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,15 @@ function Test-CreateNewAppServicePlan
2424
$location = Get-Location
2525
$capacity = 2
2626
$skuName = "S2"
27+
$tags= @{"TagKey" = "TagValue"}
2728

2829
try
2930
{
3031
#Setup
3132
New-AzResourceGroup -Name $rgname -Location $location
3233

3334
# Test
34-
$job = New-AzAppServicePlan -ResourceGroupName $rgname -Name $whpName -Location $location -Tier "Standard" -WorkerSize Medium -NumberOfWorkers $capacity -AsJob
35+
$job = New-AzAppServicePlan -ResourceGroupName $rgname -Name $whpName -Location $location -Tier "Standard" -WorkerSize Medium -NumberOfWorkers $capacity -Tags $tags -AsJob
3536
$job | Wait-Job
3637
$createResult = $job | Receive-Job
3738

@@ -40,6 +41,8 @@ function Test-CreateNewAppServicePlan
4041
Assert-AreEqual "Standard" $createResult.Sku.Tier
4142
Assert-AreEqual $skuName $createResult.Sku.Name
4243
Assert-AreEqual $capacity $createResult.Sku.Capacity
44+
Assert-AreEqual $tags.Keys $createResult.Tags.Keys
45+
Assert-AreEqual $tags.Values $createResult.Tags.Values
4346

4447
# Assert
4548

@@ -127,7 +130,7 @@ function Test-SetAppServicePlan
127130
$newWorkerSize = "Medium"
128131
$newCapacity = 2
129132
$newPerSiteScaling = $true;
130-
133+
$tags= @{"TagKey" = "TagValue"}
131134

132135
try
133136
{
@@ -173,6 +176,12 @@ function Test-SetAppServicePlan
173176
Assert-AreEqual $skuName $newresult.Sku.Name
174177
Assert-AreEqual $perSiteScaling $newresult.PerSiteScaling
175178

179+
#Set Tags
180+
$tagsResult= Set-AzAppServicePlan -ResourceGroupName $rgname -Name $whpName -Tags $tags
181+
182+
# Assert
183+
Assert-AreEqual $tags.Keys $tagsResult.Tags.Keys
184+
Assert-AreEqual $tags.Values $tagsResult.Tags.Values
176185
}
177186
finally
178187
{

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,10 +1064,12 @@ function Test-SetWebApp
10641064
{
10651065
# Setup
10661066
$rgname = Get-ResourceGroupName
1067+
$rgname1 = Get-ResourceGroupName
10671068
$webAppName = Get-WebsiteName
10681069
$location = Get-WebLocation
10691070
$appServicePlanName1 = Get-WebHostPlanName
10701071
$appServicePlanName2 = Get-WebHostPlanName
1072+
$appServicePlanName3 = Get-WebHostPlanName
10711073
$tier1 = "Shared"
10721074
$tier2 = "Standard"
10731075
$apiversion = "2015-08-01"
@@ -1159,6 +1161,39 @@ function Test-SetWebApp
11591161
Assert-AreEqual "" $webApp.SiteConfig.PhpVersion
11601162
Assert-AreEqual "1.2" $webApp.SiteConfig.MinTlsVersion
11611163

1164+
## Create two Resource Groups.
1165+
New-AzResourceGroup -Name $rgname -Location $location
1166+
New-AzResourceGroup -Name $rgname1 -Location $location
1167+
1168+
## Create the App Service Plan in $rgname.
1169+
$asp = New-AzAppServicePlan -Location $location -Tier Standard -NumberofWorkers 1 -WorkerSize Small -ResourceGroupName $rgname -Name $appServicePlanName3
1170+
1171+
## Create a Web App in each Resource Group.
1172+
$app1 = $(Get-Random)
1173+
$app2 = $(Get-Random)
1174+
New-AzWebApp -ResourceGroupName $rgname -Name $app1 -Location $location -AppServicePlan $asp.Id
1175+
New-AzWebApp -ResourceGroupName $rgname1 -Name $app2 -Location $location -AppServicePlan $asp.Id
1176+
1177+
## Get the two Web Apps.
1178+
$wa1 = Get-AzWebApp -ResourceGroupName $rgname -Name $app1
1179+
$wa2 = Get-AzWebApp -ResourceGroupName $rgname1 -Name $app2
1180+
1181+
## Change a setting on the first Web App (which is in the same Resource Group as the App Service Plan).
1182+
$currentWa1ClientAffinityEnabled=$wa1.ClientAffinityEnabled
1183+
$wa1.ClientAffinityEnabled = !$wa1.ClientAffinityEnabled
1184+
$wa1 | Set-AzWebApp
1185+
1186+
#Assert
1187+
Assert-AreNotEqual $currentWa1ClientAffinityEnabled $wa1.ClientAffinityEnabled
1188+
1189+
## Change a setting on the Second Web App (which is in not the same Resource Group as the App Service Plan).
1190+
$currentWa2ClientAffinityEnabled=$wa2.ClientAffinityEnabled
1191+
$wa2.ClientAffinityEnabled = !$wa2.ClientAffinityEnabled
1192+
$wa2 | Set-AzWebApp
1193+
1194+
#Assert
1195+
Assert-AreNotEqual $currentWa2ClientAffinityEnabled $wa2.ClientAffinityEnabled
1196+
11621197
}
11631198
finally
11641199
{

src/Websites/Websites.Test/SessionRecords/Microsoft.Azure.Commands.Websites.Test.ScenarioTests.AppServicePlanTests/TestCreateNewAppServicePlan.json

Lines changed: 265 additions & 151 deletions
Large diffs are not rendered by default.

src/Websites/Websites.Test/SessionRecords/Microsoft.Azure.Commands.Websites.Test.ScenarioTests.AppServicePlanTests/TestSetAppServicePlan.json

Lines changed: 447 additions & 189 deletions
Large diffs are not rendered by default.

src/Websites/Websites.Test/SessionRecords/Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppSlotTests/TestSetWebAppSlot.json

Lines changed: 1062 additions & 1062 deletions
Large diffs are not rendered by default.

src/Websites/Websites.Test/SessionRecords/Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppTests/TestSetWebApp.json

Lines changed: 5586 additions & 1342 deletions
Large diffs are not rendered by default.

src/Websites/Websites/ChangeLog.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21-
21+
*Adding Tag parameter for New-AzAppServicePlan and Set-AzAppServicePlan.
22+
*Stop cmdlt execution if an exception is thrown when adding a custom domain to a website.
23+
*Adding support to perform operations for App Services not in the same resource group as the App Service Plan.
24+
*Adding support to set custom hostnames for WebAppSlots
2225
## Version 1.6.0
2326
* Set-AzWebapp and Set-AzWebappSlot supports AlwaysOn, MinTls and FtpsState properties
2427
* Fixing issue where setting HttpsOnly along with changing AppservicePlan at the same time using the single Set-AzWebApp Command, was resetting HttpsOnly to default value

src/Websites/Websites/Cmdlets/AppServicePlans/NewAzureAppServicePlan.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
using Microsoft.Azure.Commands.WebApps.Utilities;
1919
using Microsoft.Azure.Management.WebSites.Models;
2020
using System;
21+
using System.Collections;
22+
using System.Collections.Generic;
2123
using System.Management.Automation;
2224

2325
namespace Microsoft.Azure.Commands.WebApps.Cmdlets.AppServicePlans
@@ -63,6 +65,9 @@ public class NewAzureAppServicePlanCmdlet : AppServicePlanBaseCmdlet
6365
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
6466
public SwitchParameter AsJob { get; set; }
6567

68+
[Parameter(ParameterSetName = ParameterSet1Name, Mandatory = false, HelpMessage = "Tags are name/value pairs that enable you to categorize resources")]
69+
public Hashtable Tags { get; set; }
70+
6671
public override void ExecuteCmdlet()
6772
{
6873
if (HyperV.IsPresent && Tier != "PremiumContainer")
@@ -107,7 +112,8 @@ public override void ExecuteCmdlet()
107112
Location = Location,
108113
Sku = sku,
109114
PerSiteScaling = PerSiteScaling,
110-
IsXenon = HyperV.IsPresent
115+
IsXenon = HyperV.IsPresent,
116+
Tags = (IDictionary<string, string>)CmdletHelpers.ConvertToStringDictionary(Tags)
111117
};
112118

113119
AppServicePlan retPlan = WebsitesClient.CreateOrUpdateAppServicePlan(ResourceGroupName, Name, appServicePlan, AseName, aseResourceGroupName);

src/Websites/Websites/Cmdlets/AppServicePlans/SetAzureAppServicePlan.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
using System.Management.Automation;
1919
using System.Text.RegularExpressions;
2020
using Microsoft.Azure.Commands.WebApps.Models.WebApp;
21+
using System.Collections;
22+
using System.Collections.Generic;
2123

2224
namespace Microsoft.Azure.Commands.WebApps.Cmdlets.AppServicePlans
2325
{
@@ -49,6 +51,9 @@ public class SetAzureAppServicePlanCmdlet : AppServicePlanBaseCmdlet
4951
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
5052
public SwitchParameter AsJob { get; set; }
5153

54+
[Parameter(ParameterSetName = ParameterSet1Name, Mandatory = false, HelpMessage = "Tags are name/value pairs that enable you to categorize resources")]
55+
public Hashtable Tags { get; set; }
56+
5257
public override void ExecuteCmdlet()
5358
{
5459
base.ExecuteCmdlet();
@@ -62,6 +67,7 @@ public override void ExecuteCmdlet()
6267
int.TryParse(Regex.Match(AppServicePlan.Sku.Name, @"\d+").Value, out workerSizeAsNumber);
6368
AppServicePlan.Sku.Name = string.IsNullOrWhiteSpace(WorkerSize) ? CmdletHelpers.GetSkuName(AppServicePlan.Sku.Tier, workerSizeAsNumber) : CmdletHelpers.GetSkuName(AppServicePlan.Sku.Tier, WorkerSize);
6469
AppServicePlan.PerSiteScaling = PerSiteScaling;
70+
AppServicePlan.Tags = (IDictionary<string, string>)CmdletHelpers.ConvertToStringDictionary(Tags);
6571
break;
6672
}
6773

src/Websites/Websites/Cmdlets/WebApps/SetAzureWebApp.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ public override void ExecuteCmdlet()
312312
CmdletHelpers.TryParseAppServicePlanMetadataFromResourceId(WebApp.ServerFarmId, out rg, out servicePlanName);
313313
// AzureStorage path is not a part of the back end siteObject, but if the PSSite Object is given as an input, we will some value for this
314314
WebApp.AzureStoragePath = null;
315-
WebsitesClient.UpdateWebApp(ResourceGroupName, location, Name, null, servicePlanName, WebApp);
315+
WebsitesClient.UpdateWebApp(ResourceGroupName, location, Name, null, servicePlanName, WebApp,rg);
316316
WebsitesClient.AddCustomHostNames(ResourceGroupName, location, Name, WebApp.HostNames.ToArray());
317317
break;
318318
}

src/Websites/Websites/Utilities/WebsitesClient.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ public HostingEnvironmentProfile CreateHostingEnvironmentProfile(string resource
9797
return CmdletHelpers.CreateHostingEnvironmentProfile(WrappedWebsitesClient.SubscriptionId, resourceGroupName, aseResourceGroupName, aseName);
9898
}
9999

100-
public void UpdateWebApp(string resourceGroupName, string location, string webAppName, string slotName, string appServicePlan, Site siteEnvelope =null)
100+
public void UpdateWebApp(string resourceGroupName, string location, string webAppName, string slotName, string appServicePlan, Site siteEnvelope =null, string appServicePlanRg = null)
101101
{
102102
var webSiteToUpdate = new Site()
103103
{
104-
ServerFarmId = appServicePlan,
104+
ServerFarmId = (string.IsNullOrEmpty(appServicePlanRg) && resourceGroupName != appServicePlanRg) ? appServicePlan : siteEnvelope.ServerFarmId,
105105
Location = location,
106106
Tags = siteEnvelope?.Tags
107107
};
@@ -112,7 +112,7 @@ public void UpdateWebApp(string resourceGroupName, string location, string webAp
112112
}
113113

114114
// make sure the serverfarm ID is nt overwritten to the old value
115-
if (appServicePlan != null)
115+
if (appServicePlan != null && (string.IsNullOrEmpty(appServicePlanRg) && resourceGroupName != appServicePlanRg))
116116
{
117117
webSiteToUpdate.ServerFarmId = appServicePlan;
118118
}

0 commit comments

Comments
 (0)