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:
Brian Coca 2020-04-28 13:55:26 -04:00 committed by GitHub
parent 7714f691eb
commit babac66f9c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 34 additions and 3 deletions

View 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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -0,0 +1 @@
shippable/posix/group1

View file

@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -eux
# run type tests
ansible-playbook -i ../../inventory types.yml -v "$@"

View 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']"