Be strict about what is a boolean for keywords (#67625)
* be strict about what is a boolean for keywords - found and fixed typo in test , 'yes' != 'yes.'
This commit is contained in:
parent
7714f691eb
commit
babac66f9c
7 changed files with 34 additions and 3 deletions
2
changelogs/fragments/play_bools_strict.yml
Normal file
2
changelogs/fragments/play_bools_strict.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- Ensure that keywords defined as booleans are correctly interpreting their input, before patch any random string would be interpreted as False
|
|
@ -23,7 +23,8 @@ This document is part of a collection on porting. The complete list of porting g
|
||||||
Playbook
|
Playbook
|
||||||
========
|
========
|
||||||
|
|
||||||
No notable changes
|
* Fixed a bug on boolean keywords that made random strings return 'False', now they should return an error if they are not a proper boolean
|
||||||
|
Example: `diff: yes-` was returning `False`.
|
||||||
|
|
||||||
|
|
||||||
Command Line
|
Command Line
|
||||||
|
|
|
@ -343,7 +343,7 @@ class FieldAttributeBase(with_metaclass(BaseMeta, object)):
|
||||||
elif attribute.isa == 'float':
|
elif attribute.isa == 'float':
|
||||||
value = float(value)
|
value = float(value)
|
||||||
elif attribute.isa == 'bool':
|
elif attribute.isa == 'bool':
|
||||||
value = boolean(value, strict=False)
|
value = boolean(value, strict=True)
|
||||||
elif attribute.isa == 'percent':
|
elif attribute.isa == 'percent':
|
||||||
# special value, which may be an integer or float
|
# special value, which may be an integer or float
|
||||||
# with an optional '%' at the end
|
# with an optional '%' at the end
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
src: results/test-add-children-elements.xml
|
src: results/test-add-children-elements.xml
|
||||||
dest: /tmp/ansible-xml-beers.xml
|
dest: /tmp/ansible-xml-beers.xml
|
||||||
check_mode: yes
|
check_mode: yes
|
||||||
diff: yes·
|
diff: yes
|
||||||
register: comparison
|
register: comparison
|
||||||
|
|
||||||
- name: Test expected result
|
- name: Test expected result
|
||||||
|
|
1
test/integration/targets/playbook/aliases
Normal file
1
test/integration/targets/playbook/aliases
Normal file
|
@ -0,0 +1 @@
|
||||||
|
shippable/posix/group1
|
6
test/integration/targets/playbook/runme.sh
Executable file
6
test/integration/targets/playbook/runme.sh
Executable file
|
@ -0,0 +1,6 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -eux
|
||||||
|
|
||||||
|
# run type tests
|
||||||
|
ansible-playbook -i ../../inventory types.yml -v "$@"
|
21
test/integration/targets/playbook/types.yml
Normal file
21
test/integration/targets/playbook/types.yml
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
- hosts: testhost
|
||||||
|
gather_facts: false
|
||||||
|
tasks:
|
||||||
|
- name: try to set 'diff' a boolean
|
||||||
|
debug: msg="not important"
|
||||||
|
diff: yes
|
||||||
|
ignore_errors: True
|
||||||
|
register: good_diff
|
||||||
|
|
||||||
|
- name: try to set 'diff' a boolean to a string (. would make it non boolean)
|
||||||
|
debug: msg="not important"
|
||||||
|
diff: yes.
|
||||||
|
ignore_errors: True
|
||||||
|
register: bad_diff
|
||||||
|
|
||||||
|
- name: Check we did error out
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- good_diff is success
|
||||||
|
- bad_diff is failed
|
||||||
|
- "'is not a valid boolean' in bad_diff['msg']"
|
Loading…
Reference in a new issue