Return-Path: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=profusion-mobi.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=rSiJFmMbsEMHE5VLBKn6cn0BQVAyyA6on55hjsMsQWM=; b=vKSfDJEfKNCBdnbGWlFOULOE0aeoys2asa1rSHCD1Um1t/sVjaGCtChbIMGfxcfIGO u8jIq27h/4yGK7UWAPmvMACPpoobnhIcudE+hNc3cbFKIHnaPzs8Ouk/F1mdmCFvt2O5 UVvlJ6UxxxvGcxmoube/iclIv9a38DvMJAwbkuwoSuvo8g+rLHSSSGCTVxn1B8JL2cZX X93nu6uKoGwwfJaMZyZts/mSdPEyhQXjacFfutdbU2GXgAnpNc/V5tKNb69FyLzpkG0D yULRODgnFxXCPxdEr7BBlrGiAwZqs0Oo06q/H0pEs/do8xMqkYDt63OhHpjdGuxUjpGv LF+Q== From: Guilherme Campos Camargo Date: Tue, 3 Apr 2018 14:56:53 -0300 Message-Id: <20180403175653.5458-9-guicc@profusion.mobi> In-Reply-To: <20180403175653.5458-1-guicc@profusion.mobi> References: <20180403175653.5458-1-guicc@profusion.mobi> Subject: [Fuego] [PATCH 8/8] Use atexit to remove the docker container after the test List-Id: Mailing list for the Fuego test framework List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: fuego@lists.linuxfoundation.org By using the destructor __del__ in the FuegoContainer class, there were occasions when self.container.delete failed to execute with an exception raised from the docker client, probably due to required resources having been release before the container deletion. By using atexit, it's guaranteed that the registered method (cleanup()) will be called when main() exits, while all the resources are still available, not causing such problem. Signed-off-by: Guilherme Campos Camargo --- engine/tests/Functional.fuego_release_test/test_run.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/engine/tests/Functional.fuego_release_test/test_run.py b/engine/tests/Functional.fuego_release_test/test_run.py index 4b43df4..b4dab55 100755 --- a/engine/tests/Functional.fuego_release_test/test_run.py +++ b/engine/tests/Functional.fuego_release_test/test_run.py @@ -1,5 +1,6 @@ #!/usr/bin/env python3 import argparse +import atexit import http import http.client import logging @@ -217,7 +218,7 @@ class FuegoContainer: self.jenkins_port = jenkins_port self.rm_after_test = rm_after_test - def __del__(self): + def delete(self): if self.container: if self.rm_after_test: LOGGER.debug("Removing Container") @@ -469,6 +470,11 @@ def main(): DEFAULT_START_SCRIPT = 'fuego-host-scripts/docker-start-container.sh' DEFAULT_JENKINS_PORT = 8080 + @atexit.register + def cleanup(): + if container: + container.delete() + def execute_tests(timeout): LOGGER.debug("Starting tests") -- 2.16.3