Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
moreati committed Dec 18, 2024
1 parent 2e9e6a7 commit 3fe01d7
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 104 deletions.
5 changes: 0 additions & 5 deletions .ci/ansible_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ def pause_if_interactive():
interesting = ci_lib.get_interesting_procs()


with ci_lib.Fold('unit_tests'):
os.environ['SKIP_MITOGEN'] = '1'
ci_lib.run('./run_tests -v')


ci_lib.check_stray_processes(interesting)


Expand Down
5 changes: 0 additions & 5 deletions .ci/localhost_ansible_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@
KEY_PATH = os.path.join(TESTS_DIR, '../data/docker/mitogen__has_sudo_pubkey.key')


with ci_lib.Fold('unit_tests'):
os.environ['SKIP_MITOGEN'] = '1'
ci_lib.run('./run_tests -v')


with ci_lib.Fold('job_setup'):
os.chmod(KEY_PATH, int('0600', 8))
# NOTE: sshpass v1.06 causes errors so pegging to 1.05 -> "msg": "Error when changing password","out": "passwd: DS error: eDSAuthFailed\n",
Expand Down
58 changes: 0 additions & 58 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,62 +24,10 @@ jobs:
fail-fast: false
matrix:
include:
- name: Ans_27_210
tox_env: py27-mode_ansible-ansible2.10
- name: Ans_27_4
tox_env: py27-mode_ansible-ansible4

- name: Ans_36_210
python_version: '3.6'
tox_env: py36-mode_ansible-ansible2.10
- name: Ans_36_4
python_version: '3.6'
tox_env: py36-mode_ansible-ansible4

- name: Ans_311_210
python_version: '3.11'
tox_env: py311-mode_ansible-ansible2.10
- name: Ans_311_3
python_version: '3.11'
tox_env: py311-mode_ansible-ansible3
- name: Ans_311_4
python_version: '3.11'
tox_env: py311-mode_ansible-ansible4
- name: Ans_311_5
python_version: '3.11'
tox_env: py311-mode_ansible-ansible5
- name: Ans_313_6
python_version: '3.13'
tox_env: py313-mode_ansible-ansible6
- name: Ans_313_7
python_version: '3.13'
tox_env: py313-mode_ansible-ansible7
- name: Ans_313_8
python_version: '3.13'
tox_env: py313-mode_ansible-ansible8
- name: Ans_313_9
python_version: '3.13'
tox_env: py313-mode_ansible-ansible9
- name: Ans_313_10
python_version: '3.13'
tox_env: py313-mode_ansible-ansible10
- name: Ans_313_11
python_version: '3.13'
tox_env: py313-mode_ansible-ansible11

- name: Van_313_11
python_version: '3.13'
tox_env: py313-mode_ansible-ansible11-strategy_linear

- name: Mito_27
tox_env: py27-mode_mitogen
- name: Mito_36
python_version: '3.6'
tox_env: py36-mode_mitogen
- name: Mito_313
python_version: '3.13'
tox_env: py313-mode_mitogen

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
Expand Down Expand Up @@ -171,12 +119,6 @@ jobs:
- name: Mito_313
tox_env: py313-mode_mitogen

- name: Loc_313_11
tox_env: py313-mode_localhost-ansible11

- name: Van_313_11
tox_env: py313-mode_localhost-ansible11-strategy_linear

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
Expand Down
21 changes: 18 additions & 3 deletions ansible_mitogen/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import ansible.constants as C
import ansible.errors
import ansible.plugins.connection
from ansible.utils.display import Display

import mitogen.core

Expand All @@ -53,6 +54,8 @@
import ansible_mitogen.utils.unsafe


display = Display()

LOG = logging.getLogger(__name__)

task_vars_msg = (
Expand Down Expand Up @@ -958,13 +961,25 @@ def reset(self):
self._action_monkey_patched_by_mitogen = True

# Workaround for https://github.com/ansible/ansible/issues/84238
self.set_options(
task_keys=task.dump_attrs(),
var_options=self._mitogen_var_options(templar),
task_keys = task.dump_attrs()
var_options = self._mitogen_var_options(templar)
display.warning(
'foo task_keys %r var_options %r connection/remote_user=%r'
% (
{k: v for k, v in task_keys.items() if 'user' in k},
{k: v for k, v in var_options.items() if 'user' in k},
self.get_option('remote_user'),
),
)
#task_keys['timeout'] = self._play_context.timeout
del task_keys['retries']
self.set_options(task_keys=task_keys, var_options=var_options)
display.warning('bar %r' % self.get_option('timeout'))

del task
del task_keys
del templar
del var_options

# Clear out state in case we were ever connected.
self.close()
Expand Down
8 changes: 5 additions & 3 deletions ansible_mitogen/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,10 @@ def reset(self, stack):
key = key_from_dict(via=context, **spec)
response = self._response_by_key.get(key)
if response is None:
LOG.debug('%r: could not find connection to shut down; '
'failed at hop %d', self, i)
LOG.warning('%r: could not find connection to shut down; '
'failed at hop %d, key %r', self, i, key)
LOG.warning('%r', stack)
LOG.warning('%r', self._response_by_key)
return False

context = response['context']
Expand Down Expand Up @@ -325,7 +327,7 @@ def _on_context_disconnect(self, context):
"""
self._lock.acquire()
try:
LOG.info('%r: Forgetting %r due to stream disconnect', self, context)
#LOG.info('%r: Forgetting %r due to stream disconnect', self, context)
self._forget_context_unlocked(context)
finally:
self._lock.release()
Expand Down
8 changes: 6 additions & 2 deletions ansible_mitogen/strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def run(self, iterator, play_context, result=0):
finally:
ansible_mitogen.process.set_worker_model(None)

def _smuggle_to_connction_reset(self, task, play_context, iterator, target_host):
def _smuggle_to_connection_reset(self, task, play_context, iterator, target_host):
# Workaround for https://github.com/ansible/ansible/issues/84238
variables = self._variable_manager.get_vars(
play=iterator._play, host=target_host, task=task,
Expand All @@ -337,13 +337,17 @@ def _smuggle_to_connction_reset(self, task, play_context, iterator, target_host)
templar = ansible.template.Templar(
loader=self._loader, variables=variables,
)
play_context = play_context.set_task_and_variable_override(task=task, variables=variables, templar=templar)
play_context.post_validate(templar=templar)
play_context.update_vars(variables)
play_context.vars.update({
'_mitogen.smuggled.reset_connection': (task, templar),
})
return play_context

def _execute_meta(self, task, play_context, iterator, target_host):
if task.args['_raw_params'] == 'reset_connection':
self._smuggle_to_connction_reset(task, play_context, iterator, target_host)
play_context = self._smuggle_to_connection_reset(task, play_context, iterator, target_host)

return super(StrategyMixin, self)._execute_meta(
task, play_context, iterator, target_host,
Expand Down
15 changes: 11 additions & 4 deletions ansible_mitogen/transport_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
import ansible.utils.shlex
import ansible.constants as C
import ansible.executor.interpreter_discovery
import ansible.utils.display
import ansible.utils.unsafe_proxy

from ansible.module_utils.six import with_metaclass
Expand All @@ -78,6 +79,8 @@

LOG = logging.getLogger(__name__)

display = ansible.utils.display.Display()


def run_interpreter_discovery_if_necessary(s, task_vars, action, rediscover_python):
"""
Expand Down Expand Up @@ -469,7 +472,9 @@ def remote_addr(self):
return self._connection_option('host', fallback_attr='remote_addr')

def remote_user(self):
return self._connection_option('remote_user')
result = self._connection_option('remote_user')
display.warning('%s.remote_user() -> %r' % (self.__class__.__name__, result))
return result

def become(self):
return self._connection.become
Expand Down Expand Up @@ -659,11 +664,13 @@ def remote_addr(self):
)

def remote_user(self):
return (
result = (
self._host_vars.get('ansible_ssh_user') or
self._host_vars.get('ansible_user') or
C.DEFAULT_REMOTE_USER
)
display.warning('%s.remote_user() -> %r' % (self.__class__.__name__, result))
return result

def become(self):
return bool(self._become_user)
Expand Down Expand Up @@ -737,8 +744,8 @@ def timeout(self):

def ansible_ssh_timeout(self):
return (
self._host_vars.get('ansible_timeout') or
self._host_vars.get('ansible_ssh_timeout') or
# self._host_vars.get('ansible_timeout') or
# self._host_vars.get('ansible_ssh_timeout') or
self.timeout()
)

Expand Down
4 changes: 0 additions & 4 deletions tests/ansible/all.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,2 @@
- import_playbook: setup/all.yml
tags: setup
- import_playbook: regression/all.yml
tags: regression
- import_playbook: integration/all.yml
tags: integration
19 changes: 0 additions & 19 deletions tests/ansible/regression/all.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1 @@
- import_playbook: issue_109__target_has_old_ansible_installed.yml
- import_playbook: issue_113__duplicate_module_imports.yml
- import_playbook: issue_118__script_not_marked_exec.yml
- import_playbook: issue_122__environment_difference.yml
- import_playbook: issue_140__thread_pileup.yml
- import_playbook: issue_152__local_action_wrong_interpreter.yml
- import_playbook: issue_152__virtualenv_python_fails.yml
- import_playbook: issue_154__module_state_leaks.yml
- import_playbook: issue_177__copy_module_failing.yml
- import_playbook: issue_332_ansiblemoduleerror_first_occurrence.yml
- import_playbook: issue_558_unarchive_failed.yml
- import_playbook: issue_590__sys_modules_crap.yml
- import_playbook: issue_591__setuptools_cwd_crash.yml
- import_playbook: issue_615__streaming_transfer.yml
- import_playbook: issue_655__wait_for_connection_error.yml
- import_playbook: issue_776__load_plugins_called_twice.yml
- import_playbook: issue_952__ask_become_pass.yml
- import_playbook: issue_1066__add_host__host_key_checking.yml
- import_playbook: issue_1079__wait_for_connection_timeout.yml
- import_playbook: issue_1087__template_streamerror.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
- env.cwd == ansible_user_dir
- (not env.mitogen_loaded) or (env.python_path.count("") == 1)
fail_msg: |
ansible_user_dir={{ ansible_user_dir }}
env={{ env }}
- name: Run some new-style from ansible.module_utils... modules
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ setenv =
# Ansible 10 (ansible-core 2.17) requires Python >= 3.7 on targets
ansible10: MITOGEN_TEST_DISTRO_SPECS=debian10-py3 debian11-py3 ubuntu2004-py3
# Ansible 11 (ansible-core 2.18) requires Python >= 3.8 on targets
ansible11: MITOGEN_TEST_DISTRO_SPECS=debian11-py3 ubuntu2004-py3
ansible11: MITOGEN_TEST_DISTRO_SPECS=ubuntu2004-py3
distros_centos: MITOGEN_TEST_DISTRO_SPECS=centos6 centos7 centos8
distros_centos5: MITOGEN_TEST_DISTRO_SPECS=centos5
distros_centos6: MITOGEN_TEST_DISTRO_SPECS=centos6
Expand Down

0 comments on commit 3fe01d7

Please sign in to comment.