Merge "Use jinja2.pass_context instead of contextfilter" into stable/train

This commit is contained in:
Zuul 2022-03-28 17:10:01 +00:00 committed by Gerrit Code Review
commit 4fecd05617
3 changed files with 19 additions and 7 deletions

View File

@ -12,13 +12,17 @@
# License for the specific language governing permissions and limitations
# under the License.
import jinja2
# NOTE: jinja2 3.1.0 dropped contextfilter in favour of pass_context.
try:
from jinja2 import pass_context
except ImportError:
from jinja2 import contextfilter as pass_context
from kolla_ansible import exception
from kolla_ansible.helpers import _call_bool_filter
@jinja2.contextfilter
@pass_context
def service_enabled(context, service):
"""Return whether a service is enabled.
@ -34,7 +38,7 @@ def service_enabled(context, service):
return _call_bool_filter(context, enabled)
@jinja2.contextfilter
@pass_context
def service_mapped_to_host(context, service):
"""Return whether a service is mapped to this host.
@ -62,7 +66,7 @@ def service_mapped_to_host(context, service):
service.get("container_name", "<unknown>"))
@jinja2.contextfilter
@pass_context
def service_enabled_and_mapped_to_host(context, service):
"""Return whether a service is enabled and mapped to this host.
@ -74,7 +78,7 @@ def service_enabled_and_mapped_to_host(context, service):
service_mapped_to_host(context, service))
@jinja2.contextfilter
@pass_context
def select_services_enabled_and_mapped_to_host(context, services):
"""Select services that are enabled and mapped to this host.

View File

@ -14,14 +14,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from jinja2.filters import contextfilter
# NOTE: jinja2 3.1.0 dropped contextfilter in favour of pass_context.
try:
from jinja2 import pass_context
except ImportError:
from jinja2 import contextfilter as 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

View File

@ -0,0 +1,4 @@
---
fixes:
- |
Fixes an issue seen when using Jinja2 3.1.0.