From 8298abc1d94bf1e9de64897b7f12a362725cfb96 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Sat, 18 Jan 2025 10:12:55 +0000 Subject: [PATCH] WIP --- .github/workflows/tests.yml | 5 ++ .../issue_655__wait_for_connection_error.yml | 39 ++++---------- .../issue_766__get_with_context.yml | 54 +++++++++++++------ .../roles/homebrew_podman/handlers/main.yml | 4 ++ .../roles/homebrew_podman/tasks/main.yml | 21 ++++++++ tests/ansible/requirements.txt | 4 +- 6 files changed, 81 insertions(+), 46 deletions(-) create mode 100644 tests/ansible/regression/roles/homebrew_podman/handlers/main.yml create mode 100644 tests/ansible/regression/roles/homebrew_podman/tasks/main.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9a275a00c..9d737b9e7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -183,6 +183,11 @@ jobs: with: python-version: ${{ matrix.python_version }} if: ${{ matrix.python_version }} + - uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - name: Show Python versions run: | set -o errexit -o nounset -o pipefail diff --git a/tests/ansible/regression/issue_655__wait_for_connection_error.yml b/tests/ansible/regression/issue_655__wait_for_connection_error.yml index a1f39f66a..a864211bc 100644 --- a/tests/ansible/regression/issue_655__wait_for_connection_error.yml +++ b/tests/ansible/regression/issue_655__wait_for_connection_error.yml @@ -8,10 +8,12 @@ hosts: localhost gather_facts: yes become: no - tasks: + + pre_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 - ansible_facts.system == 'Darwin' - ansible_facts.distribution_version is version('13.0', '<', strict=True) @@ -21,28 +23,14 @@ # On CentOS 8 /usr/libexec/platform-python is Python 3.6 - ansible_version.full is version('2.17', '>=', strict=True) + roles: + - role: homebrew_podman + when: + - ansible_facts.pkg_mgr in ['homebrew'] + + tasks: - name: set up test container and run tests inside it block: - - name: install deps - homebrew: - name: - - podman - state: present - - - name: start machine - command: - cmd: "{{ item.cmd }}" - loop: - - cmd: podman machine init - - cmd: podman machine start - - cmd: podman info - timeout: 300 - register: podman_machine - changed_when: true - - - debug: - var: podman_machine - # python bindings (docker_container) aren't working on this host, so gonna shell out - name: create container command: @@ -98,12 +86,7 @@ - name: remove test container command: - cmd: "{{ item.cmd }}" - loop: - - cmd: podman stop testMitogen - - cmd: podman machine stop + cmd: podman stop testMitogen changed_when: true - when: - - ansible_facts.pkg_mgr in ['homebrew'] tags: - issue_655 diff --git a/tests/ansible/regression/issue_766__get_with_context.yml b/tests/ansible/regression/issue_766__get_with_context.yml index 136b5dfec..42f6501e2 100644 --- a/tests/ansible/regression/issue_766__get_with_context.yml +++ b/tests/ansible/regression/issue_766__get_with_context.yml @@ -2,39 +2,59 @@ --- - 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 + + pre_tasks: + - meta: end_play + when: + # Podman versions available in Homebrew require macOS 13+ (Ventura). + # https://formulae.brew.sh/formula/podman + - ansible_facts.system == 'Darwin' + - ansible_facts.distribution_version is version('13.0', '<', strict=True) + + roles: + - role: homebrew_podman + when: + - ansible_facts.pkg_mgr in ['homebrew'] + tasks: - block: - name: Start container - delegate_to: localhost - vars: - ansible_port: 8040 - containers.podman.podman_container: - name: sysprep - image: ghcr.io/mitogen-hq/sysrepo-netopeer2:latest - auto_remove: true - detach: true - recreate: true - published_ports: - - "{{ ansible_port }}:830" + 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 - delegate_to: localhost # TODO robust condition. wait_for + search_regex? wait_for_connection? wait_for: timeout: 5 - name: Get running configuration and state data vars: - ansible_port: 8040 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 - delegate_to: localhost - containers.podman.podman_container: - name: sysprep - state: absent + command: + cmd: podman stop "{{ netconf_container_name }}" + changed_when: true + tags: + - issue_766 diff --git a/tests/ansible/regression/roles/homebrew_podman/handlers/main.yml b/tests/ansible/regression/roles/homebrew_podman/handlers/main.yml new file mode 100644 index 000000000..b41e4376c --- /dev/null +++ b/tests/ansible/regression/roles/homebrew_podman/handlers/main.yml @@ -0,0 +1,4 @@ +- name: Stop podman machine + command: + cmd: podman machine stop + changed_when: true diff --git a/tests/ansible/regression/roles/homebrew_podman/tasks/main.yml b/tests/ansible/regression/roles/homebrew_podman/tasks/main.yml new file mode 100644 index 000000000..64efb8326 --- /dev/null +++ b/tests/ansible/regression/roles/homebrew_podman/tasks/main.yml @@ -0,0 +1,21 @@ +- name: install deps + homebrew: + name: + - podman + state: present + +- name: start machine + command: + cmd: "{{ item.cmd }}" + loop: + - cmd: podman machine init + - cmd: podman machine start + - cmd: podman info + timeout: 300 + register: podman_machine + changed_when: true + handlers: + - Stop podman machine + +- debug: + var: podman_machine diff --git a/tests/ansible/requirements.txt b/tests/ansible/requirements.txt index 3fbfe5b98..11457e66d 100644 --- a/tests/ansible/requirements.txt +++ b/tests/ansible/requirements.txt @@ -1,4 +1,6 @@ -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