Skip to content

Commit 12da7cd

Browse files
authored
Merge pull request #6412 from panchagnula/sisirap-AppSettingWithIdentityFix
Set-AzureRmWebApp used with AppSettings and AssignIdentity parameters ignores the AppSettings #6294
2 parents 1e4af70 + 628ae39 commit 12da7cd

File tree

11 files changed

+7680
-3387
lines changed

11 files changed

+7680
-3387
lines changed

src/ResourceManager/Websites/ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
- Additional information about change #1
1919
-->
2020
## Current Release
21+
* `Set-AzureRmWebApp` is updated to not overwrite the AppSettings when using -AssignIdentity
22+
* `New-AzureRmWebAppSlot` is updated to honor AppServicePlan as an optional parameter
2123

2224
## Version 5.0.2
2325
* `New-AzureRMWebApp` is updated to use common algorithms from the Strategy library.

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ function Test-CreateNewWebAppSlot
406406
Assert-AreEqual $serverFarm.Id $result.ServerFarmId
407407

408408
# Create deployment slot
409-
$job = New-AzureRmWebAppSlot -ResourceGroupName $rgname -Name $appname -Slot $slotname -AppServicePlan $planName -AsJob
409+
$job = New-AzureRmWebAppSlot -ResourceGroupName $rgname -Name $appname -Slot $slotname -AsJob
410410
$job | Wait-Job
411411
$slot1 = $job | Receive-Job
412412

@@ -528,15 +528,14 @@ function Test-SetWebAppSlot
528528
Assert-Null $webApp.Identity
529529

530530
# Change service plan & set properties
531-
$job = Set-AzureRmWebAppSlot -ResourceGroupName $rgname -Name $appname -Slot $slotname -AppServicePlan $planName2 -HttpsOnly $true -AssignIdentity $true -AsJob
531+
$job = Set-AzureRmWebAppSlot -ResourceGroupName $rgname -Name $appname -Slot $slotname -AppServicePlan $planName2 -HttpsOnly $true -AsJob
532532
$job | Wait-Job
533533
$slot = $job | Receive-Job
534534

535535
# Assert
536536
Assert-AreEqual $appWithSlotName $slot.Name
537537
Assert-AreEqual $serverFarm2.Id $slot.ServerFarmId
538538
Assert-AreEqual $true $slot.HttpsOnly
539-
Assert-NotNull $slot.Identity
540539

541540
# Set config properties
542541
$slot.SiteConfig.HttpLoggingEnabled = $true
@@ -554,11 +553,16 @@ function Test-SetWebAppSlot
554553
$appSettings = @{ "setting1" = "valueA"; "setting2" = "valueB"}
555554
$connectionStrings = @{ connstring1 = @{ Type="MySql"; Value="string value 1"}; connstring2 = @{ Type = "SQLAzure"; Value="string value 2"}}
556555

557-
$slot = Set-AzureRmWebAppSlot -ResourceGroupName $rgname -Name $appname -Slot $slotname -AppSettings $appSettings -ConnectionStrings $connectionStrings -numberofworkers $numberOfWorkers
556+
$slot = Set-AzureRmWebAppSlot -ResourceGroupName $rgname -Name $appname -Slot $slotname -AppSettings $appSettings -AssignIdentity $true
557+
558+
# Assert
559+
Assert-NotNull $slot.Identity
560+
Assert-AreEqual ($appSettings.Keys.Count + 1) $slot.SiteConfig.AppSettings.Count
561+
562+
$slot = Set-AzureRmWebAppSlot -ResourceGroupName $rgname -Name $appname -Slot $slotname -AppSettings $appSettings -ConnectionStrings $connectionStrings -numberofworkers $numberOfWorkers
558563

559564
# Assert
560565
Assert-AreEqual $appWithSlotName $slot.Name
561-
Assert-AreEqual $appSettings.Keys.Count $slot.SiteConfig.AppSettings.Count
562566
foreach($nvp in $slot.SiteConfig.AppSettings)
563567
{
564568
Assert-True { $appSettings.Keys -contains $nvp.Name }

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -598,15 +598,14 @@ function Test-SetWebApp
598598
Assert-Null $webApp.Identity
599599

600600
# Change service plan & set site properties
601-
$job = Set-AzureRmWebApp -ResourceGroupName $rgname -Name $webAppName -AppServicePlan $appServicePlanName2 -HttpsOnly $true -AssignIdentity $true -AsJob
601+
$job = Set-AzureRmWebApp -ResourceGroupName $rgname -Name $webAppName -AppServicePlan $appServicePlanName2 -HttpsOnly $true -AsJob
602602
$job | Wait-Job
603603
$webApp = $job | Receive-Job
604604

605605
# Assert
606606
Assert-AreEqual $webAppName $webApp.Name
607607
Assert-AreEqual $serverFarm2.Id $webApp.ServerFarmId
608608
Assert-AreEqual $true $webApp.HttpsOnly
609-
Assert-NotNull $webApp.Identity
610609

611610
# Set config properties
612611
$webapp.SiteConfig.HttpLoggingEnabled = $true
@@ -621,21 +620,28 @@ function Test-SetWebApp
621620
Assert-AreEqual $true $webApp.SiteConfig.HttpLoggingEnabled
622621
Assert-AreEqual $true $webApp.SiteConfig.RequestTracingEnabled
623622

624-
# set app settings and connection strings
625623
$appSettings = @{ "setting1" = "valueA"; "setting2" = "valueB"}
626624
$connectionStrings = @{ connstring1 = @{ Type="MySql"; Value="string value 1"}; connstring2 = @{ Type = "SQLAzure"; Value="string value 2"}}
627625

626+
# set app settings and assign Identity
627+
$webApp = Set-AzureRmWebApp -ResourceGroupName $rgname -Name $webAppName -AppSettings $appSettings -AssignIdentity $true
628+
629+
# Assert
630+
Assert-NotNull $webApp.Identity
631+
# AssignIdentity adds an appsetting to handle enabling / disabling AssignIdentity
632+
Assert-AreEqual ($appSettings.Keys.Count + 1) $webApp.SiteConfig.AppSettings.Count
633+
Assert-NotNull $webApp.Identity
634+
635+
# set app settings and connection strings
628636
$webApp = Set-AzureRmWebApp -ResourceGroupName $rgname -Name $webAppName -AppSettings $appSettings -ConnectionStrings $connectionStrings -NumberofWorkers $capacity
629637

630638
# Assert
631639
Assert-AreEqual $webAppName $webApp.Name
632-
Assert-AreEqual $appSettings.Keys.Count $webApp.SiteConfig.AppSettings.Count
633-
foreach($nvp in $webApp.SiteConfig.AppSettings)
640+
foreach($nvp in $webApp.SiteConfig.AppSettings)
634641
{
635642
Assert-True { $appSettings.Keys -contains $nvp.Name }
636643
Assert-True { $appSettings[$nvp.Name] -match $nvp.Value }
637644
}
638-
639645
Assert-AreEqual $connectionStrings.Keys.Count $webApp.SiteConfig.ConnectionStrings.Count
640646
foreach($connStringInfo in $webApp.SiteConfig.ConnectionStrings)
641647
{

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

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

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

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

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

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

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

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

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

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

src/ResourceManager/Websites/Commands.Websites/Cmdlets/DeploymentSlots/NewAzureWebAppSlot.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public override void ExecuteCmdlet()
9090

9191
var webApp = WebsitesClient.GetWebApp(ResourceGroupName, Name, null);
9292

93-
WriteObject(WebsitesClient.CreateWebApp(ResourceGroupName, Name, Slot, webApp.Location, AppServicePlan, cloningInfo, AseName, AseResourceGroupName));
93+
WriteObject(WebsitesClient.CreateWebApp(ResourceGroupName, Name, Slot, webApp.Location, AppServicePlan==null?webApp.ServerFarmId : AppServicePlan, cloningInfo, AseName, AseResourceGroupName));
9494
}
9595
}
9696
}

src/ResourceManager/Websites/Commands.Websites/Cmdlets/DeploymentSlots/SetAzureWebAppSlot.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ public override void ExecuteCmdlet()
135135
// Update web app configuration
136136
WebsitesClient.UpdateWebAppConfiguration(ResourceGroupName, location, Name, Slot, siteConfig, AppSettings.ConvertToStringDictionary(), ConnectionStrings.ConvertToConnectionStringDictionary());
137137

138+
//update reference to WebApp object after site configuration update
139+
WebApp = WebsitesClient.GetWebApp(ResourceGroupName, Name, Slot);
140+
138141
if (parameters.Any(p => CmdletHelpers.SiteParameters.Contains(p)))
139142
{
140143

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ public override void ExecuteCmdlet()
143143
// Update web app configuration
144144
WebsitesClient.UpdateWebAppConfiguration(ResourceGroupName, location, Name, null, siteConfig, AppSettings.ConvertToStringDictionary(), ConnectionStrings.ConvertToConnectionStringDictionary());
145145

146+
//Update WebApp object after configuration update
147+
WebApp = WebsitesClient.GetWebApp(ResourceGroupName, Name, null);
148+
146149
if (parameters.Any(p => CmdletHelpers.SiteParameters.Contains(p)))
147150
{
148151

0 commit comments

Comments
 (0)