diff --git a/tests/roles/bootstrap-host/tasks/check-requirements.yml b/tests/roles/bootstrap-host/tasks/check-requirements.yml index eb1dea560d..55f705f37f 100644 --- a/tests/roles/bootstrap-host/tasks/check-requirements.yml +++ b/tests/roles/bootstrap-host/tasks/check-requirements.yml @@ -21,7 +21,7 @@ - name: Identify the space available in / shell: | - df -BG / | awk '/^[^Filesystem]/ {print $4}' | sed 's/G//' + df -BK / | awk '/^[^Filesystem]/ {print $4}' | sed 's/K//' when: - bootstrap_host_data_disk_device is not defined changed_when: false @@ -29,10 +29,44 @@ tags: - check-disk-size +# Convert root_space_available to bytes. +- name: Set root disk facts + set_fact: + host_root_space_available_bytes: "{{ ( root_space_available.stdout | int) * 1024 | int }}" + when: + - bootstrap_host_data_disk_device is not defined + tags: + - check-disk-size + +- name: Set data disk facts + set_fact: + host_data_disk_sectors: "{{ (ansible_devices[bootstrap_host_data_disk_device]['sectors'] | int) }}" + host_data_disk_sectorsize: "{{ (ansible_devices[bootstrap_host_data_disk_device]['sectorsize'] | int) }}" + when: + - bootstrap_host_data_disk_device is defined + tags: + - check-disk-size + +# Calculate the size of the bootstrap_host_data_disk_device by muliplying sectors with sectorsize. +- name: Calculate data disk size + set_fact: + host_data_disk_size_bytes: "{{ ((host_data_disk_sectors | int) * (host_data_disk_sectorsize | int)) | int }}" + when: + - bootstrap_host_data_disk_device is defined + tags: + - check-disk-size + +# Convert bootstrap_host_data_disk_min_size to bytes. +- name: Set min size fact + set_fact: + host_data_disk_min_size_bytes: "{{ ((bootstrap_host_data_disk_min_size | int) * 1024**3) | int }}" + tags: + - check-disk-size + - name: Fail if there is not enough space available in / assert: that: | - root_space_available.stdout | int >= (bootstrap_host_data_disk_min_size * 0.75) | int + (host_root_space_available_bytes | int) >= ((host_data_disk_min_size_bytes | int) * 0.75) when: - bootstrap_host_data_disk_device is not defined tags: @@ -41,8 +75,7 @@ - name: Fail if there is not enough disk space available (disk specified) assert: that: | - (ansible_devices[bootstrap_host_data_disk_device]['size'] | replace(' GB','')) | int - >= bootstrap_host_data_disk_min_size | int + (host_data_disk_size_bytes | int) >= (host_data_disk_min_size_bytes | int) when: - bootstrap_host_data_disk_device is defined tags: