|
43 | 43 | )
|
44 | 44 | from ops.pebble import ChangeError, Layer, PathError, ProtocolError, ServiceStatus
|
45 | 45 | from requests import ConnectionError
|
46 |
| -from tenacity import RetryError |
| 46 | +from tenacity import RetryError, Retrying, stop_after_attempt, wait_fixed |
47 | 47 |
|
48 | 48 | from backups import PostgreSQLBackups
|
49 | 49 | from constants import (
|
@@ -192,12 +192,16 @@ def _juju_secrets_get(self, scope: str) -> Optional[bool]:
|
192 | 192 | return
|
193 | 193 |
|
194 | 194 | if SECRET_CACHE_LABEL not in self.secrets[scope]:
|
195 |
| - try: |
196 |
| - # NOTE: Secret contents are not yet available! |
197 |
| - secret = self.model.get_secret(id=peer_data[SECRET_INTERNAL_LABEL]) |
198 |
| - except SecretNotFoundError as e: |
199 |
| - logging.debug(f"No secret found for ID {peer_data[SECRET_INTERNAL_LABEL]}, {e}") |
200 |
| - return |
| 195 | + for attempt in Retrying(stop=stop_after_attempt(3), wait=wait_fixed(1), reraise=True): |
| 196 | + with attempt: |
| 197 | + try: |
| 198 | + # NOTE: Secret contents are not yet available! |
| 199 | + secret = self.model.get_secret(id=peer_data[SECRET_INTERNAL_LABEL]) |
| 200 | + except SecretNotFoundError as e: |
| 201 | + logging.debug( |
| 202 | + f"No secret found for ID {peer_data[SECRET_INTERNAL_LABEL]}, {e}" |
| 203 | + ) |
| 204 | + return |
201 | 205 |
|
202 | 206 | logging.debug(f"Secret {peer_data[SECRET_INTERNAL_LABEL]} downloaded")
|
203 | 207 |
|
@@ -242,7 +246,7 @@ def get_secret(self, scope: str, key: str) -> Optional[str]:
|
242 | 246 | if juju_version.has_secrets:
|
243 | 247 | return self._juju_secret_get_key(scope, key)
|
244 | 248 |
|
245 |
| - def _juju_secret_set(self, scope: str, key: str, value: str) -> str: |
| 249 | + def _juju_secret_set(self, scope: str, key: str, value: str) -> Optional[str]: |
246 | 250 | """Helper function setting Juju secret."""
|
247 | 251 | if scope == UNIT_SCOPE:
|
248 | 252 | peer_data = self.unit_peer_data
|
@@ -270,6 +274,7 @@ def _juju_secret_set(self, scope: str, key: str, value: str) -> str:
|
270 | 274 | f"Error in attempt to set {scope}:{key}. "
|
271 | 275 | f"Existing keys were: {list(secret_cache.keys())}. {error}"
|
272 | 276 | )
|
| 277 | + return |
273 | 278 | logging.debug(f"Secret {scope}:{key} was {key} set")
|
274 | 279 |
|
275 | 280 | # We need to create a brand-new secret for this scope
|
|
0 commit comments