Skip to content

Webapps undelete commands #7165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Sep 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ----------------------------------------------------------------------------------
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the 'License');
Expand Down Expand Up @@ -768,7 +768,9 @@ public static Dictionary<string, object> GetCaseInsensitiveMapping()
'New-AzWebAppDatabaseBackupSetting': 'New-AzureRmWebAppDatabaseBackupSetting',
'Get-AzWebAppSSLBinding': 'Get-AzureRmWebAppSSLBinding',
'Get-AzWebAppSlot': 'Get-AzureRmWebAppSlot',
'New-AzWebApp': 'New-AzureRmWebApp'
'New-AzWebApp': 'New-AzureRmWebApp',
'Restore-AzDeletedWebApp': 'Restore-AzureRmDeletedWebApp',
'Get-AzDeletedWebApp': 'Get-AzureRmDeletedWebApp'
},
'Az.Maps': {
'Get-AzMapsAccountKey': 'Get-AzureRmMapsAccountKey',
Expand Down Expand Up @@ -2383,6 +2385,7 @@ public static Dictionary<string, object> GetCaseInsensitiveMapping()
'Remove-AzNotificationHubsNamespace': 'Remove-AzureRmNotificationHubsNamespace'
}
}

";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
<None Include="SessionRecords\Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppBackupRestoreTests\TestEditAndGetWebAppBackupConfigurationPiping.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppBackupRestoreTests\TestGetDeletedWebApp.json" />
<None Include="SessionRecords\Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppBackupRestoreTests\TestGetWebAppBackup.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand All @@ -134,6 +135,8 @@
<None Include="SessionRecords\Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppBackupRestoreTests\TestGetWebAppSnapshot.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppBackupRestoreTests\TestRestoreDeletedWebAppToExisting.json" />
<None Include="SessionRecords\Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppBackupRestoreTests\TestRestoreDeletedWebAppToNew.json" />
<None Include="SessionRecords\Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppBackupRestoreTests\TestRestoreWebAppSnapshot.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down Expand Up @@ -191,6 +194,15 @@
<None Include="SessionRecords\Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppTests\TestWebAppPublishingProfile.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppBackupRestoreTests\TestGetDeletedWebApp.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppBackupRestoreTests\TestRestoreDeletedWebAppToExisting.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="SessionRecords\Microsoft.Azure.Commands.Websites.Test.ScenarioTests.WebAppBackupRestoreTests\TestRestoreDeletedWebAppToNew.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\Storage\Commands.Storage\Commands.Storage.csproj">
Expand All @@ -206,4 +218,4 @@
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,26 @@ public void TestRestoreWebAppSnapshot()
{
WebsitesController.NewInstance.RunPsTest(_logger, "Test-RestoreWebAppSnapshot");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestGetDeletedWebApp()
{
WebsitesController.NewInstance.RunPsTest(_logger, "Test-GetDeletedWebApp");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestRestoreDeletedWebAppToExisting()
{
WebsitesController.NewInstance.RunPsTest(_logger, "Test-RestoreDeletedWebAppToExisting");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestRestoreDeletedWebAppToNew()
{
WebsitesController.NewInstance.RunPsTest(_logger, "Test-RestoreDeletedWebAppToNew");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ $snapshotRgName = 'onesdksnapshots'
$snapshotAppName = 'onesdkpremapp2'
$snapshotAppSlot = 'staging'

# Restoring a deleted web app requires an app to have a snapshot available.
# Deploy a web app and wait at least an hour for a snapshot.
# Update these global variables to re-record Test-RestoreDeletedWebApp.
$undeleteRgName = 'ps8425'
$undeleteAppName = 'ps1705'
$undeleteSlot = 'testslot'

# !!! Storage keys and SAS URIs will be stored in the backup test recordings !!!
# To find them, open the json files in a text editor and search for "listkeys"
# to find the storage keys. Search for StorageAccountUrl to find the SAS URIs.
# Remove them when re-recording the tests so that secrets are not shared.

function Test-CreateNewWebAppBackup
{
$rgName = Get-ResourceGroupName
Expand Down Expand Up @@ -374,6 +386,120 @@ function Test-RestoreWebAppSnapshot
$job | Wait-Job
}

function Test-GetDeletedWebApp
{
# Setup
$rgname = Get-ResourceGroupName
$wname = Get-WebsiteName
$slotName = "staging"
$location = Get-WebLocation
$whpName = Get-WebHostPlanName
$tier = "Standard"

try
{
#Setup
New-AzureRmResourceGroup -Name $rgname -Location $location
New-AzureRmAppServicePlan -ResourceGroupName $rgname -Name $whpName -Location $location -Tier $tier
New-AzureRmWebApp -ResourceGroupName $rgname -Name $wname -Location $location -AppServicePlan $whpName
New-AzureRmWebAppSlot -ResourceGroupName $rgname -Name $wname -Slot $slotName -AppServicePlan $planName
Remove-AzureRmWebAppSlot -ResourceGroupName $rgname -Name $wname -Slot $slotName -Force
Remove-AzureRmWebApp -ResourceGroupName $rgname -Name $wname -Force

$deletedApp = Get-AzureRmDeletedWebApp -ResourceGroupName $rgname -Name $wname -Slot "Production"
Assert-NotNull $deletedApp
Assert-AreEqual $rgname $deletedApp.ResourceGroupName
Assert-AreEqual $wname $deletedApp.Name

$deletedSlot = Get-AzureRmDeletedWebApp -ResourceGroupName $rgname -Name $wname -Slot $slotName
Assert-NotNull $deletedSlot
Assert-AreEqual $rgname $deletedSlot.ResourceGroupName
Assert-AreEqual $wname $deletedSlot.Name
Assert-AreEqual $slotName $deletedSlot.Slot
}
finally
{
# Cleanup
Remove-AzureRmAppServicePlan -ResourceGroupName $rgname -Name $whpName -Force
Remove-AzureRmResourceGroup -Name $rgname -Force
}
}

function Test-RestoreDeletedWebAppToExisting
{
# Setup
$rgname = Get-ResourceGroupName
$wname = Get-WebsiteName
$slotName = "staging"
$appWithSlotName = "$wname/$slotName"
$location = Get-WebLocation
$whpName = Get-WebHostPlanName
$tier = "Standard"

try
{
New-AzureRmResourceGroup -Name $rgname -Location $location
New-AzureRmAppServicePlan -ResourceGroupName $rgname -Name $whpName -Location $location -Tier $tier
New-AzureRmWebApp -ResourceGroupName $rgname -Name $wname -Location $location -AppServicePlan $whpName
New-AzureRmWebAppSlot -ResourceGroupName $rgname -Name $wname -Slot $slotName -AppServicePlan $planName

$deletedApp = Get-AzureRmDeletedWebApp -ResourceGroupName $undeleteRgName -Name $undeleteAppName -Slot "Production"
# Test the InputObject parameter set
$restoredApp = Restore-AzureRmDeletedWebApp $deletedApp -TargetResourceGroupName $rgname -TargetName $wname -Force
# Test the FromDeletedResourceName parameter set
$restoredSlot = Restore-AzureRmDeletedWebApp -ResourceGroupName $undeleteRgName -Name $undeleteAppName -Slot $undeleteSlot -TargetResourceGroupName $rgname -TargetName $wname -TargetSlot $slotName -Force

Assert-NotNull $restoredApp
Assert-AreEqual $rgname $restoredApp.ResourceGroup
Assert-AreEqual $wname $restoredApp.Name

Assert-NotNull $restoredSlot
Assert-AreEqual $rgname $restoredSlot.ResourceGroup
Assert-AreEqual $appWithSlotName $restoredSlot.Name
}
finally
{
# Cleanup
Remove-AzureRmWebAppSlot -ResourceGroupName $rgname -Name $wname -Slot $slotName -Force
Remove-AzureRmWebApp -ResourceGroupName $rgname -Name $wname -Force
Remove-AzureRmAppServicePlan -ResourceGroupName $rgname -Name $whpName -Force
Remove-AzureRmResourceGroup -Name $rgname -Force
}
}

function Test-RestoreDeletedWebAppToNew
{
# Setup
$rgname = Get-ResourceGroupName
$location = Get-WebLocation
$whpName = Get-WebHostPlanName
$tier = "Standard"

try
{
#Setup
New-AzureRmResourceGroup -Name $rgname -Location $location
New-AzureRmAppServicePlan -ResourceGroupName $rgname -Name $whpName -Location $location -Tier $tier
$deletedApp = Get-AzureRmDeletedWebApp -ResourceGroupName $undeleteRgName -Name $undeleteAppName -Slot "Production"
# Test piping the deleted app
$job = $deletedApp | Restore-AzureRmDeletedWebApp -TargetResourceGroupName $rgname -TargetAppServicePlanName $whpName -Force -AsJob
$result = $job | Wait-Job
Assert-AreEqual "Completed" $result.State;

$restoredApp = $job | Receive-Job
Assert-NotNull $restoredApp
Assert-AreEqual $rgname $restoredApp.ResourceGroup
Assert-AreEqual $undeleteAppName $restoredApp.Name
}
finally
{
# Cleanup
Remove-AzureRmWebApp -ResourceGroupName $rgname -Name $undeleteAppName -Force
Remove-AzureRmAppServicePlan -ResourceGroupName $rgname -Name $whpName -Force
Remove-AzureRmResourceGroup -Name $rgname -Force
}
}

# Utility functions

# Creates a new web app
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@
"Microsoft.Azure.Management.Storage.StorageManagementClient/4.0.0.0"
]
},
"ResponseBody": "{\r\n \"key1\": \"k/PoJV7QPAMDNA2xXzHkJK/2BfCgR8T07WoRDVpcSiPoKzltg4eWHLDiSoCBhA7s/3QQG2tuLOXvf64oNDBAZA==\",\r\n \"key2\": \"bJKvyMT9dnuavEHaQDohobUF9sMtg1hHm7cOKdnWcpD+ZuxCcjyMnKerUqh+bjZLgLJCkH15um3r2jjyqKUZxw==\"\r\n}",
"ResponseBody": "{\r\n \"key1\": \"REDACTED\",\r\n \"key2\": \"REDACTED\"\r\n}",
"ResponseHeaders": {
"Content-Length": [
"197"
Expand Down Expand Up @@ -1024,7 +1024,7 @@
"RequestUri": "/subscriptions/0d3ae56c-deaf-4982-b514-33d016d4a683/resourceGroups/ps1762/providers/Microsoft.Web/sites/ps5041/backup?api-version=2018-02-01",
"EncodedRequestUri": "L3N1YnNjcmlwdGlvbnMvMGQzYWU1NmMtZGVhZi00OTgyLWI1MTQtMzNkMDE2ZDRhNjgzL3Jlc291cmNlR3JvdXBzL3BzMTc2Mi9wcm92aWRlcnMvTWljcm9zb2Z0LldlYi9zaXRlcy9wczUwNDEvYmFja3VwP2FwaS12ZXJzaW9uPTIwMTgtMDItMDE=",
"RequestMethod": "POST",
"RequestBody": "{\r\n \"properties\": {\r\n \"backupName\": \"ps9111\",\r\n \"storageAccountUrl\": \"https://stops1762.blob.core.windows.net/containerps1762?sv=2017-07-29&sr=b&sig=mkK%2F8EY3js5GRaRwYB1kZU7GYhbviev5W%2B9kgi2d6ck%3D&se=2018-08-31T01%3A49%3A25Z&sp=rwdl\"\r\n }\r\n}",
"RequestBody": "{\r\n \"properties\": {\r\n \"backupName\": \"ps9111\",\r\n \"storageAccountUrl\": \"REDACTED\"\r\n }\r\n}",
"RequestHeaders": {
"Content-Type": [
"application/json; charset=utf-8"
Expand All @@ -1045,7 +1045,7 @@
"Microsoft.Azure.Management.WebSites.WebSiteManagementClient/2.0.0"
]
},
"ResponseBody": "{\r\n \"id\": \"/subscriptions/0d3ae56c-deaf-4982-b514-33d016d4a683/resourceGroups/ps1762/providers/Microsoft.Web/sites/ps5041\",\r\n \"name\": \"ps5041\",\r\n \"type\": \"Microsoft.Web/sites\",\r\n \"location\": \"West US\",\r\n \"properties\": {\r\n \"id\": 183,\r\n \"storageAccountUrl\": \"https://stops1762.blob.core.windows.net/containerps1762?sv=2017-07-29&sr=b&sig=mkK%2F8EY3js5GRaRwYB1kZU7GYhbviev5W%2B9kgi2d6ck%3D&se=2018-08-31T01%3A49%3A25Z&sp=rwdl\",\r\n \"blobName\": \"ps9111\",\r\n \"name\": \"ps9111\",\r\n \"backupName\": \"ps9111\",\r\n \"status\": \"Created\",\r\n \"sizeInBytes\": 0,\r\n \"created\": \"2018-08-30T23:49:26.1425518Z\",\r\n \"log\": null,\r\n \"databases\": null,\r\n \"scheduled\": false,\r\n \"correlationId\": \"c067b16d-2da3-4f46-97f3-8669e7cb3b07\",\r\n \"websiteSizeInBytes\": null\r\n }\r\n}",
"ResponseBody": "{\r\n \"id\": \"/subscriptions/0d3ae56c-deaf-4982-b514-33d016d4a683/resourceGroups/ps1762/providers/Microsoft.Web/sites/ps5041\",\r\n \"name\": \"ps5041\",\r\n \"type\": \"Microsoft.Web/sites\",\r\n \"location\": \"West US\",\r\n \"properties\": {\r\n \"id\": 183,\r\n \"storageAccountUrl\": \"REDACTED\",\r\n \"blobName\": \"ps9111\",\r\n \"name\": \"ps9111\",\r\n \"backupName\": \"ps9111\",\r\n \"status\": \"Created\",\r\n \"sizeInBytes\": 0,\r\n \"created\": \"2018-08-30T23:49:26.1425518Z\",\r\n \"log\": null,\r\n \"databases\": null,\r\n \"scheduled\": false,\r\n \"correlationId\": \"c067b16d-2da3-4f46-97f3-8669e7cb3b07\",\r\n \"websiteSizeInBytes\": null\r\n }\r\n}",
"ResponseHeaders": {
"Content-Length": [
"658"
Expand Down
Loading