diff --git a/lib/charms/opensearch/v0/opensearch_tls.py b/lib/charms/opensearch/v0/opensearch_tls.py index ac207369c..9891e5a78 100644 --- a/lib/charms/opensearch/v0/opensearch_tls.py +++ b/lib/charms/opensearch/v0/opensearch_tls.py @@ -30,7 +30,7 @@ generate_csr, generate_private_key, ) -from ops.charm import ActionEvent, RelationBrokenEvent, RelationJoinedEvent +from ops.charm import ActionEvent, RelationBrokenEvent, RelationCreatedEvent from ops.framework import Object # The unique Charmhub library identifier, never change it @@ -61,7 +61,7 @@ def __init__(self, charm, peer_relation: str): ) self.framework.observe( - self.charm.on[TLS_RELATION].relation_joined, self._on_tls_relation_joined + self.charm.on[TLS_RELATION].relation_created, self._on_tls_relation_created ) self.framework.observe( self.charm.on[TLS_RELATION].relation_broken, self._on_tls_relation_broken @@ -98,8 +98,8 @@ def request_new_unit_certificates(self) -> None: secrets = self.charm.secrets.get_object(Scope.UNIT, cert_type.val) self._request_certificate_renewal(Scope.UNIT, cert_type, secrets) - def _on_tls_relation_joined(self, _: RelationJoinedEvent) -> None: - """Request certificate when TLS relation joined.""" + def _on_tls_relation_created(self, _: RelationCreatedEvent) -> None: + """Request certificate when TLS relation created.""" admin_cert = self.charm.secrets.get_object(Scope.APP, CertType.APP_ADMIN.val) if self.charm.unit.is_leader() and admin_cert is None: self._request_certificate(Scope.APP, CertType.APP_ADMIN) diff --git a/tests/unit/lib/test_opensearch_tls.py b/tests/unit/lib/test_opensearch_tls.py index 17675b36c..a19043c4d 100644 --- a/tests/unit/lib/test_opensearch_tls.py +++ b/tests/unit/lib/test_opensearch_tls.py @@ -91,12 +91,12 @@ def test_find_secret(self): @patch("charms.opensearch.v0.opensearch_tls.OpenSearchTLS._request_certificate") @patch("charm.OpenSearchOperatorCharm._put_admin_user") @patch("charm.OpenSearchOperatorCharm._purge_users") - def test_on_relation_joined_admin(self, _, _put_admin_user, _request_certificate): - """Test on certificate relation joined event.""" + def test_on_relation_created_admin(self, _, _put_admin_user, _request_certificate): + """Test on certificate relation created event.""" event_mock = MagicMock() self.harness.set_leader(is_leader=True) - self.charm.tls._on_tls_relation_joined(event_mock) + self.charm.tls._on_tls_relation_created(event_mock) self.assertEqual( _request_certificate.mock_calls, [ @@ -109,12 +109,12 @@ def test_on_relation_joined_admin(self, _, _put_admin_user, _request_certificate @patch("charms.opensearch.v0.opensearch_tls.OpenSearchTLS._request_certificate") @patch("charm.OpenSearchOperatorCharm._put_admin_user") @patch("charm.OpenSearchOperatorCharm._purge_users") - def test_on_relation_joined_non_admin(self, _, _put_admin_user, _request_certificate): - """Test on certificate relation joined event.""" + def test_on_relation_created_non_admin(self, _, _put_admin_user, _request_certificate): + """Test on certificate relation created event.""" event_mock = MagicMock() self.harness.set_leader(is_leader=False) - self.charm.tls._on_tls_relation_joined(event_mock) + self.charm.tls._on_tls_relation_created(event_mock) self.assertEqual( _request_certificate.mock_calls, [