Skip to content

Commit

Permalink
{SQL} az sql midb log-replay stop: Adjust error handling for new AP…
Browse files Browse the repository at this point in the history
…I version (#24121)

* bump version

* add new parameter

* record failing tests

* more tests rec

* simplify checks and adjust err handling for new version of midb restore details API

* more fixing

* put corrrect mask

* one more

* zone tests recorded on eastus

* fix style errs

* fix style issues

Co-authored-by: Milan Brkic <[email protected]>
  • Loading branch information
ostojicb and MDCS-sql authored Oct 24, 2022
1 parent 0a510a6 commit 2a758d4
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions src/azure-cli/azure/cli/command_modules/sql/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -5208,24 +5208,32 @@ def managed_db_log_replay_stop(
'''

restore_details_client = get_sql_managed_database_restore_details_operations(cmd.cli_ctx, None)
try:
# Determine if managed DB was created using log replay service
# Raises RestoreDetailsNotAvailableOrExpired exception if there are no restore details
restore_details = restore_details_client.get(
database_name=database_name,
managed_instance_name=managed_instance_name,
resource_group_name=resource_group_name,
restore_details_name=RestoreDetailsName.DEFAULT)

# Determine if managed DB was created using log replay service, raise exception if not
restore_details = restore_details_client.get(
database_name=database_name,
managed_instance_name=managed_instance_name,
resource_group_name=resource_group_name,
restore_details_name=RestoreDetailsName.DEFAULT)
# Type must be LRSRestore in order to proceed with stop-log-replay, else raise exception
if restore_details.type_properties_type.lower() == 'lrsrestore':
return client.begin_delete(
database_name=database_name,
managed_instance_name=managed_instance_name,
resource_group_name=resource_group_name)

# If type is present, it must be lrsrestore in order to proceed with stop-log-replay
if (hasattr(restore_details, 'type_properties_type') and restore_details.type_properties_type.lower() != 'lrsrestore'):
raise CLIError(
f'Cannot stop the log replay as database {database_name} on the instance {managed_instance_name} '
f'in the resource group {resource_group_name} was not created with log replay service.')

return client.begin_delete(
database_name=database_name,
managed_instance_name=managed_instance_name,
resource_group_name=resource_group_name)
except Exception as ex:
# Map RestoreDetailsNotAvailableOrExpired to a more descriptive error
if (ex and 'RestoreDetailsNotAvailableOrExpired' in str(ex)):
raise CLIError(
f'Cannot stop the log replay as database {database_name} on the instance {managed_instance_name} '
f'in the resource group {resource_group_name} was not created with log replay service.')
raise ex


def managed_db_log_replay_complete_restore(
Expand Down

0 comments on commit 2a758d4

Please sign in to comment.