Skip to content

Commit

Permalink
chores: remove reset-instance action (#535)
Browse files Browse the repository at this point in the history
  • Loading branch information
amandahla committed Sep 24, 2024
1 parent 5353b08 commit d00fd7f
Show file tree
Hide file tree
Showing 18 changed files with 22 additions and 472 deletions.
5 changes: 0 additions & 5 deletions actions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@ anonymize-user:
type: string
required:
- username
reset-instance:
description: |
Set a new server_name before running this action.
Once a server_name is configured, you must start a new instance if you wish a different one.
This actions will erase all data and create a instance with the new server_name.
register-user:
description: |
Registers a user for the Synapse server.
Expand Down
3 changes: 1 addition & 2 deletions docs/how-to/contribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ juju deploy ./synapse_ubuntu-22.04-amd64.charm \
### Configure `server_name`

Synapse requires a `server_name` to be set before starting. Note that this cannot
be changed later so if you want a different server name, will need to run the
action `reset-instance` to re-create everything.
be changed later.

The following command will configure the `server_name` mychat.test.com:

Expand Down
22 changes: 11 additions & 11 deletions src-docs/charm.py.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ Unit that this execution is responsible for.

---

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

### <kbd>function</kbd> `build_charm_state`

Expand All @@ -91,7 +91,7 @@ Build charm state.

---

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

### <kbd>function</kbd> `get_main_unit`

Expand All @@ -108,7 +108,7 @@ Get main unit.

---

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

### <kbd>function</kbd> `get_main_unit_address`

Expand All @@ -125,7 +125,7 @@ Get main unit address. If main unit is None, use unit name.

---

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

### <kbd>function</kbd> `get_signing_key`

Expand All @@ -142,7 +142,7 @@ Get signing key from secret.

---

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

### <kbd>function</kbd> `get_unit_number`

Expand All @@ -166,7 +166,7 @@ Get unit number from unit name.

---

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

### <kbd>function</kbd> `instance_map`

Expand All @@ -183,7 +183,7 @@ Build instance_map config.

---

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

### <kbd>function</kbd> `is_main`

Expand All @@ -201,7 +201,7 @@ Verify if this unit is the main.

---

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

### <kbd>function</kbd> `peer_units_total`

Expand All @@ -218,7 +218,7 @@ Get peer units total.

---

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

### <kbd>function</kbd> `reconcile`

Expand All @@ -238,7 +238,7 @@ This is the main entry for changes that require a restart.

---

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

### <kbd>function</kbd> `set_main_unit`

Expand All @@ -256,7 +256,7 @@ Create/Renew an admin access token and put it in the peer relation.

---

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

### <kbd>function</kbd> `set_signing_key`

Expand Down
26 changes: 0 additions & 26 deletions src-docs/pebble.py.md
Original file line number Diff line number Diff line change
Expand Up @@ -250,32 +250,6 @@ This is the main entry for changes that require a restart done via Pebble.



**Raises:**

- <b>`PebbleServiceError`</b>: if something goes wrong while interacting with Pebble.


---

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

## <kbd>function</kbd> `reset_instance`

```python
reset_instance(charm_state: CharmState, container: Container) → None
```

Reset instance.



**Args:**

- <b>`charm_state`</b>: Instance of CharmState
- <b>`container`</b>: Charm container.



**Raises:**

- <b>`PebbleServiceError`</b>: if something goes wrong while interacting with Pebble.
Expand Down
1 change: 0 additions & 1 deletion src/actions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@

# Exporting methods to be used for another modules
from .register_user import RegisterUserError, register_user # noqa: F401
from .reset_instance import ResetInstanceError, reset_instance # noqa: F401
61 changes: 0 additions & 61 deletions src/actions/reset_instance.py

This file was deleted.

44 changes: 2 additions & 42 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ def __init__(self, *args: typing.Any) -> None:
self.framework.observe(
self.on[synapse.SYNAPSE_PEER_RELATION_NAME].relation_changed, self._on_relation_changed
)
self.framework.observe(self.on.reset_instance_action, self._on_reset_instance_action)
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
Expand Down Expand Up @@ -497,50 +496,11 @@ def _on_synapse_nginx_pebble_ready(self, _: ops.HookEvent) -> None:
pebble.restart_nginx(container, self.get_main_unit_address())
self._set_unit_status()

@inject_charm_state
def _on_reset_instance_action(self, event: ActionEvent, charm_state: CharmState) -> None:
"""Reset instance and report action result.
Args:
event: Event triggering the reset instance action.
charm_state: The charm state.
"""
results = {
"reset-instance": False,
}
if not self.model.unit.is_leader():
event.fail("Only the juju leader unit can run reset instance action")
return
container = self.unit.get_container(synapse.SYNAPSE_CONTAINER_NAME)
if not container.can_connect():
event.fail("Failed to connect to the container")
return
try:
self.model.unit.status = ops.MaintenanceStatus("Resetting Synapse instance")
try:
container.stop(pebble.STATS_EXPORTER_SERVICE_NAME)
except (ops.pebble.Error, RuntimeError) as e:
event.fail(f"Failed to stop Synapse Stats Exporter: {str(e)}")
pebble.reset_instance(charm_state, container)
datasource = self._database.get_relation_as_datasource()
actions.reset_instance(
container=container, charm_state=charm_state, datasource=datasource
)
logger.info("Start Synapse")
pebble.restart_synapse(charm_state, container, self.is_main())
results["reset-instance"] = True
except (pebble.PebbleServiceError, actions.ResetInstanceError) as exc:
self.model.unit.status = ops.BlockedStatus(str(exc))
event.fail(str(exc))
return
event.set_results(results)
self.model.unit.status = ops.ActiveStatus()

def _on_register_user_action(self, event: ActionEvent) -> None:
"""Reset instance and report action result.
"""Register user and report action result.
Args:
event: Event triggering the reset instance action.
event: Event triggering the register user instance action.
"""
container = self.unit.get_container(synapse.SYNAPSE_CONTAINER_NAME)
if not container.can_connect():
Expand Down
2 changes: 1 addition & 1 deletion src/charm_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ def proxy(self) -> "ProxyConfig":

# from_charm receives configuration from all integration so too many arguments.
@classmethod
def from_charm( # pylint: disable=too-many-arguments
def from_charm( # pylint: disable=too-many-arguments,too-many-positional-arguments
cls,
charm: ops.CharmBase,
datasource: typing.Optional[DatasourcePostgreSQL],
Expand Down
28 changes: 0 additions & 28 deletions src/pebble.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,34 +395,6 @@ def reconcile( # noqa: C901 pylint: disable=too-many-branches,too-many-statemen
raise PebbleServiceError(str(exc)) from exc


def reset_instance(charm_state: CharmState, container: ops.model.Container) -> None:
"""Reset instance.
Args:
charm_state: Instance of CharmState
container: Charm container.
Raises:
PebbleServiceError: if something goes wrong while interacting with Pebble.
"""
# This is needed in the case of relation with Postgresql.
# If there is open connections it won't be possible to drop the database.
try:
logger.info("Replan service to not restart")
container.add_layer(
synapse.SYNAPSE_CONTAINER_NAME,
_pebble_layer_without_restart(charm_state),
combine=True,
)
container.replan()
logger.info("Stop Synapse instance")
container.stop(synapse.SYNAPSE_SERVICE_NAME)
logger.info("Erase Synapse data")
synapse.reset_instance(container)
except ops.pebble.PathError as exc:
raise PebbleServiceError(str(exc)) from exc


def _pebble_layer(charm_state: CharmState, is_main: bool = True) -> ops.pebble.LayerDict:
"""Return a dictionary representing a Pebble layer.
Expand Down
1 change: 0 additions & 1 deletion src/synapse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
get_environment,
get_media_store_path,
get_registration_shared_secret,
reset_instance,
validate_config,
)
from .workload_configuration import ( # noqa: F401
Expand Down
2 changes: 1 addition & 1 deletion src/synapse/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def register_user(
raise RegisterUserError(str(exc)) from exc


def _generate_mac(
def _generate_mac( # pylint: disable=too-many-positional-arguments
shared_secret: str,
nonce: str,
user: str,
Expand Down
30 changes: 1 addition & 29 deletions src/synapse/workload.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,7 @@ def _check_server_name(container: ops.Container, charm_state: CharmState) -> Non
):
msg = (
f"server_name {charm_state.synapse_config.server_name} is different from the existing "
f"one {configured_server_name}. Please revert the config or run the action "
"reset-instance if you want to erase the existing instance and start a new "
"one."
f"one {configured_server_name}. Please revert the config."
)
logger.error(msg)
raise ServerNameModifiedError(
Expand Down Expand Up @@ -302,32 +300,6 @@ def validate_config(container: ops.Container) -> None:
raise WorkloadError("Validate config failed, please check the logs")


def reset_instance(container: ops.Container) -> None:
"""Erase data and config server_name.
Args:
container: Container of the charm.
Raises:
PathError: if somethings goes wrong while erasing the Synapse directory.
"""
logging.debug("Erasing directory %s", SYNAPSE_CONFIG_DIR)
try:
container.remove_path(SYNAPSE_CONFIG_DIR, recursive=True)
except PathError as path_error:
# The error "unlinkat //data: device or resource busy" is expected
# when removing the entire directory because it's a volume mount.
# The files will be removed but SYNAPSE_CONFIG_DIR directory will
# remain.
if "device or resource busy" in str(path_error):
pass
else:
logger.exception(
"exception while erasing directory %s: %r", SYNAPSE_CONFIG_DIR, path_error
)
raise


def generate_nginx_config(container: ops.Container, main_unit_address: str) -> None:
"""Generate NGINX configuration based on templates.
Expand Down
1 change: 1 addition & 0 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def synapse_app_charmhub_name_fixture() -> str:
return "synapse-charmhub"


# pylint: disable=too-many-positional-arguments
@pytest_asyncio.fixture(scope="module", name="synapse_app")
async def synapse_app_fixture(
ops_test: OpsTest,
Expand Down
Loading

0 comments on commit d00fd7f

Please sign in to comment.