From 714d8874783b507cd66a37d1dcd2f1d3ac980257 Mon Sep 17 00:00:00 2001 From: Mark Beierl Date: Thu, 18 May 2023 15:08:06 -0400 Subject: [PATCH] Wrapping Retry for Py3.10 The retrying_async library is not Python 3.10 ready, so we are providing a 3.10 compatible callback for it to use instead of the default one Change-Id: I6e98f6d7ebc2fe134b0e3fe37d180e383044b30b Signed-off-by: Mark Beierl --- n2vc/k8s_helm_conn.py | 2 +- n2vc/libjuju.py | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/n2vc/k8s_helm_conn.py b/n2vc/k8s_helm_conn.py index 813d7cc..bbe4c48 100644 --- a/n2vc/k8s_helm_conn.py +++ b/n2vc/k8s_helm_conn.py @@ -78,7 +78,7 @@ class K8sHelmConnector(K8sHelmBaseConnector): else "--skip-repos", ) try: - asyncio.ensure_future( + asyncio.create_task( self._local_async_exec(command=command, raise_exception_on_error=False) ) except Exception as e: diff --git a/n2vc/libjuju.py b/n2vc/libjuju.py index e934fd0..f36ff39 100644 --- a/n2vc/libjuju.py +++ b/n2vc/libjuju.py @@ -61,6 +61,14 @@ from retrying_async import retry RBAC_LABEL_KEY_NAME = "rbac-id" +@asyncio.coroutine +def retry_callback(attempt, exc, args, kwargs, delay=0.5, *, loop): + # Specifically overridden from upstream implementation so it can + # continue to work with Python 3.10 + yield from asyncio.sleep(attempt * delay) + return retry + + class Libjuju: def __init__( self, @@ -151,7 +159,7 @@ class Libjuju: if controller: await controller.disconnect() - @retry(attempts=3, delay=5, timeout=None) + @retry(attempts=3, delay=5, timeout=None, callback=retry_callback) async def add_model(self, model_name: str, cloud: VcaCloud): """ Create model @@ -266,7 +274,7 @@ class Libjuju: await self.disconnect_controller(controller) return application_configs - @retry(attempts=3, delay=5) + @retry(attempts=3, delay=5, callback=retry_callback) async def get_model(self, controller: Controller, model_name: str) -> Model: """ Get model from controller @@ -1840,7 +1848,9 @@ class Libjuju: finally: await self.disconnect_controller(controller) - @retry(attempts=20, delay=5, fallback=JujuLeaderUnitNotFound()) + @retry( + attempts=20, delay=5, fallback=JujuLeaderUnitNotFound(), callback=retry_callback + ) async def _get_leader_unit(self, application: Application) -> Unit: unit = None for u in application.units: -- 2.25.1