-
Notifications
You must be signed in to change notification settings - Fork 122
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
Add the ability to populate State from metadata #1454
Comments
If this does make it significantly simpler for test authors it's worth considering. Going to add it to our tentative 25.10 roadmap. |
Matrix copy-paste Wed, Nov 13, 2024 Currently I have this:
The error I'm getting is:
Where can I find an example for using a container?
and:
Would it make sense: auto populate "containers" from metadata, if not given I can see an argument that the charm always has the containers in the metadata, and that they're just I guess I would say open a feature ticket and we'll consider it. Edit: I opened one. For can_connect defaulting to True, we're stuck with the default until v8 and would really like to stick to the promise that the breaking v7 changes would be it for a good amount of time. Would True be a better default? It's maybe the more common result in tests? I see a lot of tests around the container becoming available or handling error states where it's more 50/50, but then there are some where the container isn't the focus of the test but needs to be there, and for those True is more common. It'll be easier to judge this when more tests exist across repos. I don't remember considering this when we were doing the v7 API review, and it was False in earlier versions too. Tony Meyer You could also use the Context as a context manager and then do something like:
I'm not sure whether you'd consider that simpler or not. I think doing it the way you are is fine, though. If you find that you're having to write really similar code all the time, then let us know, because we could have more helpers, like a get_file that shortcuts things, if there's a clear need for them. Pietro Pasotti |
The
State
could have some default components based on theContext
metadata, or perhaps there could be afill_from_context
method or similar.For example, this could add:
Container
for each container in the metadata (although you'd probably want to be able to specify whethercan_connect
should beTrue
orFalse
, or it seems like there might be a lot of awkwarddataclasses.replace
afterwards)config
that's the same as the defaults in the metadataNetwork
(there's essentially always a Juju network, right?)Storage
for each storage in the metadata (to the minimum side of themultiple
value if provided)StoredState
for eachops.StoredState
attribute on theContext
's charm class (not perfect since these can exist elsewhere, particularly in libs, but maybe a useful base?)I don't think it could have relations (even if we do make it possible to have data-inaccessible relations, e.g. #1452) since there's a practical difference between a relation existing (from the point of view of the unit) and not existing, wider than just the data being available.
I don't think it could include resources, even though they're in the metadata and always (?) available, because it doesn't seem like there's any way to have a sensible default location for the content.
See this Matrix discussion for more background.
The text was updated successfully, but these errors were encountered: