---

# Only when pool is raid
- name: check RAID options
  block:
    - name: get information about RAID
      command: "mdadm --detail {{ _storage_test_pool_pvs[0] }}"
      register: storage_test_mdadm
      changed_when: false

  # pre-chew regex search patterns
    - set_fact:
        storage_test_md_active_devices_re: "{{ ('Active Devices : ' ~ storage_test_pool.raid_device_count ~ '\n')|regex_escape() }}"
      when: storage_test_pool.raid_device_count is defined

    - set_fact:
        storage_test_md_spare_devices_re: "{{ ('Spare Devices : ' ~ storage_test_pool.raid_spare_count ~ '\n')|regex_escape() }}"
      when: storage_test_pool.raid_spare_count is defined

    - set_fact:
        storage_test_md_metadata_version_re: "{{ ('Version : ' ~ storage_test_pool.raid_metadata_version ~ '\n')|regex_escape() }}"
      when: storage_test_pool.raid_metadata_version is defined

    - name: check RAID active devices count
      assert:
        that: "storage_test_mdadm.stdout is regex(storage_test_md_active_devices_re)"
        msg: "Expected {{ storage_test_pool.raid_device_count }} active RAID devices."
      when: storage_test_pool.raid_device_count is defined and storage_test_pool.raid_device_count is not none

    - name: check RAID spare devices count
      assert:
        that: "storage_test_mdadm.stdout is regex(storage_test_md_spare_devices_re)"
        msg: "Expected {{ storage_test_pool.raid_spare_count }} spare RAID devices."
      when: storage_test_pool.raid_spare_count is defined and storage_test_pool.raid_spare_count is not none

    - name: check RAID metadata version
      assert:
        that: "storage_test_mdadm.stdout is regex(storage_test_md_metadata_version_re)"
        msg: "Expected {{ storage_test_pool.raid_metadata_version }} RAID metadata version."
      when: storage_test_pool.raid_metadata_version is defined and storage_test_pool.raid_metadata_version is not none

  when: storage_test_pool.raid_level != none and storage_test_pool.state != "absent"

- set_fact:
    storage_test_md_active_devices_re:
    storage_test_md_spare_devices_re:
    storage_test_md_metadata_version_re:
