Merge ~alfonsosanchezbeato/snappy-hwe-snaps/+git/wifi-ap:fix-boot-race into ~snappy-hwe-team/snappy-hwe-snaps/+git/wifi-ap:master

Proposed by Alfonso Sanchez-Beato
Status: Merged
Approved by: Konrad Zapałowicz
Approved revision: 51d1492515e8577e791531b6c3d7f0d077973f6d
Merged at revision: 119e76002456989af0902401e356ccae2e9025a6
Proposed branch: ~alfonsosanchezbeato/snappy-hwe-snaps/+git/wifi-ap:fix-boot-race
Merge into: ~snappy-hwe-team/snappy-hwe-snaps/+git/wifi-ap:master
Diff against target: 191 lines (+82/-18)
5 files modified
cmd/service/service.go (+74/-16)
spread.yaml (+0/-1)
tests/lib/prepare-each.sh (+6/-1)
tests/main/conf-from-gadget/task.yaml (+1/-0)
tests/main/conf-wizard-disabled-from-gadget/task.yaml (+1/-0)
Reviewer Review Type Date Requested Status
System Enablement Bot continuous-integration Approve
Konrad Zapałowicz (community) code Approve
Review via email: mp+342117@code.launchpad.net

Description of the change

Re-start hostapd when NM is (re)started

This is needed so we set the wifi interface as "unmanaged" in
NetworkManager. We detect NM (re)starts by watching at the service
DBus name changes. Fixes LP: #1758342.

To post a comment you must log in.
Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :

PASSED: Successfully build documentation, rev: 0e0fb0fc9167e522b53b0d454376134385bbc548

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/1058/

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

PASSED: Successfully build documentation, rev: fc0837ce8e770320218d02c9dcfa12251dbcfbef

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/1059/

Revision history for this message
System Enablement Bot (system-enablement-ci-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Konrad Zapałowicz (kzapalowicz) wrote :

LGTM so acked, two 'mater of taste' comments inline

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

PASSED: Successfully build documentation, rev: 51d1492515e8577e791531b6c3d7f0d077973f6d

Generated documentation is available at https://jenkins.canonical.com/system-enablement/job/snappy-hwe-snaps-snap-docs/1060/

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
diff --git a/cmd/service/service.go b/cmd/service/service.go
index c580f4a..ce92b7d 100644
--- a/cmd/service/service.go
+++ b/cmd/service/service.go
@@ -26,6 +26,7 @@ import (
26 "path/filepath"26 "path/filepath"
27 "time"27 "time"
2828
29 "github.com/godbus/dbus"
29 "gopkg.in/tomb.v2"30 "gopkg.in/tomb.v2"
30)31)
3132
@@ -48,6 +49,8 @@ type service struct {
48 listener net.Listener49 listener net.Listener
49 router *mux.Router50 router *mux.Router
50 ap BackgroundProcess51 ap BackgroundProcess
52 dbusConn *dbus.Conn
53 quit chan int
51}54}
5255
53func (c *serviceCommand) ServeHTTP(w http.ResponseWriter, r *http.Request) {56func (c *serviceCommand) ServeHTTP(w http.ResponseWriter, r *http.Request) {
@@ -100,26 +103,44 @@ func (s *service) setupAccesPoint() error {
100}103}
101104
102func (s *service) Shutdown() {105func (s *service) Shutdown() {
103 log.Println("Shutting down ...")106 s.quit <- 0
104 s.listener.Close()107}
105 s.tomb.Kill(nil)108
106 s.tomb.Wait()109func (s *service) createNetworkManagerMonitorCh() (chan *dbus.Signal, error) {
110 var err error
111 s.dbusConn, err = dbus.SystemBus()
112 if err != nil {
113 return nil, fmt.Errorf("Failed to connect to system bus: %v", err)
114 }
115
116 err = s.dbusConn.BusObject().Call("org.freedesktop.DBus.AddMatch", 0,
117 "type='signal',path='/org/freedesktop/DBus',"+
118 "interface='org.freedesktop.DBus',"+
119 "sender='org.freedesktop.DBus',member='NameOwnerChanged',"+
120 "arg0='org.freedesktop.NetworkManager'").Store()
121 if err != nil {
122 return nil, fmt.Errorf("Error when calling AddMatch: %v", err)
123 }
124
125 c := make(chan *dbus.Signal, 10)
126 s.dbusConn.Signal(c)
127
128 return c, nil
107}129}
108130
109func (s *service) Run() error {131func (s *service) Run() error {
132 s.quit = make(chan int)
110 s.addRoutes()133 s.addRoutes()
111 if err := s.setupAccesPoint(); err != nil {
112 return err
113 }
114134
115 var err error135 var err error
116 if validTokens, err = loadValidTokens(filepath.Join(os.Getenv("SNAP"), "conf", "default-config")); err != nil {136 if validTokens, err = loadValidTokens(filepath.Join(os.Getenv("SNAP"),
137 "conf", "default-config")); err != nil {
117 log.Println("Failed to read default configuration:", err)138 log.Println("Failed to read default configuration:", err)
118 }139 }
119140
120 // Create the socket directory and remove any stale socket141 // Create the socket directory and remove any stale socket
121 path := filepath.Join(os.Getenv("SNAP_DATA"), socketPathSuffix)142 path := filepath.Join(os.Getenv("SNAP_DATA"), socketPathSuffix)
122 if _, err := os.Stat(filepath.Dir(path)); os.IsNotExist(err) {143 if _, err = os.Stat(filepath.Dir(path)); os.IsNotExist(err) {
123 os.Mkdir(filepath.Dir(path), 0755)144 os.Mkdir(filepath.Dir(path), 0755)
124 }145 }
125 os.Remove(path)146 os.Remove(path)
@@ -131,20 +152,57 @@ func (s *service) Run() error {
131 }152 }
132153
133 s.tomb.Go(func() error {154 s.tomb.Go(func() error {
134 err := s.server.Serve(s.listener)155 err = s.server.Serve(s.listener)
135 if err != nil {156 if err != nil {
136 return fmt.Errorf("Failed to server HTTP: %s", err)157 return fmt.Errorf("Failed to start service: %s", err)
137 }158 }
138 return nil159 return err
139 })160 })
140161
141 s.tomb.Wait()162 nmChangeCh, err := s.createNetworkManagerMonitorCh()
163 if err != nil {
164 return err
165 }
166 if err = s.setupAccesPoint(); err != nil {
167 return err
168 }
142169
143 if s.ap.Running() {170 var errLp error
144 s.ap.Stop()171monitorOut:
172 for {
173 select {
174 case sign := <-nmChangeCh:
175 if len(sign.Body) != 3 {
176 errLp = fmt.Errorf("Bad number of args in " +
177 "NameOwnerChanged signal")
178 break monitorOut
179 }
180 newOwner, ok := sign.Body[2].(string)
181 if ok == false {
182 errLp = fmt.Errorf("Bad argument type in " +
183 "NameOwnerChanged signal")
184 break monitorOut
185 }
186 if newOwner != "" {
187 log.Println("NetworkManager stopped -> started")
188 s.ap.Stop()
189 if errLp = s.setupAccesPoint(); errLp != nil {
190 break monitorOut
191 }
192 }
193 case <-s.quit:
194 log.Println("Shutting down...")
195 break monitorOut
196 }
145 }197 }
146198
147 return nil199 s.dbusConn.Close()
200 s.listener.Close()
201 s.tomb.Kill(nil)
202 s.ap.Stop()
203 s.tomb.Wait()
204
205 return errLp
148}206}
149207
150type tcpKeepAliveListener struct {208type tcpKeepAliveListener struct {
diff --git a/spread.yaml b/spread.yaml
index 3a743c0..3cbdb3b 100644
--- a/spread.yaml
+++ b/spread.yaml
@@ -43,7 +43,6 @@ prepare-each: |
43 # Cleanup logs so we can just dump what has happened in the debug-each43 # Cleanup logs so we can just dump what has happened in the debug-each
44 # step below after a test case ran.44 # step below after a test case ran.
45 journalctl --rotate45 journalctl --rotate
46 sleep .1
47 journalctl --vacuum-time=1ms46 journalctl --vacuum-time=1ms
48 dmesg -c > /dev/null47 dmesg -c > /dev/null
4948
diff --git a/tests/lib/prepare-each.sh b/tests/lib/prepare-each.sh
index 7c9426a..c321930 100644
--- a/tests/lib/prepare-each.sh
+++ b/tests/lib/prepare-each.sh
@@ -1,4 +1,4 @@
1#!/bin/sh1#!/bin/sh -x
2. $TESTSLIB/utilities.sh2. $TESTSLIB/utilities.sh
33
4# Powercycle both interface to get them back into a sane state before4# Powercycle both interface to get them back into a sane state before
@@ -14,3 +14,8 @@ snap remove wireless-tools
14install_snap_under_test14install_snap_under_test
15# Give wifi-ap a bit time to settle down to avoid clashed15# Give wifi-ap a bit time to settle down to avoid clashed
16sleep 516sleep 5
17# hostapd fails due to a seccomp error in qemu. We need to re-start wifi-ap to
18# have it back. This is probably a qemu/kvm bug, so we woraround the issue for
19# the moment.
20snap restart wifi-ap
21sleep 10
diff --git a/tests/main/conf-from-gadget/task.yaml b/tests/main/conf-from-gadget/task.yaml
index e26d7bf..234515c 100644
--- a/tests/main/conf-from-gadget/task.yaml
+++ b/tests/main/conf-from-gadget/task.yaml
@@ -1,4 +1,5 @@
1summary: Verify that the default SSID can be read from a gadget snap1summary: Verify that the default SSID can be read from a gadget snap
2manual: true
2description: |3description: |
3 We check that we get the SSID name from the defaults in the gadget4 We check that we get the SSID name from the defaults in the gadget
4 snap. To do this, we re-package the gadget snap in the store after5 snap. To do this, we re-package the gadget snap in the store after
diff --git a/tests/main/conf-wizard-disabled-from-gadget/task.yaml b/tests/main/conf-wizard-disabled-from-gadget/task.yaml
index 84cbbd3..5bc2974 100644
--- a/tests/main/conf-wizard-disabled-from-gadget/task.yaml
+++ b/tests/main/conf-wizard-disabled-from-gadget/task.yaml
@@ -1,4 +1,5 @@
1summary: Verify the wizard can be disabled by default from a gadget snap1summary: Verify the wizard can be disabled by default from a gadget snap
2manual: true
23
3prepare: |4prepare: |
4 . $TESTSLIB/snap-names.sh5 . $TESTSLIB/snap-names.sh

Subscribers

People subscribed via source and target branches