wireguard: Remove NM connections when app is uninstalled

Tests:

- Install WireGuard and start the server. Uninstall the app and re-install.
Without the patch, the connection remain after uninstall. With the patch, the
connections are removed after uninstall and return to pristine state after
re-install.

- Functional tests succeed.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2026-01-29 16:08:55 -08:00 committed by James Valleroy
parent b0a841c63a
commit f4b1eb23ac
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
2 changed files with 16 additions and 0 deletions

View File

@ -96,3 +96,8 @@ class WireguardApp(app_module.App):
super().setup(old_version)
if not old_version:
self.enable()
def uninstall(self):
"""De-configure and uninstall the app."""
utils.delete_connections()
super().uninstall()

View File

@ -127,6 +127,17 @@ def enable_connections(enable):
pass # Connection is already inactive
def delete_connections():
"""Remove all WireGuard connections."""
setting_name = nm.SETTING_WIREGUARD_SETTING_NAME
client = network.get_nm_client()
for connection in client.get_connections():
if connection.get_connection_type() != setting_name:
continue
connection.delete()
def _get_public_key_from_private_key(private_key):
process = subprocess.run(['wg', 'pubkey'], check=True, capture_output=True,
input=private_key.encode())