-
Notifications
You must be signed in to change notification settings - Fork 9
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
feat!: simplify testing secret management #168
feat!: simplify testing secret management #168
Conversation
Co-authored-by: PietroPasotti <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Love the simplification. It's the third iteration of the secrets model and finally it's looking like it could be final :)
Just a few nits and naming comments, but feel free to ignore them.
scenario/mocking.py
Outdated
secret = Secret( | ||
id=secret_id, | ||
contents={0: content}, | ||
latest=content, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and this is why I'd rather more explicit argument names :)
Secret(content=content
reads so much better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, only a partial review today.
Co-authored-by: PietroPasotti <[email protected]>
@@ -441,48 +442,6 @@ def __init__( | |||
): | |||
"""Represents a simulated charm's execution context. | |||
|
|||
It is the main entry point to running a scenario test. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious why this doc block is being removed in this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's being removed because it's duplicated in the 7.0 HEAD - I moved it to Context.__doc__
when doing the autodoc work but must have incorrectly merged that in some branch because it ended up still in Context.__init__.__doc__
too.
It's being removed in this PR because Pietro noticed that it was duplicated in this PR.
I can tidy it up in a separate PR rather than this drive-by if that's preferred.
Adjust testing secret management to be simpler - in particular, to avoid needing to manually manage revisions, which should be transparent to charms. Rather than `Secret`s having a dictionary of revision:content-dict, they have two content dictionaries, `tracked_content` (required) and `latest_content` (set to the same value as `tracked_content` if not provided). This matches what charms can see: only either the tracked revision or the latest revision. A new attribute, `removed_secret_revisions` is added to `Context` to track removal of secret revisions in the `secret-remove` and `secret-expired` hooks. Calling `secret-remove --revision` in those hooks must be done, so should be tested, but don't actually change the state that's visible to the charm (for `secret-remove` the whole point is that the secret revision is no longer visible to anyone, so it should be removed). Tests could mock the `secret_remove` method, but it seems cleaner to provide a mechanism, given that this should be part of any charm that uses secrets. Charms should only remove specific revisions in the `secret-remove` and `secret-expired` hooks, and only remove the revision that's provided, but it is possible to remove arbitrary revisions. Modelling this is complicated (the state of the Juju secret is a mess afterwards) and it is always a mistake, so rather than trying to make the model fit the bad code, an exception is raised instead. A warning is logged if a secret revision is created that is the same as the existing revision - in the latest Juju this is a no-op, but in earlier version it's a problem, and either way it's something that the charm should avoid if possible. --------- Co-authored-by: PietroPasotti <[email protected]>
Adjust testing secret management to be simpler - in particular, to avoid needing to manually manage revisions, which should be transparent to charms.
Rather than
Secret
s having a dictionary of revision:content-dict, they have two content dictionaries,tracked_content
(required) andlatest_content
(set to the same value astracked_content
if not provided). This matches what charms can see: only either the tracked revision or the latest revision.A new attribute,
removed_secret_revisions
is added toContext
to track removal of secret revisions in thesecret-remove
andsecret-expired
hooks. Callingsecret-remove --revision
in those hooks must be done, so should be tested, but don't actually change the state that's visible to the charm (forsecret-remove
the whole point is that the secret revision is no longer visible to anyone, so it should be removed). Tests could mock thesecret_remove
method, but it seems cleaner to provide a mechanism, given that this should be part of any charm that uses secrets.Charms should only remove specific revisions in the
secret-remove
andsecret-expired
hooks, and only remove the revision that's provided, but it is possible to remove arbitrary revisions. Modelling this is complicated (the state of the Juju secret is a mess afterwards) and it is always a mistake, so rather than trying to make the model fit the bad code, an exception is raised instead.A warning is logged if a secret revision is created that is the same as the existing revision - in the latest Juju this is a no-op, but in earlier version it's a problem, and either way it's something that the charm should avoid if possible.