Skip to content
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

{SQL} az sql midb log-replay stop: Adjust error handling for new API version #24121

Merged
merged 21 commits into from
Oct 24, 2022

Conversation

ostojicb
Copy link
Member

@ostojicb ostojicb commented Oct 6, 2022

Related command

az sql log-replay stop
az sql log-replay show

Description

We've got new version of managed database restore details API which we use to determine whether log-replay stop cmd should drop the db or not (#22939).
As the API now returns an error for dbs with no restore details, we'd ideally want to map it to a more meaningful exception in the context of this command.
Also new properties in API response can be used to simplify checking logic.

az sql log-replay show is a simple pass-through command, so new fields from API response are automatically passed back to the user

Testing Guide

History Notes

[Component Name 1] BREAKING CHANGE: az command a: Make some customer-facing breaking change
[Component Name 2] az command b: Add some customer-facing feature


This checklist is used to make sure that common guidelines for a pull request are followed.

@ghost ghost added Auto-Assign Auto assign by bot SQL az sql labels Oct 6, 2022
@ghost ghost requested a review from yonzhan October 6, 2022 17:37
@ghost ghost assigned evelyn-ys Oct 6, 2022
@ghost ghost added this to the Oct 2022 (2022-11-01) milestone Oct 6, 2022
@@ -2131,6 +2131,10 @@ def _configure_security_policy_storage_params(arg_ctx):
###############################################
# sql managed db #
###############################################
class ContainerIdentityType(Enum):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

branched out of here #24105 to avoid conflicts, since we're both working with new sql sdk, similar commands

@ostojicb ostojicb changed the title [SQL] az sql midb log-replay stop: adjust error handling for new API version [SQL] az sql midb log-replay stop: Adjust error handling for new API version Oct 6, 2022
@yonzhan
Copy link
Collaborator

yonzhan commented Oct 6, 2022

SQL

Comment on lines 5212 to 5237
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)

# 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)
# Type must be LRSRestore in order to proceed with stop-log-replay
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)
else:
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.')
except Exception as ex:
#
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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the actual diff (once we merge #24105)

@wangzelin007
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@ostojicb
Copy link
Member Author

can we proceed with merging @wangzelin007 @evelyn-ys

@evelyn-ys evelyn-ys changed the title [SQL] az sql midb log-replay stop: Adjust error handling for new API version {SQL} az sql midb log-replay stop: Adjust error handling for new API version Oct 24, 2022
@evelyn-ys evelyn-ys merged commit 2a758d4 into Azure:dev Oct 24, 2022
avgale pushed a commit to avgale/azure-cli that referenced this pull request Aug 24, 2023
…I version (Azure#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 <mibrkic@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Assign Auto assign by bot SQL az sql
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants