aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Goddard <mark@stackhpc.com>2022-03-24 16:25:12 +0000
committerMark Goddard <mark@stackhpc.com>2022-03-24 16:29:26 +0000
commitfc2292b230fb2be03acb2273f097c566f59ba8fc (patch)
tree4315ad8169db43cd0408afbf2ae2a183461ff59b
parentefadc9591327edabf13d6c0b74178993bf5ef382 (diff)
downloadkolla-ansible-fc2292b230fb2be03acb2273f097c566f59ba8fc.tar.gz
kolla-ansible-fc2292b230fb2be03acb2273f097c566f59ba8fc.zip
Use jinja2.pass_context instead of contextfilter
The contextfilter decorator was deprecated in jinja2 3.0.0, and has been dropped in 3.1.0. This results in the following warning, and failed attempts to use filters: [WARNING]: Skipping plugin (filters.py) as it seems to be invalid: module 'jinja2' has no attribute 'contextfilter' This change switches to use the pass_context decorator. The minimum version of Jinja2 is raised to 3 to ensure pass_context is present. Change-Id: I649dd6211d3ae72b9539bc44652ef8cf5d579777
-rw-r--r--kolla_ansible/filters.py8
-rw-r--r--kolla_ansible/kolla_address.py4
-rw-r--r--releasenotes/notes/jinja2-pass-context-2afc328ade8c407b.yaml4
-rw-r--r--requirements.txt2
4 files changed, 11 insertions, 7 deletions
diff --git a/kolla_ansible/filters.py b/kolla_ansible/filters.py
index 94c4ae58a..7eb826b7c 100644
--- a/kolla_ansible/filters.py
+++ b/kolla_ansible/filters.py
@@ -18,7 +18,7 @@ from kolla_ansible import exception
from kolla_ansible.helpers import _call_bool_filter
-@jinja2.contextfilter
+@jinja2.pass_context
def service_enabled(context, service):
"""Return whether a service is enabled.
@@ -34,7 +34,7 @@ def service_enabled(context, service):
return _call_bool_filter(context, enabled)
-@jinja2.contextfilter
+@jinja2.pass_context
def service_mapped_to_host(context, service):
"""Return whether a service is mapped to this host.
@@ -62,7 +62,7 @@ def service_mapped_to_host(context, service):
service.get("container_name", "<unknown>"))
-@jinja2.contextfilter
+@jinja2.pass_context
def service_enabled_and_mapped_to_host(context, service):
"""Return whether a service is enabled and mapped to this host.
@@ -74,7 +74,7 @@ def service_enabled_and_mapped_to_host(context, service):
service_mapped_to_host(context, service))
-@jinja2.contextfilter
+@jinja2.pass_context
def select_services_enabled_and_mapped_to_host(context, services):
"""Select services that are enabled and mapped to this host.
diff --git a/kolla_ansible/kolla_address.py b/kolla_ansible/kolla_address.py
index f40b59f6a..12dff1ad1 100644
--- a/kolla_ansible/kolla_address.py
+++ b/kolla_ansible/kolla_address.py
@@ -14,14 +14,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-from jinja2.filters import contextfilter
+from jinja2.filters import pass_context
from jinja2.runtime import Undefined
from kolla_ansible.exception import FilterError
from kolla_ansible.helpers import _call_bool_filter
-@contextfilter
+@pass_context
def kolla_address(context, network_name, hostname=None):
"""returns IP address on the requested network
diff --git a/releasenotes/notes/jinja2-pass-context-2afc328ade8c407b.yaml b/releasenotes/notes/jinja2-pass-context-2afc328ade8c407b.yaml
new file mode 100644
index 000000000..3a7ecc729
--- /dev/null
+++ b/releasenotes/notes/jinja2-pass-context-2afc328ade8c407b.yaml
@@ -0,0 +1,4 @@
+---
+fixes:
+ - |
+ Fixes an issue seen when using Jinja2 3.1.0.
diff --git a/requirements.txt b/requirements.txt
index e85f7744c..59147c1bd 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -11,7 +11,7 @@ cryptography>=2.1 # BSD/Apache-2.0
oslo.utils>=3.33.0 # Apache-2.0
# templating
-Jinja2>=2.10 # BSD License (3 clause)
+Jinja2>=3 # BSD License (3 clause)
# Ansible's json_query
jmespath>=0.9.3 # MIT