---
- name: Test null raid pool
  hosts: all
  become: true
  vars:
    storage_safe_mode: false
    storage_use_partitions: true
    mount_location1: '/opt/test1'
    volume1_size: '2g'
  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

    - name: Get existing raids (before run)
      command: "cat /proc/mdstat"
      register: storage_test_mdstat1
      changed_when: false

    - name: Check that raid_level null does not create raid
      include_role:
        name: linux-system-roles.storage
      vars:
        storage_pools:
          - name: vg1
            disks: "{{ unused_disks }}"
            type: lvm
            raid_level: "null"
            state: present
            volumes:
              - name: lv1
                size: "{{ volume1_size }}"
                mount_point: "{{ mount_location1 }}"

    - name: Get existing raids (after run)
      command: "cat /proc/mdstat"
      register: storage_test_mdstat2
      changed_when: false

    # Cleanup before assert so it is always executed
    - name: Cleanup
      include_role:
        name: linux-system-roles.storage
      vars:
        storage_pools:
          - name: vg1
            disks: "{{ unused_disks }}"
            type: lvm
            raid_level: "null"
            state: absent
            volumes:
              - name: lv1
                size: "{{ volume1_size }}"
                mount_point: "{{ mount_location1 }}"

    - name: Compare mdstat results
      assert:
        that:
          - storage_test_mdstat1.stdout == storage_test_mdstat2.stdout
        msg: "Raid created when it should not be"
