From: Cory Johns Date: Fri, 3 Mar 2017 16:16:04 +0000 (-0500) Subject: Retry calls to charmstore and increase timeout to 5s X-Git-Tag: 0.4.0~16^2~4 X-Git-Url: https://osm.etsi.org/gitweb/?a=commitdiff_plain;h=c41ac81a29cb6357a6ba4a25a70232a46d322e70;p=osm%2FN2VC.git Retry calls to charmstore and increase timeout to 5s --- diff --git a/juju/model.py b/juju/model.py index 91aba25..812f35b 100644 --- a/juju/model.py +++ b/juju/model.py @@ -13,7 +13,8 @@ from functools import partial from pathlib import Path import yaml -from theblues import charmstore +import theblues.charmstore +import theblues.errors from .client import client from .client import watcher @@ -1760,7 +1761,7 @@ class CharmStore(object): """ def __init__(self, loop): self.loop = loop - self._cs = charmstore.CharmStore() + self._cs = theblues.charmstore.CharmStore(timeout=5) def __getattr__(self, name): """ @@ -1774,7 +1775,13 @@ class CharmStore(object): else: async def coro(*args, **kwargs): method = partial(attr, *args, **kwargs) - return await self.loop.run_in_executor(None, method) + for attempt in range(1, 4): + try: + return await self.loop.run_in_executor(None, method) + except theblues.errors.ServerError: + if attempt == 3: + raise + await asyncio.sleep(1, loop=self.loop) setattr(self, name, coro) wrapper = coro return wrapper