From 41673476856dc4b9449dc5faef34443e9940d284 Mon Sep 17 00:00:00 2001 From: Pavel Cahyna Date: Mon, 21 Oct 2019 19:13:31 +0200 Subject: [PATCH] More test fixes - Check for errors properly in LVM error test, part 1 Remove ignore_errors in non-safe-mode tests and instead catch errors. Comment out the currently broken tests. - Check safe_mode properly in the LVM tests Do not use ignore_errors, catch the error instead. - Disable the resizing test, resizing does not seem to work at all currently. - Remove the explicit setting of storage_safe_mode to true True should be the default. - Safe mode should now be the default, account for this - Check that safe mode works even when the filesystem is unmounted. - Verify that replacing a fs by a LVM pool fails in safe mode - Cleanup properly. --- tests/tests_disk_errors.yml | 99 ++++++++++++- tests/tests_lvm_errors.yml | 278 ++++++++++++++++++++++++++++-------- 2 files changed, 311 insertions(+), 66 deletions(-) diff --git a/tests/tests_disk_errors.yml b/tests/tests_disk_errors.yml index fab86937..7112f6ed 100644 --- a/tests/tests_disk_errors.yml +++ b/tests/tests_disk_errors.yml @@ -73,7 +73,6 @@ include_role: name: storage vars: - storage_safe_mode: true storage_volumes: - name: test1 type: disk @@ -101,6 +100,61 @@ not blivet_output.changed" msg: "Unexpected behavior w/ existing data on specified disks" + - name: Unmount file system + include_role: + name: storage + vars: + storage_volumes: + - name: test1 + type: disk + fs_type: 'ext4' + disks: "{{ unused_disks }}" + mount_point: none + + - name: Test for correct handling of safe_mode with unmounted filesystem + block: + - name: Try to replace the file system on disk in safe mode + include_role: + name: storage + vars: + storage_volumes: + - name: test1 + type: disk + fs_type: 'ext3' + disks: "{{ unused_disks }}" + + - 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: Remount file system + include_role: + name: storage + vars: + storage_volumes: + - name: test1 + type: disk + fs_type: 'ext4' + disks: "{{ unused_disks }}" + mount_point: "{{ mount_location }}" + - name: stat the file stat: path: "{{ testfile }}" @@ -118,7 +172,6 @@ include_role: name: storage vars: - storage_safe_mode: true storage_pools: - name: foo disks: "{{ unused_disks }}" @@ -145,6 +198,38 @@ not blivet_output.changed" msg: "Unexpected behavior w/ existing data on specified disks" + - name: Test for correct handling of safe_mode with existing filesystem + block: + - name: Try to create LVM pool on disk that already belongs to an existing filesystem + include_role: + name: storage + vars: + storage_pools: + - name: foo + 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: stat the file stat: path: "{{ testfile }}" @@ -169,15 +254,15 @@ - name: Verify the output assert: that: not blivet_output.failed - msg: "failed to create partition pool over existing file system using default value of safe_mode" + msg: "failed to create partition pool over existing file system w/o safe_mode" - name: Clean up include_role: name: storage vars: storage_safe_mode: false - storage_volumes: - - name: test1 - type: disk + storage_pools: + - name: foo + type: partition disks: "{{ unused_disks }}" - present: false + state: absent diff --git a/tests/tests_lvm_errors.yml b/tests/tests_lvm_errors.yml index adcbb905..e8be1535 100644 --- a/tests/tests_lvm_errors.yml +++ b/tests/tests_lvm_errors.yml @@ -33,13 +33,32 @@ size: "{{ volume1_size }}" mount_point: "{{ mount_location1 }}" - - 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('unable to resolve.+disk')|length>0 and - not blivet_output.changed }}" - msg: "Unexpected behavior w/ non-existent pool disk" - ignore_errors: yes + 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 + + # the following does not work properly + # - debug: + # msg: "{{ 'failed: ' + blivet_output.failed | string + + # 'msg: ' + blivet_output.msg + + # 'changed: ' + blivet_output.changed | string }}" + + # - name: Verify the output + # assert: + # that: "{{ blivet_output.failed and + # blivet_output.msg|regex_search('unable to resolve.+disk')|length>0 and + # not blivet_output.changed }}" + # msg: "Unexpected behavior w/ non-existent pool disk" - name: Test for correct handling of invalid size specification. block: @@ -55,13 +74,27 @@ size: "{{ invalid_size }}" mount_point: "{{ mount_location1 }}" - - 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('invalid size.+for volume') and - not blivet_output.changed }}" - msg: "Unexpected behavior w/ invalid volume size" - ignore_errors: yes + 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 + + # the following does not work properly + # - name: Verify the output + # assert: + # that: "{{ blivet_output.failed and + # blivet_output.msg|regex_search('invalid size.+for volume') and + # not blivet_output.changed }}" + # msg: "Unexpected behavior w/ invalid volume size" - name: Test for correct handling of too-large volume size. block: @@ -77,13 +110,27 @@ size: "{{ too_large_size }}" mount_point: "{{ mount_location1 }}" - - 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('size.+exceeds.+space in pool') and - not blivet_output.changed }}" - msg: "Unexpected behavior w/ too-large volume size" - ignore_errors: yes + 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 + + # the following does not work properly + # - name: Verify the output + # assert: + # that: "{{ blivet_output.failed and + # blivet_output.msg|regex_search('size.+exceeds.+space in pool') and + # not blivet_output.changed }}" + # msg: "Unexpected behavior w/ too-large volume size" - name: Test for correct handling of non-list disk specification. block: @@ -99,13 +146,27 @@ size: "{{ too_large_size }}" mount_point: "{{ mount_location1 }}" - - 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('disk.+list') and - not blivet_output.changed }}" - msg: "Unexpected behavior w/ disks not in list form" - ignore_errors: yes + 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 + + # the following does not work properly + # - name: Verify the output + # assert: + # that: "{{ blivet_output.failed and + # blivet_output.msg|regex_search('disk.+list') and + # not blivet_output.changed }}" + # msg: "Unexpected behavior w/ disks not in list form" - name: Test for correct handling of missing disk specification. block: @@ -121,13 +182,27 @@ size: "{{ too_large_size }}" mount_point: "{{ mount_location1 }}" - - 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('no disks.+pool') and - not blivet_output.changed }}" - msg: "Unexpected behavior w/ no disks specified" - ignore_errors: yes + 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 + + # the following does not work properly + # - name: Verify the output + # assert: + # that: "{{ blivet_output.failed and + # blivet_output.msg|regex_search('no disks.+pool') and + # not blivet_output.changed }}" + # msg: "Unexpected behavior w/ no disks specified" - name: Test for correct handling of LVM volume not defined within a pool. block: @@ -142,34 +217,47 @@ size: "{{ volume1_size }}" mount_point: "{{ mount_location1 }}" - - 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('failed to find pool .+ for volume') and - not blivet_output.changed }}" - msg: "Unexpected behavior w/ LVM volume defined outside of any pool" - ignore_errors: yes + 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 + + # the following does not work properly + # - name: Verify the output + # assert: + # that: "{{ blivet_output.failed and + # blivet_output.msg|regex_search('failed to find pool .+ for volume') and + # 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 vars: - storage_safe_mode: true storage_pools: - name: testpool1 type: lvm @@ -179,6 +267,20 @@ 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 @@ -186,11 +288,12 @@ 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 vars: - storage_safe_mode: true storage_pools: - name: testpool1 type: lvm @@ -205,16 +308,33 @@ that: "{{ not blivet_output.failed and blivet_output.changed }}" msg: "Unexpected behavior w/ existing data on specified disks" + when: false + + - 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 vars: - storage_safe_mode: true storage_pools: - name: foo 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 @@ -222,14 +342,54 @@ 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" + + 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 - ignore_errors: yes + - 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