---
# Only when pool is stratis
- name: Check Stratis options
  when: storage_test_pool.type == 'stratis'
  block:
    - name: Get stratis pool information
      ansible.builtin.script: >-
        scripts/stratis_pool_info.py
        "{{ storage_test_pool.name }}"
      args:
        executable: "{{ ansible_python.executable }}"
      register: storage_test_stratis_report
      changed_when: false

    - name: Print script output
      debug:
        msg: "{{ storage_test_stratis_report.stdout }}"

    - name: Get information about Stratis
      set_fact:
        _stratis_pool_info: "{{ storage_test_stratis_report.stdout | from_json }}"

    - name: Verify that the pools was created
      assert:
        that: _stratis_pool_info.name == storage_test_pool.name
        msg: >-
          Stratis pool '{{ storage_test_pool.name }}' not found
      when: storage_test_pool.state == 'present'

    - name: Verify that encryption is correctly set
      assert:
        that: storage_test_pool.name in _stratis_pool_info.key_desc
        msg: >-
          Stratis pool '{{ storage_test_pool.name }}' is not encrypted
      when:
        - storage_test_pool.state == 'present'
        - storage_test_pool.encryption

    - name: Verify that Clevis/Tang encryption is correctly set
      assert:
        that: _stratis_pool_info.clevis_pin == 'tang' and _stratis_pool_info.clevis_args['url'] == storage_test_pool.encryption_tang_url
        msg: >-
          Stratis pool '{{ storage_test_pool.name }}' Clevis is not correctly configured
      when:
        - storage_test_pool.state == 'present'
        - storage_test_pool.encryption
        - storage_test_pool.encryption_clevis_pin == 'tang'

- name: Reset variable used by test
  set_fact:
    storage_test_stratis_report:
