[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 15/33] tests/docker: reduce scary warnings by cleaning up clea
From: |
Alex Bennée |
Subject: |
[PATCH v3 15/33] tests/docker: reduce scary warnings by cleaning up clean up |
Date: |
Tue, 24 Sep 2019 22:00:48 +0100 |
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 <address@hidden>
---
v2
- drop the try/except approach and be smarter
- use uuid4 as uuid1 can generate clashes in parallel builds
fixup! tests/docker: reduce scary warnings by cleaning up clean up
---
tests/docker/docker.py | 34 ++++++++++++++++------------------
1 file changed, 16 insertions(+), 18 deletions(-)
diff --git a/tests/docker/docker.py b/tests/docker/docker.py
index 29613afd489..3112892fdf5 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):
--
2.20.1
- [PATCH v3 02/33] target/alpha: Fix SWCR_MAP_UMZ, (continued)
- [PATCH v3 02/33] target/alpha: Fix SWCR_MAP_UMZ, Alex Bennée, 2019/09/24
- [PATCH v3 07/33] target/alpha: Tidy helper_fp_exc_raise_s, Alex Bennée, 2019/09/24
- [PATCH v3 03/33] target/alpha: Fix SWCR_TRAP_ENABLE_MASK, Alex Bennée, 2019/09/24
- [PATCH v3 05/33] target/alpha: Write to fpcr_flush_to_zero once, Alex Bennée, 2019/09/24
- [PATCH v3 11/33] target/ppc: fix signal delivery for ppc64abi32, Alex Bennée, 2019/09/24
- [PATCH v3 21/33] tests/tcg: add simple record/replay smoke test for aarch64, Alex Bennée, 2019/09/24
- [PATCH v3 06/33] target/alpha: Mask IOV exception with INV for user-only, Alex Bennée, 2019/09/24
- [PATCH v3 13/33] tests/docker: fix DOCKER_PARTIAL_IMAGES, Alex Bennée, 2019/09/24
- [PATCH v3 04/33] target/alpha: Handle SWCR_MAP_DMZ earlier, Alex Bennée, 2019/09/24
- [PATCH v3 15/33] tests/docker: reduce scary warnings by cleaning up clean up,
Alex Bennée <=
- [PATCH v3 08/33] tests/migration: Fail on unexpected migration states, Alex Bennée, 2019/09/24
- [PATCH v3 12/33] tests/docker: add sanitizers back to clang build, Alex Bennée, 2019/09/24
- [PATCH v3 10/33] migration/postcopy: Recognise the recovery states as 'in_postcopy', Alex Bennée, 2019/09/24
- [PATCH v3 09/33] tests/migration/postcopy: trim migration bandwidth, Alex Bennée, 2019/09/24
- [PATCH v3 27/33] docker: remove debian8-mxe definitions, Alex Bennée, 2019/09/24
- [PATCH v3 17/33] tests/tcg: clean-up some comments after the de-tangling, Alex Bennée, 2019/09/24