- name: Get the backing device path
  command: realpath /dev/disk/by-uuid/{{ _storage_test_pool_member_path|regex_replace('^.*/luks-', '') }}
  register: _storage_test_member_backing_dev
  when: storage_test_pool.encryption and storage_test_pool.state == 'present'

- name: Ensure cryptsetup is present
  package:
    name: cryptsetup
    state: present

- name: Collect LUKS info for this member
  command: cryptsetup luksDump {{ _storage_test_member_backing_dev.stdout }}
  register: _storage_test_luks_dump
  when: storage_test_pool.encryption and storage_test_pool.state == 'present'
  changed_when: false

- name: Check LUKS version
  assert:
    that: "{{ _storage_test_luks_dump.stdout|regex_search('^\\s+Version: ' + storage_test_pool.encryption_luks_version + '$') }}"
    msg: "Wrong LUKS version for pool {{ storage_test_pool.name }}"
  when: storage_test_pool.state == 'present' and storage_test_pool.encryption and storage_test_pool.encryption_luks_version

- name: Check LUKS key size
  assert:
    that: "{{ _storage_test_luks_dump.stdout|regex_search('^\\s+Key: ' + storage_test_pool.encryption_key_size|string + ' bits$') }}"
    msg: "Wrong key size for pool {{ storage_test_pool.name }}"
  when: storage_test_pool.state == 'present' and storage_test_pool.encryption and storage_test_pool.encryption_key_size

- name: Check LUKS cipher
  assert:
    that: "{{ _storage_test_luks_dump.stdout|regex_search('^\\s+Cipher: ' + storage_test_pool.encryption_cipher + '$') }}"
    msg: "Wrong key size for pool {{ storage_test_pool.name }}"
  when: storage_test_pool.state == 'present' and storage_test_pool.encryption and storage_test_pool.encryption_cipher
