-
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
charm state initial prototype #28
base: main
Are you sure you want to change the base?
Conversation
This looks good, I suppose what it is doing is somehow patching the Minor side note, I remember we discussed a preference not to put a HTTP call on a |
Yeah I agree it's not a good pattern, but the design of the If making requests in a property hurts our eyes, we can write the example like: import requests
def get_temperature():
return requests.get('http://nieuwekerk.delft.nl/temp...').json()['celsius']
class MyCharmStateBackend(CharmStateBackend):
@property
def temperature(self) -> int:
return get_temperature() which if you squint still hurts your eyes, but it's a bit less in your face. Do you see better alternatives? |
I'm ok with either one, just thought I would ask the question |
If I'm understanding this correctly, this would require you to write your charm in a specific way, with properties for all charm-state attributes (would it also require So I'm not a fan -- I think it's better to have |
This prototype is based on the ISD014 - Managing Charm Complexity spec that was introduced/discussed in Prague. The spec proposes to have a separate 'state' class for charms which mediates all interactions between the charm and 'the world' outside of juju and pebble. This implementation indeed assumes that the charm will be written according to that spec (or that the author is willing to write an ad-hoc facade to present to Scenario as-if it did actually implement the spec). If the spec is accepted, in its present form, I think having the ability in scenario to 'natively' integrate with it in this way would be very valuable.
Like the idea to pass in callbacks, but I'm not convinced that ops-scenario should only worry about ops stuff. |
The present implementation allows you to customize that attribute (it's the first argument to |
Thanks, that's a fair point of view. I'm going to take another look at ISD014 - Managing Charm Complexity. I'm a bit wary of this approach, though -- my understanding was that that spec would be a recommendation of how to structure complex charms, not something we'd make opinionated in the tooling. |
I like opinionated tooling :) But I agree that given the drafty status of the spec, it may be premature to have tooling whose opinions are stronger than those of the spec itself. |
this PR adds to scenario charm-state mocking utilities.
Charm State
Suppose that your charm code makes an http call to a server somewhere to get some data, say, the current temperature reading from a sensor on top of the Nieuwe Kerk in Delft, The Netherlands.
If you follow the best practices of how to structure your charm code, then you are aware that this piece of data, at runtime, is categorised as 'charm state'.
Scenario offers a way to plug into this system natively, and integrate this charm state data structure into its own
State
tree.If your charm code looks like this:
Then you can write scenario tests like that: