new filter human_bytes: convert a string (ex: 1Mo, 1K) into bytes (#12074)

* Rework human_readable and human_to_bytes.
New filter human_to_bytes.

* Fix for python 3.
This commit is contained in:
Yannig
2016-08-24 21:04:20 +02:00
committed by Toshio Kuratomi
parent 733f977ad2
commit 27b0f3241b
3 changed files with 112 additions and 67 deletions

View File

@@ -61,13 +61,40 @@
- 'diff_result.stdout == ""'
- name: Verify human_readable
tags: "human_readable"
assert:
that:
- '"1.00 Bytes" == 1|human_readable'
- '"1.00 bits" == 1|human_readable(isbits=True)'
- '"10.00 KB" == 10240|human_readable'
- '"97.66 MB" == 102400000|human_readable'
- '"0.10 GB" == 102400000|human_readable(unit="G")'
- '"0.10 Gb" == 102400000|human_readable(isbits=True, unit="G")'
- name: Verify human_to_bytes
tags: "human_to_bytes"
assert:
that:
- "{{'0'|human_to_bytes}} == 0"
- "{{'0.1'|human_to_bytes}} == 0"
- "{{'0.9'|human_to_bytes}} == 1"
- "{{'1'|human_to_bytes}} == 1"
- "{{'10.00 KB'|human_to_bytes}} == 10240"
- "{{ '11 MB'|human_to_bytes}} == 11534336"
- "{{ '1.1 GB'|human_to_bytes}} == 1181116006"
- "{{'10.00 Kb'|human_to_bytes(isbits=True)}} == 10240"
- name: Verify human_to_bytes (bad string)
tags: "human_to_bytes"
set_fact: bad_string="{{'10.00 foo'|human_to_bytes}}"
ignore_errors: yes
register: _
- name: Verify human_to_bytes (bad string)
tags: "human_to_bytes"
assert:
that: "{{_.failed}}"
- name: Container lookups with extract
assert:
that: