From 368d14566f34959fae4812299cc3066c31c01c0a Mon Sep 17 00:00:00 2001 From: Pavel Cahyna Date: Mon, 21 Oct 2019 19:13:31 +0200 Subject: [PATCH] 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. --- tests/tests_lvm_errors.yml | 161 ++++++++++++++++++++++++++++--------- 1 file changed, 125 insertions(+), 36 deletions(-) diff --git a/tests/tests_lvm_errors.yml b/tests/tests_lvm_errors.yml index adcbb905..b68d231f 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,13 +217,27 @@ 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: Test for correct handling of safe_mode block: