Skip to content

Commit

Permalink
Add regression tests for the new connection logic.
Browse files Browse the repository at this point in the history
Co-authored-by: Alex Willmer <[email protected]>
Co-authored-by: Mark Farrell <[email protected]>
  • Loading branch information
3 people committed Jan 20, 2025
1 parent 8ebeaff commit 211079f
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 2 deletions.
1 change: 1 addition & 0 deletions tests/ansible/regression/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- 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_766__get_with_context.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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
tasks:
- meta: end_play
when:
# Podman versions available in Homebrew have dropped macOS 12 support.
# Podman versions available in Homebrew require macOS 13+ (Ventura).
# https://formulae.brew.sh/formula/podman
# See also
# - issue_766__get_with_context.yml
- ansible_facts.system == 'Darwin'
- ansible_facts.distribution_version is version('13.0', '<', strict=True)

Expand Down
64 changes: 64 additions & 0 deletions tests/ansible/regression/issue_766__get_with_context.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# https://github.com/mitogen-hq/mitogen/issues/776
---
- name: regression/issue_766__get_with_context.yml
hosts: localhost
# Gather facts to use *and* to trigger any "could not recover task_vars" error
# https://github.com/mitogen-hq/mitogen/pull/1215#issuecomment-2596421111
gather_facts: true
vars:
netconf_container_image: ghcr.io/mitogen-hq/sysrepo-netopeer2:latest
netconf_container_name: sysprep
netconf_container_port: 8030

tasks:
- meta: end_play
when:
# Podman can be installed on macOS, but authenticating to gchr.io isn't
# worth the trouble right now.
# See also
# - issue_655__wait_for_connection_error.yml
- ansible_facts.system == 'Darwin'

- meta: end_play
when:
# A failure during the ansible.netcommon.netconf_get task, when run
# with Ansible 4 (ansible-core 2.11) & associated collections.
# ansible.module_utils.connection.ConnectionError: Method not found
# https://github.com/mitogen-hq/mitogen/actions/runs/12854359099/job/35838635886
- ansible_version.full is version('2.11', '>=', strict=True)
- ansible_version.full is version('2.12', '<', strict=True)

- block:
- name: Start container
command:
cmd: >-
podman run
--name "{{ netconf_container_name }}"
--detach
--rm
--publish "{{ netconf_container_port }}:830"
"{{ netconf_container_image }}"
changed_when: true

- name: Wait for container
# TODO robust condition. wait_for + search_regex? wait_for_connection?
wait_for:
timeout: 5

- name: Get running configuration and state data
vars:
ansible_connection: netconf
ansible_user: netconf
ansible_password: netconf
ansible_port: "{{ netconf_container_port }}"
ansible_host_key_checking: false
ansible_python_interpreter: "{{ ansible_playbook_python }}"
ansible.netcommon.netconf_get:

always:
- name: Cleanup container
command:
cmd: podman stop "{{ netconf_container_name }}"
changed_when: true
tags:
- issue_766
8 changes: 7 additions & 1 deletion tests/ansible/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
paramiko==2.3.2 # Last 2.6-compat version.
paramiko==2.12.0; python_version <= '2.7'
paramiko==3.5.0; python_version >= '3.6'

# Incompatible with pip >= 72, due to removal of `setup.py test`:
# ModuleNotFoundError: No module named 'setuptools.command.test'
# https://github.com/pypa/setuptools/issues/4519
hdrhistogram==0.6.1

ncclient==0.6.13; python_version <= '2.7'
ncclient==0.6.16; python_version > '2.7'

PyYAML==3.11; python_version < '2.7'
PyYAML==5.3.1; python_version >= '2.7' # Latest release (Jan 2021)

0 comments on commit 211079f

Please sign in to comment.