Skip to content
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 support for cloud spec #119

Merged
merged 26 commits into from
May 29, 2024
Merged

Conversation

IronCore864
Copy link
Collaborator

@IronCore864 IronCore864 commented Apr 8, 2024

Add support for cloud spec with an e2e test.

@IronCore864 IronCore864 changed the title Cloud spec feat: add support for cloud spec Apr 8, 2024
@IronCore864 IronCore864 marked this pull request as ready for review April 8, 2024 08:54
Copy link
Collaborator

@PietroPasotti PietroPasotti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!
@tonyandrewmeyer let me know what you think about the cloudspec dataclass ownership, we should make that decision once and for all if we didn't already :)

scenario/mocking.py Outdated Show resolved Hide resolved
scenario/state.py Show resolved Hide resolved
tests/test_e2e/test_cloud_spec.py Outdated Show resolved Hide resolved
@IronCore864
Copy link
Collaborator Author

Thanks for the review, I have refactored according to your comments. Please take another look :)

Copy link
Collaborator

@PietroPasotti PietroPasotti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks better! Thanks :)
One more round and I think we're there

scenario/mocking.py Outdated Show resolved Hide resolved
scenario/state.py Show resolved Hide resolved
scenario/state.py Show resolved Hide resolved
scenario/state.py Outdated Show resolved Hide resolved
scenario/state.py Outdated Show resolved Hide resolved
scenario/state.py Outdated Show resolved Hide resolved
scenario/mocking.py Show resolved Hide resolved
Copy link
Collaborator

@tonyandrewmeyer tonyandrewmeyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a few comments as well.

One other thing: I think it would be worth having the consistency checker validate that State.cloud_spec is None if State.model.type == "kubernetes"

scenario/mocking.py Show resolved Hide resolved
scenario/state.py Outdated Show resolved Hide resolved
scenario/state.py Outdated Show resolved Hide resolved
scenario/state.py Outdated Show resolved Hide resolved
scenario/state.py Show resolved Hide resolved
scenario/state.py Outdated Show resolved Hide resolved
tests/test_e2e/test_cloud_spec.py Outdated Show resolved Hide resolved
tests/test_e2e/test_cloud_spec.py Outdated Show resolved Hide resolved
IronCore864 and others added 2 commits April 10, 2024 07:45
Co-authored-by: PietroPasotti <[email protected]>
Co-authored-by: PietroPasotti <[email protected]>
@IronCore864
Copy link
Collaborator Author

After discussion in standup, we decided to keep the CloudSpec dataclass in scenario but remove the from_dict method for now.

scenario/consistency_checker.py Outdated Show resolved Hide resolved
scenario/mocking.py Outdated Show resolved Hide resolved
scenario/state.py Outdated Show resolved Hide resolved
tests/test_consistency_checker.py Outdated Show resolved Hide resolved
tests/test_e2e/test_cloud_spec.py Outdated Show resolved Hide resolved
tests/test_e2e/test_cloud_spec.py Outdated Show resolved Hide resolved
scenario/state.py Outdated Show resolved Hide resolved
scenario/state.py Outdated Show resolved Hide resolved
scenario/state.py Outdated Show resolved Hide resolved
scenario/state.py Show resolved Hide resolved
@benhoyt
Copy link
Collaborator

benhoyt commented Apr 10, 2024

Adding as a top-level comment as well to avoid it getting lost: it seems strange to me to have AuthType as an enum but not cloud type. I think we should do none or both, unless there's a good reason not to? It looks like we're leaning towards enums, so let's do enums for both. We should also link to the Juju source in a comment, for reference.

@IronCore864
Copy link
Collaborator Author

After discussion in the standup today we decided to use str, instead of Enum at some places then str at other places. Also it's consistent with ops. Closing some comments due to this.

@IronCore864
Copy link
Collaborator Author

I have done yet another refactoring according to your reviews, please take a look @tonyandrewmeyer @PietroPasotti.

For the record, I still don't feel this is right, but I've done it anyway to try to make it consistent:

  • copy-pasting ops.CloudSpec and ops.CloudCredential to scenario
  • delete from_dict method, which is what's used in ops, and is (subjectively) easier to use than instantiating a class
  • add a conversion method so that it returns an ops object (it's not like that by porting the ops.CloudSpec to scenario, it is separated with ops and has nothing to do with ops any more)
  • build two objects in the UT which are the same.

For another record, there are inconsistent code in consistency_checker (the irony is in the file name 🤣):

Some places do:

errors = []
warnings = []

# do something

return Results(errors, warnings)

Other places do:

errors = []

# do something

return Results(errors, [])

I think the latter is less readable since I need to click into the definition of Results to know what the second parameter is and why it's an empty list. In this PR I chose the first one; I will create another PR to fix the second cases to the first so that the code is more consistent.

scenario/state.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@tonyandrewmeyer tonyandrewmeyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you be able to add a short example into the README? Ideally, we have all of the state documented there.

tests/test_e2e/test_cloud_spec.py Outdated Show resolved Hide resolved
scenario/state.py Outdated Show resolved Hide resolved
scenario/mocking.py Outdated Show resolved Hide resolved
@IronCore864
Copy link
Collaborator Author

IronCore864 commented Apr 15, 2024

Would you be able to add a short example into the README? Ideally, we have all of the state documented there.

README updated.

Also made "to ops" methods "private". It makes sense to make them private; I thought one of them was used in the test but it wasn't, my bad.

Only discussion left open: _to_ops, _to_ops_object, _to_ops_cloud_spec naming convention.

@PietroPasotti
Copy link
Collaborator

Would you be able to add a short example into the README? Ideally, we have all of the state documented there.

README updated.

Also made "to ops" methods "private". It makes sense to make them private; I thought one of them was used in the test but it wasn't, my bad.

Only discussion left open: _to_ops, _to_ops_object, _to_ops_cloud_spec naming convention.

IMHO _to_ops is clear enough, so long as there's only one ops object that each scenario.state one can map to.

Copy link
Collaborator

@benhoyt benhoyt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very close -- just a few nit comments now.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
scenario/__init__.py Show resolved Hide resolved
scenario/state.py Outdated Show resolved Hide resolved
scenario/state.py Outdated Show resolved Hide resolved
scenario/state.py Outdated Show resolved Hide resolved
tests/test_e2e/test_cloud_spec.py Outdated Show resolved Hide resolved
@IronCore864
Copy link
Collaborator Author

Very close -- just a few nit comments now.

All updated, please take another look.

Copy link
Collaborator

@benhoyt benhoyt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, thanks for the updates!

README.md Show resolved Hide resolved
Copy link
Collaborator

@tonyandrewmeyer tonyandrewmeyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me - thanks! I would suggest that @PietroPasotti has a final review before it's merged, though, since I'm still pretty new to Scenario.

Copy link
Collaborator

@PietroPasotti PietroPasotti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some thoughts on the defaults that need discussing, but the rest looks good! 👍

scenario/consistency_checker.py Outdated Show resolved Hide resolved
scenario/state.py Show resolved Hide resolved
scenario/state.py Outdated Show resolved Hide resolved
scenario/state.py Show resolved Hide resolved
tests/test_e2e/test_cloud_spec.py Show resolved Hide resolved
tests/test_e2e/test_cloud_spec.py Show resolved Hide resolved
@IronCore864
Copy link
Collaborator Author

@PietroPasotti can't reply you in one of your comment so I'm putting it here in another separate comment: Regarding enum vs str, there is a discussion in previous comments where we decided to make it consistent as str, so it's resolved.

@PietroPasotti
Copy link
Collaborator

@IronCore864 @tonyandrewmeyer where are we on this PR?

@tonyandrewmeyer
Copy link
Collaborator

@IronCore864 @tonyandrewmeyer where are we on this PR?

I thought everything had been resolved (merging is fine with me). @IronCore864 were you wanting a final review from @PietroPasotti ?

@IronCore864
Copy link
Collaborator Author

Sorry for getting back at it so late, I just finished some other tasks and could only get back at it now.

It seems all comments are resolved, and in my latest commit, I fixed the comment improvement specified by @PietroPasotti.

@tonyandrewmeyer it's ready to be merged, I don't have write access to this repo.

@PietroPasotti PietroPasotti merged commit 1df85e1 into canonical:main May 29, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants