1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Fix yum integration tests (#35177)

* use tests instead of filters

* Don't check 'rc', use success/failed tests

- yum module use 'fail_json' which set 'failed'
- 'rc' is for backward compatibility:
  bbd6b8bb42/lib/ansible/executor/task_executor.py (L571)
- besides yum module doesn't document any return values

* Allow to run tests twice in a row

ansible-test is executed with '--retry-on-error' switch, then tests must
be able to executed twice in a row.

Error was:
TASK [yum : install group] ***
ok: [testhost] => {
    "attempts": 1,
    "changed": false,
    "failed": false,
    "invocation": { [...] },
    "msg": "",
    "rc": 0,
    "results": []
}

TASK [yum : verify installation of the group] ***
fatal: [testhost]: FAILED! => {
    "assertion": "yum_result.changed",
    "attempts": 1,
    "changed": false,
    "evaluated_to": false,
    "failed": true
}
This commit is contained in:
Pilou 2018-01-27 12:35:18 +01:00 committed by Martin Krizek
parent eeeea1406b
commit 47d8d8c36e
2 changed files with 96 additions and 106 deletions

View file

@ -18,7 +18,32 @@
# Note: We install the yum package onto Fedora so that this will work on dnf systems # Note: We install the yum package onto Fedora so that this will work on dnf systems
# We want to test that for people who don't want to upgrade their systems. # We want to test that for people who don't want to upgrade their systems.
- include: 'yum.yml'
- block:
- include: 'yum.yml'
always:
- name: remove installed packages
yum:
name:
- bc
- sos
state: absent
# On CentOS 6 'yum groupremove "Development Tools"' fails when groupremove_leaf_only
# isn't enabled, that's why a package belonging to "Development Tools" (autoconf)
# is removed instead of the whole group.
- name: remove installed group
yum:
name: "@Development tools"
state: absent
when:
- (ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux'] and ansible_distribution_major_version|int > 6) or ansible_distribution in ['Fedora']
- name: remove a package from a group
yum:
name: 'autoconf'
state: absent
when:
- ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux'] and ansible_distribution_major_version|int <= 6
when: when:
- ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux', 'Fedora'] - ansible_distribution in ['RedHat', 'CentOS', 'ScientificLinux', 'Fedora']
- ansible_python.version.major == 2 - ansible_python.version.major == 2

View file

@ -5,14 +5,14 @@
- name: check sos with rpm - name: check sos with rpm
shell: rpm -q sos shell: rpm -q sos
failed_when: False ignore_errors: True
register: rpm_result register: rpm_result
- name: verify uninstallation of sos - name: verify uninstallation of sos
assert: assert:
that: that:
- "yum_result.rc == 0" - "yum_result is success"
- "rpm_result.rc == 1" - "rpm_result is failed"
# UNINSTALL AGAIN # UNINSTALL AGAIN
- name: uninstall sos again in check mode - name: uninstall sos again in check mode
@ -23,7 +23,7 @@
- name: verify no change on re-uninstall in check mode - name: verify no change on re-uninstall in check mode
assert: assert:
that: that:
- "not yum_result.changed" - "not yum_result is changed"
- name: uninstall sos again - name: uninstall sos again
yum: name=sos state=removed yum: name=sos state=removed
@ -32,7 +32,7 @@
- name: verify no change on re-uninstall - name: verify no change on re-uninstall
assert: assert:
that: that:
- "not yum_result.changed" - "not yum_result is changed"
# INSTALL # INSTALL
- name: install sos in check mode - name: install sos in check mode
@ -43,32 +43,28 @@
- name: verify installation of sos in check mode - name: verify installation of sos in check mode
assert: assert:
that: that:
- "yum_result.changed" - "yum_result is changed"
- name: install sos - name: install sos
yum: name=sos state=present yum: name=sos state=present
register: yum_result register: yum_result
- name: check sos with rpm
shell: rpm -q sos
failed_when: False
register: rpm_result
- name: verify installation of sos - name: verify installation of sos
assert: assert:
that: that:
- "yum_result.rc == 0" - "yum_result is success"
- "yum_result.changed" - "yum_result is changed"
- "rpm_result.rc == 0"
- name: verify yum module outputs - name: verify yum module outputs
assert: assert:
that: that:
- "'changed' in yum_result" - "'changed' in yum_result"
- "'msg' in yum_result" - "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result" - "'results' in yum_result"
- name: check sos with rpm
shell: rpm -q sos
# INSTALL AGAIN # INSTALL AGAIN
- name: install sos again in check mode - name: install sos again in check mode
yum: name=sos state=present yum: name=sos state=present
@ -77,7 +73,7 @@
- name: verify no change on second install in check mode - name: verify no change on second install in check mode
assert: assert:
that: that:
- "not yum_result.changed" - "not yum_result is changed"
- name: install sos again - name: install sos again
yum: name=sos state=present yum: name=sos state=present
@ -85,7 +81,7 @@
- name: verify no change on second install - name: verify no change on second install
assert: assert:
that: that:
- "not yum_result.changed" - "not yum_result is changed"
# INSTALL AGAIN WITH LATEST # INSTALL AGAIN WITH LATEST
- name: install sos again with state latest in check mode - name: install sos again with state latest in check mode
@ -95,7 +91,7 @@
- name: verify install sos again with state latest in check mode - name: verify install sos again with state latest in check mode
assert: assert:
that: that:
- "not yum_result.changed" - "not yum_result is changed"
- name: install sos again with state latest idempotence - name: install sos again with state latest idempotence
yum: name=sos state=latest yum: name=sos state=latest
@ -103,7 +99,7 @@
- name: verify install sos again with state latest idempotence - name: verify install sos again with state latest idempotence
assert: assert:
that: that:
- "not yum_result.changed" - "not yum_result is changed"
# INSTALL WITH LATEST # INSTALL WITH LATEST
- name: uninstall sos - name: uninstall sos
@ -121,7 +117,7 @@
- name: verify install sos with state latest in check mode - name: verify install sos with state latest in check mode
assert: assert:
that: that:
- "yum_result.changed" - "yum_result is changed"
- name: install sos with state latest - name: install sos with state latest
yum: name=sos state=latest yum: name=sos state=latest
@ -129,7 +125,7 @@
- name: verify install sos with state latest - name: verify install sos with state latest
assert: assert:
that: that:
- "yum_result.changed" - "yum_result is changed"
- name: install sos with state latest idempotence - name: install sos with state latest idempotence
yum: name=sos state=latest yum: name=sos state=latest
@ -137,50 +133,43 @@
- name: verify install sos with state latest idempotence - name: verify install sos with state latest idempotence
assert: assert:
that: that:
- "not yum_result.changed" - "not yum_result is changed"
# Multiple packages # Multiple packages
- name: uninstall sos and bc - name: uninstall sos and bc
yum: name=sos,bc state=removed yum: name=sos,bc state=removed
register: yum_result
- name: check sos with rpm - name: check sos with rpm
shell: rpm -q sos shell: rpm -q sos
failed_when: False ignore_errors: True
register: rpm_sos_result register: rpm_sos_result
- name: check bc with rpm - name: check bc with rpm
shell: rpm -q bc shell: rpm -q bc
failed_when: False ignore_errors: True
register: rpm_bc_result register: rpm_bc_result
- name: verify packages installed - name: verify packages installed
assert: assert:
that: that:
- "rpm_sos_result.rc != 0" - "rpm_sos_result is failed"
- "rpm_bc_result.rc != 0" - "rpm_bc_result is failed"
- name: install sos and bc as comma separated - name: install sos and bc as comma separated
yum: name=sos,bc state=present yum: name=sos,bc state=present
register: yum_result register: yum_result
- name: check sos with rpm
shell: rpm -q sos
failed_when: False
register: rpm_sos_result
- name: check bc with rpm
shell: rpm -q bc
failed_when: False
register: rpm_bc_result
- name: verify packages installed - name: verify packages installed
assert: assert:
that: that:
- "yum_result.rc == 0" - "yum_result is success"
- "yum_result.changed" - "yum_result is changed"
- "rpm_sos_result.rc == 0"
- "rpm_bc_result.rc == 0" - name: check sos with rpm
shell: rpm -q sos
- name: check bc with rpm
shell: rpm -q bc
- name: uninstall sos and bc - name: uninstall sos and bc
yum: name=sos,bc state=removed yum: name=sos,bc state=removed
@ -194,23 +183,17 @@
state: present state: present
register: yum_result register: yum_result
- name: check sos with rpm
shell: rpm -q sos
failed_when: False
register: rpm_sos_result
- name: check bc with rpm
shell: rpm -q bc
failed_when: False
register: rpm_bc_result
- name: verify packages installed - name: verify packages installed
assert: assert:
that: that:
- "yum_result.rc == 0" - "yum_result is success"
- "yum_result.changed" - "yum_result is changed"
- "rpm_sos_result.rc == 0"
- "rpm_bc_result.rc == 0" - name: check sos with rpm
shell: rpm -q sos
- name: check bc with rpm
shell: rpm -q bc
- name: uninstall sos and bc - name: uninstall sos and bc
yum: name=sos,bc state=removed yum: name=sos,bc state=removed
@ -222,23 +205,17 @@
state: present state: present
register: yum_result register: yum_result
- name: check sos with rpm
shell: rpm -q sos
failed_when: False
register: rpm_sos_result
- name: check sos with rpm
shell: rpm -q bc
failed_when: False
register: rpm_bc_result
- name: verify packages installed - name: verify packages installed
assert: assert:
that: that:
- "yum_result.rc == 0" - "yum_result is success"
- "yum_result.changed" - "yum_result is changed"
- "rpm_sos_result.rc == 0"
- "rpm_bc_result.rc == 0" - name: check sos with rpm
shell: rpm -q sos
- name: check sos with rpm
shell: rpm -q bc
- name: uninstall sos and bc - name: uninstall sos and bc
yum: name=sos,bc state=removed yum: name=sos,bc state=removed
@ -260,26 +237,22 @@
yum: name=sos state=present installroot='/' yum: name=sos state=present installroot='/'
register: yum_result register: yum_result
- name: check sos with rpm
shell: rpm -q sos --root=/
failed_when: False
register: rpm_result
- name: verify installation of sos - name: verify installation of sos
assert: assert:
that: that:
- "yum_result.rc == 0" - "yum_result is success"
- "yum_result.changed" - "yum_result is changed"
- "rpm_result.rc == 0"
- name: verify yum module outputs - name: verify yum module outputs
assert: assert:
that: that:
- "'changed' in yum_result" - "'changed' in yum_result"
- "'msg' in yum_result" - "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result" - "'results' in yum_result"
- name: check sos with rpm
shell: rpm -q sos --root=/
- name: uninstall sos - name: uninstall sos
yum: yum:
name: sos name: sos
@ -296,15 +269,14 @@
- name: verify installation of the group - name: verify installation of the group
assert: assert:
that: that:
- "yum_result.rc == 0" - "yum_result is success"
- "yum_result.changed" - "yum_result is changed"
- name: verify yum module outputs - name: verify yum module outputs
assert: assert:
that: that:
- "'changed' in yum_result" - "'changed' in yum_result"
- "'msg' in yum_result" - "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result" - "'results' in yum_result"
- name: install the group again - name: install the group again
@ -316,15 +288,14 @@
- name: verify nothing changed - name: verify nothing changed
assert: assert:
that: that:
- "yum_result.rc == 0" - "yum_result is success"
- "not yum_result.changed" - "not yum_result is changed"
- name: verify yum module outputs - name: verify yum module outputs
assert: assert:
that: that:
- "'changed' in yum_result" - "'changed' in yum_result"
- "'msg' in yum_result" - "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result" - "'results' in yum_result"
- name: install the group again but also with a package that is not yet installed - name: install the group again but also with a package that is not yet installed
@ -338,15 +309,14 @@
- name: verify sos is installed - name: verify sos is installed
assert: assert:
that: that:
- "yum_result.rc == 0" - "yum_result is success"
- "yum_result.changed" - "yum_result is changed"
- name: verify yum module outputs - name: verify yum module outputs
assert: assert:
that: that:
- "'changed' in yum_result" - "'changed' in yum_result"
- "'msg' in yum_result" - "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result" - "'results' in yum_result"
- name: try to install the group again, with --check to check 'changed' - name: try to install the group again, with --check to check 'changed'
@ -359,7 +329,7 @@
- name: verify nothing changed - name: verify nothing changed
assert: assert:
that: that:
- "not yum_result.changed" - "not yum_result is changed"
- name: verify yum module outputs - name: verify yum module outputs
assert: assert:
@ -378,8 +348,8 @@
- name: verify installation of the non existing group failed - name: verify installation of the non existing group failed
assert: assert:
that: that:
- "yum_result.rc == 1" - "yum_result is failed"
- "not yum_result.changed" - "not yum_result is changed"
- "yum_result is failed" - "yum_result is failed"
- name: verify yum module outputs - name: verify yum module outputs
@ -387,7 +357,6 @@
that: that:
- "'changed' in yum_result" - "'changed' in yum_result"
- "'msg' in yum_result" - "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result" - "'results' in yum_result"
- name: try to install non existing file - name: try to install non existing file
@ -401,7 +370,7 @@
assert: assert:
that: that:
- "yum_result is failed" - "yum_result is failed"
- "not yum_result.changed" - "not yum_result is changed"
- name: verify yum module outputs - name: verify yum module outputs
assert: assert:
@ -420,7 +389,7 @@
assert: assert:
that: that:
- "yum_result is failed" - "yum_result is failed"
- "not yum_result.changed" - "not yum_result is changed"
- name: verify yum module outputs - name: verify yum module outputs
assert: assert:
@ -454,7 +423,7 @@
- name: verify httpd not installed - name: verify httpd not installed
assert: assert:
that: that:
- "not yum_result.changed" - "not yum_result is changed"
- "'Packages providing httpd not installed due to update_only specified' in yum_result.results" - "'Packages providing httpd not installed due to update_only specified' in yum_result.results"
- name: try to install not compatible arch rpm, should fail - name: try to install not compatible arch rpm, should fail
@ -467,8 +436,7 @@
- name: verify that yum failed - name: verify that yum failed
assert: assert:
that: that:
- "yum_result.rc == 1" - "not yum_result is changed"
- "not yum_result.changed"
- "yum_result is failed" - "yum_result is failed"
# setup for testing installing an RPM from url # setup for testing installing an RPM from url
@ -499,8 +467,8 @@
- name: verify installation - name: verify installation
assert: assert:
that: that:
- "yum_result.rc == 0" - "yum_result is success"
- "yum_result.changed" - "yum_result is changed"
- "yum_result is not failed" - "yum_result is not failed"
- name: verify yum module outputs - name: verify yum module outputs
@ -508,7 +476,6 @@
that: that:
- "'changed' in yum_result" - "'changed' in yum_result"
- "'msg' in yum_result" - "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result" - "'results' in yum_result"
- name: install the downloaded rpm again - name: install the downloaded rpm again
@ -520,8 +487,8 @@
- name: verify installation - name: verify installation
assert: assert:
that: that:
- "yum_result.rc == 0" - "yum_result is success"
- "not yum_result.changed" - "not yum_result is changed"
- "yum_result is not failed" - "yum_result is not failed"
- name: verify yum module outputs - name: verify yum module outputs
@ -529,7 +496,6 @@
that: that:
- "'changed' in yum_result" - "'changed' in yum_result"
- "'msg' in yum_result" - "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result" - "'results' in yum_result"
- name: clean up - name: clean up
@ -546,8 +512,8 @@
- name: verify installation - name: verify installation
assert: assert:
that: that:
- "yum_result.rc == 0" - "yum_result is success"
- "yum_result.changed" - "yum_result is changed"
- "yum_result is not failed" - "yum_result is not failed"
- name: verify yum module outputs - name: verify yum module outputs
@ -555,7 +521,6 @@
that: that:
- "'changed' in yum_result" - "'changed' in yum_result"
- "'msg' in yum_result" - "'msg' in yum_result"
- "'rc' in yum_result"
- "'results' in yum_result" - "'results' in yum_result"
- name: Create a temp RPM file which does not contain nevra information - name: Create a temp RPM file which does not contain nevra information