---
- name: Test cache volume fatal errors
  hosts: all
  become: true
  vars:
    storage_safe_mode: false
    volume_group_size: '10g'
    volume_size: '5g'
    cache_size: '4g'
  tags:
    - tests::lvm

  tasks:
    - name: Run the role
      include_role:
        name: linux-system-roles.storage

    - name: Mark tasks to be skipped
      set_fact:
        storage_skip_checks:
          - blivet_available
          - "{{ (lookup('env',
                        'SYSTEM_ROLES_REMOVE_CLOUD_INIT') in ['', 'false']) |
                ternary('packages_installed', '') }}"
          - service_facts

    - name: Get unused disks
      include_tasks: get_unused_disk.yml
      vars:
        max_return: 2
        disks_needed: 2
        match_sector_size: true

    - name: Verify that creating a cached partition volume fails
      include_tasks: verify-role-failed.yml
      vars:
        __storage_failed_params:
          storage_pools:
            - name: "{{ unused_disks[0] }}"
              type: partition
              disks: "{{ unused_disks }}"
              volumes:
                - name: test1
                  type: partition
                  cached: true

    - name: Verify that creating cache on unused disk fails
      include_tasks: verify-role-failed.yml
      vars:
        __storage_failed_params:
          storage_pools:
            - name: foo
              disks: "{{ [unused_disks[0]] }}"
              volumes:
                - name: test1
                  size: "{{ volume_size }}"
                  cached: true
                  cache_size: "{{ cache_size }}"
                  cache_devices: "{{ [unused_disks[1]] }}"
