Merge ~morphis/snappy-hwe-snaps/+git/network-manager:move-dhcp-leases into ~snappy-hwe-team/snappy-hwe-snaps/+git/network-manager:master

Proposed by Simon Fels
Status: Merged
Approved by: Simon Fels
Approved revision: fc93640aea921f0ffae2f03ccb00bda7c9d313ab
Merged at revision: 6a9f9e50b11cfd1e735388b6f85e50cd4ed6ce45
Proposed branch: ~morphis/snappy-hwe-snaps/+git/network-manager:move-dhcp-leases
Merge into: ~snappy-hwe-team/snappy-hwe-snaps/+git/network-manager:master
Prerequisite: ~morphis/snappy-hwe-snaps/+git/network-manager:remove-netplan-completely
Diff against target: 134 lines (+83/-2)
4 files modified
bin/dhcp-lease-mover (+26/-0)
bin/networkmanager (+9/-2)
snapcraft.yaml (+16/-0)
tests/main/dhcp-leases-are-moved/task.yaml (+32/-0)
Reviewer Review Type Date Requested Status
System Enablement Bot continuous-integration Approve
Jim Hodapp (community) Approve
Alfonso Sanchez-Beato Approve
Review via email: mp+309847@code.launchpad.net

This proposal supersedes a proposal from 2016-11-02.

Description of the change

Add transitioning of DHCP lease files from SNAP_DATA to /run

The current implementation stores DHCP lease files inside /run which means they are lost after rebooting the system. This can lead to problems with losing a previously assigned IP address if the lease is still valid. We can't just simply move the leases back to SNAP_DATA as probert/console-conf needs to read them from /run. To satisfy this requirement until probert/console-conf are fixed we're syncing the lease files from SNAP_DATA to /run whenever they change.

This is based on top of https://code.launchpad.net/~morphis/snappy-hwe-snaps/+git/network-manager/+merge/309743

To post a comment you must log in.
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alfonso Sanchez-Beato (alfonsosanchezbeato) wrote :

LGTM

review: Approve
Revision history for this message
Jim Hodapp (jhodapp) wrote :

LGTM

review: Approve
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/bin/dhcp-lease-mover b/bin/dhcp-lease-mover
2new file mode 100755
3index 0000000..c54aeb0
4--- /dev/null
5+++ b/bin/dhcp-lease-mover
6@@ -0,0 +1,26 @@
7+#!/bin/sh
8+set -x
9+
10+lease_path=$SNAP_DATA/state/dhcp
11+public_lease_path=/run/NetworkManager/dhcp/
12+
13+if [ ! -e $public_lease_path ] ; then
14+ mkdir -p $public_lease_path
15+fi
16+
17+if [ ! -e $lease_path ] ; then
18+ mkdir -p $lease_path
19+fi
20+
21+# Copy all leases when we start to make sure we're in sync
22+rm -f $public_lease_path/*
23+cp $lease_path/* $public_lease_path
24+
25+# Now we wait until a lease changes, gets added or removed and when
26+# that happened we simply just move all leases files into the public
27+# location.
28+while $SNAP/usr/bin/inotifywait -e create,modify,delete,move $lease_path ; do
29+ sleep 1
30+ rm -f $public_lease_path/*
31+ cp $lease_path/* $public_lease_path
32+done
33diff --git a/bin/networkmanager b/bin/networkmanager
34index 7c003d5..f72fa93 100755
35--- a/bin/networkmanager
36+++ b/bin/networkmanager
37@@ -1,6 +1,5 @@
38 #!/bin/sh
39-set -e
40-set -x
41+set -ex
42
43 # Create all necessary directories we need at runtime
44 mkdir -p $SNAP_DATA/conf/system-connections
45@@ -25,6 +24,7 @@ mkdir -p $SNAP_DATA/conf.d
46 # State dir where network-manager stores several things like the
47 # secret key used for IPv6
48 mkdir -p $SNAP_DATA/state
49+mkdir -p $SNAP_DATA/state/dhcp
50
51 # If netplan is not configured to render by default to NetworkManager
52 # configuration files we disable management of any ethernet device
53@@ -60,6 +60,13 @@ else
54 fi
55 fi
56
57+# HACK: Until we've fixed probert to look in $SNAP_DATA/state/dhcp or
58+# somewhere else for our lease files we use inotifywatch to monitor
59+# our lease files and copy all over when something has changed. This
60+# background process gets stopped when our systemd service unit gets
61+# stopped.
62+$SNAP/bin/dhcp-lease-mover &
63+
64 export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$SNAP/usr/lib/NetworkManager"
65
66 $SNAP/usr/sbin/NetworkManager \
67diff --git a/snapcraft.yaml b/snapcraft.yaml
68index 37dfc66..2e9044f 100644
69--- a/snapcraft.yaml
70+++ b/snapcraft.yaml
71@@ -32,9 +32,25 @@ parts:
72 plugin: copy
73 files:
74 bin/networkmanager: bin/networkmanager
75+ bin/dhcp-lease-mover: bin/dhcp-lease-mover
76 conf/NetworkManager.conf: etc/NetworkManager/NetworkManager.conf
77 data/copyright: usr/share/doc/network-manager/copyright
78
79+ inotify-tools:
80+ plugin: nil
81+ stage-packages:
82+ - libinotifytools0
83+ - inotify-tools
84+ filesets:
85+ wanted:
86+ - usr/share/doc/inotify-tools/copyright
87+ - usr/bin/inotifywait
88+ - usr/share/doc/libinotifytools0/copyright
89+ - usr/lib/libinotifytools.so.0.4.1
90+ - usr/lib/libinotifytools.so.0
91+ snap:
92+ - $wanted
93+
94 networkmanager:
95 plugin: autotools
96
97diff --git a/tests/main/dhcp-leases-are-moved/task.yaml b/tests/main/dhcp-leases-are-moved/task.yaml
98new file mode 100644
99index 0000000..fff2d6a
100--- /dev/null
101+++ b/tests/main/dhcp-leases-are-moved/task.yaml
102@@ -0,0 +1,32 @@
103+summary: Verify that the DHCP leases are moved to the correct location
104+
105+execute: |
106+ . $TESTSLIB/utilities.sh
107+ case "$SPREAD_REBOOT" in
108+ 0)
109+ switch_netplan_to_network_manager
110+ REBOOT
111+ ;;
112+ 1)
113+ # Now we have network-manager also with ethernet support
114+ test -e /run/NetworkManager/dhcp
115+ test -e /var/snap/network-manager/current/state/dhcp
116+
117+ num_leases=`ls -1 /var/snap/network-manager/current/state/dhcp | wc -l`
118+ num_public_leases=`ls -1 /run/NetworkManager/dhcp | wc -l`
119+ test $num_leases -eq $num_public_leases
120+
121+ # Create a new lease file and ensure it gets copied over
122+ test ! -e /run/NetworkManager/dhcp/temp.lease
123+ touch /var/snap/network-manager/current/state/dhcp/temp.lease
124+ sleep 2
125+ test -e /run/NetworkManager/dhcp/temp.lease
126+ # Ensure that the lease is also removed from /run again when it
127+ # gets removed from SNAP_DATA
128+ rm /var/snap/network-manager/current/state/dhcp/temp.lease
129+ sleep 2
130+ test ! -e /var/snap/network-manager/current/state/dhcp/temp.lease
131+ ;;
132+ *)
133+ ;;
134+ esac

Subscribers

People subscribed via source and target branches