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

fix: adjust Harness secret behaviour to align with Juju #1248

Merged
merged 12 commits into from
Jun 25, 2024

Conversation

tonyandrewmeyer
Copy link
Contributor

@tonyandrewmeyer tonyandrewmeyer commented Jun 5, 2024

Adjust Harness so that the errors match what Juju does in practice (I tested each case - the results are in a table in a comment in #1229).

  • When Juju responds with a message including "not found", we raise SecretNotFoundError
  • When Juju responds with any other message (such as "permission denied"), we raise ModelError
  • When Juju succeeds and only fails at the completion of the hook, we raise RuntimeError - in production, the charm cannot catch this, but we do want to surface this error, so RuntimeError seems most approprate

In addition:

  • Update the documentation to clarify when secret content is cached (this was a request from the discussion with the data platform team in Madrid)
  • Correct the documentation regarding when ModelError and when SecretNotFoundError will be raised with the secret methods
  • Don't clear the Secret object local cache of the secret content on set_contents. The contents won't change until refresh is used, so there's no point forcing the next call to get the content from Juju.

Juju may change the responses so that there is increased consistency (probably via this bug) but it seems best if we fix the behaviour to match now, and then if Juju changes in the future, we can update ops then (also deciding at that time how to handle the issue that different Juju versions will have different behaviour).

Fixes #1229.

@tonyandrewmeyer tonyandrewmeyer marked this pull request as ready for review June 6, 2024 07:30
Copy link
Collaborator

@benhoyt benhoyt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, thanks. One minor comment, though I don't have strong feelings about it, so if you think that paragraph should stay in, go ahead.

ops/model.py Outdated Show resolved Hide resolved
@tonyandrewmeyer
Copy link
Contributor Author

@IronCore864 would you mind reviewing this when you have time? Thanks!

ops/charm.py Show resolved Hide resolved
ops/testing.py Show resolved Hide resolved
@tonyandrewmeyer tonyandrewmeyer merged commit 79706f4 into canonical:main Jun 25, 2024
26 checks passed
@tonyandrewmeyer tonyandrewmeyer deleted the secret-errors-1229 branch June 25, 2024 03:45
amandahla pushed a commit to amandahla/operator that referenced this pull request Jun 26, 2024
Adjust Harness so that the errors match what Juju does in practice (I
tested each case - the results are in a table in a comment in canonical#1229).
* When Juju responds with a message including "not found", we raise
`SecretNotFoundError`
* When Juju responds with any other message (such as "permission
denied"), we raise `ModelError`
* When Juju succeeds and only fails at the completion of the hook, we
raise `RuntimeError` - in production, the charm cannot catch this, but
we do want to surface this error, so `RuntimeError` seems most
approprate

In addition:
* Update the documentation to clarify when secret content is cached
(this was a request from the discussion with the data platform team in
Madrid)
* Correct the documentation regarding when `ModelError` and when
`SecretNotFoundError` will be raised with the secret methods
* Don't clear the `Secret` object local cache of the secret content on
`set_contents`. The contents won't change until `refresh` is used, so
there's no point forcing the next call to get the content from Juju.

Juju may change the responses so that there is increased consistency
(probably via [this bug](https://bugs.launchpad.net/juju/+bug/2067336))
but it seems best if we fix the behaviour to match now, and then if Juju
changes in the future, we can update ops then (also deciding at that
time how to handle the issue that different Juju versions will have
different behaviour).

Fixes canonical#1229.
tonyandrewmeyer added a commit to tonyandrewmeyer/operator that referenced this pull request Jun 26, 2024
Adjust Harness so that the errors match what Juju does in practice (I
tested each case - the results are in a table in a comment in canonical#1229).
* When Juju responds with a message including "not found", we raise
`SecretNotFoundError`
* When Juju responds with any other message (such as "permission
denied"), we raise `ModelError`
* When Juju succeeds and only fails at the completion of the hook, we
raise `RuntimeError` - in production, the charm cannot catch this, but
we do want to surface this error, so `RuntimeError` seems most
approprate

In addition:
* Update the documentation to clarify when secret content is cached
(this was a request from the discussion with the data platform team in
Madrid)
* Correct the documentation regarding when `ModelError` and when
`SecretNotFoundError` will be raised with the secret methods
* Don't clear the `Secret` object local cache of the secret content on
`set_contents`. The contents won't change until `refresh` is used, so
there's no point forcing the next call to get the content from Juju.

Juju may change the responses so that there is increased consistency
(probably via [this bug](https://bugs.launchpad.net/juju/+bug/2067336))
but it seems best if we fix the behaviour to match now, and then if Juju
changes in the future, we can update ops then (also deciding at that
time how to handle the issue that different Juju versions will have
different behaviour).

Fixes canonical#1229.
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

Successfully merging this pull request may close these issues.

Harness not modelling permission denied for user secrets
4 participants