Need a way to abort charm execution
See original GitHub issueAs a charmer, I’d like a way to abort charm execution from anywhere. Use case: I have a charm with many event handlers, but regardless of which event we’re in, I want the charm to do nothing and exit with blocked state if a certain precondition is not met, say, a certain config value is provided. Right now I have to, for each event handler, add a check:
if not self.condition():
self.unit.status = ...
return
I could raise an exception in __init__
, but that would leave the charm in error state.
I propose to add a Framework.abort()
method that raises an exception that gets caught in main
and terminates charm execution without committing any state (status will pass through because that’s committed synchronously).
With that, I would only need to add these three lines:
# in MyCharm.__main__:
if not self.condition():
self.unit.status=...
self.framework.abort()
Issue Analytics
- State:
- Created a year ago
- Comments:21 (16 by maintainers)
Top Results From Across the Web
Charm — Charm4py 1.0.0 documentation
abort (message): Aborts the program, printing the specified message and a stack trace of the PE which aborted. It can be called from...
Read more >Charm hooks - doc - Charmhub - Juju Discourse
Hooks are executable files in a charm's hooks directory; hooks with ... enter an error state if the unit agent process is aborted...
Read more >A Stay of Execution for Lizzy | Dishonored Wiki - Fandom
An Officer executes three guards. The mission starts outside Coldridge Prison where Daud must infiltrate the building and find Lizzy Stride.
Read more >Service Report CRM_SOCM_SERVICE_REPORT - SAP Blogs
I personally think that the report should only be used by a ChaRM administrator or IT-operator, but not by any other users.
Read more >Charm++ Documentation - Read the Docs
will not interrupt an executing method to start any other work, and all calls ... Every Charm++ program must have at least one...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@benhoyt I will add it as part of sdk tutorial and also add “how to” section on juju.is
I will let you review it once ready
@benhoyt for my best understanding of what happens when in terms of syncing with juju: see the second section of this doc https://discourse.charmhub.io/t/talking-to-a-workload-control-flow-from-a-to-z/6161
The logic of the code you wrote above is what we need, the issue is: do we want to expose a high-level callable that abstracts it, or do we leave it to the charmers to remember to call
framework.commit()
before they exit?