Skip to content

Commit 41b4380

Browse files
Marcin Juszkiewiczmarkgoddard
authored andcommitted
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. This change has been updated to also support Jinja2 2.x releases, since the Wallaby upper constraints specify 2.11.3. In practice, most users will not use UC to install kolla. This change also includes a backport of I7d4788f5b63fba24e3b2f9b15c16866ff811d83e: Always use the distro-provided libvirt-python This patch switches masakari-monitors image to follow nova-compute and ceilometer-compute images. This will be used and required after [1] merges. Usage of libvirt-python from PyPI has already proven to be problematic on CentOS Stream in our stable branches. [2] With this patch we avoid those issues as well. [1] https://review.opendev.org/c/openstack/masakari-monitors/+/804913 [2] https://review.opendev.org/c/openstack/kolla/+/797102 Depends-On: https://review.opendev.org/c/openstack/masakari-monitors/+/804913 NOTE(hrw): added removal of libvirt-python from upper-constraints as we have never version of libvirt that Wallaby used. (cherry picked from commit 72fcc0f) CoAuthored-by: Mark Goddard <[email protected]> Change-Id: I5efab66e487e06abd1a56af97d7e7caa1ebc880d
1 parent ba22f9e commit 41b4380

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

docker/masakari/masakari-monitors/Dockerfile.j2

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ LABEL maintainer="{{ maintainer }}" name="{{ image_name }}" build-date="{{ build
3535
{% if base_package_type == 'rpm' %}
3636

3737
{% set masakari_monitors_packages = [
38-
'libvirt-devel',
38+
'python3-libvirt',
3939
'pacemaker-cli',
4040
'tcpdump',
4141
] %}
4242

4343
{% elif base_package_type == 'deb' %}
4444

4545
{% set masakari_monitors_packages = [
46-
'libvirt-dev',
46+
'python3-libvirt',
4747
'pacemaker-cli-utils',
4848
'tcpdump',
4949
] %}
@@ -58,7 +58,9 @@ ADD masakari-monitors-archive /masakari-monitors-source
5858
'/masakari-monitors'
5959
] %}
6060

61+
# NOTE(hrw): distros may provide other version of libvirt
6162
RUN ln -s masakari-monitors-source/* masakari-monitors \
63+
&& sed -i -e "/^libvirt-python/d" /requirements/upper-constraints.txt \
6264
&& {{ macros.install_pip(masakari_monitors_pip_packages | customizable("pip_packages")) }} \
6365
&& mkdir -p /etc/masakari-monitors \
6466
&& chown -R masakari: /etc/masakari-monitors

kolla/template/filters.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from jinja2 import contextfilter
15+
# NOTE: jinja2 3.1.0 dropped contextfilter in favour of pass_context.
16+
try:
17+
from jinja2 import pass_context
18+
except ImportError:
19+
from jinja2 import contextfilter as pass_context
20+
1621
from jinja2 import Undefined
1722

1823

19-
@contextfilter
24+
@pass_context
2025
def customizable(context, val_list, call_type):
2126
# NOTE(mgoddard): Don't try to customise undefined values. There are cases
2227
# where this might happen, for example using a generic template overrides

kolla/template/methods.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
import os
1616
import yaml
1717

18-
from jinja2 import contextfunction
18+
# NOTE: jinja2 3.1.0 dropped contextfilter in favour of pass_context.
19+
try:
20+
from jinja2 import pass_context
21+
except ImportError:
22+
from jinja2 import contextfilter as pass_context
1923

2024

2125
def debian_package_install(packages, clean_package_cache=True):
@@ -71,7 +75,7 @@ def debian_package_install(packages, clean_package_cache=True):
7175
return ' && '.join(cmds)
7276

7377

74-
@contextfunction
78+
@pass_context
7579
def handle_repos(context, reponames, mode):
7680
"""NOTE(hrw): we need to handle CentOS, Debian and Ubuntu with one macro.
7781
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
Fixes an issue seen when using Jinja2 3.1.0.

0 commit comments

Comments
 (0)