Skip to content

Commit

Permalink
rollback data from relation unit
Browse files Browse the repository at this point in the history
  • Loading branch information
PietroPasotti committed Apr 25, 2024
1 parent 6ee0c8b commit af21a0f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
7 changes: 1 addition & 6 deletions ops/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -971,8 +971,7 @@ def _emit_relation_broken(self, relation_name: str, relation_id: int,
app = self._model.get_app(remote_app)
self._charm.on[relation_name].relation_broken.emit(relation, app)

def add_relation_unit(self, relation_id: int, remote_unit_name: str,
data: Optional[Mapping[str, str]] = None) -> None:
def add_relation_unit(self, relation_id: int, remote_unit_name: str) -> None:
"""Add a new unit to a relation.
This will trigger a `relation_joined` event. This would naturally be
Expand All @@ -993,7 +992,6 @@ def add_relation_unit(self, relation_id: int, remote_unit_name: str,
Args:
relation_id: The integer relation identifier (as returned by :meth:`add_relation`).
remote_unit_name: A string representing the remote unit that is being added.
data: A str:str mapping to put in the unit's databag.
"""
self._backend._relation_list_map[relation_id].append(remote_unit_name)
# we can write remote unit data iff we are not in a hook env
Expand Down Expand Up @@ -1027,9 +1025,6 @@ def add_relation_unit(self, relation_id: int, remote_unit_name: str,
self._charm.on[relation_name].relation_joined.emit(
relation, remote_unit.app, remote_unit)

if data is not None:
self.update_relation_data(relation_id, remote_unit_name, data)

def remove_relation_unit(self, relation_id: int, remote_unit_name: str) -> None:
"""Remove a unit from a relation.
Expand Down
7 changes: 5 additions & 2 deletions test/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,11 @@ def test_remote_units_get_from_div_app(self):
app_data={"app": "data"},
unit_data={"unit": "data"}
)
self.harness.add_relation_unit(relation_id, 'remoteapp/1', data={"some": "other"})
self.harness.add_relation_unit(relation_id, 'remoteapp/2', data={"some": "yams"})
self.harness.add_relation_unit(relation_id, 'remoteapp/1')
self.harness.add_relation_unit(relation_id, 'remoteapp/2')

self.harness.update_relation_data(relation_id, "remoteapp/1", {"some": "other"})
self.harness.update_relation_data(relation_id, "remoteapp/2", {"some": "yams"})

rel_db1 = self.ensure_relation('db1')

Expand Down

0 comments on commit af21a0f

Please # to comment.