← Back to team overview

netplan-developers team mailing list archive

[Merge] ~morphis/netplan/+git/netplan:nm-snap-support into netplan:master

 

Simon Fels has proposed merging ~morphis/netplan/+git/netplan:nm-snap-support into netplan:master.

Requested reviews:
  Developers of netplan (netplan-developers)

For more details, see:
https://code.launchpad.net/~morphis/netplan/+git/netplan/+merge/306607

Add support for the network-manager snap

If the network-manager snap is installed we should restart its service unit rather than the one of the debian package to get it to read its configuration files again.
-- 
Your team Developers of netplan is requested to review the proposed merge of ~morphis/netplan/+git/netplan:nm-snap-support into netplan:master.
diff --git a/src/netplan b/src/netplan
index bdef802..84f71c8 100755
--- a/src/netplan
+++ b/src/netplan
@@ -235,6 +235,15 @@ def command_generate():
     logging.debug('command generate: running %s', argv)
     os.execv(argv[0], argv)
 
+def change_network_manager_service(action):
+    service_name = 'NetworkManager.service'
+
+    # If the network-manager snap is installed use its service
+    # name rather than the one of the deb packaged NetworkManager
+    if os.path.exists('/etc/systemd/system/snap.network-manager.networkmanager.service'):
+        service = 'snap.network-manager.networkmanager.service'
+
+    subprocess.check_call(['systemctl', 'stop', '--no-block', service_name])
 
 def command_apply():  # pragma: nocover (covered in autopkgtest)
     if subprocess.call([path_generate]) != 0:
@@ -259,7 +268,7 @@ def command_apply():  # pragma: nocover (covered in autopkgtest)
             for device in devices:
                 # ignore failures here -- some/many devices might not be managed by NM
                 subprocess.call(['nmcli', 'device', 'disconnect', device], stderr=subprocess.DEVNULL)
-            subprocess.check_call(['systemctl', 'stop', '--no-block', 'NetworkManager.service'])
+            change_network_manager_service('stop')
     else:
         logging.debug('no netplan generated NM configuration exists')
 
@@ -278,8 +287,7 @@ def command_apply():  # pragma: nocover (covered in autopkgtest)
         subprocess.check_call(['systemctl', 'start', '--no-block', 'systemd-networkd.service'] +
                               [os.path.basename(f) for f in glob('/run/systemd/system/*.wants/netplan-wpa@*.service')])
     if restart_nm:
-        subprocess.call(['systemctl', 'start', '--no-block', 'NetworkManager.service'])
-
+        change_network_manager_service('start')
 
 def command_ifupdown_migrate():
     netplan_config = {}

Follow ups