[2.7] JUJU_HOOK_NAME is only present in debug-hooks sessions

Bug #1854505 reported by Dmitrii Shcherbakov
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Canonical Juju
Fix Released
High
Dmitrii Shcherbakov
2.7
Fix Released
High
Heather Lanigan

Bug Description

JUJU_HOOK_NAME is only added to tmux sessions created via debug-hooks.

Contrary to that, JUJU_{ACTION, FUNCTION}_NAME is always set for functions and they are not handled by debug-hooks at all.

Docs suggest that JUJU_HOOK_NAME is "available to charms during hook execution." which is incorrect:
https://discourse.jujucharms.com/t/juju-environment-variables/1162

It is possible to extract a hook name from JUJU_CONTEXT_ID but its format (<unit_name>-<hook_name>-<rand-int-63>) is not publicly documented:

https://github.com/juju/juju/blob/juju-2.7.0/worker/uniter/runner/context/contextfactory.go#L242
https://github.com/juju/juju/blob/juju-2.7.0/worker/uniter/runner/context/contextfactory.go#L154-L158

------------

The reason why JUJU_HOOK_NAME is needed is to give charm frameworks an identification mechanism for what exactly gets executed: an action or a hook for a regular event.

While currently the presence/lack of JUJU_{ACTION,FUNCTION}_NAME and the value of argv[0] provide the same information, if a single entrypoint style of execution (hooks/process-event, functions/process-function) will be supported by Juju, argv[0] will no longer be possible to rely on.

-----------

Another reason to consider this is that Python charms can only rely on argv[0] on Linux distributions - not Windows. For Windows Python places a full path after symlink resolution into argv[0].

Example: for hooks/install -> ..\lib\charm.py, argv[0] will be <disk-letter>:\<charm_dir_path>\lib\charm.py

https://github.com/python/cpython/blob/3.6/Python/sysmodule.c#L2161-L2259 (3.6)
https://github.com/python/cpython/blob/3.7/Python/pathconfig.c#L280-L393 (3.7)

The Windows-specific replacement logic:
https://github.com/python/cpython/blob/3.7/Python/pathconfig.c#L352-L360

Revision history for this message
Dmitrii Shcherbakov (dmitriis) wrote :
Revision history for this message
Gustavo Niemeyer (niemeyer) wrote :

Given we have a soft agreement to introduce a new hook that runs when any other hook would run, we'll need that variable anyway. We can look at both changes in the same work.

Revision history for this message
Richard Harding (rharding) wrote :

Agree with Gustavo on tying it to the new "process_event" hook. I've targeted the bug and will make sure this goes into the spec and notes for that feature that the team is kicking off work on tomorrow.

Changed in juju:
status: New → Triaged
importance: Undecided → High
milestone: none → 2.8-beta1
description: updated
John A Meinel (jameinel)
Changed in juju:
status: Triaged → In Progress
Changed in juju:
status: In Progress → Fix Committed
Changed in juju:
assignee: nobody → Dmitrii Shcherbakov (dmitriis)
Revision history for this message
Heather Lanigan (hmlanigan) wrote :
Harry Pidcock (hpidcock)
Changed in juju:
status: Fix Committed → Fix Released
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.