Skip to content

Commit 59a7f48

Browse files
committed
fix: fix issues with bootable snapshot code
Signed-off-by: Rich Megginson <rmeggins@redhat.com>
1 parent e4bf75f commit 59a7f48

3 files changed

Lines changed: 19 additions & 19 deletions

File tree

tasks/main.yml

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,14 @@
1414
use: "{{ (__snapshot_is_ostree | d(false)) |
1515
ternary('ansible.posix.rhel_rpm_ostree', omit) }}"
1616

17-
- name: Get snapm version
18-
check_mode: false
19-
command: snapm --version
20-
changed_when: false
21-
register: __snapshot_snapm_version_output
22-
# Ignore errors as snapm may not be available
23-
ignore_errors: true
17+
- name: Get package facts
18+
package_facts:
19+
no_log: "{{ ansible_verbosity < 2 }}"
2420

25-
- name: Set snapm availability fact
21+
- name: Set snapm availability fact and version
2622
set_fact:
27-
__snapshot_snapm_available: "{{ __snapshot_snapm_version_output is success }}"
28-
29-
- name: Set snapm version
30-
set_fact:
31-
__snapshot_snapm_version: "{{ __snapshot_snapm_version_output.stdout }}"
32-
when: __snapshot_snapm_available
23+
__snapshot_snapm_available: "{{ 'snapm' in ansible_facts.packages }}"
24+
__snapshot_snapm_version: "{{ ansible_facts.packages.get('snapm', [{}])[0].get('version', '0.0') }}"
3325

3426
# Determine if bootable support is needed
3527
# If snapshot_lvm_bootable is set to true, or any of the volumes in snapshot_lvm_set

tests/tests_basic_bootable.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,14 @@
129129
assert:
130130
that: not snapshot_cmd["changed"]
131131

132+
rescue:
133+
- name: Do not fail if snapm is too old for test
134+
assert:
135+
that: ansible_failed_result.msg is search(msg1) or ansible_failed_result.msg is search(msg2)
136+
vars:
137+
msg1: "Package snapm version .* is too old"
138+
msg2: "Package snapm version 0.5 or later is required to use bootable snapsets"
139+
132140
always:
133141
- name: Cleanup
134142
include_tasks: tasks/cleanup.yml

tests/tests_set_bootable.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,12 @@
9999
assert:
100100
that: not snapshot_cmd["changed"]
101101
rescue:
102-
- name: Check if error is due to snapm version too old
103-
fail:
104-
msg: Unexpected error occurred {{ ansible_failed_result | to_nice_json }}
105-
when: not ansible_failed_result.msg is search(err_msg)
102+
- name: Do not fail if snapm is too old for test
103+
assert:
104+
that: ansible_failed_result.msg is search(msg1) or ansible_failed_result.msg is search(msg2)
106105
vars:
107-
err_msg: Package snapm .*version 0.5 or later is required to use bootable snapsets
106+
msg1: "Package snapm version .* is too old"
107+
msg2: "Package snapm version 0.5 or later is required to use bootable snapsets"
108108
always:
109109
- name: Cleanup
110110
include_tasks: tasks/cleanup.yml

0 commit comments

Comments
 (0)