aboutsummaryrefslogtreecommitdiff
path: root/tests/docker
diff options
context:
space:
mode:
authorAlex Bennée <alex.bennee@linaro.org>2019-09-19 17:51:27 +0100
committerAlex Bennée <alex.bennee@linaro.org>2019-09-26 19:00:53 +0100
commit529994e20448243c4ad50d8984978d6ad3a01fe9 (patch)
tree3404431da26fa1ca22a81c553326ad45ce63667f /tests/docker
parent5fac0cfaaa30a36730f8db27b314e4514a314c25 (diff)
downloadqemu-529994e20448243c4ad50d8984978d6ad3a01fe9.zip
qemu-529994e20448243c4ad50d8984978d6ad3a01fe9.tar.gz
qemu-529994e20448243c4ad50d8984978d6ad3a01fe9.tar.bz2
tests/docker: reduce scary warnings by cleaning up clean up
There was in the clean-up code caused by attempting to inspect images which finished before we got there. Clean up the clean up code by: - only track the one instance at a time - use --filter for docker ps instead of doing it by hand - just call docker rm -f to be done with it - use uuid.uuid4() for a random uid Signed-off-by: Alex Bennée <alex.bennee@linaro.org> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Diffstat (limited to 'tests/docker')
-rwxr-xr-xtests/docker/docker.py34
1 files changed, 16 insertions, 18 deletions
diff --git a/tests/docker/docker.py b/tests/docker/docker.py
index 29613af..3112892 100755
--- a/tests/docker/docker.py
+++ b/tests/docker/docker.py
@@ -215,7 +215,7 @@ class Docker(object):
""" Running Docker commands """
def __init__(self):
self._command = _guess_engine_command()
- self._instances = []
+ self._instance = None
atexit.register(self._kill_instances)
signal.signal(signal.SIGTERM, self._kill_instances)
signal.signal(signal.SIGHUP, self._kill_instances)
@@ -234,21 +234,19 @@ class Docker(object):
cmd = ["ps", "-q"]
if not only_active:
cmd.append("-a")
+
+ filter = "--filter=label=com.qemu.instance.uuid"
+ if only_known:
+ if self._instance:
+ filter += "=%s" % (self._instance)
+ else:
+ # no point trying to kill, we finished
+ return
+
+ print("filter=%s" % (filter))
+ cmd.append(filter)
for i in self._output(cmd).split():
- resp = self._output(["inspect", i])
- labels = json.loads(resp)[0]["Config"]["Labels"]
- active = json.loads(resp)[0]["State"]["Running"]
- if not labels:
- continue
- instance_uuid = labels.get("com.qemu.instance.uuid", None)
- if not instance_uuid:
- continue
- if only_known and instance_uuid not in self._instances:
- continue
- print("Terminating", i)
- if active:
- self._do(["kill", i])
- self._do(["rm", i])
+ self._do(["rm", "-f", i])
def clean(self):
self._do_kill_instances(False, False)
@@ -325,9 +323,9 @@ class Docker(object):
return checksum == _text_checksum(_dockerfile_preprocess(dockerfile))
def run(self, cmd, keep, quiet, as_user=False):
- label = uuid.uuid1().hex
+ label = uuid.uuid4().hex
if not keep:
- self._instances.append(label)
+ self._instance = label
if as_user:
uid = os.getuid()
@@ -340,7 +338,7 @@ class Docker(object):
"com.qemu.instance.uuid=" + label] + cmd,
quiet=quiet)
if not keep:
- self._instances.remove(label)
+ self._instance = None
return ret
def command(self, cmd, argv, quiet):