mirror of
https://github.com/kernelkit/infix.git
synced 2026-07-31 13:03:02 +02:00
If a container has not yet stopped/started we may for proto RESTCONF get "invalid URI" result back for some container actions. With this change we allow the action to be retried up to three times before passing on the error. In tests on Qemu (x86_64) this happens very rarely and need at most one retry before succeeding. Verified by iterating the same basic test over night (9000+ iterations). Fixes #558 Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
49 lines
1.4 KiB
Python
49 lines
1.4 KiB
Python
"""Manage Infix containers"""
|
|
import time
|
|
from infamy.util import warn
|
|
|
|
|
|
class Container:
|
|
"""Helper methods"""
|
|
IMAGE = "curios-httpd-v24.05.0.tar.gz"
|
|
|
|
def __init__(self, target):
|
|
self.system = target
|
|
|
|
def _find(self, name):
|
|
oper = self.system.get_data("/infix-containers:containers")
|
|
if not oper:
|
|
return None
|
|
|
|
for container in oper["containers"]["container"]:
|
|
if container["name"] == name:
|
|
return container
|
|
return None
|
|
|
|
def exists(self, name):
|
|
"""Check if container {name} runs on target."""
|
|
container = self._find(name)
|
|
if not container:
|
|
return False
|
|
return True
|
|
|
|
def running(self, name):
|
|
"""Check if container {name} exists and is running."""
|
|
container = self._find(name)
|
|
if container and container["running"]:
|
|
return True
|
|
return False
|
|
|
|
def action(self, name, act):
|
|
"""Call container action (context RPC), retry three times."""
|
|
xpath = f"/infix-containers:containers/container[name='{name}']/{act}"
|
|
|
|
for attempt in range(3):
|
|
try:
|
|
return self.system.call_action(xpath)
|
|
except Exception as e:
|
|
warn(f"failed {act} {name} ({attempt + 1}/3): {e}")
|
|
time.sleep(1)
|
|
if attempt == 2:
|
|
raise
|