Skip to content

Commit 6202ba2

Browse files
committed
Set-AzureRmWebApp used with AppSettings and AssignIdentity parameters
ignores the AppSettings Azure#6294
1 parent a99ffe9 commit 6202ba2

File tree

6 files changed

+4733
-1558
lines changed

6 files changed

+4733
-1558
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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/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.WebAppTests/TestSetWebApp.json

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

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)