Skip to content

Commit 6e105be

Browse files
committed
WIP
1 parent 67c7bd0 commit 6e105be

File tree

6 files changed

+26
-106
lines changed

6 files changed

+26
-106
lines changed

.github/workflows/tests.yml

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ on:
99
- docs-master
1010

1111
env:
12-
#ANSIBLE_VERBOSITY: 3
12+
ANSIBLE_VERBOSITY: 3
1313
#MITOGEN_LOG_LEVEL: DEBUG
1414
MITOGEN_TEST_IMAGE_TEMPLATE: "ghcr.io/mitogen-hq/%(distro)s-test"
1515

@@ -26,43 +26,7 @@ jobs:
2626
include:
2727
- name: Ans_27_210
2828
tox_env: py27-mode_ansible-ansible2.10
29-
- name: Ans_27_4
30-
tox_env: py27-mode_ansible-ansible4
31-
32-
- name: Ans_36_210
33-
python_version: '3.6'
34-
tox_env: py36-mode_ansible-ansible2.10
35-
- name: Ans_36_4
36-
python_version: '3.6'
37-
tox_env: py36-mode_ansible-ansible4
38-
39-
- name: Ans_311_210
40-
python_version: '3.11'
41-
tox_env: py311-mode_ansible-ansible2.10
42-
- name: Ans_311_3
43-
python_version: '3.11'
44-
tox_env: py311-mode_ansible-ansible3
45-
- name: Ans_311_4
46-
python_version: '3.11'
47-
tox_env: py311-mode_ansible-ansible4
48-
- name: Ans_311_5
49-
python_version: '3.11'
50-
tox_env: py311-mode_ansible-ansible5
51-
- name: Ans_313_6
52-
python_version: '3.13'
53-
tox_env: py313-mode_ansible-ansible6
54-
- name: Ans_313_7
55-
python_version: '3.13'
56-
tox_env: py313-mode_ansible-ansible7
57-
- name: Ans_313_8
58-
python_version: '3.13'
59-
tox_env: py313-mode_ansible-ansible8
60-
- name: Ans_313_9
61-
python_version: '3.13'
62-
tox_env: py313-mode_ansible-ansible9
63-
- name: Ans_313_10
64-
python_version: '3.13'
65-
tox_env: py313-mode_ansible-ansible10
29+
6630
- name: Ans_313_11
6731
python_version: '3.13'
6832
tox_env: py313-mode_ansible-ansible11
@@ -71,15 +35,6 @@ jobs:
7135
python_version: '3.13'
7236
tox_env: py313-mode_ansible-ansible11-strategy_linear
7337

74-
- name: Mito_27
75-
tox_env: py27-mode_mitogen
76-
- name: Mito_36
77-
python_version: '3.6'
78-
tox_env: py36-mode_mitogen
79-
- name: Mito_313
80-
python_version: '3.13'
81-
tox_env: py313-mode_mitogen
82-
8338
steps:
8439
- uses: actions/checkout@v4
8540
- uses: actions/setup-python@v5
@@ -171,12 +126,6 @@ jobs:
171126
- name: Mito_313
172127
tox_env: py313-mode_mitogen
173128

174-
- name: Loc_313_11
175-
tox_env: py313-mode_localhost-ansible11
176-
177-
- name: Van_313_11
178-
tox_env: py313-mode_localhost-ansible11-strategy_linear
179-
180129
steps:
181130
- uses: actions/checkout@v4
182131
- uses: actions/setup-python@v5

ansible_mitogen/mixins.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -460,23 +460,27 @@ def _low_level_execute_command(self, cmd, sudoable=True, in_data=None,
460460
# chicken-and-egg issue, mitogen needs a python to run low_level_execute_command
461461
# which is required by Ansible's discover_interpreter function
462462
if self._mitogen_discovering_interpreter:
463-
possible_pythons = [
464-
'python3',
465-
'python2',
466-
'python'
467-
]
463+
if self._connection.transport in {'ssh'}:
464+
possible_pythons = [
465+
'$(for p in python3 python2 python; do command -v "$p" 2>/dev/null && break; done;)',
466+
]
467+
else:
468+
possible_pythons = ['python3' 'python2', 'python']
468469
else:
469470
# not used, just adding a filler value
470471
possible_pythons = ['python']
471472

472473
for possible_python in possible_pythons:
473474
try:
475+
LOG.debug('_low_level_execute_command(): trying %s', possible_python)
474476
self._mitogen_interpreter_candidate = possible_python
475477
rc, stdout, stderr = self._connection.exec_command(
476478
cmd, in_data, sudoable, mitogen_chdir=chdir,
477479
)
480+
LOG.debug('_low_level_execute_command(): got rc=%d, stdout=%r, stderr=%r', rc, stdout, stderr)
478481
# TODO: what exception is thrown?
479-
except:
482+
except BaseException as exc:
483+
LOG.debug('%r._low_level_execute_command for possible_python=%r: %s, %r', self, possible_python, type(exc), exc)
480484
# we've reached the last python attempted and failed
481485
if possible_python == possible_pythons[-1]:
482486
raise

mitogen/parent.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,7 +1454,7 @@ def get_python_argv(self):
14541454
return self.options.python_path
14551455
return [self.options.python_path]
14561456

1457-
def get_boot_command(self):
1457+
def _first_stage_base64(self):
14581458
source = inspect.getsource(self._first_stage)
14591459
source = textwrap.dedent('\n'.join(source.strip().split('\n')[2:]))
14601460
source = source.replace(' ', ' ')
@@ -1464,17 +1464,23 @@ def get_boot_command(self):
14641464
str(len(preamble_compressed)))
14651465
compressed = zlib.compress(source.encode(), 9)
14661466
encoded = binascii.b2a_base64(compressed).replace(b('\n'), b(''))
1467+
return encoded.decode('ascii')
14671468

1469+
def _bootstrap_argv(self):
14681470
# Just enough to decode, decompress, and exec the first stage.
14691471
# Priorities: wider compatibility, faster startup, shorter length.
14701472
# `import os` here, instead of stage 1, to save a few bytes.
14711473
# `sys.path=...` for https://github.com/python/cpython/issues/115911.
1472-
return self.get_python_argv() + [
1474+
return [
14731475
'-c',
14741476
'import sys;sys.path=[p for p in sys.path if p];import binascii,os,zlib;'
1475-
'exec(zlib.decompress(binascii.a2b_base64("%s")))' % (encoded.decode(),),
1477+
'exec(zlib.decompress(binascii.a2b_base64(sys.argv[1])))',
1478+
self._first_stage_base64(),
14761479
]
14771480

1481+
def get_boot_command(self):
1482+
return self.get_python_argv() + self._bootstrap_argv()
1483+
14781484
def get_econtext_config(self):
14791485
assert self.options.max_message_size is not None
14801486
parent_ids = mitogen.parent_ids[:]
@@ -1510,7 +1516,7 @@ def _get_name(self):
15101516

15111517
def start_child(self):
15121518
args = self.get_boot_command()
1513-
LOG.debug('command line for %r: %s', self, Argv(args))
1519+
LOG.debug('command line for %r: %s', self, args)
15141520
try:
15151521
return self.create_child(args=args, **self.create_child_args)
15161522
except OSError:

mitogen/ssh.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,8 @@ def get_boot_command(self):
296296
if self.options.ssh_args:
297297
bits += self.options.ssh_args
298298
bits.append(self.options.hostname)
299-
base = super(Connection, self).get_boot_command()
300299

301-
base_parts = []
302-
for s in base:
303-
val = s if s in self.SHLEX_IGNORE else shlex_quote(s).strip()
304-
base_parts.append(val)
305-
return bits + base_parts
300+
# https://datatracker.ietf.org/doc/html/rfc4254#section-6.5
301+
python_argv = self.get_python_argv()
302+
bootstrap_argv = self._bootstrap_argv()
303+
return bits + python_argv + [shlex_quote(s) for s in bootstrap_argv]

tests/ansible/all.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
- import_playbook: setup/all.yml
22
tags: setup
3-
- import_playbook: regression/all.yml
4-
tags: regression
53
- import_playbook: integration/all.yml
64
tags: integration

tests/ansible/integration/all.yml

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,5 @@
22
#
33
# This playbook imports all tests that are known to work at present.
44
#
5-
6-
- import_playbook: action/all.yml
7-
tags: action
8-
- import_playbook: async/all.yml
9-
tags: async
10-
- import_playbook: become/all.yml
11-
tags: become
12-
- import_playbook: connection/all.yml
13-
tags: connection
14-
- import_playbook: connection_delegation/all.yml
15-
tags: connection_delegation
16-
- import_playbook: connection_loader/all.yml
17-
tags: connection_loader
18-
- import_playbook: context_service/all.yml
19-
tags: context_service
20-
- import_playbook: glibc_caches/all.yml
21-
tags: glibc_caches
225
- import_playbook: interpreter_discovery/all.yml
236
tags: interpreter_discovery
24-
- import_playbook: local/all.yml
25-
tags: local
26-
- import_playbook: module_utils/all.yml
27-
tags: module_utils
28-
- import_playbook: playbook_semantics/all.yml
29-
tags: playbook_semantics
30-
- import_playbook: process/all.yml
31-
tags: process
32-
- import_playbook: runner/all.yml
33-
tags: runner
34-
- import_playbook: ssh/all.yml
35-
tags: ssh
36-
- import_playbook: strategy/all.yml
37-
tags: strategy
38-
- import_playbook: stub_connections/all.yml
39-
tags: stub_connections
40-
- import_playbook: transport_config/all.yml
41-
tags: transport_config

0 commit comments

Comments
 (0)