mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Test case and fix for shlex.split unicode bug
When operating on a unicode string in python 2.6, shlex.split returns a result that does not work with the file constructor. To reproduce this requires a task include that is templated (this is because the templated string is a unicode result, whereas a non- templated string is a non-unicode string) [will@centos6.3] $ python Python 2.6.6 (r266:84292, Sep 11 2012, 08:34:23) [GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import shlex >>> shlex.split(u'abc') ['a\x00\x00\x00b\x00\x00\x00c\x00\x00\x00'] [will@fedora17] $ python Python 2.7.3 (default, Jul 24 2012, 10:05:38) [GCC 4.7.0 20120507 (Red Hat 4.7.0-5)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import shlex >>> shlex.split(u'abc') ['abc'] The proposed fix (coercing the include parameters to string before the shlex.split) may not be ideal but it does fix the bug for my test case.
This commit is contained in:
parent
5cac2a763b
commit
9d87733f98
4 changed files with 33 additions and 1 deletions
|
@ -194,7 +194,7 @@ class Play(object):
|
||||||
task_vars['_original_file'] = original_file
|
task_vars['_original_file'] = original_file
|
||||||
|
|
||||||
if 'include' in x:
|
if 'include' in x:
|
||||||
tokens = shlex.split(x['include'])
|
tokens = shlex.split(str(x['include']))
|
||||||
items = ['']
|
items = ['']
|
||||||
included_additional_conditions = list(additional_conditions)
|
included_additional_conditions = list(additional_conditions)
|
||||||
for k in x:
|
for k in x:
|
||||||
|
|
|
@ -211,6 +211,27 @@ class TestPlaybook(unittest.TestCase):
|
||||||
|
|
||||||
assert utils.jsonify(expected, format=True) == utils.jsonify(actual,format=True)
|
assert utils.jsonify(expected, format=True) == utils.jsonify(actual,format=True)
|
||||||
|
|
||||||
|
def test_task_includes(self):
|
||||||
|
pb = os.path.join(self.test_dir, 'task-includer.yml')
|
||||||
|
actual = self._run(pb)
|
||||||
|
|
||||||
|
# if different, this will output to screen
|
||||||
|
print "**ACTUAL**"
|
||||||
|
print utils.jsonify(actual, format=True)
|
||||||
|
expected = {
|
||||||
|
"localhost": {
|
||||||
|
"changed": 0,
|
||||||
|
"failures": 0,
|
||||||
|
"ok": 1,
|
||||||
|
"skipped": 0,
|
||||||
|
"unreachable": 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print "**EXPECTED**"
|
||||||
|
print utils.jsonify(expected, format=True)
|
||||||
|
|
||||||
|
assert utils.jsonify(expected, format=True) == utils.jsonify(actual,format=True)
|
||||||
|
|
||||||
def test_playbook_vars(self):
|
def test_playbook_vars(self):
|
||||||
test_callbacks = TestCallbacks()
|
test_callbacks = TestCallbacks()
|
||||||
playbook = ansible.playbook.PlayBook(
|
playbook = ansible.playbook.PlayBook(
|
||||||
|
|
2
test/task-included.yml
Normal file
2
test/task-included.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
---
|
||||||
|
- action: debug msg="$internal"
|
9
test/task-includer.yml
Normal file
9
test/task-includer.yml
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
---
|
||||||
|
- hosts: all
|
||||||
|
connection: local
|
||||||
|
gather_facts: no
|
||||||
|
vars:
|
||||||
|
- internal: xyz
|
||||||
|
|
||||||
|
tasks:
|
||||||
|
- include: task-included.yml internal=$internal
|
Loading…
Reference in a new issue