Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin' into ISD-1357-synapse-upgrade-s…
Browse files Browse the repository at this point in the history
…ynapse
  • Loading branch information
amandahla committed Nov 24, 2023
2 parents 0c5960d + c5e8b96 commit 6525ba4
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 41 deletions.
16 changes: 2 additions & 14 deletions src-docs/charm.py.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Unit that this execution is responsible for.

---

<a href="../src/charm.py#L102"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/charm.py#L95"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>function</kbd> `change_config`

Expand All @@ -87,7 +87,7 @@ Change configuration.

---

<a href="../src/charm.py#L212"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>
<a href="../src/charm.py#L218"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>function</kbd> `get_admin_access_token`

Expand All @@ -102,16 +102,4 @@ Get admin access token.
**Returns:**
admin access token or None if fails.

---

<a href="../src/charm.py#L92"><img align="right" style="float:right;" src="https://img.shields.io/badge/-source-cccccc?style=flat-square"></a>

### <kbd>function</kbd> `replan_nginx`

```python
replan_nginx() → None
```

Replan NGINX.


38 changes: 22 additions & 16 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,42 +82,40 @@ def __init__(self, *args: typing.Any) -> None:
self._mjolnir = Mjolnir(self, charm_state=self._charm_state)
self.framework.observe(self.on.config_changed, self._on_config_changed)
self.framework.observe(self.on.reset_instance_action, self._on_reset_instance_action)
self.framework.observe(self.on.synapse_pebble_ready, self._on_pebble_ready)
self.framework.observe(self.on.synapse_pebble_ready, self._on_synapse_pebble_ready)
self.framework.observe(
self.on.synapse_nginx_pebble_ready, self._on_synapse_nginx_pebble_ready
)
self.framework.observe(self.on.register_user_action, self._on_register_user_action)
self.framework.observe(
self.on.promote_user_admin_action, self._on_promote_user_admin_action
)
self.framework.observe(self.on.anonymize_user_action, self._on_anonymize_user_action)

def replan_nginx(self) -> None:
"""Replan NGINX."""
container = self.unit.get_container(synapse.SYNAPSE_NGINX_CONTAINER_NAME)
if not container.can_connect():
self.unit.status = ops.MaintenanceStatus("Waiting for pebble")
return
self.model.unit.status = ops.MaintenanceStatus("Configuring Synapse NGINX")
self.pebble_service.replan_nginx(container)
self.model.unit.status = ops.ActiveStatus()

def change_config(self) -> None:
"""Change configuration."""
container = self.unit.get_container(synapse.SYNAPSE_CONTAINER_NAME)
if not container.can_connect():
self.unit.status = ops.MaintenanceStatus("Waiting for pebble")
self.unit.status = ops.MaintenanceStatus("Waiting for Synapse pebble")
return
self.model.unit.status = ops.MaintenanceStatus("Configuring Synapse")
try:
self.pebble_service.change_config(container)
except PebbleServiceError as exc:
self.model.unit.status = ops.BlockedStatus(str(exc))
return
self.replan_nginx()
container = self.unit.get_container(synapse.SYNAPSE_NGINX_CONTAINER_NAME)
if not container.can_connect():
self.unit.status = ops.MaintenanceStatus("Waiting for Synapse NGINX pebble")
return
self.pebble_service.replan_nginx(container)
self.model.unit.status = ops.ActiveStatus()

def _set_workload_version(self) -> None:
"""Set workload version with Synapse version."""
container = self.unit.get_container(synapse.SYNAPSE_CONTAINER_NAME)
if not container.can_connect():
self.unit.status = ops.MaintenanceStatus("Waiting for pebble")
self.unit.status = ops.MaintenanceStatus("Waiting for Synapse pebble")
return
try:
synapse_version = synapse.get_version()
Expand All @@ -130,10 +128,18 @@ def _on_config_changed(self, _: ops.HookEvent) -> None:
self.change_config()
self._set_workload_version()

def _on_pebble_ready(self, _: ops.HookEvent) -> None:
"""Handle pebble ready event."""
def _on_synapse_pebble_ready(self, _: ops.HookEvent) -> None:
"""Handle synapse pebble ready event."""
self.change_config()

def _on_synapse_nginx_pebble_ready(self, _: ops.HookEvent) -> None:
"""Handle synapse nginx pebble ready event."""
container = self.unit.get_container(synapse.SYNAPSE_NGINX_CONTAINER_NAME)
if not container.can_connect():
self.unit.status = ops.MaintenanceStatus("Waiting for Synapse NGINX pebble")
return
self.pebble_service.replan_nginx(container)

def _on_reset_instance_action(self, event: ActionEvent) -> None:
"""Reset instance and report action result.
Expand Down
2 changes: 1 addition & 1 deletion src/database_observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def _change_config(self) -> None:
"""Change the configuration."""
container = self._charm.unit.get_container(synapse.SYNAPSE_CONTAINER_NAME)
if not container.can_connect() or self._pebble_service is None:
self._charm.unit.status = ops.MaintenanceStatus("Waiting for pebble")
self._charm.unit.status = ops.MaintenanceStatus("Waiting for Synapse pebble")
return
try:
self._pebble_service.change_config(container)
Expand Down
4 changes: 2 additions & 2 deletions src/mjolnir.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def _on_collect_status(self, event: ops.CollectStatusEvent) -> None:
return
container = self._charm.unit.get_container(synapse.SYNAPSE_CONTAINER_NAME)
if not container.can_connect():
self._charm.unit.status = ops.MaintenanceStatus("Waiting for pebble")
self._charm.unit.status = ops.MaintenanceStatus("Waiting for Synapse pebble")
return
mjolnir_service = container.get_services(MJOLNIR_SERVICE_NAME)
if mjolnir_service:
Expand Down Expand Up @@ -151,7 +151,7 @@ def enable_mjolnir(self, admin_access_token: str) -> None:
"""
container = self._charm.unit.get_container(synapse.SYNAPSE_CONTAINER_NAME)
if not container.can_connect():
self._charm.unit.status = ops.MaintenanceStatus("Waiting for pebble")
self._charm.unit.status = ops.MaintenanceStatus("Waiting for Synapse pebble")
return
self._charm.model.unit.status = ops.MaintenanceStatus("Configuring Mjolnir")
mjolnir_user = actions.register_user(
Expand Down
2 changes: 1 addition & 1 deletion src/saml_observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def _enable_saml(self) -> None:
"""Enable SAML."""
container = self._charm.unit.get_container(synapse.SYNAPSE_CONTAINER_NAME)
if not container.can_connect() or self._pebble_service is None:
self._charm.unit.status = ops.MaintenanceStatus("Waiting for pebble")
self._charm.unit.status = ops.MaintenanceStatus("Waiting for Synapse pebble")
return
try:
self._pebble_service.enable_saml(container)
Expand Down
9 changes: 5 additions & 4 deletions src/synapse/workload.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def check_nginx_ready() -> ops.pebble.CheckDict:
check = Check(CHECK_NGINX_READY_NAME)
check.override = "replace"
check.level = "ready"
check.tcp = {"port": SYNAPSE_NGINX_PORT}
check.http = {"url": f"http://localhost:{SYNAPSE_NGINX_PORT}/health"}
return check.to_dict()


Expand Down Expand Up @@ -339,9 +339,10 @@ def enable_federation_domain_whitelist(container: ops.Container, charm_state: Ch
config = container.pull(SYNAPSE_CONFIG_PATH).read()
current_yaml = yaml.safe_load(config)
if charm_state.synapse_config.federation_domain_whitelist is not None:
current_yaml[
"federation_domain_whitelist"
] = charm_state.synapse_config.federation_domain_whitelist.split(",")
current_yaml["federation_domain_whitelist"] = [
item.strip()
for item in charm_state.synapse_config.federation_domain_whitelist.split(",")
]
container.push(SYNAPSE_CONFIG_PATH, yaml.safe_dump(current_yaml))
except ops.pebble.PathError as exc:
raise WorkloadError(str(exc)) from exc
Expand Down
8 changes: 6 additions & 2 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,11 @@ async def grafana_app_fixture(
"""Deploy grafana."""
async with ops_test.fast_forward():
app = await model.deploy(
"grafana-k8s",
grafana_app_name,
application_name=grafana_app_name,
channel="stable",
series="focal",
revision=82, # last one compatible with Juju 2
trust=True,
)
await model.wait_for_idle(raise_on_blocked=True, status=ACTIVE_STATUS_NAME)
Expand All @@ -295,9 +297,11 @@ async def deploy_prometheus_fixture(
"""Deploy prometheus."""
async with ops_test.fast_forward():
app = await model.deploy(
"prometheus-k8s",
prometheus_app_name,
application_name=prometheus_app_name,
channel="stable",
series="focal",
revision=129, # last one compatible with Juju 2
trust=True,
)
await model.wait_for_idle(raise_on_blocked=True, status=ACTIVE_STATUS_NAME)
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,3 +418,18 @@ def test_disable_password_config_is_called(
harness.charm.pebble_service.change_config(container=MagicMock())

disable_password_config_mock.assert_called_once()


def test_nginx_replan(harness: Harness, monkeypatch: pytest.MonkeyPatch) -> None:
"""
arrange: start the Synapse charm, mock replan_nginx call.
act: fire that NGINX container is ready.
assert: Pebble Service replan NGINX is called.
"""
harness.begin()
replan_nginx_mock = MagicMock()
monkeypatch.setattr(harness.charm.pebble_service, "replan_nginx", replan_nginx_mock)

harness.container_pebble_ready(synapse.SYNAPSE_NGINX_CONTAINER_NAME)

replan_nginx_mock.assert_called_once()
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ commands =
[testenv:integration]
description = Run integration tests
deps =
juju==2.9.42.4
juju==2.9.45.0
pytest
pytest-asyncio
pytest-operator
Expand Down

0 comments on commit 6525ba4

Please sign in to comment.