Skip to content

Commit

Permalink
Enable no-wait and test validation for DeploymentErrors and Provision… (
Browse files Browse the repository at this point in the history
  • Loading branch information
LaylaLiu-gmail authored and ksayid committed Jan 8, 2025
1 parent 3821b90 commit 8640f1a
Show file tree
Hide file tree
Showing 9 changed files with 14,481 additions and 6,700 deletions.
3 changes: 3 additions & 0 deletions src/containerapp/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Release History
upcoming
++++++
* 'az containerapp debug': Open an SSH-like interactive shell within a container app debug console.
* 'az containerapp connected-env certificate upload/remove': Support `--no-wait`.
* 'az containerapp connected-env dapr-component set/remove': Support `--no-wait`.
* 'az containerapp connected-env storage set/remove': Support `--no-wait`.

1.1.0b1
++++++
Expand Down
45 changes: 38 additions & 7 deletions src/containerapp/azext_containerapp/_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ def create_or_update_certificate(cls, cmd, resource_group_name, name, certificat
return r.json()

@classmethod
def delete_certificate(cls, cmd, resource_group_name, name, certificate_name):
def delete_certificate(cls, cmd, resource_group_name, name, certificate_name, no_wait=False):
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
sub_id = get_subscription_id(cmd.cli_ctx)
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/connectedEnvironments/{}/certificates/{}?api-version={}"
Expand All @@ -587,7 +587,16 @@ def delete_certificate(cls, cmd, resource_group_name, name, certificate_name):
certificate_name,
cls.api_version)

return send_raw_request(cmd.cli_ctx, "DELETE", request_url, body=None)
r = send_raw_request(cmd.cli_ctx, "DELETE", request_url, body=None)

if no_wait:
return # API doesn't return JSON (it returns no content)
elif r.status_code == 202:
operation_url = r.headers.get(HEADER_LOCATION)
poll_results(cmd, operation_url)
logger.warning('Certificate %s was successfully deleted', certificate_name)

return

@classmethod
def check_name_availability(cls, cmd, resource_group_name, name, name_availability_request):
Expand Down Expand Up @@ -635,7 +644,7 @@ def create_or_update(cls, cmd, resource_group_name, environment_name, name, dapr
return r.json()

@classmethod
def delete(cls, cmd, resource_group_name, environment_name, name):
def delete(cls, cmd, resource_group_name, environment_name, name, no_wait=False):
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
sub_id = get_subscription_id(cmd.cli_ctx)
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/connectedEnvironments/{}/daprComponents/{}?api-version={}"
Expand All @@ -647,7 +656,15 @@ def delete(cls, cmd, resource_group_name, environment_name, name):
name,
cls.api_version)

send_raw_request(cmd.cli_ctx, "DELETE", request_url)
r = send_raw_request(cmd.cli_ctx, "DELETE", request_url)

if no_wait:
return # API doesn't return JSON (it returns no content)
elif r.status_code == 202:
operation_url = r.headers.get(HEADER_LOCATION)
poll_results(cmd, operation_url)
logger.warning('Dapr component %s was successfully deleted', name)

return

@classmethod
Expand Down Expand Up @@ -700,7 +717,7 @@ class ConnectedEnvStorageClient():
api_version = PREVIEW_API_VERSION

@classmethod
def create_or_update(cls, cmd, resource_group_name, env_name, name, storage_envelope):
def create_or_update(cls, cmd, resource_group_name, env_name, name, storage_envelope, no_wait=False):
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
sub_id = get_subscription_id(cmd.cli_ctx)
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/connectedEnvironments/{}/storages/{}?api-version={}"
Expand All @@ -714,10 +731,17 @@ def create_or_update(cls, cmd, resource_group_name, env_name, name, storage_enve

r = send_raw_request(cmd.cli_ctx, "PUT", request_url, body=json.dumps(storage_envelope))

if no_wait:
return r.json()
elif r.status_code == 201:
operation_url = r.headers.get(HEADER_AZURE_ASYNC_OPERATION)
poll_status(cmd, operation_url)
r = send_raw_request(cmd.cli_ctx, "GET", request_url)

return r.json()

@classmethod
def delete(cls, cmd, resource_group_name, env_name, name):
def delete(cls, cmd, resource_group_name, env_name, name, no_wait=False):
management_hostname = cmd.cli_ctx.cloud.endpoints.resource_manager
sub_id = get_subscription_id(cmd.cli_ctx)
url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/connectedEnvironments/{}/storages/{}?api-version={}"
Expand All @@ -729,7 +753,14 @@ def delete(cls, cmd, resource_group_name, env_name, name):
name,
cls.api_version)

send_raw_request(cmd.cli_ctx, "DELETE", request_url)
r = send_raw_request(cmd.cli_ctx, "DELETE", request_url)

if no_wait:
return # API doesn't return JSON (it returns no content)
elif r.status_code == 202:
operation_url = r.headers.get(HEADER_LOCATION)
poll_results(cmd, operation_url)
logger.warning('Storage %s was successfully deleted', name)

return

Expand Down
8 changes: 4 additions & 4 deletions src/containerapp/azext_containerapp/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,13 @@ def load_command_table(self, args):
with self.command_group('containerapp connected-env dapr-component', is_preview=True) as g:
g.custom_command('list', 'connected_env_list_dapr_components')
g.custom_show_command('show', 'connected_env_show_dapr_component')
g.custom_command('set', 'connected_env_create_or_update_dapr_component')
g.custom_command('remove', 'connected_env_remove_dapr_component')
g.custom_command('set', 'connected_env_create_or_update_dapr_component', supports_no_wait=True, exception_handler=ex_handler_factory())
g.custom_command('remove', 'connected_env_remove_dapr_component', supports_no_wait=True, exception_handler=ex_handler_factory())

with self.command_group('containerapp connected-env certificate', is_preview=True) as g:
g.custom_command('list', 'connected_env_list_certificates')
g.custom_command('upload', 'connected_env_upload_certificate')
g.custom_command('delete', 'connected_env_delete_certificate', confirmation=True, exception_handler=ex_handler_factory())
g.custom_command('upload', 'connected_env_upload_certificate', supports_no_wait=True, exception_handler=ex_handler_factory())
g.custom_command('delete', 'connected_env_delete_certificate', supports_no_wait=True, confirmation=True, exception_handler=ex_handler_factory())

with self.command_group('containerapp connected-env storage', is_preview=True) as g:
g.custom_show_command('show', 'connected_env_show_storage')
Expand Down
21 changes: 11 additions & 10 deletions src/containerapp/azext_containerapp/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1853,18 +1853,18 @@ def connected_env_show_dapr_component(cmd, resource_group_name, dapr_component_n
return ConnectedEnvDaprComponentClient.show(cmd, resource_group_name, environment_name, name=dapr_component_name)


def connected_env_remove_dapr_component(cmd, resource_group_name, dapr_component_name, environment_name):
def connected_env_remove_dapr_component(cmd, resource_group_name, dapr_component_name, environment_name, no_wait=False):
_validate_subscription_registered(cmd, CONTAINER_APPS_RP)

try:
r = ConnectedEnvDaprComponentClient.delete(cmd, resource_group_name, environment_name, name=dapr_component_name)
r = ConnectedEnvDaprComponentClient.delete(cmd, resource_group_name, environment_name, name=dapr_component_name, no_wait=no_wait)
logger.warning("Dapr componenet successfully deleted.")
return r
except Exception as e:
handle_raw_exception(e)


def connected_env_create_or_update_dapr_component(cmd, resource_group_name, environment_name, dapr_component_name, yaml):
def connected_env_create_or_update_dapr_component(cmd, resource_group_name, environment_name, dapr_component_name, yaml, no_wait=False):
_validate_subscription_registered(cmd, CONTAINER_APPS_RP)

yaml_dapr_component = load_yaml_file(yaml)
Expand Down Expand Up @@ -1893,7 +1893,8 @@ def connected_env_create_or_update_dapr_component(cmd, resource_group_name, envi
r = ConnectedEnvDaprComponentClient.create_or_update(cmd, resource_group_name=resource_group_name,
environment_name=environment_name,
dapr_component_envelope=dapr_component_envelope,
name=dapr_component_name)
name=dapr_component_name,
no_wait=no_wait)
return r
except Exception as e:
handle_raw_exception(e)
Expand Down Expand Up @@ -1929,7 +1930,7 @@ def both_match(c):
handle_raw_exception(e)


def connected_env_upload_certificate(cmd, name, resource_group_name, certificate_file, certificate_name=None, certificate_password=None, location=None, prompt=False):
def connected_env_upload_certificate(cmd, name, resource_group_name, certificate_file, certificate_name=None, certificate_password=None, location=None, prompt=False, no_wait=False):
_validate_subscription_registered(cmd, CONTAINER_APPS_RP)

blob, thumbprint = load_cert_file(certificate_file, certificate_password)
Expand Down Expand Up @@ -1972,7 +1973,7 @@ def connected_env_upload_certificate(cmd, name, resource_group_name, certificate
handle_raw_exception(e)

try:
r = ConnectedEnvCertificateClient.create_or_update_certificate(cmd, resource_group_name, name, cert_name, certificate)
r = ConnectedEnvCertificateClient.create_or_update_certificate(cmd, resource_group_name, name, cert_name, certificate, no_wait)
return r
except Exception as e:
handle_raw_exception(e)
Expand Down Expand Up @@ -2010,7 +2011,7 @@ def connected_env_list_storages(cmd, name, resource_group_name):
handle_raw_exception(e)


def connected_env_create_or_update_storage(cmd, storage_name, resource_group_name, name, azure_file_account_name=None, azure_file_share_name=None, azure_file_account_key=None, access_mode=None): # pylint: disable=redefined-builtin
def connected_env_create_or_update_storage(cmd, storage_name, resource_group_name, name, azure_file_account_name=None, azure_file_share_name=None, azure_file_account_key=None, access_mode=None, no_wait=False): # pylint: disable=redefined-builtin
_validate_subscription_registered(cmd, CONTAINER_APPS_RP)

r = None
Expand All @@ -2033,16 +2034,16 @@ def connected_env_create_or_update_storage(cmd, storage_name, resource_group_nam
storage_envelope["properties"]["azureFile"] = storage_def

try:
return ConnectedEnvStorageClient.create_or_update(cmd, resource_group_name, name, storage_name, storage_envelope)
return ConnectedEnvStorageClient.create_or_update(cmd, resource_group_name, name, storage_name, storage_envelope, no_wait)
except CLIError as e:
handle_raw_exception(e)


def connected_env_remove_storage(cmd, storage_name, name, resource_group_name):
def connected_env_remove_storage(cmd, storage_name, name, resource_group_name, no_wait=False):
_validate_subscription_registered(cmd, CONTAINER_APPS_RP)

try:
return ConnectedEnvStorageClient.delete(cmd, resource_group_name, name, storage_name)
return ConnectedEnvStorageClient.delete(cmd, resource_group_name, name, storage_name, no_wait)
except CLIError as e:
handle_raw_exception(e)

Expand Down
Loading

0 comments on commit 8640f1a

Please sign in to comment.