Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
moreati committed Sep 10, 2022
2 parents 7dfc4a2 + 4a5d529 commit dcab8e5
Show file tree
Hide file tree
Showing 24 changed files with 116 additions and 84 deletions.
12 changes: 6 additions & 6 deletions .ci/azure-pipelines-steps.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@

parameters:
name: ''
pool: ''
sign: false

steps:
- task: UsePythonVersion@0
displayName: Install python
inputs:
versionSpec: '$(python.version)'
condition: ne(variables['python.version'], '')

- script: |
sudo apt-get update
sudo apt-get install -y python2-dev
displayName: Install build deps
condition: and(eq(variables['python.version'], ''), eq(variables['Agent.OS'], 'Linux'))

- script: python -mpip install tox
displayName: Install tooling

Expand Down
62 changes: 4 additions & 58 deletions .ci/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,61 +9,18 @@
#ANSIBLE_VERBOSITY: 3

jobs:
- job: Mac1015
- job: mac11
# vanilla Ansible is really slow
timeoutInMinutes: 120
steps:
- template: azure-pipelines-steps.yml
pool:
# https://github.com/actions/virtual-environments/blob/main/images/macos/macos-10.15-Readme.md
vmImage: macOS-10.15
strategy:
matrix:
Mito_27:
python.version: '2.7'
tox.env: py27-mode_mitogen
Mito_36:
python.version: '3.6'
tox.env: py36-mode_mitogen
Mito_310:
python.version: '3.10'
tox.env: py310-mode_mitogen

# TODO: test python3, python3 tests are broken
Loc_27_210:
python.version: '2.7'
tox.env: py27-mode_localhost-ansible2.10
Loc_27_4:
python.version: '2.7'
tox.env: py27-mode_localhost-ansible4

# NOTE: this hangs when ran in Ubuntu 18.04
Van_27_210:
python.version: '2.7'
tox.env: py27-mode_localhost-ansible2.10
STRATEGY: linear
ANSIBLE_SKIP_TAGS: resource_intensive
Van_27_4:
python.version: '2.7'
tox.env: py27-mode_localhost-ansible4
STRATEGY: linear
ANSIBLE_SKIP_TAGS: resource_intensive

- job: Mac11
# vanilla Ansible is really slow
timeoutInMinutes: 120
steps:
- template: azure-pipelines-steps.yml
pool:
# https://github.com/actions/virtual-environments/blob/main/images/macos/
# https://github.com/actions/runner-images/blob/main/images/macos/macos-11-Readme.md
vmImage: macOS-11
strategy:
matrix:
Mito_27:
tox.env: py27-mode_mitogen
Mito_37:
python.version: '3.7'
tox.env: py37-mode_mitogen
Mito_310:
python.version: '3.10'
tox.env: py310-mode_mitogen
Expand All @@ -86,38 +43,29 @@ jobs:

- job: Linux
pool:
# https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu1804-README.md
vmImage: "Ubuntu 18.04"
# https://github.com/actions/runner-images/blob/main/images/linux/Ubuntu2004-Readme.md
vmImage: ubuntu-20.04
steps:
- template: azure-pipelines-steps.yml
strategy:
matrix:
Mito_27_centos6:
python.version: '2.7'
tox.env: py27-mode_mitogen-distro_centos6
Mito_27_centos7:
python.version: '2.7'
tox.env: py27-mode_mitogen-distro_centos7
Mito_27_centos8:
python.version: '2.7'
tox.env: py27-mode_mitogen-distro_centos8
Mito_27_debian9:
python.version: '2.7'
tox.env: py27-mode_mitogen-distro_debian9
Mito_27_debian10:
python.version: '2.7'
tox.env: py27-mode_mitogen-distro_debian10
Mito_27_debian11:
python.version: '2.7'
tox.env: py27-mode_mitogen-distro_debian11
Mito_27_ubuntu1604:
python.version: '2.7'
tox.env: py27-mode_mitogen-distro_ubuntu1604
Mito_27_ubuntu1804:
python.version: '2.7'
tox.env: py27-mode_mitogen-distro_ubuntu1804
Mito_27_ubuntu2004:
python.version: '2.7'
tox.env: py27-mode_mitogen-distro_ubuntu2004

Mito_36_centos6:
Expand Down Expand Up @@ -177,10 +125,8 @@ jobs:
tox.env: py310-mode_mitogen-distro_ubuntu2004

Ans_27_210:
python.version: '2.7'
tox.env: py27-mode_ansible-ansible2.10
Ans_27_4:
python.version: '2.7'
tox.env: py27-mode_ansible-ansible4

Ans_36_210:
Expand Down
18 changes: 18 additions & 0 deletions ansible_mitogen/plugins/connection/mitogen_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,24 @@
accepts.
version_added: "2.5"
options:
ssh_args:
type: str
vars:
- name: ssh_args
- name: ansible_ssh_args
- name: ansible_mitogen_ssh_args
ssh_common_args:
type: str
vars:
- name: ssh_args
- name: ansible_ssh_common_args
- name: ansible_mitogen_ssh_common_args
ssh_extra_args:
type: str
vars:
- name: ssh_args
- name: ansible_ssh_extra_args
- name: ansible_mitogen_ssh_extra_args
"""

try:
Expand Down
2 changes: 1 addition & 1 deletion tests/ansible/hosts/group_vars/all.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
pkg_mgr_python_interpreter: /usr/bin/python
pkg_mgr_python_interpreter: python
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils import external3
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

import json
import ansible.module_utils.basic
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python
# I am an Ansible new-style Python module. I return details about the Python
# interpreter I run within.

Expand Down
2 changes: 1 addition & 1 deletion tests/ansible/lib/modules/custom_python_external_module.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python
# I expect the quote from modules2/module_utils/joker.py.

from ansible.module_utils.basic import AnsibleModule
Expand Down
2 changes: 1 addition & 1 deletion tests/ansible/lib/modules/custom_python_external_pkg.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.externalpkg import extmod
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python
# I am an Ansible Python JSONARGS module. I should receive an encoding string.

json_arguments = """<<INCLUDE_ANSIBLE_MODULE_JSON_ARGS>>"""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python
# I am an Ansible new-style Python module. I leak state from each invocation
# into a class variable and a global variable.

Expand Down
2 changes: 1 addition & 1 deletion tests/ansible/lib/modules/custom_python_modify_environ.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python
# I am an Ansible new-style Python module. I modify the process environment and
# don't clean up after myself.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python
# I am an Ansible new-style Python module. I should receive an encoding string.

import sys
Expand Down
2 changes: 1 addition & 1 deletion tests/ansible/lib/modules/custom_python_os_getcwd.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python
# #591: call os.getcwd() before AnsibleModule ever gets a chance to fix up the
# process environment.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python
# issue #555: I'm a module that cutpastes an old hack.

from ansible.module_utils.basic import AnsibleModule
Expand Down
2 changes: 1 addition & 1 deletion tests/ansible/lib/modules/custom_python_run_script.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python
# I am an Ansible new-style Python module. I run the script provided in the
# parameter.

Expand Down
2 changes: 1 addition & 1 deletion tests/ansible/lib/modules/custom_python_uses_distro.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python
# issue #590: I am an Ansible new-style Python module that tries to use
# ansible.module_utils.distro.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python
# I am an Ansible Python WANT_JSON module. I should receive a JSON-encoded file.

import sys
Expand Down
2 changes: 1 addition & 1 deletion tests/ansible/lib/modules/mitogen_test_gethostbyname.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

# I am a module that indirectly depends on glibc cached /etc/resolv.conf state.

Expand Down
2 changes: 1 addition & 1 deletion tests/ansible/lib/modules/test_echo_module.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# (c) 2012, Michael DeHaan <michael.dehaan@gmail.com>
Expand Down
2 changes: 1 addition & 1 deletion tests/ansible/tests/connection_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def make_connection(self):
conn = self.klass(play_context, new_stdin=False)
# conn functions don't fetch ActionModuleMixin objs from _get_task_vars()
# through the usual walk-the-stack approach so we'll not run interpreter discovery here
conn._action = mock.MagicMock(_possible_python_interpreter='/usr/bin/python')
conn._action = mock.MagicMock(_possible_python_interpreter=testlib.base_executable())
conn.on_action_run(
task_vars={},
delegate_to_hostname=None,
Expand Down
2 changes: 1 addition & 1 deletion tests/data/minimize_samples/hashbang.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#/usr/bin/python -c
#/usr/bin/env python -c
# coding: utf-8
# comment
2 changes: 1 addition & 1 deletion tests/data/minimize_samples/hashbang_min.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#/usr/bin/python -c
#/usr/bin/env python -c
# coding: utf-8

68 changes: 68 additions & 0 deletions tests/testlib.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import errno
import io
import logging
import os
import random
import re
import socket
import stat
import sys
import threading
import time
import traceback
import unittest

try:
import configparser
except ImportError:
import ConfigParser as configparser

import psutil
import subprocess32 as subprocess

Expand Down Expand Up @@ -62,6 +69,67 @@
mitogen.core.LOG.propagate = True


def base_executable(executable=None):
'''Return the path of the Python executable used to create the virtualenv.
'''
# https://docs.python.org/3/library/venv.html
# https://github.com/pypa/virtualenv/blob/main/src/virtualenv/discovery/py_info.py
# https://virtualenv.pypa.io/en/16.7.9/reference.html#compatibility-with-the-stdlib-venv-module
if executable is None:
executable = sys.executable

if not executable:
raise ValueError

try:
base_executable = sys._base_executable
except AttributeError:
base_executable = None

if base_executable and base_executable != executable:
return 'be', base_executable

# Python 2.x only has sys.base_prefix if running outside a virtualenv.
try:
sys.base_prefix
except AttributeError:
# Python 2.x outside a virtualenv
return executable

# Python 3.3+ has sys.base_prefix. In a virtualenv it differs to sys.prefix.
if sys.base_prefix == sys.prefix:
return executable

while executable.startswith(sys.prefix) and stat.S_ISLNK(os.lstat(executable).st_mode):
dirname = os.path.dirname(executable)
target = os.path.join(dirname, os.readlink(executable))
executable = os.path.abspath(os.path.normpath(target))
print(executable)

if executable.startswith(sys.base_prefix):
return executable

# Virtualenvs record details in pyvenv.cfg
parser = configparser.RawConfigParser()
with io.open(os.path.join(sys.prefix, 'pyvenv.cfg'), encoding='utf-8') as f:
content = u'[virtualenv]\n' + f.read()
try:
parser.read_string(content)
except AttributeError:
parser.readfp(io.StringIO(content))

# virtualenv style pyvenv.cfg includes the base executable.
# venv style pyvenv.cfg doesn't.
try:
return parser.get(u'virtualenv', u'base-executable')
except configparser.NoOptionError:
pass

basename = os.path.basename(executable)
home = parser.get(u'virtualenv', u'home')
return os.path.join(home, basename)


def data_path(suffix):
path = os.path.join(DATA_DIR, suffix)
if path.endswith('.key'):
Expand Down

0 comments on commit dcab8e5

Please sign in to comment.