Skip to content

Commit

Permalink
Do not use ignore_errors: yes in a test block
Browse files Browse the repository at this point in the history
- this makes all test asserts pointless.

Instead catch the error using rescue.

Actually verify that data heve not been destroyed.
  • Loading branch information
pcahyna committed Oct 15, 2019
1 parent a597f0f commit 2fd8c33
Showing 1 changed file with 33 additions and 6 deletions.
39 changes: 33 additions & 6 deletions tests/tests_disk_errors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,41 @@
fs_type: 'ext3'
disks: "{{ unused_disks }}"

- name: Verify the output
- name: UNREACH
fail:
msg: "this should be unreachable"

rescue:
- name: Check that we failed in the role
assert:
that: "{{ blivet_output.failed and
blivet_output.msg|regex_search('cannot remove existing formatting on volume.*in safe mode') and
not blivet_output.changed }}"
msg: "Unexpected behavior w/ existing data on specified disks"
that:
- ansible_failed_task.name != 'UNREACH'
msg: "Role has not failed when it should have"
vars:
# Ugh! needed to expand ansible_failed_task
storage_provider: blivet

- name: Verify the output
assert:
that: "blivet_output.failed and
blivet_output.msg|regex_search('cannot remove existing formatting on volume.*in safe mode') and
not blivet_output.changed"
msg: "Unexpected behavior w/ existing data on specified disks"

- name: Try to create a partition pool on the disk already containing a file system in safe_mode
- name: stat the file
stat:
path: "{{ testfile }}"
register: stat_r

- name: assert file presence
assert:
that:
stat_r.stat.isreg is defined and stat_r.stat.isreg
msg: "data lost!"

- name: Test for correct handling of safe_mode
block:
- name: Try to create a LVM pool on the disk already containing a file system in safe_mode
include_role:
name: storage
vars:
Expand Down

0 comments on commit 2fd8c33

Please sign in to comment.