Fix shebang. shebang and interpreter path weren't being templated (#33698)

* Fix shebang.  shebang and interpreter path weren't being templated

Fixes #18665
Fixes #33696
This commit is contained in:
Toshio Kuratomi 2017-12-08 06:59:24 -08:00 committed by GitHub
parent c8a5e689e3
commit b455901904
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 22 deletions

View file

@ -93,26 +93,35 @@ class TestSlurp(object):
assert amc._slurp('some_file') == '#!/usr/bin/python\ndef test(args):\nprint("hi")\n'
@pytest.fixture
def templar():
class FakeTemplar(object):
def template(self, template_string, *args, **kwargs):
return template_string
return FakeTemplar()
class TestGetShebang(object):
"""Note: We may want to change the API of this function in the future. It isn't a great API"""
def test_no_interpreter_set(self):
assert amc._get_shebang(u'/usr/bin/python', {}) == (None, u'/usr/bin/python')
def test_no_interpreter_set(self, templar):
assert amc._get_shebang(u'/usr/bin/python', {}, templar) == (None, u'/usr/bin/python')
def test_non_python_interpreter(self):
assert amc._get_shebang(u'/usr/bin/ruby', {}) == (None, u'/usr/bin/ruby')
def test_non_python_interpreter(self, templar):
assert amc._get_shebang(u'/usr/bin/ruby', {}, templar) == (None, u'/usr/bin/ruby')
def test_interpreter_set_in_task_vars(self):
assert amc._get_shebang(u'/usr/bin/python', {u'ansible_python_interpreter': u'/usr/bin/pypy'}) == \
def test_interpreter_set_in_task_vars(self, templar):
assert amc._get_shebang(u'/usr/bin/python', {u'ansible_python_interpreter': u'/usr/bin/pypy'}, templar) == \
(u'#!/usr/bin/pypy', u'/usr/bin/pypy')
def test_non_python_interpreter_in_task_vars(self):
assert amc._get_shebang(u'/usr/bin/ruby', {u'ansible_ruby_interpreter': u'/usr/local/bin/ruby'}) == \
def test_non_python_interpreter_in_task_vars(self, templar):
assert amc._get_shebang(u'/usr/bin/ruby', {u'ansible_ruby_interpreter': u'/usr/local/bin/ruby'}, templar) == \
(u'#!/usr/local/bin/ruby', u'/usr/local/bin/ruby')
def test_with_args(self):
assert amc._get_shebang(u'/usr/bin/python', {u'ansible_python_interpreter': u'/usr/bin/python3'}, args=('-tt', '-OO')) == \
def test_with_args(self, templar):
assert amc._get_shebang(u'/usr/bin/python', {u'ansible_python_interpreter': u'/usr/bin/python3'}, templar, args=('-tt', '-OO')) == \
(u'#!/usr/bin/python3 -tt -OO', u'/usr/bin/python3')
def test_python_via_env(self):
assert amc._get_shebang(u'/usr/bin/python', {u'ansible_python_interpreter': u'/usr/bin/env python'}) == \
def test_python_via_env(self, templar):
assert amc._get_shebang(u'/usr/bin/python', {u'ansible_python_interpreter': u'/usr/bin/env python'}, templar) == \
(u'#!/usr/bin/env python', u'/usr/bin/env python')