Extend unit tests
This commit is contained in:
parent
33affd2e58
commit
dfdaac3d32
@ -37,7 +37,7 @@ LIBAPI = 0
|
||||
|
||||
# Increment this PATCH version before using `charmcraft publish-lib` or reset
|
||||
# to 0 if you are raising the major API version
|
||||
LIBPATCH = 1
|
||||
LIBPATCH = 2
|
||||
|
||||
|
||||
# TODO: add your code here! Happy coding!
|
||||
@ -122,8 +122,9 @@ class OVSDBCMSRequires(Object):
|
||||
"""Retrieve value for key from all related units."""
|
||||
values = []
|
||||
relation = self.framework.model.get_relation(self.relation_name)
|
||||
for unit in relation.units:
|
||||
values.append(relation.data[unit].get(key))
|
||||
if relation:
|
||||
for unit in relation.units:
|
||||
values.append(relation.data[unit].get(key))
|
||||
return values
|
||||
|
||||
|
||||
@ -196,7 +197,8 @@ class OVSDBCMSProvides(Object):
|
||||
|
||||
def set_unit_data(self, settings: typing.Dict[str, str]) -> None:
|
||||
"""Publish settings on the peer unit data bag."""
|
||||
relation = self.framework.model.get_relation(self.relation_name)
|
||||
for k, v in settings.items():
|
||||
relation.data[self.model.unit][k] = v
|
||||
relations = self.framework.model.relations[self.relation_name]
|
||||
for relation in relations:
|
||||
for k, v in settings.items():
|
||||
relation.data[self.model.unit][k] = v
|
||||
|
||||
|
@ -53,10 +53,6 @@ class TestOVNRelayWallabyOperatorCharm(test_utils.CharmTestCase):
|
||||
PATCHES = []
|
||||
|
||||
def setUp(self):
|
||||
self.container_calls = {
|
||||
'push': {},
|
||||
'pull': [],
|
||||
'remove_path': []}
|
||||
super().setUp(charm, self.PATCHES)
|
||||
self.harness = test_utils.get_harness(
|
||||
_OVNRelayWallabyOperatorCharm,
|
||||
@ -68,3 +64,17 @@ class TestOVNRelayWallabyOperatorCharm(test_utils.CharmTestCase):
|
||||
self.assertEqual(self.harness.charm.seen_events, [])
|
||||
self.harness.container_pebble_ready('ovsdb-server')
|
||||
self.assertEqual(len(self.harness.charm.seen_events), 1)
|
||||
|
||||
def test_all_relations(self):
|
||||
self.harness.set_leader()
|
||||
self.assertEqual(self.harness.charm.seen_events, [])
|
||||
test_utils.set_all_pebbles_ready(self.harness)
|
||||
test_utils.add_all_relations(self.harness)
|
||||
self.assertEqual(
|
||||
sorted(list(set(
|
||||
self.container_calls.updated_files('ovsdb-server')))),
|
||||
[
|
||||
'/etc/ovn/cert_host',
|
||||
'/etc/ovn/key_host',
|
||||
'/etc/ovn/ovn-central.crt',
|
||||
'/root/ovn-relay-wrapper.sh'])
|
||||
|
Loading…
x
Reference in New Issue
Block a user