From 37de60a1ad60ee117cca86ef55af64f88ab30e82 Mon Sep 17 00:00:00 2001 From: romill Date: Sat, 27 Jan 2024 13:25:14 +0530 Subject: [PATCH] fix(disk): implements retries for deleting disk This update implements a retry mechanism for the disk deletion operation through the "rio apply" command. This enhancement ensures that deletion attempts are systematically retried in the occurrence of errors, irrespective of the existing disk status. Wrike Ticket: https://www.wrike.com/open.htm?id=1160572877 --- riocli/disk/model.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/riocli/disk/model.py b/riocli/disk/model.py index 1f3514e3..98eae4a0 100644 --- a/riocli/disk/model.py +++ b/riocli/disk/model.py @@ -74,20 +74,17 @@ def create_object(self, client: Client, **kwargs) -> typing.Any: def update_object(self, client: Client, obj: typing.Any) -> typing.Any: pass - def delete_object(self, client: Client, obj: typing.Any) -> typing.Any: - self._poll_till_available(client, obj) + def delete_object(self, client: Client, obj: typing.Any, sleep_interval=10, retries=12) -> typing.Any: volume_instance = client.get_volume_instance(obj.internalDeploymentGUID) - volume_instance.destroy_volume_instance() - - def _poll_till_available(self, client: Client, obj: typing.Any, sleep_interval=5, retries=20): - dep_guid = obj.internalDeploymentGUID - deployment = client.get_deployment(deployment_id=dep_guid) - - for _ in range(retries): - status = deployment.get_status().status - if status != 'Available': - sleep(sleep_interval) - continue + for attempt in range(retries): + sleep(sleep_interval) + try: + volume_instance.destroy_volume_instance() + except Exception as e: + if attempt == retries - 1: + raise e + else: + return @classmethod def pre_process(cls, client: Client, d: typing.Dict) -> None: