Jinja template error causes Juju manila-plugin-relation-changed hook to fail

Bug #2025507 reported by Jadon Naas
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Manila Generic Backend Charm
In Progress
Undecided
Jadon Naas
2023.1
New
Undecided
Unassigned
Yoga
New
Undecided
Unassigned
Zed
New
Undecided
Unassigned

Bug Description

When I try to deploy the stable/yoga release of charm-manila-generic, the charm enters an error state with a failed hook. Here is the traceback from the unit logs for manila-generic/0.

2023-06-30 19:08:34 INFO juju.worker.uniter resolver.go:145 awaiting error resolution for "relation-changed" hook
2023-06-30 19:08:35 INFO unit.manila-generic/0.juju-log server.go:316 manila-plugin:31: Reactive main running for hook manila-plugin-relation-changed
2023-06-30 19:08:35 ERROR unit.manila-generic/0.juju-log server.go:316 manila-plugin:31: Unable to find implementation for relation: requires of juju-info
2023-06-30 19:08:35 INFO unit.manila-generic/0.juju-log server.go:316 manila-plugin:31: Invoking reactive handler: hooks/relations/manila-plugin/provides.py:50:changed
2023-06-30 19:08:35 INFO unit.manila-generic/0.juju-log server.go:316 manila-plugin:31: Invoking reactive handler: reactive/manila_generic_handlers.py:31:send_config
2023-06-30 19:08:35 ERROR unit.manila-generic/0.juju-log server.go:316 manila-plugin:31: Hook error:
Traceback (most recent call last):
  File "/var/lib/juju/agents/unit-manila-generic-0/.venv/lib/python3.10/site-packages/charms/reactive/__init__.py", line 74, in main
    bus.dispatch(restricted=restricted_mode)
  File "/var/lib/juju/agents/unit-manila-generic-0/.venv/lib/python3.10/site-packages/charms/reactive/bus.py", line 390, in dispatch
    _invoke(other_handlers)
  File "/var/lib/juju/agents/unit-manila-generic-0/.venv/lib/python3.10/site-packages/charms/reactive/bus.py", line 359, in _invoke
    handler.invoke()
  File "/var/lib/juju/agents/unit-manila-generic-0/.venv/lib/python3.10/site-packages/charms/reactive/bus.py", line 181, in invoke
    self._action(*args)
  File "/var/lib/juju/agents/unit-manila-generic-0/charm/reactive/manila_generic_handlers.py", line 41, in send_config
    generic_charm.get_config_for_principal(
  File "/var/lib/juju/agents/unit-manila-generic-0/charm/lib/charm/openstack/manila_generic.py", line 204, in get_config_for_principal
    rendered_configs = charmhelpers.core.templating.render(
  File "/var/lib/juju/agents/unit-manila-generic-0/.venv/lib/python3.10/site-packages/charmhelpers/core/templating.py", line 80, in render
    content = template.render(context)
  File "/var/lib/juju/agents/unit-manila-generic-0/.venv/lib/python3.10/site-packages/jinja2/environment.py", line 1291, in render
    self.environment.handle_exception()
  File "/var/lib/juju/agents/unit-manila-generic-0/.venv/lib/python3.10/site-packages/jinja2/environment.py", line 926, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "templates/mitaka/manila.conf", line 25, in top-level template code
    {% include "parts/authentication_data" %}
  File "/var/lib/juju/agents/unit-manila-generic-0/.venv/lib/python3.10/site-packages/jinja2/environment.py", line 926, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "templates/parts/authentication_data", line 3, in template
    {{ # Defense mechanism introduced in the charm release 21.10 because of a
jinja2.exceptions.TemplateSyntaxError: unexpected char '#' at 123

2023-06-30 19:08:35 WARNING unit.manila-generic/0.manila-plugin-relation-changed logger.go:60 Traceback (most recent call last):
2023-06-30 19:08:35 WARNING unit.manila-generic/0.manila-plugin-relation-changed logger.go:60 File "/var/lib/juju/agents/unit-manila-generic-0/charm/hooks/manila-plugin-relation-changed", line 22, in <module>
2023-06-30 19:08:35 WARNING unit.manila-generic/0.manila-plugin-relation-changed logger.go:60 main()
2023-06-30 19:08:35 WARNING unit.manila-generic/0.manila-plugin-relation-changed logger.go:60 File "/var/lib/juju/agents/unit-manila-generic-0/.venv/lib/python3.10/site-packages/charms/reactive/__init__.py", line 74, in main
2023-06-30 19:08:35 WARNING unit.manila-generic/0.manila-plugin-relation-changed logger.go:60 bus.dispatch(restricted=restricted_mode)
2023-06-30 19:08:35 WARNING unit.manila-generic/0.manila-plugin-relation-changed logger.go:60 File "/var/lib/juju/agents/unit-manila-generic-0/.venv/lib/python3.10/site-packages/charms/reactive/bus.py", line 390, in dispatch
2023-06-30 19:08:35 WARNING unit.manila-generic/0.manila-plugin-relation-changed logger.go:60 _invoke(other_handlers)
2023-06-30 19:08:35 WARNING unit.manila-generic/0.manila-plugin-relation-changed logger.go:60 File "/var/lib/juju/agents/unit-manila-generic-0/.venv/lib/python3.10/site-packages/charms/reactive/bus.py", line 359, in _invoke
2023-06-30 19:08:35 WARNING unit.manila-generic/0.manila-plugin-relation-changed logger.go:60 handler.invoke()
2023-06-30 19:08:35 WARNING unit.manila-generic/0.manila-plugin-relation-changed logger.go:60 File "/var/lib/juju/agents/unit-manila-generic-0/.venv/lib/python3.10/site-packages/charms/reactive/bus.py", line 181, in invoke
2023-06-30 19:08:35 WARNING unit.manila-generic/0.manila-plugin-relation-changed logger.go:60 self._action(*args)
2023-06-30 19:08:35 WARNING unit.manila-generic/0.manila-plugin-relation-changed logger.go:60 File "/var/lib/juju/agents/unit-manila-generic-0/charm/reactive/manila_generic_handlers.py", line 41, in send_config
2023-06-30 19:08:35 WARNING unit.manila-generic/0.manila-plugin-relation-changed logger.go:60 generic_charm.get_config_for_principal(
2023-06-30 19:08:35 WARNING unit.manila-generic/0.manila-plugin-relation-changed logger.go:60 File "/var/lib/juju/agents/unit-manila-generic-0/charm/lib/charm/openstack/manila_generic.py", line 204, in get_config_for_principal
2023-06-30 19:08:35 WARNING unit.manila-generic/0.manila-plugin-relation-changed logger.go:60 rendered_configs = charmhelpers.core.templating.render(
2023-06-30 19:08:35 WARNING unit.manila-generic/0.manila-plugin-relation-changed logger.go:60 File "/var/lib/juju/agents/unit-manila-generic-0/.venv/lib/python3.10/site-packages/charmhelpers/core/templating.py", line 80, in render
2023-06-30 19:08:35 WARNING unit.manila-generic/0.manila-plugin-relation-changed logger.go:60 content = template.render(context)
2023-06-30 19:08:35 WARNING unit.manila-generic/0.manila-plugin-relation-changed logger.go:60 File "/var/lib/juju/agents/unit-manila-generic-0/.venv/lib/python3.10/site-packages/jinja2/environment.py", line 1291, in render
2023-06-30 19:08:35 WARNING unit.manila-generic/0.manila-plugin-relation-changed logger.go:60 self.environment.handle_exception()
2023-06-30 19:08:35 WARNING unit.manila-generic/0.manila-plugin-relation-changed logger.go:60 File "/var/lib/juju/agents/unit-manila-generic-0/.venv/lib/python3.10/site-packages/jinja2/environment.py", line 926, in handle_exception
2023-06-30 19:08:35 WARNING unit.manila-generic/0.manila-plugin-relation-changed logger.go:60 raise rewrite_traceback_stack(source=source)
2023-06-30 19:08:35 WARNING unit.manila-generic/0.manila-plugin-relation-changed logger.go:60 File "templates/mitaka/manila.conf", line 25, in top-level template code
2023-06-30 19:08:35 WARNING unit.manila-generic/0.manila-plugin-relation-changed logger.go:60 {% include "parts/authentication_data" %}
2023-06-30 19:08:35 WARNING unit.manila-generic/0.manila-plugin-relation-changed logger.go:60 File "/var/lib/juju/agents/unit-manila-generic-0/.venv/lib/python3.10/site-packages/jinja2/environment.py", line 926, in handle_exception
2023-06-30 19:08:35 WARNING unit.manila-generic/0.manila-plugin-relation-changed logger.go:60 raise rewrite_traceback_stack(source=source)
2023-06-30 19:08:35 WARNING unit.manila-generic/0.manila-plugin-relation-changed logger.go:60 File "templates/parts/authentication_data", line 3, in template
2023-06-30 19:08:35 WARNING unit.manila-generic/0.manila-plugin-relation-changed logger.go:60 {{ # Defense mechanism introduced in the charm release 21.10 because of a
2023-06-30 19:08:35 WARNING unit.manila-generic/0.manila-plugin-relation-changed logger.go:60 jinja2.exceptions.TemplateSyntaxError: unexpected char '#' at 123
2023-06-30 19:08:35 ERROR juju.worker.uniter.operation runhook.go:140 hook "manila-plugin-relation-changed" (via explicit, bespoke hook script) failed: exit status 1

The problem is a typo in the Jinja2 template at templates/parts/authentication_data. It looks like there was supposed to be a comment, but the syntax is incorrect. If you replace

{{ # Defense mechanism introduced in the charm release 21.10 because of a
     relation data key renaming, and would be safe to remove 2 releases later.
#}}

with

{# Defense mechanism introduced in the charm release 21.10 because of a
     relation data key renaming, and would be safe to remove 2 releases later.
#}

The error goes away, the hook fires successfully, and Juju reports a green running status for the manila-generic unit. {# #} is the correct syntax for comments in Jinja2 templates according to the Jinja2 docs at https://jinja.palletsprojects.com/en/3.1.x/templates/#comments.

I will submit a small patch to fix this error in the template and look at backporting it.

Revision history for this message
Jadon Naas (jadonn) wrote :
Changed in charm-manila-generic:
status: New → In Progress
assignee: nobody → Jadon Naas (jadonn)
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.