From 36f00cdf1a9d8ae029b0ea2ea912c539562ad34a Mon Sep 17 00:00:00 2001 From: Patrick Kingston <66141901+pkingstonxyz@users.noreply.github.com> Date: Mon, 8 Sep 2025 09:41:22 -0400 Subject: [PATCH] Expand integration test coverage for `deb822_repository` module PR #85586 --- .../targets/deb822_repository/tasks/main.yml | 125 ++++++++++++++++++ 1 file changed, 125 insertions(+) diff --git a/test/integration/targets/deb822_repository/tasks/main.yml b/test/integration/targets/deb822_repository/tasks/main.yml index 585792f73a2..1165ead9d0d 100644 --- a/test/integration/targets/deb822_repository/tasks/main.yml +++ b/test/integration/targets/deb822_repository/tasks/main.yml @@ -32,6 +32,104 @@ assert: that: no_python3_debian.msg is contains 'python3-debian is not installed' + - name: check failure when in check mode + deb822_repository: + name: myrepo + types: deb + uris: "http://example.com/debian/" + suites: stable + components: main + register: no_python3_debian_check + check_mode: true + ignore_errors: true + + - name: assert check mode failure without python3-debian + assert: + that: no_python3_debian_check is failed + + - name: find apt path + command: + cmd: which apt + register: aptpath + + - name: hide apt from ansible + command: + cmd: mv {{ aptpath.stdout_lines[0] }} /usr/bin/apthidden + become: true + + - name: run deb822 with installation to check failure on nonexistent apt + deb822_repository: + name: myrepo + types: deb + uris: "http://example.com/debian/" + suites: stable + components: main + install_python_debian: true + register: failed_no_apt + ignore_errors: true + + - name: assert failure + assert: + that: failed_no_apt is failed + + - name: move apt back + command: + cmd: mv /usr/bin/apthidden {{ aptpath.stdout_lines[0] }} + become: true + + - name: break apt update + copy: + content: "deb [invalid syntax] http://invalid.example.com/debian stable main" + dest: /etc/apt/sources.list.d/broken.list + + - name: run deb822 with installation to check failure on apt update + deb822_repository: + name: myrepo + types: deb + uris: "http://example.com/debian/" + suites: stable + components: main + install_python_debian: true + register: failed_apt_update + ignore_errors: true + + - name: assert failure + assert: + that: failed_apt_update.msg is contains 'Failed update' + + - name: restore apt update + file: + path: /etc/apt/sources.list.d/broken.list + state: absent + + - name: create apt preference file to break python3-debian installation + copy: + content: | + Package: python3-debian + Pin: release * + Pin-Priority: -1 # Never install + dest: /etc/apt/preferences.d/99-break-python3-debian.pref + + - name: run deb822 with installation to check failure on apt install + deb822_repository: + name: myrepo + types: deb + uris: "http://example.com/debian/" + suites: stable + components: main + install_python_debian: true + register: failed_apt_install + ignore_errors: true + + - name: assert failure on broken install + assert: + that: failed_apt_install is failed + + - name: remove preference file + file: + path: /etc/apt/preferences.d/99-break-python3-debian.pref + state: absent + - name: run deb822 to check for python3-debian installation deb822_repository: name: myrepo @@ -57,6 +155,33 @@ that: - not py3_deb_install.changed + - name: use venv to test interpreter respawn into installed environment + vars: + venv_dir: "{{ output_dir }}/nodeb_venv" + venv_python: "{{ venv_dir }}/bin/python" + block: + - name: ensure venv exists + pip: + name: coverage + virtualenv: "{{ venv_dir }}" + virtualenv_command: "{{ ansible_python_interpreter }} -m venv" + + - name: run deb822 WITHOUT python3-debian installed to test respawning + deb822_repository: + name: myrepo + types: deb + uris: "http://example.com/debian/" + suites: stable + components: main + register: no_python3_debian + vars: + ansible_python_interpreter: "{{ venv_python }}" + ignore_errors: true + - name: Clean up the previously added basic Debian repository + deb822_repository: + name: myrepo + state: absent + - import_tasks: test.yml - import_tasks: install.yml