---
- name: Verify role raises correct error
  block:
    - name: Store global variable value copy
      set_fact:
        storage_safe_mode_global: "{{ storage_safe_mode | d(true) }}"
        storage_pools_global: "{{ storage_pools | d([]) }}"
        storage_volumes_global: "{{ storage_volumes | d([]) }}"

    - name: Verify role raises correct error
      include_role:
        name: fedora.linux_system_roles.storage
      vars:
        storage_pools: "{{ __storage_failed_params.get('storage_pools', storage_pools_global) }}"
        storage_volumes: "{{ __storage_failed_params.get('storage_volumes', storage_volumes_global) }}"
        storage_safe_mode: "{{ __storage_failed_params.get('storage_safe_mode', storage_safe_mode_global) }}"

    - name: Unreachable task
      fail:
        msg: UNREACH

  rescue:
    - name: Check that we failed in the role
      assert:
        that: ansible_failed_result.msg != 'UNREACH'
        msg: Role has not failed when it should have

    - name: Verify the blivet output and error message are correct
      assert:
        that:
          - blivet_output.failed
          - blivet_output.msg is search(__storage_failed_regex)
          - not blivet_output.changed
        msg: "{{ __storage_failed_msg }}"
      when:
        - __storage_failed_regex is defined
        - __storage_failed_msg is defined

    - name: Verify correct exception or error message
      assert:
        that: msg_msg is search(__storage_failed_exception) or exception is search(__storage_failed_exception) or msg_stdout is search(__storage_failed_exception) or msg_stderr is search(__storage_failed_exception) or stdout is search(__storage_failed_exception) or stderr is search(__storage_failed_exception)
      when: __storage_failed_exception is defined
      vars:
        msg_msg: "{{ ansible_failed_result.msg.msg | d('') }}"
        exception: "{{ ansible_failed_result.msg.exception | d('') }}"
        msg_stdout: "{{ ansible_failed_result.msg.module_stdout | d('') }}"
        msg_stderr: "{{ ansible_failed_result.msg.module_stderr | d('') }}"
        stdout: "{{ ansible_failed_result.module_stdout | d('') }}"
        stderr: "{{ ansible_failed_result.module_stderr | d('') }}"
