Skip to content

Commit

Permalink
fix(lxd): Make pycloudlib resilient to lxd image list failure
Browse files Browse the repository at this point in the history
  • Loading branch information
holmanb committed Dec 7, 2023
1 parent b77d523 commit f96e947
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pycloudlib/lxd/_images.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
"""LXD/LXD images' related functionalities."""
import contextlib
import functools
import itertools
import json
import logging
from typing import Any, List, Optional, Sequence, Tuple

from pycloudlib.util import subp

_REMOTE_DAILY = "ubuntu-daily"
_REMOTE_RELEASE = "ubuntu"
log = logging.getLogger(__name__)


def find_last_fingerprint(
Expand Down Expand Up @@ -145,4 +148,13 @@ def _find_images(
if filters is not None:
compiled_filters = map(lambda f: f"{f[0]}={f[1]}", filters)
cmd.extend(compiled_filters)
return json.loads(subp(cmd))
iter = 5

# retry for resilience against connection reset by peer
for i in range(iter):
try:
return json.loads(subp(cmd))
except RuntimeError as e:
if i == iter - 1:
raise e
log.warning("Failed to get image list, retrying due to: %s", e)

0 comments on commit f96e947

Please sign in to comment.