Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Separate the 'context' and 'side effects' aspects of the context #171

Closed
tonyandrewmeyer opened this issue Aug 12, 2024 · 4 comments
Closed

Comments

@tonyandrewmeyer
Copy link
Collaborator

The context has a bunch of "this is the context the event runs in":

  • charm_spec
  • charm_root (in terms of what's there when the event starts - anything the charm writes to it is more state)
  • juju_version
  • app_trusted

But there's also a lot of side-effects, which have grown noticeably in 7.x:

  • juju_log
  • app_status_history
  • unit_status_history
  • workload_version_history
  • requested_storages
  • exec_history (TBC)
  • removed_secret_revisions
  • emitted_events
  • action_logs
  • action_results

I feel like it would be cleaner if Context was more cleanly just the context (plus config, like the settings for capturing events), and the side effects were available some other way.

@tonyandrewmeyer
Copy link
Collaborator Author

This is just spitballing here, but what if the side-effects were only available when you ran the event with the context manager, so all of those attributes moved from Context to Manager, filled when you did mgr.run()?

It's more of a hassle to use them but it does feel like a more natural fit to me, and most tests shouldn't need to access any of them - two main exceptions being action tests, most of which I assume do want to check the results, and secret-remove events, most of which should be checking that the expected revision was removed.

@PietroPasotti
Copy link
Collaborator

I like this suggestion. It also has the benefit of reinforcing the principle that scenario is chiefly a black-box testing thing. If you want to peer into the box, you have to take an extra step.

@tonyandrewmeyer
Copy link
Collaborator Author

Of course, an issue now is that we're promising that the version will stay at 7.x for a while, and they couldn't be removed from Context without moving to 8.

I do still think this would be worth doing, though. They could be added to Manager in a minor release and the other location could have a DeprecationWarning emitted, and if new side effect attributes get added they could then only be on Manager.

@tonyandrewmeyer
Copy link
Collaborator Author

Moved to canonical/operator#1422

@tonyandrewmeyer tonyandrewmeyer closed this as not planned Won't fix, can't repro, duplicate, stale Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants