-
Notifications
You must be signed in to change notification settings - Fork 121
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!: add error if meta not passed when config or actions are in ops.testing #1497
base: main
Are you sure you want to change the base?
Conversation
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.
What we lose here is being able to do simple contexts like:
ctx = testing.Context(MyCharm, actions={'foo': {'description': '...'}})
Although this isn't that much longer:
ctx = testing.Context(MyCharm, meta={'name': '...'}, actions={'foo': {'description': '...'}})
I think I'm ok with the backwards compatibility breakage - I think generally people are autoloading so this is unlikely to break for anyone. It doesn't seem like there's a backwards compatible option outside of docs or warnings.
An alternative to this would be that if meta/config/actions was None
then we could attempt autoloading that specific piece. That does get a bit weird if they're all in charmcraft.yaml, though. Basically, meta/config/actions would be an override over the autoload, rather than an alternative. I think this is what the OP was expecting?
I wonder if we're going to have some backwards compatibility breakage if it would be worth doing more and trying to solve the single-YAML issue too (#1424).
# def test_foo(): | ||
# ctx = Context(MyCharm, config={"foo": "bar"}) | ||
# ctx.run(..., State()) | ||
|
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.
# def test_foo(): | |
# ctx = Context(MyCharm, config={"foo": "bar"}) | |
# ctx.run(..., State()) |
I'm assuming this is leftover rather than meant as an example?
f"Cannot automatically setup scenario with `charm_type`={charm_type}. " | ||
"This is likely because this charm has some nonstandard repository setup and Scenario " | ||
"can't find the charmcraft|(metadata|config|actions) yamls in their usual location. " | ||
"Please parse and provide their contents manually via the `meta`, `config` " | ||
"and `actions` Context parameters.", |
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.
I suppose if we're improving error messages we ought to avoid Scenario as a proper noun 😞
f"Cannot automatically setup scenario with `charm_type`={charm_type}. " | |
"This is likely because this charm has some nonstandard repository setup and Scenario " | |
"can't find the charmcraft|(metadata|config|actions) yamls in their usual location. " | |
"Please parse and provide their contents manually via the `meta`, `config` " | |
"and `actions` Context parameters.", | |
f"Cannot automatically set up with `charm_type`={charm_type}. " | |
"This is likely because this charm has some non-standard repository setup and the " | |
"charmcraft|(metadata|config|actions) YAML files aren't in their usual location. " | |
"Please parse and provide their contents manually via the `meta`, `config` " | |
"and `actions` Context parameters.", |
raise ContextSetupError( | ||
"Scenario doesn't support overriding `actions|config` without overriding `meta` too." | ||
) |
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 I suppose here also 😞
raise ContextSetupError( | |
"Scenario doesn't support overriding `actions|config` without overriding `meta` too." | |
) | |
raise ContextSetupError( | |
"To override `actions|config` you must also override `meta`." | |
) |
with create_tempcharm( | ||
tmp_path, legacy=legacy, meta={"type": "charm", "name": "sergio"} | ||
) as charm: | ||
# metadata not found: |
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.
I found this initially confusing because there's metadata two lines above, maybe this would be clearer?
# metadata not found: | |
# metadata not found in YAML: |
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.
I think this is reasonable. Re Tony's comment:
Basically, meta/config/actions would be an override over the autoload, rather than an alternative. I think this is what the OP was expecting?
That sounds too magical to me. I think it should be one or the other, not an override of (some) parts -- I think that would just be confusing.
Currently, if
meta
isn't passed toContext
, and the metadata isn't auto-loaded, a default meta of{'name': '<charm-name>'}
is set. This can be confusing to users if they pass inconfig
oractions
(which prevents auto-loading) and expect themeta
to be auto-loaded.This PR changes he behaviour so that if
actions
orconfig
are passed in, thenmeta
must be passed in as well.Fixes #1492