Skip to content

Commit 61d8564

Browse files
ISD-2819 restart synapse and MAS if MAS config has changed (#779)
1 parent a8cf731 commit 61d8564

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

src/pebble.py

+33-2
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,28 @@ def _get_synapse_config(container: ops.model.Container) -> dict:
219219
raise PebbleServiceError(str(exc)) from exc
220220

221221

222+
def _get_mas_config(container: ops.model.Container) -> dict:
223+
"""Get the current MAS configuration.
224+
225+
Args:
226+
container: Synapse container.
227+
228+
Returns:
229+
dict: MAS configuration.
230+
231+
Raises:
232+
PebbleServiceError: if something goes wrong while interacting with Pebble.
233+
"""
234+
try:
235+
config = container.pull(MAS_CONFIGURATION_PATH).read()
236+
return yaml.safe_load(config)
237+
except ops.pebble.PathError as exc:
238+
# If the MAS config has not been created, we return an empty dict to trigger a replan
239+
if exc.kind == "not-found":
240+
return {}
241+
raise PebbleServiceError(str(exc)) from exc
242+
243+
222244
def _push_synapse_config(
223245
container: ops.model.Container,
224246
current_synapse_config: dict,
@@ -317,7 +339,16 @@ def reconcile( # noqa: C901
317339
PebbleServiceError: if something goes wrong while interacting with Pebble.
318340
"""
319341
try:
320-
restart_mas(container, rendered_mas_configuration, charm_state)
342+
343+
existing_mas_config = _get_mas_config(container=container)
344+
mas_config_has_changed = DeepDiff(
345+
existing_mas_config,
346+
yaml.safe_load(rendered_mas_configuration),
347+
ignore_order=True,
348+
ignore_string_case=True,
349+
)
350+
if mas_config_has_changed:
351+
restart_mas(container, rendered_mas_configuration, charm_state)
321352

322353
if _environment_has_changed(container=container, charm_state=charm_state, is_main=is_main):
323354
# Configurations set via environment variables:
@@ -402,7 +433,7 @@ def reconcile( # noqa: C901
402433
ignore_string_case=True,
403434
)
404435

405-
if config_has_changed:
436+
if config_has_changed or mas_config_has_changed:
406437
logging.info("Configuration has changed, Synapse will be restarted.")
407438
logging.debug("The change is: %s", config_has_changed)
408439
# Push worker configuration

tests/unit/conftest.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from ops.testing import Harness
1818

1919
import synapse
20-
from auth.mas import MAS_EXECUTABLE_PATH
20+
from auth.mas import MAS_CONFIGURATION_PATH, MAS_EXECUTABLE_PATH
2121
from charm import SynapseCharm
2222
from s3_parameters import S3Parameters
2323

@@ -139,6 +139,13 @@ def harness_fixture(request, monkeypatch) -> typing.Generator[Harness, None, Non
139139
harness.set_can_connect(synapse.SYNAPSE_CONTAINER_NAME, True)
140140
synapse_container.make_dir("/data", make_parents=True)
141141
synapse_container.push(f"/data/{TEST_SERVER_NAME}.signing.key", "123")
142+
synapse_container.make_dir("/mas", make_parents=True)
143+
synapse_container.push(
144+
MAS_CONFIGURATION_PATH,
145+
yaml.safe_dump(
146+
{"http": {"listeners": [{"name": "web", "binds": [{"address": "[::]:8081"}]}]}}
147+
),
148+
)
142149
# unused-variable disabled to pass constants values to inner function
143150
command_path = synapse.SYNAPSE_COMMAND_PATH
144151
command_migrate_config = synapse.COMMAND_MIGRATE_CONFIG

0 commit comments

Comments
 (0)