From 938ed4c2077eef8cf37d5eb8f4820f2ad0b93f95 Mon Sep 17 00:00:00 2001 From: Smruti Ranjan Senapati Date: Mon, 22 Jul 2024 21:44:26 +0530 Subject: [PATCH] fix(v2client): fix retry exceeded error code description and action --- riocli/package/util.py | 2 +- riocli/rosbag/job.py | 10 +++---- riocli/v2client/client.py | 15 ++++++---- riocli/{deployment => v2client}/errors.py | 0 riocli/v2client/util.py | 36 +++++++++++++++++++++++ 5 files changed, 52 insertions(+), 11 deletions(-) rename riocli/{deployment => v2client}/errors.py (100%) create mode 100644 riocli/v2client/util.py diff --git a/riocli/package/util.py b/riocli/package/util.py index b6527d35..b959ce08 100644 --- a/riocli/package/util.py +++ b/riocli/package/util.py @@ -26,7 +26,7 @@ def find_package(client: Client, package_name: str, package_version: str, - ) -> Munch | None: + ) -> Munch: package_obj = None diff --git a/riocli/rosbag/job.py b/riocli/rosbag/job.py index 37e0a999..a53398f8 100644 --- a/riocli/rosbag/job.py +++ b/riocli/rosbag/job.py @@ -21,7 +21,7 @@ ROSBagOnDemandUploadOptions, ROSBagTimeRange from riocli.config import new_client -from riocli.deployment.util import name_to_guid as deployment_name_to_guid +# from riocli.deployment.util import name_to_guid as deployment_name_to_guid from riocli.rosbag.util import ROSBagJobNotFound from riocli.utils import inspect_with_format from riocli.utils import tabulate_data @@ -103,7 +103,7 @@ def job_inspect(job_guid: str, format_type: str) -> None: @click.argument('deployment-name') @click.option('--component-instance-ids', help='Filter by component instance ids ', multiple=True) @click.option('--guids', help='Filter by job guids', multiple=True) -@deployment_name_to_guid +# @deployment_name_to_guid def job_stop(deployment_guid: str, deployment_name: str, component_instance_ids: typing.List[str], guids: typing.List[str]) -> None: """ @@ -126,7 +126,7 @@ def job_stop(deployment_guid: str, deployment_name: str, component_instance_ids: @click.option('--guids', help='Filter by job guids ', multiple=True) @click.option('--statuses', help='Filter by rosbag job statuses ', multiple=True, default=['Starting', 'Running'], type=click.Choice(['Starting', 'Running', 'Error', 'Stopping', 'Stopped'], case_sensitive=True)) -@deployment_name_to_guid +# @deployment_name_to_guid def job_list(deployment_guid: str, deployment_name: str, component_instance_ids: typing.List[str], guids: typing.List[str], statuses: typing.List[str]) -> None: """ @@ -153,7 +153,7 @@ def job_list(deployment_guid: str, deployment_name: str, 'format (1985-04-12T23:20:50.52Z)', required=True) @click.option('--upload-to', help='Rosbags recorded before or at this time are uploaded. Specify time in RFC 3339 ' 'format (1985-04-12T23:20:50.52Z)', required=True) -@deployment_name_to_guid +# @deployment_name_to_guid def job_trigger_upload(deployment_guid: str, deployment_name: str, job_guid: str, upload_from: str, upload_to: str) -> None: """ @@ -224,7 +224,7 @@ def job_trigger_upload(deployment_guid: str, deployment_name: str, job_guid: str @click.argument('job-guid') @click.option('--upload-mode', help='Change upload mode', type=click.Choice([t for t in ROSBagUploadTypes]), required=True) -@deployment_name_to_guid +# @deployment_name_to_guid def update_job(deployment_guid: str, deployment_name: str, job_guid: str, upload_mode: str) -> None: """ Update the Rosbag Job diff --git a/riocli/v2client/client.py b/riocli/v2client/client.py index 75859f3c..dcbd559d 100644 --- a/riocli/v2client/client.py +++ b/riocli/v2client/client.py @@ -30,6 +30,7 @@ from riocli.v2client.enums import DeploymentPhaseConstants, DiskStatusConstants from riocli.v2client.error import (RetriesExhausted, DeploymentNotRunning, ImagePullError, NetworkNotFound, DeploymentNotFound) +from riocli.v2client.util import process_errors def handle_server_errors(response: requests.Response): @@ -941,8 +942,10 @@ def poll_network( network = self.get_network(name) status = network.status - raise RetriesExhausted('Retried {} time done with an interval of {} seconds. Network status: {}'.format( - retry_count, sleep_interval, status.phase)) + msg = 'Retries exhausted: Tried {} times with {}s interval. Network: phase={} status={} \n{}'.format( + retry_count, sleep_interval, status.phase, status.status, process_errors(status.get('error_codes', []))) + + raise RetriesExhausted(msg) def list_deployments( self, @@ -1082,8 +1085,10 @@ def poll_deployment( deployment = self.get_deployment(name) status = deployment.status - raise RetriesExhausted('Retried {} time done with an interval of {} seconds. Deployment status: {}'.format( - retry_count, sleep_interval, status.phase)) + msg = 'Retries exhausted: Tried {} times with {}s interval. Deployment: phase={} status={} \n{}'.format( + retry_count, sleep_interval, status.phase, status.status, process_errors(status.get('error_codes', []))) + + raise RetriesExhausted(msg) def stream_deployment_logs( self, @@ -1207,5 +1212,5 @@ def poll_disk( disk = self.get_disk(name) status = disk.status - raise RetriesExhausted('Retried {} time done with an interval of {} seconds. Disk status: {}'.format( + raise RetriesExhausted('Retries exhausted: Tried {} times with {}s interval. Disk: status={}'.format( retry_count, sleep_interval, status.status)) diff --git a/riocli/deployment/errors.py b/riocli/v2client/errors.py similarity index 100% rename from riocli/deployment/errors.py rename to riocli/v2client/errors.py diff --git a/riocli/v2client/util.py b/riocli/v2client/util.py new file mode 100644 index 00000000..23a2aa64 --- /dev/null +++ b/riocli/v2client/util.py @@ -0,0 +1,36 @@ +import typing + +import click + +from riocli.constants import Colors +from riocli.v2client.errors import ERRORS + + +def process_errors(errors: typing.List[str]) -> str: + err_fmt = '[{}] {}\nAction: {}' + support_action = ('Report the issue together with the relevant' + ' details to the support team') + + action, description = '', '' + msgs = [] + for code in errors: + if code in ERRORS: + description = ERRORS[code]['description'] + action = ERRORS[code]['action'] + elif code.startswith('DEP_E2'): + description = 'Internal rapyuta.io error in the components deployed on cloud' + action = support_action + elif code.startswith('DEP_E3'): + description = 'Internal rapyuta.io error in the components deployed on a device' + action = support_action + elif code.startswith('DEP_E4'): + description = 'Internal rapyuta.io error' + action = support_action + + code = click.style(code, fg=Colors.YELLOW) + description = click.style(description, fg=Colors.RED) + action = click.style(action, fg=Colors.GREEN) + + msgs.append(err_fmt.format(code, description, action)) + + return '\n'.join(msgs) \ No newline at end of file