-
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
refactor: import the ops-scenario repository #1406
refactor: import the ops-scenario repository #1406
Conversation
Adds support for `collect-status`
fix falsy config defaults
fix secret id canonicalization
Remove scripts
added container fs temporary dir cleanup in
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 a quick look for now, will give some more thoughts later.
Something that comes to mind is: is the idea to do (eventually) from ops.scenario import ...?
still on the table, or is the 'scenario' namespace going to remain toplevel?
try: | ||
from ops._main import CHARM_STATE_FILE, _Dispatcher, _get_event_args # type: ignore | ||
from ops._main import logger as ops_logger # type: ignore | ||
except ImportError: |
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.
the imports here should be simplified now that we know what ops version we're being shipped with
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.
or, maybe not, since it's still an independent package that could be installed alongside older ops. nvm
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 probably true that it could still theoretically be installed alongside older ops, but in that case why wouldn't you also just use an older ops-scenario version? I think part of the reason it's good in a single repo is so we can do atomic commits for things that use _private
functions.
However, it might make sense to keep this PR limited to just copying code 1:1, and then subsequent PRs for updates to those files. Will make review saner I think, and mean we're not tempted to include other changes here.
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.
Yeah, I had to bump the minimum ops version in this PR so the compatibility code can be removed, but I would rather do it in another PR, since this one is already complicated to review.
return dispatcher, framework, charm | ||
|
||
|
||
class Ops: |
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.
perhaps we can do that later, but now is a good time to trim down ops_main_mock and start using directly some of the newer stuff in ops
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 it is good to do that soon, but not in this PR, which is already very large/complex.
As of ops 2.17 you can do this: from ops import testing
ctx = testing.Context(MyCharm)
ctx.run(ctx.on.start(), testing.State()) The intention is to encourage use in that form. |
One thing to note is we'll want to merge with the "Rebase and merge" option (re-enabling that in Settings temporarily). |
Thanks @tonyandrewmeyer, this is excellent work. A few thoughts/questions:
|
No. I briefly scanned through the commits (I was originally thinking of ones that said "accidentally committed password") but only the title and that's not really going to tell the whole story. I could read through the details of all the commits, but that would take quite a while.
A fresh ops-scenario clone is 2.6M (.git is 1.8M). operator/.git is 3.2M main@HEAD. operator/.git is 4.8M when cloned with
Since this will be a rebase-and-merge, does that mean I can do that now rather than in a follow-up PR because the hashes won't change?
Ok, I can change that.
|
Thanks! I think 50% bigger is totally reasonable. I was thinking of 10x or worse blow-up. I don't think we need to do anything further here. If there were passwords, they'd been in the public ops-scenario repo already. :-)
Yeah, that sounds right.
Great, that sounds fine to me.
👍 |
@@ -304,7 +304,7 @@ def test_relation_data(): | |||
), | |||
} | |||
|
|||
# which is very idiomatic and superbly explicit. Noice. | |||
# which is very idiomatic and superbly explicit. |
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.
This is funny
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 made me sad to remove it, but codespell complained and it seemed silly to keep it and put in a codespell bypass just for this.
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.
hahaha I think I added that during an early live demo, too bad it has to go :)
Thank you for a very clean series of commits, @tonyandrewmeyer. The consistency checker fix seems simple enough to me that it would be fine to solve it in this PR even if it's not strictly needed to get everything that's currently working in scenario working here, especially since it's the last commit, so doesn't interfere with understanding the others. More for my own understanding than anything, are these all the follow up issues coming out of this PR?
edit: These will all be in Jira under the epic for this. I'll wait to hear back on the situation with tox potentially installing scenario from PyPI in testing. I wasn't clear on explanation of the |
[Ben]
Yes, and if there was a "get rid of the password I committed earlier" commit I assume they would have been invalidated too. But security scanners tend to look through a repo's entire history and in my experience it's a pain to have to explain that a problem was already solved. [James]
Yes. It could be made to work by just adjusting the working directory and putting an appropriate secret into our repo, but I would rather go straight to Trusted Publisher and we also need to decide if ops-scenario will still publish automatically whenever the version is increased or if it moves to a manual process like ops.
Yes. I am super baffled by this. I'm hoping that if I come back to it in a few days it'll be really obvious.
Yes. I suspect there's a bunch of type annotation improvements that could be made in general - I don't think that was a focus for ops-scenario in general.
I believe if I do the I think that is everything that directly arises from this PR. There are some other things that should be done (e.g. using the |
Thanks, @tonyandrewmeyer. I don't have a strong opinion on relative imports, just wondering about the resolution for this:
If this is working correctly with |
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.
Thanks for your work on this. Let's get final approval from @PietroPasotti as well.
It is the case now - I think it was mixing local and PyPI previously (a few small extra things to fix showed up afterwards also). It's not perfect now, because of the way that Tox doesn't know to regenerate an environment if it's a local install but it will work correctly and is ok for now I think. |
elif storage not in state.storages: | ||
elif (storage.name, storage.index) not in { | ||
(s.name, s.index) for s in state.storages | ||
}: | ||
errors.append( | ||
f"cannot emit {event.name} because storage {storage.name} " |
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.
we might want to mention the storage.index as well in this error message too since we're basing our check on that
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.
Good point. I'll do a follow-up PR to do that and add tests for this case, rather than making this one even larger.
@@ -476,7 +478,7 @@ def check_secrets_consistency( | |||
return Results(errors, []) | |||
|
|||
assert event.secret is not None | |||
if event.secret not in state.secrets: | |||
if event.secret.id not in {s.id for s in state.secrets}: | |||
secret_key = event.secret.id if event.secret.id else event.secret.label |
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.
if there is a chance that secret.id could be None (seems implied by this line) then we have to be careful about putting them in a set comprehension? or perhaps this line is old code that can now be removed
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'll check on this, but I believe the event's secret should always have an ID and we seem to type it that way. Could indeed be older code.
@@ -304,7 +304,7 @@ def test_relation_data(): | |||
), | |||
} | |||
|
|||
# which is very idiomatic and superbly explicit. Noice. | |||
# which is very idiomatic and superbly explicit. |
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.
hahaha I think I added that during an early live demo, too bad it has to go :)
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.
Overall it looks great! Thanks for this humongous work :)
@benhoyt would you be able to merge this please? You need to enable rebase & merge, do it, then turn that off again, for this special-case. Thanks! |
@tonyandrewmeyer I've enabled Rebase and Merge temporarily -- go ahead and rebase+merge this one (I'll let you do the honours!), and then I'll disable that setting again. |
e41c3ad
to
51ba92f
Compare
Adds the content of the ops-scenario repository (including history) into the repository, for easier long-term maintenance. The previous ops-scenario content is located primarily in the new top-level
testing
folder (named forops[testing]
), other than some content that has been removed (e.g. separatedocs
,.pre-commit-config.yaml
and so on) or merged (e.g.tox.ini
).There are more than 700 commits because the history is imported, and a lot of new code, so this will be an unusual one to review. I suggest starting with the most recent commits (basically everything after what's in ops-scenario) and then reviewing each commit individually. To be clear: I didn't touch any of the ones before this, they were generated with a
git merge --allow-unrelated-histories
from a clone of the canonical/ops-scenario repo.The commits are:
type: ignore
andAny
uses, but it's reasonable and better than before and gets us to a place where the static checks pass with the same config as for the rest of the code. I feel like further improvements can be done separately (and also ideally type checking the ops-scenario tests, I guess).trigger
helper anyway, so maybe the problem just goes away in time.pytest.raises
does not work for one set of tests (previously shadowed so not running), any advice on that would be great. I'm also not sure why the other tests weren't failing previously, since they were clearly wrong.Note that I have not done the
"
to'
conversion in this. It seems like that could be a separate and dedicated PR.There's essentially no code changes, other than addressing issues that the operator tox
unit
,lint
, orstatic
found, just a bunch of moving things around.