mirror of https://github.com/ansible/ansible.git
Catch errors getting filters (#74127)
* Catch errors getting filters, and fail * Add changelog * Switch to warnings instead of errors, to match other plugin loader behavior * Add tests * Handle collectionspull/74291/head
parent
28a2d9b4ae
commit
1082e2ab79
@ -0,0 +1,5 @@
|
||||
bugfixes:
|
||||
- Templating - Ensure we catch exceptions when calling ``.filters()`` or
|
||||
``.tests()`` on their respective plugins and properly error, instead of
|
||||
aborting which results in no filters being added to the jinja2 environment
|
||||
(https://github.com/ansible/ansible/pull/74127)
|
||||
@ -0,0 +1 @@
|
||||
shippable/posix/group5
|
||||
@ -0,0 +1,11 @@
|
||||
# Copyright (c) 2021 Matt Martz <matt@sivel.net>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
class FilterModule:
|
||||
def filters(self):
|
||||
raise TypeError('bad_collection_filter')
|
||||
@ -0,0 +1,13 @@
|
||||
# Copyright (c) 2021 Matt Martz <matt@sivel.net>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
class FilterModule:
|
||||
def filters(self):
|
||||
return {
|
||||
'hello': lambda x: 'Hello, %s!' % x,
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
# Copyright (c) 2021 Matt Martz <matt@sivel.net>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
class TestModule:
|
||||
def tests(self):
|
||||
raise TypeError('bad_collection_test')
|
||||
@ -0,0 +1,13 @@
|
||||
# Copyright (c) 2021 Matt Martz <matt@sivel.net>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
class TestModule:
|
||||
def tests(self):
|
||||
return {
|
||||
'world': lambda x: x.lower() == 'world',
|
||||
}
|
||||
@ -0,0 +1,11 @@
|
||||
# Copyright (c) 2021 Matt Martz <matt@sivel.net>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
class FilterModule:
|
||||
def filters(self):
|
||||
raise TypeError('bad_filter')
|
||||
@ -0,0 +1,13 @@
|
||||
# Copyright (c) 2021 Matt Martz <matt@sivel.net>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
class FilterModule:
|
||||
def filters(self):
|
||||
return {
|
||||
'hello': lambda x: 'Hello, %s!' % x,
|
||||
}
|
||||
@ -0,0 +1,10 @@
|
||||
- hosts: localhost
|
||||
gather_facts: false
|
||||
tasks:
|
||||
- assert:
|
||||
that:
|
||||
- '"World"|hello == "Hello, World!"'
|
||||
- '"World" is world'
|
||||
|
||||
- '"World"|foo.bar.hello == "Hello, World!"'
|
||||
- '"World" is foo.bar.world'
|
||||
@ -0,0 +1,22 @@
|
||||
- shell: ansible-playbook {{ verbosity }} playbook.yml
|
||||
args:
|
||||
chdir: '{{ role_path }}'
|
||||
vars:
|
||||
verbosity: "{{ '' if not ansible_verbosity else '-' ~ ('v' * ansible_verbosity) }}"
|
||||
register: result
|
||||
|
||||
- debug:
|
||||
var: result
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- '"[WARNING]: Skipping filter plugin" in result.stderr'
|
||||
- '"[WARNING]: Skipping test plugin" in result.stderr'
|
||||
- |
|
||||
result.stderr|regex_findall('bad_filter')|length == 2
|
||||
- |
|
||||
result.stderr|regex_findall('bad_test')|length == 2
|
||||
- |
|
||||
result.stderr|regex_findall('bad_collection_filter')|length == 2
|
||||
- |
|
||||
result.stderr|regex_findall('bad_collection_test')|length == 2
|
||||
@ -0,0 +1,11 @@
|
||||
# Copyright (c) 2021 Matt Martz <matt@sivel.net>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
class TestModule:
|
||||
def tests(self):
|
||||
raise TypeError('bad_test')
|
||||
@ -0,0 +1,13 @@
|
||||
# Copyright (c) 2021 Matt Martz <matt@sivel.net>
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
class TestModule:
|
||||
def tests(self):
|
||||
return {
|
||||
'world': lambda x: x.lower() == 'world',
|
||||
}
|
||||
Loading…
Reference in New Issue