From 6472723ba82fda84c2be9b28f895597528245abb Mon Sep 17 00:00:00 2001 From: Matt Clay Date: Tue, 14 Nov 2017 17:08:48 -0800 Subject: [PATCH] Add missing ansible-test --remote-terminate support. (#32918) * Expand ansible-test --remote-terminate support: - windows-integration - network-integration These commands previously accepted the option, but did not support it. * Terminate windows and network instances when done. --- test/runner/lib/executor.py | 24 ++++++++++++++++++++---- test/runner/lib/thread.py | 5 +++++ test/utils/shippable/network.sh | 9 ++++++++- test/utils/shippable/windows.sh | 9 ++++++++- 4 files changed, 41 insertions(+), 6 deletions(-) diff --git a/test/runner/lib/executor.py b/test/runner/lib/executor.py index 97a7874be3e..8237d59400a 100644 --- a/test/runner/lib/executor.py +++ b/test/runner/lib/executor.py @@ -317,10 +317,10 @@ def command_network_integration(args): all_targets = tuple(walk_network_integration_targets(include_hidden=True)) internal_targets = command_integration_filter(args, all_targets, init_callback=network_init) + instances = [] # type: list [lib.thread.WrappedThread] if args.platform: configs = dict((config['platform_version'], config) for config in args.metadata.instance_config) - instances = [] # type: list [lib.thread.WrappedThread] for platform_version in args.platform: platform, version = platform_version.split('/', 1) @@ -346,7 +346,15 @@ def command_network_integration(args): with open(filename, 'w') as inventory_fd: inventory_fd.write(inventory) - command_integration_filtered(args, internal_targets, all_targets) + success = False + + try: + command_integration_filtered(args, internal_targets, all_targets) + success = True + finally: + if args.remote_terminate == 'always' or (args.remote_terminate == 'success' and success): + for instance in instances: + instance.result.stop() def network_init(args, internal_targets): @@ -467,10 +475,10 @@ def command_windows_integration(args): all_targets = tuple(walk_windows_integration_targets(include_hidden=True)) internal_targets = command_integration_filter(args, all_targets, init_callback=windows_init) + instances = [] # type: list [lib.thread.WrappedThread] if args.windows: configs = dict((config['platform_version'], config) for config in args.metadata.instance_config) - instances = [] # type: list [lib.thread.WrappedThread] for version in args.windows: config = configs['windows/%s' % version] @@ -492,7 +500,15 @@ def command_windows_integration(args): with open(filename, 'w') as inventory_fd: inventory_fd.write(inventory) - command_integration_filtered(args, internal_targets, all_targets) + success = False + + try: + command_integration_filtered(args, internal_targets, all_targets) + success = True + finally: + if args.remote_terminate == 'always' or (args.remote_terminate == 'success' and success): + for instance in instances: + instance.result.stop() def windows_init(args, internal_targets): # pylint: disable=locally-disabled, unused-argument diff --git a/test/runner/lib/thread.py b/test/runner/lib/thread.py index 8dbc88f8c6f..8bded9e9265 100644 --- a/test/runner/lib/thread.py +++ b/test/runner/lib/thread.py @@ -23,6 +23,7 @@ class WrappedThread(threading.Thread): super(WrappedThread, self).__init__() self._result = queue.Queue() self.action = action + self.result = None def run(self): """ @@ -41,9 +42,13 @@ class WrappedThread(threading.Thread): :rtype: any """ result, exception = self._result.get() + if exception: if sys.version_info[0] > 2: raise exception[1].with_traceback(exception[2]) # noinspection PyRedundantParentheses exec('raise exception[0], exception[1], exception[2]') # pylint: disable=locally-disabled, exec-used + + self.result = result + return result diff --git a/test/utils/shippable/network.sh b/test/utils/shippable/network.sh index 079a01df5b9..8ae99b06425 100755 --- a/test/utils/shippable/network.sh +++ b/test/utils/shippable/network.sh @@ -41,7 +41,14 @@ else fi for version in "${python_versions[@]}"; do + # terminate remote instances on the final python version tested + if [ "${version}" = "${python_versions[-1]}" ]; then + terminate="always" + else + terminate="never" + fi + # shellcheck disable=SC2086 ansible-test network-integration --color -v --retry-on-error "${target}" --docker default --python "${version}" \ - ${COVERAGE:+"$COVERAGE"} ${CHANGED:+"$CHANGED"} "${platforms[@]}" + ${COVERAGE:+"$COVERAGE"} ${CHANGED:+"$CHANGED"} "${platforms[@]}" --remote-terminate "${terminate}" done diff --git a/test/utils/shippable/windows.sh b/test/utils/shippable/windows.sh index 0aa99ee3d70..9d4a82c0969 100755 --- a/test/utils/shippable/windows.sh +++ b/test/utils/shippable/windows.sh @@ -67,7 +67,14 @@ for version in "${python_versions[@]}"; do ci="windows/ci/minimal/" fi + # terminate remote instances on the final python version tested + if [ "${version}" = "${python_versions[-1]}" ]; then + terminate="always" + else + terminate="never" + fi + # shellcheck disable=SC2086 ansible-test windows-integration --color -v --retry-on-error "${ci}" --docker default --python "${version}" ${COVERAGE:+"$COVERAGE"} ${CHANGED:+"$CHANGED"} \ - "${platforms[@]}" --changed-all-target "${changed_all_target}" + "${platforms[@]}" --changed-all-target "${changed_all_target}" --remote-terminate "${terminate}" done