Skip to content

Commit

Permalink
Check safe_mode properly in the LVM tests
Browse files Browse the repository at this point in the history
Do not use ignore_errors, catch the error instead.
  • Loading branch information
pcahyna committed Oct 22, 2019
1 parent 368d145 commit 1158d45
Showing 1 changed file with 92 additions and 20 deletions.
112 changes: 92 additions & 20 deletions tests/tests_lvm_errors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -239,21 +239,21 @@
# not blivet_output.changed }}"
# msg: "Unexpected behavior w/ LVM volume defined outside of any pool"

- name: Create a pool
include_role:
name: storage
vars:
storage_pools:
- name: testpool1
type: lvm
disks: "{{ unused_disks }}"
volumes:
- name: testvol1
fs_type: 'ext4'
size: '1g'

- name: Test for correct handling of safe_mode
block:
- name: Create a pool
include_role:
name: storage
vars:
storage_pools:
- name: testpool1
type: lvm
disks: "{{ unused_disks }}"
volumes:
- name: testvol1
fs_type: 'ext4'
size: '1g'

- name: Try to replace file system in safe mode
include_role:
name: storage
Expand All @@ -268,13 +268,29 @@
fs_type: 'ext3'
size: '1g'

- name: UNREACH
fail:
msg: "this should be unreachable"

rescue:
- name: Check that we failed in the role
assert:
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: Test for correct handling of safe_mode with resize
block:
- name: Try to resize in safe mode
include_role:
name: storage
Expand All @@ -294,6 +310,8 @@
that: "{{ not blivet_output.failed and blivet_output.changed }}"
msg: "Unexpected behavior w/ existing data on specified disks"

- name: Test for correct handling of safe_mode with existing pool
block:
- name: Try to create LVM pool on disks that already belong to an existing pool
include_role:
name: storage
Expand All @@ -304,21 +322,75 @@
disks: "{{ unused_disks }}"
type: lvm

- name: UNREACH
fail:
msg: "this should be unreachable"

rescue:
- name: Check that we failed in the role
assert:
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 and/or devices on disk.*in safe mode') and
not blivet_output.changed }}"
msg: "Unexpected behavior w/ existing data on specified disks"

- name: Clean up
- name: Test for correct handling of safe_mode
block:
- name: Try to replace a pool by a file system on disk in safe mode
include_role:
name: storage
vars:
storage_pools:
- name: testpool1
type: lvm
disks: "{{ unused_disks }}"
state: absent
storage_volumes:
- name: test1
type: disk
fs_type: 'ext3'
disks:
- "{{ unused_disks[0] }}"

- name: UNREACH
fail:
msg: "this should be unreachable"

ignore_errors: yes
rescue:
- name: Check that we failed in the role
assert:
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: 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: Clean up
include_role:
name: storage
vars:
storage_safe_mode: false
storage_pools:
- name: testpool1
type: lvm
disks: "{{ unused_disks }}"
state: absent

0 comments on commit 1158d45

Please sign in to comment.