Stop services for goneaway events for relations
Implement stop-services function for the charm. For relations amqp, ovsdb-cms, reset the corresponding snap data. Add mandatory_relations to openstack-hypervisor charm. Depends-On: https://review.opendev.org/c/openstack/charm-ops-sunbeam/+/899012 Change-Id: Ie6a735d4cad281c080e47208cf87f34e50d00fd1
This commit is contained in:
parent
3c7295f19d
commit
028658215e
@ -28,6 +28,8 @@ import socket
|
||||
import string
|
||||
from typing import (
|
||||
List,
|
||||
Optional,
|
||||
Set,
|
||||
)
|
||||
|
||||
import charms.operator_libs_linux.v2.snap as snap
|
||||
@ -65,6 +67,8 @@ class HypervisorOperatorCharm(sunbeam_charm.OSBaseOperatorCharm):
|
||||
METADATA_SECRET_KEY = "ovn-metadata-proxy-shared-secret"
|
||||
DEFAULT_SECRET_LENGTH = 32
|
||||
|
||||
mandatory_relations = {"amqp", "identity-credentials", "ovsdb-cms"}
|
||||
|
||||
def __init__(self, framework: ops.framework.Framework) -> None:
|
||||
"""Run constructor."""
|
||||
super().__init__(framework)
|
||||
@ -324,6 +328,21 @@ class HypervisorOperatorCharm(sunbeam_charm.OSBaseOperatorCharm):
|
||||
self.enable_telemetry = False
|
||||
self.configure_charm(event)
|
||||
|
||||
def stop_services(self, relation: Optional[Set[str]]) -> None:
|
||||
"""Stop services based on relation goneaway event."""
|
||||
snap_data = {}
|
||||
for relation_ in relation:
|
||||
logger.info(f"In stop_services for relation {relation_}")
|
||||
if relation_ == "amqp":
|
||||
logger.debug("Resetting rabbitmq url")
|
||||
snap_data.update({"rabbitmq.url": ""})
|
||||
elif relation_ == "ovsdb-cms":
|
||||
logger.debug("Resetting OVN SB connection")
|
||||
snap_data.update({"network.ovn-sb-connection": ""})
|
||||
|
||||
if snap_data:
|
||||
self.set_snap_data(snap_data)
|
||||
|
||||
|
||||
if __name__ == "__main__": # pragma: no cover
|
||||
main(HypervisorOperatorCharm)
|
||||
|
@ -108,11 +108,11 @@ class TestCharm(test_utils.CharmTestCase):
|
||||
self.socket.getfqdn.return_value = "test.local"
|
||||
self.initial_setup()
|
||||
self.harness.set_leader()
|
||||
test_utils.add_complete_amqp_relation(self.harness)
|
||||
test_utils.add_complete_identity_credentials_relation(self.harness)
|
||||
hypervisor_snap_mock.ensure.assert_any_call(
|
||||
"latest", channel="essex/stable"
|
||||
)
|
||||
test_utils.add_complete_amqp_relation(self.harness)
|
||||
test_utils.add_complete_identity_credentials_relation(self.harness)
|
||||
metadata = self.harness.charm.metadata_secret()
|
||||
ovn_cacert = (
|
||||
test_utils.TEST_CA + "\n" + "\n".join(test_utils.TEST_CHAIN)
|
||||
@ -193,11 +193,11 @@ class TestCharm(test_utils.CharmTestCase):
|
||||
self.socket.getfqdn.return_value = "test.local"
|
||||
self.initial_setup()
|
||||
self.harness.set_leader()
|
||||
test_utils.add_complete_amqp_relation(self.harness)
|
||||
test_utils.add_complete_identity_credentials_relation(self.harness)
|
||||
hypervisor_snap_mock.ensure.assert_any_call(
|
||||
"latest", channel="essex/stable"
|
||||
)
|
||||
test_utils.add_complete_amqp_relation(self.harness)
|
||||
test_utils.add_complete_identity_credentials_relation(self.harness)
|
||||
metadata = self.harness.charm.metadata_secret()
|
||||
ovn_cacert = (
|
||||
test_utils.TEST_CA + "\n" + "\n".join(test_utils.TEST_CHAIN)
|
||||
|
Loading…
x
Reference in New Issue
Block a user