From 794e08292b344303df2482132161ff35d3705416 Mon Sep 17 00:00:00 2001 From: Teodoro Cook Date: Wed, 27 Mar 2024 17:23:15 -0600 Subject: [PATCH] Refactor package hold verification tests (#25) --- molecule/hold/verify.yml | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/molecule/hold/verify.yml b/molecule/hold/verify.yml index 8361ea5..ed02fc2 100644 --- a/molecule/hold/verify.yml +++ b/molecule/hold/verify.yml @@ -63,20 +63,26 @@ ansible.builtin.package_facts: - name: Verify package versions - ansible.builtin.fail: - msg: "Expected installed version for package {{ _package }} to be {{ _version }}, found {{ _installed }}" + ansible.builtin.assert: + that: + - _package in packages + - _version == _installed + fail_msg: "Expected {{ _package }}={{ _version }}, found {{ _package }}={{ _installed }}" + success_msg: "Found {{ _package }}={{ _version }}" vars: _package: "{{ item.split('=') | first }}" _version: "{{ item.split('=') | last }}" _installed: "{{ (packages[_package] | default([{'version': 'None'}]))[0].version }}" loop: "{{ mongos_package_list }}" - when: - - ansible_os_family == "Debian" - - _package not in packages or _version != _installed + when: ansible_os_family == "Debian" - name: Verify package versions - ansible.builtin.fail: - msg: "Expected installed version for package {{ _package }} to be {{ _version }}, found {{ _installed }}" + ansible.builtin.assert: + that: + - _package in packages + - _version == _installed + fail_msg: "Expected {{ _package }}={{ _version }}, found {{ _package }}={{ _installed }}" + success_msg: "Found {{ _package }}={{ _version }}" vars: _prefix: "^{{ _package }}-" _suffix: "-.*$" @@ -84,6 +90,4 @@ _version: "{{ item.1 | regex_replace(_prefix, '') | regex_replace(_suffix, '') }}" _installed: "{{ (packages[_package] | default([{'version': 'None'}]))[0].version }}" loop: "{{ mongos_packages | zip(mongos_package_list) }}" - when: - - ansible_os_family == "RedHat" - - _package not in packages or _version != _installed + when: ansible_os_family == "RedHat"