Skip to content

Commit 5b1ad06

Browse files
authored
[App Service] Fix #30908: az webapp snapshot restore: Fix the error "no resource group found" when trying to restore a snapshot backup to a paired region (#30364)
1 parent aae9d1e commit 5b1ad06

2 files changed

Lines changed: 17 additions & 9 deletions

File tree

src/azure-cli/azure/cli/command_modules/appservice/custom.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3354,18 +3354,14 @@ def list_snapshots(cmd, resource_group_name, name, slot=None):
33543354

33553355
def restore_snapshot(cmd, resource_group_name, name, time, slot=None, restore_content_only=False, # pylint: disable=redefined-outer-name
33563356
source_resource_group=None, source_name=None, source_slot=None):
3357-
from azure.cli.core.commands.client_factory import get_subscription_id
33583357
SnapshotRecoverySource, SnapshotRestoreRequest = cmd.get_models('SnapshotRecoverySource', 'SnapshotRestoreRequest')
33593358
client = web_client_factory(cmd.cli_ctx)
33603359
recover_config = not restore_content_only
33613360
if all([source_resource_group, source_name]):
33623361
# Restore from source app to target app
3363-
sub_id = get_subscription_id(cmd.cli_ctx)
3364-
source_id = "/subscriptions/" + sub_id + "/resourceGroups/" + source_resource_group + \
3365-
"/providers/Microsoft.Web/sites/" + source_name
3366-
if source_slot:
3367-
source_id = source_id + "/slots/" + source_slot
3368-
source = SnapshotRecoverySource(id=source_id)
3362+
src_webapp = _generic_site_operation(cmd.cli_ctx, source_resource_group, source_name, 'get', source_slot)
3363+
3364+
source = SnapshotRecoverySource(id=src_webapp.id, location=src_webapp.location)
33693365
request = SnapshotRestoreRequest(overwrite=False, snapshot_time=time, recovery_source=source,
33703366
recover_configuration=recover_config)
33713367
if slot:

src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_webapp_commands_thru_mock.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,8 @@ def test_list_webapp_snapshots(self, site_op_mock):
352352
site_op_mock.assert_called_with(cli_ctx_mock, 'rg', 'web1', 'list_snapshots', None)
353353

354354
@mock.patch('azure.cli.command_modules.appservice.custom.web_client_factory', autospec=True)
355-
def test_restore_snapshot(self, client_factory_mock):
355+
@mock.patch('azure.cli.command_modules.appservice.custom._generic_site_operation', autospec=True)
356+
def test_restore_snapshot(self, generic_site_op_mock, client_factory_mock):
356357
cmd_mock = _get_test_cmd()
357358
cli_ctx_mock = mock.MagicMock()
358359
cli_ctx_mock.data = {'subscription_id': 'sub1'}
@@ -361,11 +362,22 @@ def test_restore_snapshot(self, client_factory_mock):
361362
client = mock.MagicMock()
362363
client.web_apps.restore_snapshot_slot = mock.MagicMock()
363364
client.web_apps.restore_snapshot = mock.MagicMock()
365+
366+
Site = cmd_mock.get_models('Site')
367+
site = Site(name='src_web', location='location')
368+
site.slot_name = 'src_slot'
369+
site.resouce_group = 'src_rg'
370+
site.id = '/subscriptions/sub1/resourceGroups/src_rg/providers/Microsoft.Web/sites/src_web/slots/src_slot'
371+
372+
generic_site_op_mock.return_value = site
373+
364374
client_factory_mock.return_value = client
375+
376+
365377

366378
SnapshotRecoverySource, SnapshotRestoreRequest = \
367379
cmd_mock.get_models('SnapshotRecoverySource', 'SnapshotRestoreRequest')
368-
source = SnapshotRecoverySource(id='/subscriptions/sub1/resourceGroups/src_rg/providers/Microsoft.Web/sites/src_web/slots/src_slot')
380+
source = SnapshotRecoverySource(id='/subscriptions/sub1/resourceGroups/src_rg/providers/Microsoft.Web/sites/src_web/slots/src_slot', location='location')
369381
request = SnapshotRestoreRequest(overwrite=False, snapshot_time='2018-12-07T02:01:31.4708832Z',
370382
recovery_source=source, recover_configuration=False)
371383
overwrite_request = SnapshotRestoreRequest(overwrite=True, snapshot_time='2018-12-07T02:01:31.4708832Z', recover_configuration=True)

0 commit comments

Comments
 (0)