Merge "Add helpers to peer relation adapter for unit data" into main

This commit is contained in:
Zuul 2023-02-17 10:31:36 +00:00 committed by Gerrit Code Review
commit e56122a481
2 changed files with 21 additions and 5 deletions

View File

@ -18,6 +18,7 @@ import json
import logging
from typing import (
Callable,
Dict,
List,
Optional,
Tuple,
@ -581,6 +582,21 @@ class BasePeerHandler(RelationHandler):
else:
return json.loads(ready)
def set_unit_data(self, settings: Dict[str, str]) -> None:
"""Publish settings on the peer unit data bag."""
self.interface.set_unit_data(settings)
def get_all_unit_values(
self, key: str, include_local_unit: bool = False
) -> List[str]:
"""Retrieve value for key from all related units.
:param include_local_unit: Include value set by local unit
"""
return self.interface.get_all_unit_values(
key, include_local_unit=include_local_unit
)
class CephClientHandler(RelationHandler):
"""Handler for ceph-client interface."""

View File

@ -249,29 +249,29 @@ class TestOSBaseOperatorAPICharm(_TestOSBaseOperatorAPICharm):
rel_id, "my-service/1", {"today": "monday"}
)
self.assertEqual(
self.harness.charm.peers.interface.get_all_unit_values(
self.harness.charm.peers.get_all_unit_values(
"today",
include_local_unit=False,
),
["monday"],
)
self.assertEqual(
self.harness.charm.peers.interface.get_all_unit_values(
self.harness.charm.peers.get_all_unit_values(
"today",
include_local_unit=True,
),
["monday"],
)
self.harness.charm.peers.interface.set_unit_data({"today": "friday"})
self.harness.charm.peers.set_unit_data({"today": "friday"})
self.assertEqual(
self.harness.charm.peers.interface.get_all_unit_values(
self.harness.charm.peers.get_all_unit_values(
"today",
include_local_unit=False,
),
["monday"],
)
self.assertEqual(
self.harness.charm.peers.interface.get_all_unit_values(
self.harness.charm.peers.get_all_unit_values(
"today",
include_local_unit=True,
),