diff --git a/.ci/ansible_tests.py b/.ci/ansible_tests.py index 665e2c60..3c3684f4 100755 --- a/.ci/ansible_tests.py +++ b/.ci/ansible_tests.py @@ -7,7 +7,6 @@ import signal import sys import ci_lib -from ci_lib import run TESTS_DIR = os.path.join(ci_lib.GIT_ROOT, 'tests/ansible') @@ -40,10 +39,10 @@ with ci_lib.Fold('job_setup'): os.chdir(TESTS_DIR) os.chmod('../data/docker/mitogen__has_sudo_pubkey.key', int('0600', 7)) - run("mkdir %s", HOSTS_DIR) + ci_lib.run("mkdir %s", HOSTS_DIR) for path in glob.glob(TESTS_DIR + '/hosts/*'): if not path.endswith('default.hosts'): - run("ln -s %s %s", path, HOSTS_DIR) + ci_lib.run("ln -s %s %s", path, HOSTS_DIR) inventory_path = os.path.join(HOSTS_DIR, 'target') with open(inventory_path, 'w') as fp: @@ -63,14 +62,14 @@ with ci_lib.Fold('job_setup'): ci_lib.dump_file(inventory_path) if not ci_lib.exists_in_path('sshpass'): - run("sudo apt-get update") - run("sudo apt-get install -y sshpass") + ci_lib.run("sudo apt-get update") + ci_lib.run("sudo apt-get install -y sshpass") with ci_lib.Fold('ansible'): playbook = os.environ.get('PLAYBOOK', 'all.yml') try: - run('./run_ansible_playbook.py %s -i "%s" %s', + ci_lib.run('./run_ansible_playbook.py %s -i "%s" %s', playbook, HOSTS_DIR, ' '.join(sys.argv[1:])) except: pause_if_interactive() diff --git a/.ci/ci_lib.py b/.ci/ci_lib.py index 67d20a27..000a7a83 100644 --- a/.ci/ci_lib.py +++ b/.ci/ci_lib.py @@ -1,4 +1,3 @@ - from __future__ import absolute_import from __future__ import print_function diff --git a/.ci/localhost_ansible_tests.py b/.ci/localhost_ansible_tests.py index 92377c7d..69d67cd1 100755 --- a/.ci/localhost_ansible_tests.py +++ b/.ci/localhost_ansible_tests.py @@ -6,7 +6,6 @@ import subprocess import sys import ci_lib -from ci_lib import run TESTS_DIR = os.path.join(ci_lib.GIT_ROOT, 'tests/ansible') @@ -52,11 +51,11 @@ with ci_lib.Fold('machine_prep'): if os.path.expanduser('~mitogen__user1') == '~mitogen__user1': os.chdir(IMAGE_PREP_DIR) - run("ansible-playbook -c local -i localhost, _user_accounts.yml") + ci_lib.run("ansible-playbook -c local -i localhost, _user_accounts.yml") with ci_lib.Fold('ansible'): os.chdir(TESTS_DIR) playbook = os.environ.get('PLAYBOOK', 'all.yml') - run('./run_ansible_playbook.py %s -l target %s', + ci_lib.run('./run_ansible_playbook.py %s -l target %s', playbook, ' '.join(sys.argv[1:])) diff --git a/ansible_mitogen/affinity.py b/ansible_mitogen/affinity.py index 7f4c8db5..635ee7b9 100644 --- a/ansible_mitogen/affinity.py +++ b/ansible_mitogen/affinity.py @@ -73,7 +73,9 @@ necessarily involves preventing the scheduler from making load balancing decisions. """ -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function +__metaclass__ = type + import ctypes import logging import mmap diff --git a/ansible_mitogen/connection.py b/ansible_mitogen/connection.py index a4ceba4b..6df3dfcf 100644 --- a/ansible_mitogen/connection.py +++ b/ansible_mitogen/connection.py @@ -26,8 +26,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function from __future__ import unicode_literals +__metaclass__ = type import errno import logging @@ -40,10 +41,8 @@ import time import ansible.constants as C import ansible.errors import ansible.plugins.connection -import ansible.utils.shlex import mitogen.core -import mitogen.fork import mitogen.utils import ansible_mitogen.mixins @@ -1097,7 +1096,7 @@ class Connection(ansible.plugins.connection.ConnectionBase): s = fp.read(self.SMALL_FILE_LIMIT + 1) finally: fp.close() - except OSError: + except OSError as e: self._throw_io_error(e, in_path) raise diff --git a/ansible_mitogen/loaders.py b/ansible_mitogen/loaders.py index b8bbb7e8..cd05feac 100644 --- a/ansible_mitogen/loaders.py +++ b/ansible_mitogen/loaders.py @@ -30,7 +30,10 @@ Stable names for PluginLoader instances across Ansible versions. """ -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function +__metaclass__ = type + +import ansible.errors import ansible_mitogen.utils diff --git a/ansible_mitogen/logging.py b/ansible_mitogen/logging.py index 00a70184..40b2b339 100644 --- a/ansible_mitogen/logging.py +++ b/ansible_mitogen/logging.py @@ -26,7 +26,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function +__metaclass__ = type + import logging import os @@ -36,8 +38,8 @@ import mitogen.utils try: from __main__ import display except ImportError: - from ansible.utils.display import Display - display = Display() + import ansible.utils.display + display = ansible.utils.display.Display() #: The process name set via :func:`set_process_name`. diff --git a/ansible_mitogen/mixins.py b/ansible_mitogen/mixins.py index c4d793e8..690998f1 100644 --- a/ansible_mitogen/mixins.py +++ b/ansible_mitogen/mixins.py @@ -26,7 +26,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function +__metaclass__ = type + import logging import os import pwd diff --git a/ansible_mitogen/module_finder.py b/ansible_mitogen/module_finder.py index 89aa2beb..cec465c1 100644 --- a/ansible_mitogen/module_finder.py +++ b/ansible_mitogen/module_finder.py @@ -26,8 +26,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function from __future__ import unicode_literals +__metaclass__ = type import collections import imp diff --git a/ansible_mitogen/parsing.py b/ansible_mitogen/parsing.py index 27fca7cd..2ca50315 100644 --- a/ansible_mitogen/parsing.py +++ b/ansible_mitogen/parsing.py @@ -26,8 +26,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function from __future__ import unicode_literals +__metaclass__ = type import mitogen.core diff --git a/ansible_mitogen/planner.py b/ansible_mitogen/planner.py index 90d5bb3c..86690f7d 100644 --- a/ansible_mitogen/planner.py +++ b/ansible_mitogen/planner.py @@ -34,8 +34,9 @@ files/modules known missing. [0] "Ansible Module Architecture", developing_program_flow_modules.html """ -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function from __future__ import unicode_literals +__metaclass__ = type import json import logging @@ -43,11 +44,10 @@ import os import random import re -from ansible.executor import module_common -from ansible.collections.list import list_collection_dirs +import ansible.collections.list import ansible.errors -import ansible.module_utils -import ansible.release +import ansible.executor.module_common + import mitogen.core import mitogen.select @@ -192,7 +192,7 @@ class BinaryPlanner(Planner): @classmethod def detect(cls, path, source): - return module_common._is_binary(source) + return ansible.executor.module_common._is_binary(source) def get_push_files(self): return [mitogen.core.to_text(self._inv.module_path)] @@ -269,7 +269,7 @@ class JsonArgsPlanner(ScriptPlanner): @classmethod def detect(cls, path, source): - return module_common.REPLACER_JSONARGS in source + return ansible.executor.module_common.REPLACER_JSONARGS in source class WantJsonPlanner(ScriptPlanner): @@ -298,11 +298,11 @@ class NewStylePlanner(ScriptPlanner): preprocessing the module. """ runner_name = 'NewStyleRunner' - MARKER = re.compile(b'from ansible(?:_collections|\.module_utils)\.') + MARKER = re.compile(br'from ansible(?:_collections|\.module_utils)\.') @classmethod def detect(cls, path, source): - return cls.MARKER.search(source) != None + return cls.MARKER.search(source) is not None def _get_interpreter(self): return None, None @@ -362,7 +362,7 @@ class NewStylePlanner(ScriptPlanner): module_name='ansible_module_%s' % (self._inv.module_name,), module_path=self._inv.module_path, search_path=self.get_search_path(), - builtin_path=module_common._MODULE_UTILS_PATH, + builtin_path=ansible.executor.module_common._MODULE_UTILS_PATH, context=self._inv.connection.context, ) return self._module_map @@ -405,7 +405,7 @@ class ReplacerPlanner(NewStylePlanner): @classmethod def detect(cls, path, source): - return module_common.REPLACER in source + return ansible.executor.module_common.REPLACER in source class OldStylePlanner(ScriptPlanner): @@ -427,12 +427,6 @@ _planners = [ ] -try: - _get_ansible_module_fqn = module_common._get_ansible_module_fqn -except AttributeError: - _get_ansible_module_fqn = None - - def py_modname_from_path(name, path): """ Fetch the logical name of a new-style module as it might appear in @@ -442,11 +436,12 @@ def py_modname_from_path(name, path): package hierarchy approximated on the target, enabling relative imports to function correctly. For example, "ansible.modules.system.setup". """ - if _get_ansible_module_fqn: - try: - return _get_ansible_module_fqn(path) - except ValueError: - pass + try: + return ansible.executor.module_common._get_ansible_module_fqn(path) + except AttributeError: + pass + except ValueError: + pass return 'ansible.modules.' + name @@ -528,12 +523,15 @@ def _invoke_isolated_task(invocation, planner): context.shutdown() -def _get_planner(name, path, source): +def _get_planner(invocation, source): for klass in _planners: - if klass.detect(path, source): - LOG.debug('%r accepted %r (filename %r)', klass, name, path) + if klass.detect(invocation.module_path, source): + LOG.debug( + '%r accepted %r (filename %r)', + klass, invocation.module_name, invocation.module_path, + ) return klass - LOG.debug('%r rejected %r', klass, name) + LOG.debug('%r rejected %r', klass, invocation.module_name) raise ansible.errors.AnsibleError(NO_METHOD_MSG + repr(invocation)) @@ -564,7 +562,7 @@ def _load_collections(invocation): Goes through all collection path possibilities and stores paths to installed collections Stores them on the current invocation to later be passed to the master service """ - for collection_path in list_collection_dirs(): + for collection_path in ansible.collections.list.list_collection_dirs(): invocation._extra_sys_paths.add(collection_path.decode('utf-8')) @@ -596,8 +594,7 @@ def invoke(invocation): module_source = invocation.get_module_source() _fix_py35(invocation, module_source) _planner_by_path[invocation.module_path] = _get_planner( - invocation.module_name, - invocation.module_path, + invocation, module_source ) diff --git a/ansible_mitogen/plugins/action/mitogen_get_stack.py b/ansible_mitogen/plugins/action/mitogen_get_stack.py index 0d0afe86..a8634e57 100644 --- a/ansible_mitogen/plugins/action/mitogen_get_stack.py +++ b/ansible_mitogen/plugins/action/mitogen_get_stack.py @@ -26,14 +26,15 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from __future__ import absolute_import -from __future__ import unicode_literals - """ Fetch the connection configuration stack that would be used to connect to a target, without actually connecting to it. """ +from __future__ import absolute_import, division, print_function +from __future__ import unicode_literals +__metaclass__ = type + import ansible_mitogen.connection from ansible.plugins.action import ActionBase diff --git a/ansible_mitogen/plugins/connection/mitogen_buildah.py b/ansible_mitogen/plugins/connection/mitogen_buildah.py index 017214b2..10ab6b41 100644 --- a/ansible_mitogen/plugins/connection/mitogen_buildah.py +++ b/ansible_mitogen/plugins/connection/mitogen_buildah.py @@ -26,7 +26,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function +__metaclass__ = type + import os.path import sys diff --git a/ansible_mitogen/plugins/connection/mitogen_doas.py b/ansible_mitogen/plugins/connection/mitogen_doas.py index 1113d7c6..963ec597 100644 --- a/ansible_mitogen/plugins/connection/mitogen_doas.py +++ b/ansible_mitogen/plugins/connection/mitogen_doas.py @@ -26,7 +26,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function +__metaclass__ = type + import os.path import sys diff --git a/ansible_mitogen/plugins/connection/mitogen_docker.py b/ansible_mitogen/plugins/connection/mitogen_docker.py index b71ef5f1..e0dd2120 100644 --- a/ansible_mitogen/plugins/connection/mitogen_docker.py +++ b/ansible_mitogen/plugins/connection/mitogen_docker.py @@ -26,7 +26,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function +__metaclass__ = type + import os.path import sys diff --git a/ansible_mitogen/plugins/connection/mitogen_jail.py b/ansible_mitogen/plugins/connection/mitogen_jail.py index c7475fb1..a432e17d 100644 --- a/ansible_mitogen/plugins/connection/mitogen_jail.py +++ b/ansible_mitogen/plugins/connection/mitogen_jail.py @@ -26,7 +26,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function +__metaclass__ = type + import os.path import sys diff --git a/ansible_mitogen/plugins/connection/mitogen_kubectl.py b/ansible_mitogen/plugins/connection/mitogen_kubectl.py index 7f99376d..bae41609 100644 --- a/ansible_mitogen/plugins/connection/mitogen_kubectl.py +++ b/ansible_mitogen/plugins/connection/mitogen_kubectl.py @@ -27,12 +27,13 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function +__metaclass__ = type + import os.path import sys -from ansible.errors import AnsibleConnectionFailure -from ansible.module_utils.six import iteritems +import ansible.errors try: import ansible_mitogen @@ -61,7 +62,7 @@ class Connection(ansible_mitogen.connection.Connection): def __init__(self, *args, **kwargs): if not _get_result: - raise AnsibleConnectionFailure(self.not_supported_msg) + raise ansible.errors.AnsibleConnectionFailure(self.not_supported_msg) super(Connection, self).__init__(*args, **kwargs) def get_extra_args(self): @@ -72,8 +73,10 @@ class Connection(ansible_mitogen.connection.Connection): # Ansible >= 2.10, _get_result is a get_with_context_result connection_options = _get_result.object.connection_options parameters = [] - for key, option in iteritems(connection_options): - if self.get_task_var('ansible_' + key) is not None: - parameters += [ option, self.get_task_var('ansible_' + key) ] + for key in connection_options: + task_var_name = 'ansible_%s' % key + task_var = self.get_task_var(task_var_name) + if task_var is not None: + parameters += [connection_options[key], task_var] return parameters diff --git a/ansible_mitogen/plugins/connection/mitogen_local.py b/ansible_mitogen/plugins/connection/mitogen_local.py index a98c834c..6ff86733 100644 --- a/ansible_mitogen/plugins/connection/mitogen_local.py +++ b/ansible_mitogen/plugins/connection/mitogen_local.py @@ -26,7 +26,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function +__metaclass__ = type + import os.path import sys diff --git a/ansible_mitogen/plugins/connection/mitogen_lxc.py b/ansible_mitogen/plugins/connection/mitogen_lxc.py index 696c9abd..8850b3d7 100644 --- a/ansible_mitogen/plugins/connection/mitogen_lxc.py +++ b/ansible_mitogen/plugins/connection/mitogen_lxc.py @@ -26,7 +26,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function +__metaclass__ = type + import os.path import sys diff --git a/ansible_mitogen/plugins/connection/mitogen_lxd.py b/ansible_mitogen/plugins/connection/mitogen_lxd.py index 95e692a0..25370ef5 100644 --- a/ansible_mitogen/plugins/connection/mitogen_lxd.py +++ b/ansible_mitogen/plugins/connection/mitogen_lxd.py @@ -26,7 +26,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function +__metaclass__ = type + import os.path import sys diff --git a/ansible_mitogen/plugins/connection/mitogen_machinectl.py b/ansible_mitogen/plugins/connection/mitogen_machinectl.py index 0f5a0d28..1f538797 100644 --- a/ansible_mitogen/plugins/connection/mitogen_machinectl.py +++ b/ansible_mitogen/plugins/connection/mitogen_machinectl.py @@ -26,7 +26,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function +__metaclass__ = type + import os.path import sys diff --git a/ansible_mitogen/plugins/connection/mitogen_podman.py b/ansible_mitogen/plugins/connection/mitogen_podman.py index 96e94ed2..e423aac8 100644 --- a/ansible_mitogen/plugins/connection/mitogen_podman.py +++ b/ansible_mitogen/plugins/connection/mitogen_podman.py @@ -26,7 +26,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function +__metaclass__ = type + import os.path import sys diff --git a/ansible_mitogen/plugins/connection/mitogen_setns.py b/ansible_mitogen/plugins/connection/mitogen_setns.py index 20c6f137..4d70892f 100644 --- a/ansible_mitogen/plugins/connection/mitogen_setns.py +++ b/ansible_mitogen/plugins/connection/mitogen_setns.py @@ -26,7 +26,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function +__metaclass__ = type + import os.path import sys diff --git a/ansible_mitogen/plugins/connection/mitogen_ssh.py b/ansible_mitogen/plugins/connection/mitogen_ssh.py index 1c81dae5..5a6abaa9 100644 --- a/ansible_mitogen/plugins/connection/mitogen_ssh.py +++ b/ansible_mitogen/plugins/connection/mitogen_ssh.py @@ -26,7 +26,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function +__metaclass__ = type + import os.path import sys diff --git a/ansible_mitogen/plugins/connection/mitogen_su.py b/ansible_mitogen/plugins/connection/mitogen_su.py index 4ab2711e..9395cc5f 100644 --- a/ansible_mitogen/plugins/connection/mitogen_su.py +++ b/ansible_mitogen/plugins/connection/mitogen_su.py @@ -26,7 +26,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function +__metaclass__ = type + import os.path import sys diff --git a/ansible_mitogen/plugins/connection/mitogen_sudo.py b/ansible_mitogen/plugins/connection/mitogen_sudo.py index 130f5445..ef549428 100644 --- a/ansible_mitogen/plugins/connection/mitogen_sudo.py +++ b/ansible_mitogen/plugins/connection/mitogen_sudo.py @@ -26,7 +26,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function +__metaclass__ = type + import os.path import sys diff --git a/ansible_mitogen/plugins/strategy/mitogen.py b/ansible_mitogen/plugins/strategy/mitogen.py index 66872663..abbe7672 100644 --- a/ansible_mitogen/plugins/strategy/mitogen.py +++ b/ansible_mitogen/plugins/strategy/mitogen.py @@ -26,7 +26,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function +__metaclass__ = type + import os.path import sys diff --git a/ansible_mitogen/plugins/strategy/mitogen_free.py b/ansible_mitogen/plugins/strategy/mitogen_free.py index ffe2fbd9..4f4e1f81 100644 --- a/ansible_mitogen/plugins/strategy/mitogen_free.py +++ b/ansible_mitogen/plugins/strategy/mitogen_free.py @@ -26,7 +26,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function +__metaclass__ = type + import os.path import sys diff --git a/ansible_mitogen/plugins/strategy/mitogen_host_pinned.py b/ansible_mitogen/plugins/strategy/mitogen_host_pinned.py index 23eccd36..c3396c5f 100644 --- a/ansible_mitogen/plugins/strategy/mitogen_host_pinned.py +++ b/ansible_mitogen/plugins/strategy/mitogen_host_pinned.py @@ -26,7 +26,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function +__metaclass__ = type + import os.path import sys diff --git a/ansible_mitogen/plugins/strategy/mitogen_linear.py b/ansible_mitogen/plugins/strategy/mitogen_linear.py index 1b198e61..b1b03aef 100644 --- a/ansible_mitogen/plugins/strategy/mitogen_linear.py +++ b/ansible_mitogen/plugins/strategy/mitogen_linear.py @@ -26,7 +26,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function +__metaclass__ = type + import os.path import sys diff --git a/ansible_mitogen/process.py b/ansible_mitogen/process.py index 1fc7bf80..9276614b 100644 --- a/ansible_mitogen/process.py +++ b/ansible_mitogen/process.py @@ -26,7 +26,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function +__metaclass__ = type + import atexit import logging import multiprocessing diff --git a/ansible_mitogen/runner.py b/ansible_mitogen/runner.py index 06402344..31ccf1cf 100644 --- a/ansible_mitogen/runner.py +++ b/ansible_mitogen/runner.py @@ -36,6 +36,9 @@ Each class in here has a corresponding Planner class in planners.py that knows how to build arguments for it, preseed related data, etc. """ +from __future__ import absolute_import, division, print_function +__metaclass__ = type + import atexit import imp import os diff --git a/ansible_mitogen/services.py b/ansible_mitogen/services.py index 2eb3b2e4..b0f5c70e 100644 --- a/ansible_mitogen/services.py +++ b/ansible_mitogen/services.py @@ -39,18 +39,18 @@ connections, grant access to files by children, and register for notification when a child has completed a job. """ -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function from __future__ import unicode_literals +__metaclass__ = type import logging import os -import os.path import sys import threading import ansible.constants -import mitogen +import mitogen.core import mitogen.service import mitogen.utils import ansible_mitogen.loaders diff --git a/ansible_mitogen/strategy.py b/ansible_mitogen/strategy.py index e0b326e5..0a98e316 100644 --- a/ansible_mitogen/strategy.py +++ b/ansible_mitogen/strategy.py @@ -26,7 +26,9 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function +__metaclass__ = type + import os import signal import threading @@ -43,7 +45,7 @@ import ansible_mitogen.mixins import ansible_mitogen.process import ansible.executor.process.worker -from ansible.utils.sentinel import Sentinel +import ansible.utils.sentinel def _patch_awx_callback(): @@ -54,12 +56,11 @@ def _patch_awx_callback(): # AWX uses sitecustomize.py to force-load this package. If it exists, we're # running under AWX. try: - from awx_display_callback.events import EventContext - from awx_display_callback.events import event_context + import awx_display_callback.events except ImportError: return - if hasattr(EventContext(), '_local'): + if hasattr(awx_display_callback.events.EventContext(), '_local'): # Patched version. return @@ -68,8 +69,8 @@ def _patch_awx_callback(): ctx = tls.setdefault('_ctx', {}) ctx.update(kwargs) - EventContext._local = threading.local() - EventContext.add_local = patch_add_local + awx_display_callback.events.EventContext._local = threading.local() + awx_display_callback.events.EventContext.add_local = patch_add_local _patch_awx_callback() @@ -279,7 +280,7 @@ class StrategyMixin(object): name=task.action, class_only=True, ) - if play_context.connection is not Sentinel: + if play_context.connection is not ansible.utils.sentinel.Sentinel: # 2.8 appears to defer computing this until inside the worker. # TODO: figure out where it has moved. ansible_mitogen.loaders.connection_loader.get( diff --git a/ansible_mitogen/target.py b/ansible_mitogen/target.py index a24955d2..2c65c516 100644 --- a/ansible_mitogen/target.py +++ b/ansible_mitogen/target.py @@ -33,6 +33,9 @@ Helper functions intended to be executed on the target. These are entrypoints for file transfer, module execution and sundry bits like changing file modes. """ +from __future__ import absolute_import, division, print_function +__metaclass__ = type + import errno import grp import operator @@ -51,7 +54,6 @@ import types logging = __import__('logging') import mitogen.core -import mitogen.fork import mitogen.parent import mitogen.service from mitogen.core import b diff --git a/ansible_mitogen/transport_config.py b/ansible_mitogen/transport_config.py index ffae2bb8..b488b851 100644 --- a/ansible_mitogen/transport_config.py +++ b/ansible_mitogen/transport_config.py @@ -26,9 +26,6 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from __future__ import absolute_import -from __future__ import unicode_literals - """ Mitogen extends Ansible's target configuration mechanism in several ways that require some care: @@ -60,6 +57,10 @@ information from PlayContext, and another that takes (almost) all information from HostVars. """ +from __future__ import absolute_import, division, print_function +from __future__ import unicode_literals +__metaclass__ = type + import abc import os import ansible.utils.shlex diff --git a/ansible_mitogen/utils.py b/ansible_mitogen/utils.py index 399c181a..25c5a692 100644 --- a/ansible_mitogen/utils.py +++ b/ansible_mitogen/utils.py @@ -1,4 +1,5 @@ -from __future__ import absolute_import +from __future__ import absolute_import, division, print_function +__metaclass__ = type import distutils.version diff --git a/mitogen/buildah.py b/mitogen/buildah.py index f850234d..7a1e3f80 100644 --- a/mitogen/buildah.py +++ b/mitogen/buildah.py @@ -30,7 +30,6 @@ import logging -import mitogen.core import mitogen.parent diff --git a/mitogen/core.py b/mitogen/core.py index d64f48fb..bee722e6 100644 --- a/mitogen/core.py +++ b/mitogen/core.py @@ -2717,7 +2717,7 @@ class Latch(object): raise e assert cookie == got_cookie, ( - "Cookie incorrect; got %r, expected %r" \ + "Cookie incorrect; got %r, expected %r" % (binascii.hexlify(got_cookie), binascii.hexlify(cookie)) ) @@ -3672,7 +3672,6 @@ class Dispatcher(object): self._service_recv.notify = None self.recv.close() - @classmethod @takes_econtext def forget_chain(cls, chain_id, econtext): diff --git a/mitogen/fakessh.py b/mitogen/fakessh.py index e62cf84a..2d660248 100644 --- a/mitogen/fakessh.py +++ b/mitogen/fakessh.py @@ -103,7 +103,6 @@ import tempfile import threading import mitogen.core -import mitogen.master import mitogen.parent from mitogen.core import LOG, IOLOG @@ -200,7 +199,7 @@ class Process(object): def _on_stdin(self, msg): if msg.is_dead: - IOLOG.debug('%r._on_stdin() -> %r', self, data) + IOLOG.debug('%r._on_stdin() -> %r', self, msg) self.pump.protocol.close() return @@ -437,7 +436,7 @@ def run(dest, router, args, deadline=None, econtext=None): fp.write(inspect.getsource(mitogen.core)) fp.write('\n') fp.write('ExternalContext(%r).main()\n' % ( - _get_econtext_config(context, sock2), + _get_econtext_config(econtext, sock2), )) finally: fp.close() diff --git a/mitogen/kubectl.py b/mitogen/kubectl.py index 374ab747..5d3994ae 100644 --- a/mitogen/kubectl.py +++ b/mitogen/kubectl.py @@ -28,7 +28,6 @@ # !mitogen: minify_safe -import mitogen.core import mitogen.parent diff --git a/mitogen/lxc.py b/mitogen/lxc.py index a86ce5f0..21dfef59 100644 --- a/mitogen/lxc.py +++ b/mitogen/lxc.py @@ -28,7 +28,6 @@ # !mitogen: minify_safe -import mitogen.core import mitogen.parent diff --git a/mitogen/lxd.py b/mitogen/lxd.py index 675dddcd..09034abf 100644 --- a/mitogen/lxd.py +++ b/mitogen/lxd.py @@ -28,7 +28,6 @@ # !mitogen: minify_safe -import mitogen.core import mitogen.parent diff --git a/mitogen/parent.py b/mitogen/parent.py index c3efe28a..32aa3cb6 100644 --- a/mitogen/parent.py +++ b/mitogen/parent.py @@ -1508,7 +1508,7 @@ class Connection(object): def get_preamble(self): suffix = ( - '\nExternalContext(%r).main()\n' %\ + '\nExternalContext(%r).main()\n' % (self.get_econtext_config(),) ) partial = get_core_source_partial() diff --git a/mitogen/podman.py b/mitogen/podman.py index 01e02e94..acc46a33 100644 --- a/mitogen/podman.py +++ b/mitogen/podman.py @@ -31,7 +31,6 @@ import logging -import mitogen.core import mitogen.parent diff --git a/mitogen/service.py b/mitogen/service.py index d4f5f730..0e5f6419 100644 --- a/mitogen/service.py +++ b/mitogen/service.py @@ -31,7 +31,6 @@ import grp import logging import os -import os.path import pprint import pwd import stat diff --git a/mitogen/utils.py b/mitogen/utils.py index b1347d02..4e7a59a9 100644 --- a/mitogen/utils.py +++ b/mitogen/utils.py @@ -33,10 +33,8 @@ import logging import os import sys -import mitogen import mitogen.core import mitogen.master -import mitogen.parent iteritems = getattr(dict, 'iteritems', dict.items) diff --git a/tests/ansible/integration/module_utils/roles/modrole/module_utils/external2.py b/tests/ansible/integration/module_utils/roles/modrole/module_utils/external2.py index a00278a0..4ea8bc90 100644 --- a/tests/ansible/integration/module_utils/roles/modrole/module_utils/external2.py +++ b/tests/ansible/integration/module_utils/roles/modrole/module_utils/external2.py @@ -1,3 +1,2 @@ - def path(): return "integration/module_utils/roles/modrole/module_utils/external2.py" diff --git a/tests/ansible/integration/module_utils/roles/overrides_modrole/library/uses_custom_known_hosts.py b/tests/ansible/integration/module_utils/roles/overrides_modrole/library/uses_custom_known_hosts.py index f0e9439b..688fc45a 100644 --- a/tests/ansible/integration/module_utils/roles/overrides_modrole/library/uses_custom_known_hosts.py +++ b/tests/ansible/integration/module_utils/roles/overrides_modrole/library/uses_custom_known_hosts.py @@ -1,11 +1,11 @@ #!/usr/bin/python import json -from ansible.module_utils.basic import path +import ansible.module_utils.basic def main(): print(json.dumps({ - 'path': path() + 'path': ansible.module_utils.basic.path() })) if __name__ == '__main__': diff --git a/tests/ansible/integration/runner/atexit.yml b/tests/ansible/integration/runner/atexit.yml index 9cab0a5d..65673561 100644 --- a/tests/ansible/integration/runner/atexit.yml +++ b/tests/ansible/integration/runner/atexit.yml @@ -17,7 +17,7 @@ - custom_python_run_script: script: | - import atexit, shutil + import atexit, os, shutil path = '{{path}}' os.mkdir(path, int('777', 8)) atexit.register(shutil.rmtree, path) diff --git a/tests/ansible/lib/action/action_passthrough.py b/tests/ansible/lib/action/action_passthrough.py index 2748a932..04e95f47 100644 --- a/tests/ansible/lib/action/action_passthrough.py +++ b/tests/ansible/lib/action/action_passthrough.py @@ -1,8 +1,5 @@ - import traceback -import sys -from ansible.plugins.strategy import StrategyBase from ansible.plugins.action import ActionBase diff --git a/tests/ansible/lib/action/connection_passthrough.py b/tests/ansible/lib/action/connection_passthrough.py index 1e9211e4..b639061b 100644 --- a/tests/ansible/lib/action/connection_passthrough.py +++ b/tests/ansible/lib/action/connection_passthrough.py @@ -1,8 +1,5 @@ - import traceback -import sys -from ansible.plugins.strategy import StrategyBase from ansible.plugins.action import ActionBase diff --git a/tests/ansible/lib/action/determine_strategy.py b/tests/ansible/lib/action/determine_strategy.py index b4b067c1..b76783e9 100644 --- a/tests/ansible/lib/action/determine_strategy.py +++ b/tests/ansible/lib/action/determine_strategy.py @@ -1,4 +1,3 @@ - import sys from ansible.plugins.strategy import StrategyBase diff --git a/tests/ansible/lib/action/mitogen_shutdown_all.py b/tests/ansible/lib/action/mitogen_shutdown_all.py index 59191450..14ab0656 100644 --- a/tests/ansible/lib/action/mitogen_shutdown_all.py +++ b/tests/ansible/lib/action/mitogen_shutdown_all.py @@ -5,9 +5,7 @@ required for reliable LRU tests. import ansible_mitogen.connection import ansible_mitogen.services -import mitogen.service -from ansible.plugins.strategy import StrategyBase from ansible.plugins.action import ActionBase diff --git a/tests/ansible/lib/callback/fork_histogram.py b/tests/ansible/lib/callback/fork_histogram.py index 15260cb5..de5f4712 100644 --- a/tests/ansible/lib/callback/fork_histogram.py +++ b/tests/ansible/lib/callback/fork_histogram.py @@ -1,4 +1,3 @@ - # Monkey-patch os.fork() to produce a latency histogram on run completion. # Requires 'hdrhsitograms' PyPI module. diff --git a/tests/ansible/lib/callback/nice_stdout.py b/tests/ansible/lib/callback/nice_stdout.py index 7c90a499..5345083e 100644 --- a/tests/ansible/lib/callback/nice_stdout.py +++ b/tests/ansible/lib/callback/nice_stdout.py @@ -1,7 +1,6 @@ from __future__ import unicode_literals import io import os -import sys from ansible import constants as C from ansible.module_utils import six diff --git a/tests/ansible/lib/filters/mitogen_tests.py b/tests/ansible/lib/filters/mitogen_tests.py index e7614658..a9037ccc 100644 --- a/tests/ansible/lib/filters/mitogen_tests.py +++ b/tests/ansible/lib/filters/mitogen_tests.py @@ -1,4 +1,3 @@ - from ansible.module_utils._text import to_text diff --git a/tests/ansible/lib/module_utils/external2.py b/tests/ansible/lib/module_utils/external2.py index c815dcdb..9a4a9bd9 100644 --- a/tests/ansible/lib/module_utils/external2.py +++ b/tests/ansible/lib/module_utils/external2.py @@ -1,3 +1,2 @@ - def path(): return "ansible/lib/module_utils/external2.py" diff --git a/tests/ansible/lib/module_utils/externalpkg/extmod.py b/tests/ansible/lib/module_utils/externalpkg/extmod.py index 619be5dd..a3c0f525 100644 --- a/tests/ansible/lib/module_utils/externalpkg/extmod.py +++ b/tests/ansible/lib/module_utils/externalpkg/extmod.py @@ -1,3 +1,2 @@ - def path(): return 'ansible/lib/module_utils/externalpkg/extmod.py' diff --git a/tests/ansible/lib/modules/custom_python_detect_environment.py b/tests/ansible/lib/modules/custom_python_detect_environment.py index 3735007d..65f660a8 100644 --- a/tests/ansible/lib/modules/custom_python_detect_environment.py +++ b/tests/ansible/lib/modules/custom_python_detect_environment.py @@ -4,7 +4,6 @@ from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.basic import get_module_path -from ansible.module_utils import six import os import pwd diff --git a/tests/ansible/lib/modules/custom_python_json_args_module.py b/tests/ansible/lib/modules/custom_python_json_args_module.py index a63ce8e6..846037ec 100755 --- a/tests/ansible/lib/modules/custom_python_json_args_module.py +++ b/tests/ansible/lib/modules/custom_python_json_args_module.py @@ -1,8 +1,6 @@ #!/usr/bin/python # I am an Ansible Python JSONARGS module. I should receive an encoding string. -import sys - json_arguments = """<>""" print("{") diff --git a/tests/ansible/lib/modules/custom_python_modify_environ.py b/tests/ansible/lib/modules/custom_python_modify_environ.py index 347bedf2..9767f855 100644 --- a/tests/ansible/lib/modules/custom_python_modify_environ.py +++ b/tests/ansible/lib/modules/custom_python_modify_environ.py @@ -5,9 +5,6 @@ from ansible.module_utils.basic import AnsibleModule import os -import pwd -import socket -import sys def main(): diff --git a/tests/ansible/lib/modules/custom_python_prehistoric_module.py b/tests/ansible/lib/modules/custom_python_prehistoric_module.py index d44f51ec..7ce15208 100644 --- a/tests/ansible/lib/modules/custom_python_prehistoric_module.py +++ b/tests/ansible/lib/modules/custom_python_prehistoric_module.py @@ -2,13 +2,6 @@ # issue #555: I'm a module that cutpastes an old hack. from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.basic import get_module_path -from ansible.module_utils import six - -import os -import pwd -import socket -import sys import sys reload(sys) diff --git a/tests/ansible/lib/modules/custom_python_run_script.py b/tests/ansible/lib/modules/custom_python_run_script.py index 31e0609f..4a6243d0 100644 --- a/tests/ansible/lib/modules/custom_python_run_script.py +++ b/tests/ansible/lib/modules/custom_python_run_script.py @@ -3,12 +3,7 @@ # parameter. from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.basic import get_module_path -from ansible.module_utils import six -import os -import pwd -import socket import sys diff --git a/tests/ansible/tests/affinity_test.py b/tests/ansible/tests/affinity_test.py index 1227263c..0051a701 100644 --- a/tests/ansible/tests/affinity_test.py +++ b/tests/ansible/tests/affinity_test.py @@ -1,4 +1,3 @@ - import multiprocessing import os import sys diff --git a/tests/ansible/tests/connection_test.py b/tests/ansible/tests/connection_test.py index 377b5d24..8a831a5e 100644 --- a/tests/ansible/tests/connection_test.py +++ b/tests/ansible/tests/connection_test.py @@ -1,17 +1,12 @@ - from __future__ import absolute_import import os -import os.path -import subprocess import tempfile -import time import mock import ansible.errors import ansible.playbook.play_context import mitogen.core -import mitogen.utils import ansible_mitogen.connection import ansible_mitogen.plugins.connection.mitogen_local @@ -25,7 +20,6 @@ class MuxProcessMixin(object): @classmethod def setUpClass(cls): - #mitogen.utils.log_to_file() cls.model = ansible_mitogen.process.get_classic_worker_model( _init_logging=False ) diff --git a/tests/ansible/tests/env_file_watcher_test.py b/tests/ansible/tests/env_file_watcher_test.py index de023903..6ca1b7e0 100644 --- a/tests/ansible/tests/env_file_watcher_test.py +++ b/tests/ansible/tests/env_file_watcher_test.py @@ -1,5 +1,4 @@ import os -import sys import tempfile import testlib diff --git a/tests/ansible/tests/target_test.py b/tests/ansible/tests/target_test.py index 4b40a113..0e588baa 100644 --- a/tests/ansible/tests/target_test.py +++ b/tests/ansible/tests/target_test.py @@ -1,4 +1,3 @@ - from __future__ import absolute_import import os.path import subprocess diff --git a/tests/bench/large_messages.py b/tests/bench/large_messages.py index e977e36d..8593a33a 100644 --- a/tests/bench/large_messages.py +++ b/tests/bench/large_messages.py @@ -1,10 +1,5 @@ - # Verify _receive_one() quadratic behaviour fixed. -import subprocess -import time -import socket - import mitogen import mitogen.core diff --git a/tests/bench/latch_roundtrip.py b/tests/bench/latch_roundtrip.py index 1198aa48..cbc48374 100644 --- a/tests/bench/latch_roundtrip.py +++ b/tests/bench/latch_roundtrip.py @@ -3,9 +3,7 @@ Measure latency of IPC between two local threads. """ import threading -import time -import mitogen import mitogen.core import mitogen.utils import ansible_mitogen.affinity diff --git a/tests/bench/local.py b/tests/bench/local.py index aefeb84d..0653a0de 100644 --- a/tests/bench/local.py +++ b/tests/bench/local.py @@ -2,8 +2,6 @@ Measure latency of .local() setup. """ -import time - import mitogen import mitogen.core import mitogen.utils diff --git a/tests/bench/megatime.py b/tests/bench/megatime.py index 40cd9986..87062769 100755 --- a/tests/bench/megatime.py +++ b/tests/bench/megatime.py @@ -2,7 +2,6 @@ import sys import os -import time import mitogen.core diff --git a/tests/bench/roundtrip.py b/tests/bench/roundtrip.py index 8f31b1a2..774dfc5b 100644 --- a/tests/bench/roundtrip.py +++ b/tests/bench/roundtrip.py @@ -2,9 +2,6 @@ Measure latency of local RPC. """ -import time - -import mitogen import mitogen.core import mitogen.utils import ansible_mitogen.affinity diff --git a/tests/bench/service.py b/tests/bench/service.py index 267ae3f6..d3a71b79 100644 --- a/tests/bench/service.py +++ b/tests/bench/service.py @@ -1,9 +1,6 @@ """ Measure latency of local service RPC. """ - -import time - import mitogen import mitogen.core import mitogen.service diff --git a/tests/bench/ssh-roundtrip.py b/tests/bench/ssh-roundtrip.py index 06c596c0..c5f14574 100644 --- a/tests/bench/ssh-roundtrip.py +++ b/tests/bench/ssh-roundtrip.py @@ -3,9 +3,7 @@ Measure latency of SSH RPC. """ import sys -import time -import mitogen import mitogen.core import mitogen.utils import ansible_mitogen.affinity diff --git a/tests/bench/throughput.py b/tests/bench/throughput.py index acb51afa..7d67d158 100644 --- a/tests/bench/throughput.py +++ b/tests/bench/throughput.py @@ -1,11 +1,7 @@ # Verify throughput over sudo and SSH at various compression levels. import os -import random -import socket -import subprocess import tempfile -import time import mitogen import mitogen.core diff --git a/tests/buildah_test.py b/tests/buildah_test.py index bf053fde..8412cff3 100644 --- a/tests/buildah_test.py +++ b/tests/buildah_test.py @@ -1,7 +1,5 @@ import os -import mitogen - import testlib diff --git a/tests/call_function_test.py b/tests/call_function_test.py index dcd3d343..1e838bda 100644 --- a/tests/call_function_test.py +++ b/tests/call_function_test.py @@ -1,9 +1,7 @@ -import logging import time import mitogen.core import mitogen.parent -import mitogen.master from mitogen.core import str_partition import testlib diff --git a/tests/connection_test.py b/tests/connection_test.py index 169fde97..5b54e090 100644 --- a/tests/connection_test.py +++ b/tests/connection_test.py @@ -1,4 +1,3 @@ - import os import signal import sys diff --git a/tests/context_test.py b/tests/context_test.py index cbfe4418..ee9292c4 100644 --- a/tests/context_test.py +++ b/tests/context_test.py @@ -1,4 +1,3 @@ - import pickle import mitogen.core diff --git a/tests/create_child_test.py b/tests/create_child_test.py index 1881c628..d9bbd1a1 100644 --- a/tests/create_child_test.py +++ b/tests/create_child_test.py @@ -1,9 +1,7 @@ - import fcntl import os import stat import sys -import time import tempfile import mitogen.core diff --git a/tests/data/importer/module_finder_testmod/regular_mod.py b/tests/data/importer/module_finder_testmod/regular_mod.py index a7c0403b..07f8759f 100644 --- a/tests/data/importer/module_finder_testmod/regular_mod.py +++ b/tests/data/importer/module_finder_testmod/regular_mod.py @@ -1,6 +1,2 @@ - -import sys - - def say_hi(): print('hi') diff --git a/tests/data/importer/module_finder_testmod/sibling_dep_mod_abs_import.py b/tests/data/importer/module_finder_testmod/sibling_dep_mod_abs_import.py index 5e64ffd6..1dedc812 100644 --- a/tests/data/importer/module_finder_testmod/sibling_dep_mod_abs_import.py +++ b/tests/data/importer/module_finder_testmod/sibling_dep_mod_abs_import.py @@ -1,3 +1,2 @@ - from __future__ import absolute_import from module_finder_testmod.regular_mod import say_hi diff --git a/tests/data/importer/module_finder_testmod/sibling_dep_mod_py2_import.py b/tests/data/importer/module_finder_testmod/sibling_dep_mod_py2_import.py index aaefff70..f5b17796 100644 --- a/tests/data/importer/module_finder_testmod/sibling_dep_mod_py2_import.py +++ b/tests/data/importer/module_finder_testmod/sibling_dep_mod_py2_import.py @@ -1,2 +1 @@ - from regular_mod import say_hi diff --git a/tests/data/importer/pkg_like_plumbum/colors.py b/tests/data/importer/pkg_like_plumbum/colors.py index bff19555..a36ec98b 100644 --- a/tests/data/importer/pkg_like_plumbum/colors.py +++ b/tests/data/importer/pkg_like_plumbum/colors.py @@ -1,4 +1,3 @@ - # coding=utf-8 import sys diff --git a/tests/data/importer/simple_pkg/a.py b/tests/data/importer/simple_pkg/a.py index ce5f1887..5d369cad 100644 --- a/tests/data/importer/simple_pkg/a.py +++ b/tests/data/importer/simple_pkg/a.py @@ -1,4 +1,3 @@ - import simple_pkg.b diff --git a/tests/data/importer/simple_pkg/b.py b/tests/data/importer/simple_pkg/b.py index 5e5d67b2..c0883bd5 100644 --- a/tests/data/importer/simple_pkg/b.py +++ b/tests/data/importer/simple_pkg/b.py @@ -1,3 +1,2 @@ - def subtract_one(n): return n - 1 diff --git a/tests/data/importer/simple_pkg/ping.py b/tests/data/importer/simple_pkg/ping.py index 722f7b87..84330482 100644 --- a/tests/data/importer/simple_pkg/ping.py +++ b/tests/data/importer/simple_pkg/ping.py @@ -1,5 +1,3 @@ - - def ping(*args): return args diff --git a/tests/data/importer/webproject/serve_django_app.py b/tests/data/importer/webproject/serve_django_app.py index afa67f0c..a9ad1e80 100644 --- a/tests/data/importer/webproject/serve_django_app.py +++ b/tests/data/importer/webproject/serve_django_app.py @@ -1,4 +1,3 @@ - import os import sys diff --git a/tests/data/main_with_no_exec_guard.py b/tests/data/main_with_no_exec_guard.py index 153e4743..7c23a769 100644 --- a/tests/data/main_with_no_exec_guard.py +++ b/tests/data/main_with_no_exec_guard.py @@ -1,4 +1,3 @@ - import logging import mitogen.master diff --git a/tests/data/stubs/stub-python.py b/tests/data/stubs/stub-python.py index d9239c2b..f18b0b68 100755 --- a/tests/data/stubs/stub-python.py +++ b/tests/data/stubs/stub-python.py @@ -2,7 +2,6 @@ import json import os -import subprocess import sys os.environ['ORIGINAL_ARGV'] = json.dumps(sys.argv) diff --git a/tests/data/stubs/stub-su.py b/tests/data/stubs/stub-su.py index 1f5e512d..e353a752 100755 --- a/tests/data/stubs/stub-su.py +++ b/tests/data/stubs/stub-su.py @@ -2,7 +2,6 @@ import json import os -import subprocess import sys import time diff --git a/tests/doas_test.py b/tests/doas_test.py index 76403513..4e847942 100644 --- a/tests/doas_test.py +++ b/tests/doas_test.py @@ -1,9 +1,7 @@ - import os -import mitogen +import mitogen.core import mitogen.doas -import mitogen.parent import testlib diff --git a/tests/docker_test.py b/tests/docker_test.py index b5c18b06..6f1b5cca 100644 --- a/tests/docker_test.py +++ b/tests/docker_test.py @@ -1,7 +1,5 @@ import os -import mitogen - import testlib diff --git a/tests/fakessh_test.py b/tests/fakessh_test.py index 7fc749d8..52321495 100644 --- a/tests/fakessh_test.py +++ b/tests/fakessh_test.py @@ -1,4 +1,3 @@ - import os import shutil import unittest diff --git a/tests/file_service_test.py b/tests/file_service_test.py index 192f1a82..2a2008b3 100644 --- a/tests/file_service_test.py +++ b/tests/file_service_test.py @@ -1,4 +1,3 @@ - import sys import mitogen.service diff --git a/tests/first_stage_test.py b/tests/first_stage_test.py index 541cf523..ad7165b3 100644 --- a/tests/first_stage_test.py +++ b/tests/first_stage_test.py @@ -1,4 +1,3 @@ - import subprocess import mitogen.parent diff --git a/tests/fork_test.py b/tests/fork_test.py index 8d86fc32..86e60cfc 100644 --- a/tests/fork_test.py +++ b/tests/fork_test.py @@ -1,7 +1,5 @@ - import os import random -import struct import sys import unittest diff --git a/tests/importer_test.py b/tests/importer_test.py index 4e844ae1..e48c02a4 100644 --- a/tests/importer_test.py +++ b/tests/importer_test.py @@ -1,4 +1,3 @@ - import sys import threading import types diff --git a/tests/io_op_test.py b/tests/io_op_test.py index 9ab627db..55adfa11 100644 --- a/tests/io_op_test.py +++ b/tests/io_op_test.py @@ -1,4 +1,3 @@ - import errno import select diff --git a/tests/iter_split_test.py b/tests/iter_split_test.py index b6c48a4a..74c46c0a 100644 --- a/tests/iter_split_test.py +++ b/tests/iter_split_test.py @@ -1,12 +1,7 @@ - import unittest -import mock - import mitogen.core -import testlib - try: next except NameError: diff --git a/tests/jail_test.py b/tests/jail_test.py index 182e2219..5c0ad946 100644 --- a/tests/jail_test.py +++ b/tests/jail_test.py @@ -1,9 +1,5 @@ - import os -import mitogen -import mitogen.parent - import testlib diff --git a/tests/kubectl_test.py b/tests/kubectl_test.py index b772ad0b..2b21cfd6 100644 --- a/tests/kubectl_test.py +++ b/tests/kubectl_test.py @@ -1,9 +1,5 @@ - import os -import mitogen -import mitogen.parent - import testlib diff --git a/tests/latch_test.py b/tests/latch_test.py index 9853e8bc..e7e2768d 100644 --- a/tests/latch_test.py +++ b/tests/latch_test.py @@ -1,4 +1,3 @@ - import sys import threading diff --git a/tests/local_test.py b/tests/local_test.py index 9a42ca67..a361777d 100644 --- a/tests/local_test.py +++ b/tests/local_test.py @@ -1,9 +1,6 @@ - import os import sys -import mitogen - import testlib diff --git a/tests/log_handler_test.py b/tests/log_handler_test.py index 52a17084..c270c20a 100644 --- a/tests/log_handler_test.py +++ b/tests/log_handler_test.py @@ -1,4 +1,3 @@ - import logging import mock import sys diff --git a/tests/lxc_test.py b/tests/lxc_test.py index af0968ee..81d27318 100644 --- a/tests/lxc_test.py +++ b/tests/lxc_test.py @@ -1,7 +1,7 @@ import os -import mitogen import mitogen.lxc +import mitogen.parent try: any diff --git a/tests/lxd_test.py b/tests/lxd_test.py index 4033b915..6573e1ba 100644 --- a/tests/lxd_test.py +++ b/tests/lxd_test.py @@ -1,6 +1,5 @@ import os -import mitogen import mitogen.lxd import mitogen.parent diff --git a/tests/master_test.py b/tests/master_test.py index 98acdf6e..2af00718 100644 --- a/tests/master_test.py +++ b/tests/master_test.py @@ -1,5 +1,4 @@ import inspect -import unittest import testlib import mitogen.master @@ -15,7 +14,6 @@ class ScanCodeImportsTest(testlib.TestCase): SIMPLE_EXPECT = [ (level, 'inspect', ()), - (level, 'unittest', ()), (level, 'testlib', ()), (level, 'mitogen.master', ()), ] diff --git a/tests/message_test.py b/tests/message_test.py index 8e0919ab..b5f5cf08 100644 --- a/tests/message_test.py +++ b/tests/message_test.py @@ -1,4 +1,3 @@ - import sys import struct import unittest diff --git a/tests/mitogen_protocol_test.py b/tests/mitogen_protocol_test.py index f498eda2..03e6517c 100644 --- a/tests/mitogen_protocol_test.py +++ b/tests/mitogen_protocol_test.py @@ -1,4 +1,3 @@ - import mock import mitogen.core diff --git a/tests/module_finder_test.py b/tests/module_finder_test.py index 64059853..171c8b4c 100644 --- a/tests/module_finder_test.py +++ b/tests/module_finder_test.py @@ -7,7 +7,6 @@ import mitogen.master from mitogen.core import b import testlib -from testlib import MODS_DIR class ConstructorTest(testlib.TestCase): @@ -87,14 +86,14 @@ class PkgutilMethodTest(testlib.TestCase): def test_empty_source_pkg(self): path, src, is_pkg = self.call('module_finder_testmod') self.assertEqual(path, - os.path.join(MODS_DIR, 'module_finder_testmod/__init__.py')) + os.path.join(testlib.MODS_DIR, 'module_finder_testmod/__init__.py')) self.assertEqual(mitogen.core.b(''), src) self.assertTrue(is_pkg) def test_empty_source_module(self): path, src, is_pkg = self.call('module_finder_testmod.empty_mod') self.assertEqual(path, - os.path.join(MODS_DIR, 'module_finder_testmod/empty_mod.py')) + os.path.join(testlib.MODS_DIR, 'module_finder_testmod/empty_mod.py')) self.assertEqual(mitogen.core.b(''), src) self.assertFalse(is_pkg) @@ -102,7 +101,7 @@ class PkgutilMethodTest(testlib.TestCase): from module_finder_testmod import regular_mod path, src, is_pkg = self.call('module_finder_testmod.regular_mod') self.assertEqual(path, - os.path.join(MODS_DIR, 'module_finder_testmod/regular_mod.py')) + os.path.join(testlib.MODS_DIR, 'module_finder_testmod/regular_mod.py')) self.assertEqual(mitogen.core.to_text(src), inspect.getsource(regular_mod)) self.assertFalse(is_pkg) @@ -165,7 +164,7 @@ class GetModuleViaParentEnumerationTest(testlib.TestCase): # plumbum has been eating too many rainbow-colored pills import pkg_like_plumbum.colors path, src, is_pkg = self.call('pkg_like_plumbum.colors') - modpath = os.path.join(MODS_DIR, 'pkg_like_plumbum/colors.py') + modpath = os.path.join(testlib.MODS_DIR, 'pkg_like_plumbum/colors.py') self.assertEqual(path, modpath) with open(modpath, 'rb') as f: @@ -183,7 +182,7 @@ class GetModuleViaParentEnumerationTest(testlib.TestCase): # ensure we can resolve the subpackage. path, src, is_pkg = self.call('pkg_like_ansible.module_utils.distro') - modpath = os.path.join(MODS_DIR, + modpath = os.path.join(testlib.MODS_DIR, 'pkg_like_ansible/module_utils/distro/__init__.py') self.assertEqual(path, modpath) with open(modpath, 'rb') as f: @@ -194,7 +193,7 @@ class GetModuleViaParentEnumerationTest(testlib.TestCase): path, src, is_pkg = self.call( 'pkg_like_ansible.module_utils.distro._distro' ) - modpath = os.path.join(MODS_DIR, + modpath = os.path.join(testlib.MODS_DIR, 'pkg_like_ansible/module_utils/distro/_distro.py') self.assertEqual(path, modpath) with open(modpath, 'rb') as f: @@ -213,7 +212,7 @@ class GetModuleViaParentEnumerationTest(testlib.TestCase): # ensure we can resolve the subpackage. path, src, is_pkg = self.call('pkg_like_ansible.module_utils.sys_distro') - modpath = os.path.join(MODS_DIR, + modpath = os.path.join(testlib.MODS_DIR, 'pkg_like_ansible/module_utils/sys_distro/__init__.py') self.assertEqual(path, modpath) with open(modpath, 'rb') as f: @@ -224,7 +223,7 @@ class GetModuleViaParentEnumerationTest(testlib.TestCase): path, src, is_pkg = self.call( 'pkg_like_ansible.module_utils.sys_distro._distro' ) - modpath = os.path.join(MODS_DIR, + modpath = os.path.join(testlib.MODS_DIR, 'pkg_like_ansible/module_utils/sys_distro/_distro.py') self.assertEqual(path, modpath) with open(modpath, 'rb') as f: @@ -268,7 +267,6 @@ class FakeSshTest(testlib.TestCase): self.assertEqual(related, [ 'mitogen', 'mitogen.core', - 'mitogen.master', 'mitogen.parent', ]) @@ -282,8 +280,6 @@ class FindRelatedTest(testlib.TestCase): SIMPLE_EXPECT = set([ u'mitogen', u'mitogen.core', - u'mitogen.master', - u'mitogen.minify', u'mitogen.parent', ]) @@ -302,7 +298,7 @@ class FindRelatedTest(testlib.TestCase): if sys.version_info > (2, 6): class DjangoMixin(object): - WEBPROJECT_PATH = os.path.join(MODS_DIR, 'webproject') + WEBPROJECT_PATH = os.path.join(testlib.MODS_DIR, 'webproject') # TODO: rip out Django and replace with a static tree of weird imports # that don't depend on .. Django! The hack below is because the version diff --git a/tests/podman_test.py b/tests/podman_test.py index 0da4f3a6..8e981678 100644 --- a/tests/podman_test.py +++ b/tests/podman_test.py @@ -1,7 +1,5 @@ import os -import mitogen - import testlib diff --git a/tests/poller_test.py b/tests/poller_test.py index 26d79fa1..4b6bdc0e 100644 --- a/tests/poller_test.py +++ b/tests/poller_test.py @@ -1,4 +1,3 @@ - import errno import os import select diff --git a/tests/polyfill_functions_test.py b/tests/polyfill_functions_test.py index 175062c8..222da7b5 100644 --- a/tests/polyfill_functions_test.py +++ b/tests/polyfill_functions_test.py @@ -1,4 +1,3 @@ - import testlib import mitogen.core diff --git a/tests/push_file_service_test.py b/tests/push_file_service_test.py index 935e646c..f494a5af 100644 --- a/tests/push_file_service_test.py +++ b/tests/push_file_service_test.py @@ -1,5 +1,3 @@ - -import os import tempfile import mitogen.core diff --git a/tests/reaper_test.py b/tests/reaper_test.py index 905c5d8a..b60b13a4 100644 --- a/tests/reaper_test.py +++ b/tests/reaper_test.py @@ -1,4 +1,3 @@ - import signal import testlib diff --git a/tests/receiver_test.py b/tests/receiver_test.py index 1c69eb45..aaf15b2b 100644 --- a/tests/receiver_test.py +++ b/tests/receiver_test.py @@ -1,4 +1,3 @@ - import sys import threading import unittest diff --git a/tests/responder_test.py b/tests/responder_test.py index 01ef506a..3ab60be3 100644 --- a/tests/responder_test.py +++ b/tests/responder_test.py @@ -1,4 +1,3 @@ - import mock import textwrap import subprocess diff --git a/tests/router_test.py b/tests/router_test.py index ea8eded2..656ca734 100644 --- a/tests/router_test.py +++ b/tests/router_test.py @@ -1,7 +1,6 @@ import errno import os import sys -import time import zlib import testlib diff --git a/tests/select_test.py b/tests/select_test.py index 23233de4..deaa37a6 100644 --- a/tests/select_test.py +++ b/tests/select_test.py @@ -1,3 +1,4 @@ +import mitogen.core import mitogen.select import testlib diff --git a/tests/setns_test.py b/tests/setns_test.py index 174dcbb9..b0161ef8 100644 --- a/tests/setns_test.py +++ b/tests/setns_test.py @@ -1,11 +1,8 @@ - -import os import socket import sys import unittest -import mitogen -import mitogen.parent +import mitogen.core import testlib diff --git a/tests/signals_test.py b/tests/signals_test.py index ad1cfe6f..bf842e20 100644 --- a/tests/signals_test.py +++ b/tests/signals_test.py @@ -1,4 +1,3 @@ - import testlib import mitogen.core diff --git a/tests/soak/cpu_load.py b/tests/soak/cpu_load.py index 5a86fd0e..cfc65896 100644 --- a/tests/soak/cpu_load.py +++ b/tests/soak/cpu_load.py @@ -7,7 +7,6 @@ weirdness. Useful for exposing otherwise difficult to hit races in the library. import ctypes import multiprocessing import os -import time LIBC = ctypes.CDLL('libc.so.6') sched_yield = LIBC.sched_yield diff --git a/tests/ssh_test.py b/tests/ssh_test.py index 9b1cabf3..c1a0b9eb 100644 --- a/tests/ssh_test.py +++ b/tests/ssh_test.py @@ -1,8 +1,6 @@ import os -import sys import tempfile -import mitogen import mitogen.ssh import mitogen.utils diff --git a/tests/su_test.py b/tests/su_test.py index ed12be50..d8952b53 100644 --- a/tests/su_test.py +++ b/tests/su_test.py @@ -1,7 +1,6 @@ - import os -import mitogen +import mitogen.core import mitogen.su import testlib diff --git a/tests/sudo_test.py b/tests/sudo_test.py index 748211b8..2df05ec7 100644 --- a/tests/sudo_test.py +++ b/tests/sudo_test.py @@ -1,9 +1,5 @@ - import os -import mitogen -import mitogen.sudo - import testlib diff --git a/tests/testlib.py b/tests/testlib.py index e90396b2..8ab895c4 100644 --- a/tests/testlib.py +++ b/tests/testlib.py @@ -1,4 +1,3 @@ - import errno import logging import os @@ -64,14 +63,6 @@ if faulthandler is not None: mitogen.core.LOG.propagate = True - -def get_fd_count(): - """ - Return the number of FDs open by this process. - """ - return psutil.Process().num_fds() - - def data_path(suffix): path = os.path.join(DATA_DIR, suffix) if path.endswith('.key'): @@ -341,7 +332,7 @@ class TestCase(unittest.TestCase): # This is done in setUpClass() so we have a chance to run before any # Broker() instantiations in setUp() etc. mitogen.fork.on_fork() - cls._fd_count_before = get_fd_count() + cls._fds_before = psutil.Process().open_files() # Ignore children started by external packages - in particular # multiprocessing.resource_tracker.main()`, started when some Ansible # versions instantiate a `multithreading.Lock()`. @@ -372,7 +363,11 @@ class TestCase(unittest.TestCase): def _teardown_check_fds(self): mitogen.core.Latch._on_fork() - if get_fd_count() != self._fd_count_before: + fds_after = psutil.Process().open_files() + fds_leaked = len(self._fds_before) != len(fds_after) + if not fds_leaked: + return + else: if sys.platform == 'linux': subprocess.check_call( 'lsof +E -w -p %i | grep -vw mem' % (os.getpid(),), @@ -383,8 +378,8 @@ class TestCase(unittest.TestCase): 'lsof -w -p %i | grep -vw mem' % (os.getpid(),), shell=True, ) - assert 0, "%s leaked FDs. Count before: %s, after: %s" % ( - self, self._fd_count_before, get_fd_count(), + assert 0, "%s leaked FDs: %s\nBefore:\t%s\nAfter:\t%s" % ( + self, fds_leaked, self._fds_before, fds_after, ) # Some class fixtures (like Ansible MuxProcess) start persistent children diff --git a/tests/timer_test.py b/tests/timer_test.py index af8c5e19..ff30c905 100644 --- a/tests/timer_test.py +++ b/tests/timer_test.py @@ -1,6 +1,3 @@ - -import time - import mock import mitogen.core diff --git a/tests/two_three_compat_test.py b/tests/two_three_compat_test.py index 694db163..4490e5d2 100644 --- a/tests/two_three_compat_test.py +++ b/tests/two_three_compat_test.py @@ -1,5 +1,4 @@ import mitogen.core -import mitogen.master import testlib import simple_pkg.ping diff --git a/tests/types_test.py b/tests/types_test.py index 3c6c4cd2..7c212b70 100644 --- a/tests/types_test.py +++ b/tests/types_test.py @@ -1,4 +1,3 @@ - import sys try: diff --git a/tests/unix_test.py b/tests/unix_test.py index f65079c8..aecc62ba 100644 --- a/tests/unix_test.py +++ b/tests/unix_test.py @@ -1,4 +1,3 @@ - import os import socket import subprocess diff --git a/tests/utils_test.py b/tests/utils_test.py index 2c7f70b7..8ff730ef 100644 --- a/tests/utils_test.py +++ b/tests/utils_test.py @@ -1,12 +1,4 @@ -#!/usr/bin/env python - -import os -import tempfile - -import mock - import mitogen.core -import mitogen.parent import mitogen.master import mitogen.utils from mitogen.core import b