Add --docker-terminate flag to ansible-test (#68688)

* Add --docker-terminate flag to ansible-test

Signed-off-by: Rick Elrod <rick@elrod.me>
pull/46579/head
Rick Elrod 5 years ago committed by GitHub
parent 4916be24fd
commit 13aef3c2e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,2 @@
minor_changes:
- ansible-test - --docker flag now has an associated --docker-terminate flag which controls if and when the docker container is removed following tests

@ -1031,6 +1031,12 @@ def add_extra_docker_options(parser, integration=True):
default=None,
help='set seccomp confinement for the test container: %(choices)s')
docker.add_argument('--docker-terminate',
metavar='WHEN',
help='terminate docker container: %(choices)s (default: %(default)s)',
choices=['never', 'always', 'success'],
default='always')
if not integration:
return

@ -59,6 +59,7 @@ class EnvironmentConfig(CommonConfig):
self.docker_keep_git = args.docker_keep_git if 'docker_keep_git' in args else False # type: bool
self.docker_seccomp = args.docker_seccomp if 'docker_seccomp' in args else None # type: str
self.docker_memory = args.docker_memory if 'docker_memory' in args else None
self.docker_terminate = args.docker_terminate if 'docker_terminate' in args else None # type: str
if self.docker_seccomp is None:
self.docker_seccomp = get_docker_completion().get(self.docker_raw, {}).get('seccomp', 'default')

@ -230,6 +230,7 @@ def delegate_docker(args, exclude, require, integration_targets):
httptester_id = None
test_id = None
success = False
options = {
'--docker': 1,
@ -352,6 +353,9 @@ def delegate_docker(args, exclude, require, integration_targets):
try:
docker_exec(args, test_id, cmd, options=cmd_options)
# docker_exec will throw SubprocessError if not successful
# If we make it here, all the prep work earlier and the docker_exec line above were all successful.
success = True
finally:
local_test_root = os.path.dirname(os.path.join(data_context().content.root, data_context().content.results_path))
@ -368,7 +372,8 @@ def delegate_docker(args, exclude, require, integration_targets):
docker_rm(args, httptester_id)
if test_id:
docker_rm(args, test_id)
if args.docker_terminate == 'always' or (args.docker_terminate == 'success' and success):
docker_rm(args, test_id)
def delegate_remote(args, exclude, require, integration_targets):

Loading…
Cancel
Save