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

Upgrade to Relation #19

Merged
merged 19 commits into from
Apr 5, 2023
Merged

Upgrade to Relation #19

merged 19 commits into from
Apr 5, 2023

Conversation

PietroPasotti
Copy link
Collaborator

@PietroPasotti PietroPasotti commented Mar 29, 2023

This PR addresses several limitations of the existing Relation implementation:

1

we did not have enough data in the Event datastructure to mock the following relation-event-specific envvars

  • JUJU_UNIT_NAME
  • JUJU_APP_NAME
  • JUJU_DEPARTING_UNIT -- only for *-relation-departed

This PR adds that functionality and corresponding tests.

2

We lacked facilities to correctly mock peer and subordinate relation types.
This PR adds two new types: PeerRelation and SubordinateRelation to address that need.

@PietroPasotti PietroPasotti changed the title Event parameters to allow setting juju-relation envvars Upgrade to Relation Mar 30, 2023
@PietroPasotti PietroPasotti marked this pull request as draft March 31, 2023 07:37
@PietroPasotti
Copy link
Collaborator Author

PietroPasotti commented Mar 31, 2023

Up for discussion:
I made the choice to have:

PeerRelation(local_app_data={}, local_unit_data={}, peers_data ={})
SubordinateRelation(local_app_data={}, local_unit_data={}, remote_unit_data={})

rather than:

Relation(type='peer', local_app_data={}, local_unit_data={}, remote_units_data={})
Relation(type='subordinate', local_app_data={}, local_unit_data={}, remote_units_data={0:{}})

This allows to:

  1. have named kwargs that make more sense in the context of the relation type. Instead of 'remote', which suggests that the application is different, use 'peers'. For subordinates, use 'primary' instead of 'remote' as terminology.
  2. prevent at the root some user errors: a peer relation has no 'remote app databag' that can be different from the 'local' one. Using a different constructor without a remote_app_databag gets rid of that risk. Similarly, in the context of a subordinate relation, "this unit" can only see ONE 'remote unit' at a time (the primary it is attached to). This means we'd have to impose constraints on the contents of remote_units_data conditionally on the type param, which felt like a bad idea.

On the other hand:

  • two extra types to maintain, import, know about...
  • ?

@simskij @benhoyt @Abuelodelanada @sed-i @rbarry82 @lucabello @dstathis thoughts?

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
pyproject.toml Show resolved Hide resolved
scenario/consistency_checker.py Outdated Show resolved Hide resolved
scenario/consistency_checker.py Outdated Show resolved Hide resolved
scenario/consistency_checker.py Outdated Show resolved Hide resolved
scenario/mocking.py Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
scenario/consistency_checker.py Show resolved Hide resolved
scenario/consistency_checker.py Outdated Show resolved Hide resolved
scenario/consistency_checker.py 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
tox.ini Show resolved Hide resolved
Copy link
Contributor

@ghislainbourgeois ghislainbourgeois left a comment

Choose a reason for hiding this comment

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

Overall I like the approach, I think the UX is good.

scenario/consistency_checker.py Outdated Show resolved Hide resolved
scenario/consistency_checker.py Outdated Show resolved Hide resolved
Copy link
Contributor

@ghislainbourgeois ghislainbourgeois left a comment

Choose a reason for hiding this comment

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

I left only a small nitpick, feel free to close it if you don't think it is doable/valuable.

scenario/runtime.py Outdated Show resolved Hide resolved
@PietroPasotti PietroPasotti marked this pull request as ready for review April 5, 2023 09:01
@PietroPasotti PietroPasotti merged commit 400ebe3 into main Apr 5, 2023
@simskij
Copy link
Member

simskij commented Apr 5, 2023

Up for discussion: I made the choice to have:

PeerRelation(local_app_data={}, local_unit_data={}, peers_data ={})
SubordinateRelation(local_app_data={}, local_unit_data={}, remote_unit_data={})

rather than:

Relation(type='peer', local_app_data={}, local_unit_data={}, remote_units_data={})
Relation(type='subordinate', local_app_data={}, local_unit_data={}, remote_units_data={0:{}})

This allows to:

  1. have named kwargs that make more sense in the context of the relation type. Instead of 'remote', which suggests that the application is different, use 'peers'. For subordinates, use 'primary' instead of 'remote' as terminology.
  2. prevent at the root some user errors: a peer relation has no 'remote app databag' that can be different from the 'local' one. Using a different constructor without a remote_app_databag gets rid of that risk. Similarly, in the context of a subordinate relation, "this unit" can only see ONE 'remote unit' at a time (the primary it is attached to). This means we'd have to impose constraints on the contents of remote_units_data conditionally on the type param, which felt like a bad idea.

On the other hand:

  • two extra types to maintain, import, know about...
  • ?

@simskij @benhoyt @Abuelodelanada @sed-i @rbarry82 @lucabello @dstathis thoughts?

I do indeed agree that your first suggestion makes the most sense. To me, a good rule of thumb usually is: If you can avoid args, do.

This was referenced Apr 14, 2023
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.

6 participants