Merge lp:~jonas-drange/ubuntu-push/vivid-fix-lp1469398 into lp:ubuntu-push/vivid-overlay

Proposed by Jonas G. Drange
Status: Merged
Approved by: Jonas G. Drange
Approved revision: 411
Merged at revision: 150
Proposed branch: lp:~jonas-drange/ubuntu-push/vivid-fix-lp1469398
Merge into: lp:ubuntu-push/vivid-overlay
Diff against target: 199 lines (+35/-48)
2 files modified
poller/poller.go (+24/-34)
poller/poller_test.go (+11/-14)
To merge this branch: bzr merge lp:~jonas-drange/ubuntu-push/vivid-fix-lp1469398
Reviewer Review Type Date Requested Status
Ubuntu Push Hackers Pending
Review via email: mp+272564@code.launchpad.net

Commit message

* Address bug 1469398 by checking NetworkManager.State

Description of the change

* Address bug 1469398 by checking NetworkManager.State

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'poller/poller.go'
2--- poller/poller.go 2015-04-29 15:22:03 +0000
3+++ poller/poller.go 2015-09-28 10:22:34 +0000
4@@ -25,9 +25,9 @@
5 "time"
6
7 "launchpad.net/ubuntu-push/bus"
8+ "launchpad.net/ubuntu-push/bus/networkmanager"
9 "launchpad.net/ubuntu-push/bus/polld"
10 "launchpad.net/ubuntu-push/bus/powerd"
11- "launchpad.net/ubuntu-push/bus/urfkill"
12 "launchpad.net/ubuntu-push/client/session"
13 "launchpad.net/ubuntu-push/logger"
14 "launchpad.net/ubuntu-push/util"
15@@ -69,7 +69,7 @@
16 log logger.Logger
17 powerd powerd.Powerd
18 polld polld.Polld
19- urfkill urfkill.URfkill
20+ nm networkmanager.NetworkManager
21 cookie string
22 sessionState stater
23 requestWakeupCh chan struct{}
24@@ -101,12 +101,13 @@
25 if p.powerd != nil || p.polld != nil {
26 return ErrAlreadyStarted
27 }
28+
29 powerdEndp := bus.SystemBus.Endpoint(powerd.BusAddress, p.log)
30 polldEndp := bus.SessionBus.Endpoint(polld.BusAddress, p.log)
31- urEndp := bus.SystemBus.Endpoint(urfkill.BusAddress, p.log)
32- urWLANKillswitchEndp := bus.SystemBus.Endpoint(urfkill.WLANKillswitchBusAddress, p.log)
33+ nmEndp := bus.SystemBus.Endpoint(networkmanager.BusAddress, p.log)
34+
35 var wg sync.WaitGroup
36- wg.Add(4)
37+ wg.Add(3)
38 go func() {
39 n := util.NewAutoRedialer(powerdEndp).Redial()
40 p.log.Debugf("powerd dialed on try %d", n)
41@@ -118,20 +119,15 @@
42 wg.Done()
43 }()
44 go func() {
45- n := util.NewAutoRedialer(urEndp).Redial()
46- p.log.Debugf("URfkill dialed on try %d", n)
47- wg.Done()
48- }()
49- go func() {
50- n := util.NewAutoRedialer(urWLANKillswitchEndp).Redial()
51- p.log.Debugf("URfkill (WLAN killswitch) dialed on try %d", n)
52+ n := util.NewAutoRedialer(nmEndp).Redial()
53+ p.log.Debugf("NetworkManager dialed on try %d", n)
54 wg.Done()
55 }()
56 wg.Wait()
57
58 p.powerd = powerd.New(powerdEndp, p.log)
59 p.polld = polld.New(polldEndp, p.log)
60- p.urfkill = urfkill.New(urEndp, urWLANKillswitchEndp, p.log)
61+ p.nm = networkmanager.New(nmEndp, p.log)
62
63 // busy sleep loop to workaround go's timer/sleep
64 // not accounting for time when the system is suspended
65@@ -154,7 +150,7 @@
66 if p.log == nil {
67 return ErrUnconfigured
68 }
69- if p.powerd == nil || p.polld == nil || p.urfkill == nil {
70+ if p.powerd == nil || p.polld == nil || p.nm == nil {
71 return ErrNotStarted
72 }
73 wakeupCh, err := p.powerd.WatchWakeups()
74@@ -165,19 +161,13 @@
75 if err != nil {
76 return err
77 }
78- flightMode := p.urfkill.IsFlightMode()
79- wlanKillswitchState := p.urfkill.GetWLANKillswitchState()
80- flightModeCh, _, err := p.urfkill.WatchFlightMode()
81- if err != nil {
82- return err
83- }
84- wlanKillswitchStateCh, _, err := p.urfkill.WatchWLANKillswitchState()
85- if err != nil {
86- return err
87- }
88-
89+ nmState := p.nm.GetState()
90+ nmStateCh, _, err := p.nm.WatchState()
91+ if err != nil {
92+ return err
93+ }
94 filteredWakeUpCh := make(chan bool)
95- go p.control(wakeupCh, filteredWakeUpCh, flightMode, flightModeCh, wlanKillswitchState, wlanKillswitchStateCh)
96+ go p.control(wakeupCh, filteredWakeUpCh, nmState, nmStateCh)
97 go p.run(filteredWakeUpCh, doneCh)
98 return nil
99 }
100@@ -195,9 +185,10 @@
101 return t, cookie, err
102 }
103
104-func (p *poller) control(wakeupCh <-chan bool, filteredWakeUpCh chan<- bool, flightMode bool, flightModeCh <-chan bool, wlanKillswitchState urfkill.KillswitchState, wlanKillswitchStateCh <-chan urfkill.KillswitchState) {
105- wirelessEnabled := wlanKillswitchState == urfkill.KillswitchStateUnblocked
106- dontPoll := flightMode && !wirelessEnabled
107+func (p *poller) control(wakeupCh <-chan bool, filteredWakeUpCh chan<- bool, nmState networkmanager.State, nmStateCh <-chan networkmanager.State) {
108+ connected := nmState == networkmanager.ConnectedGlobal
109+ dontPoll := !connected
110+ p.log.Debugf("nmState: %v, networkmanager.ConnectedGlobal: %v", nmState, networkmanager.ConnectedGlobal)
111 var t time.Time
112 cookie := ""
113 holdsWakeLock := false
114@@ -234,12 +225,11 @@
115 filteredWakeUpCh <- true
116 }
117 }
118- case flightMode = <-flightModeCh:
119- case wlanKillswitchState = <-wlanKillswitchStateCh:
120- wirelessEnabled = wlanKillswitchState == urfkill.KillswitchStateUnblocked
121+ case nmState = <-nmStateCh:
122+ connected = nmState == networkmanager.ConnectedGlobal
123 }
124- newDontPoll := flightMode && !wirelessEnabled
125- p.log.Debugf("control: flightMode:%v wirelessEnabled:%v prevDontPoll:%v dontPoll:%v wakeupReq:%v holdsWakeLock:%v", flightMode, wirelessEnabled, dontPoll, newDontPoll, !t.IsZero(), holdsWakeLock)
126+ newDontPoll := !connected
127+ p.log.Debugf("control: nmState:%v prevDontPoll:%v dontPoll:%v wakeupReq:%v holdsWakeLock:%v", nmState, dontPoll, newDontPoll, !t.IsZero(), holdsWakeLock)
128 if newDontPoll != dontPoll {
129 if dontPoll = newDontPoll; dontPoll {
130 if !t.IsZero() {
131
132=== modified file 'poller/poller_test.go'
133--- poller/poller_test.go 2015-04-29 15:22:03 +0000
134+++ poller/poller_test.go 2015-09-28 10:22:34 +0000
135@@ -21,7 +21,7 @@
136
137 . "launchpad.net/gocheck"
138
139- "launchpad.net/ubuntu-push/bus/urfkill"
140+ "launchpad.net/ubuntu-push/bus/networkmanager"
141 "launchpad.net/ubuntu-push/client/session"
142 helpers "launchpad.net/ubuntu-push/testing"
143 )
144@@ -92,8 +92,8 @@
145 }
146
147 const (
148- wlanOn = urfkill.KillswitchStateUnblocked
149- wlanOff = urfkill.KillswitchStateSoftBlocked
150+ connectedGlobal = networkmanager.ConnectedGlobal
151+ disconnectedGlobal = networkmanager.Disconnected
152 )
153
154 func (s *PrSuite) TestStep(c *C) {
155@@ -117,7 +117,7 @@
156 ch := make(chan string)
157 // now, run
158 filteredWakeUpCh := make(chan bool)
159- go p.control(wakeupCh, filteredWakeUpCh, false, nil, wlanOn, nil)
160+ go p.control(wakeupCh, filteredWakeUpCh, connectedGlobal, nil)
161 go func() { ch <- p.step(filteredWakeUpCh, doneCh, "old cookie") }()
162 select {
163 case s := <-ch:
164@@ -143,9 +143,8 @@
165 wakeUpCh := make(chan bool)
166 filteredWakeUpCh := make(chan bool)
167 s.myd.watchWakeCh = make(chan bool, 1)
168- flightModeCh := make(chan bool)
169- wlanKillswitchStateCh := make(chan urfkill.KillswitchState)
170- go p.control(wakeUpCh, filteredWakeUpCh, false, flightModeCh, wlanOn, wlanKillswitchStateCh)
171+ nmStateCh := make(chan networkmanager.State)
172+ go p.control(wakeUpCh, filteredWakeUpCh, connectedGlobal, nmStateCh)
173
174 // works
175 err := p.requestWakeup()
176@@ -161,19 +160,17 @@
177 wakeUpCh <- true
178 <-filteredWakeUpCh
179
180- // flight mode
181- flightModeCh <- true
182- wlanKillswitchStateCh <- wlanOff
183+ nmStateCh <- disconnectedGlobal
184 err = p.requestWakeup()
185 c.Assert(err, IsNil)
186 c.Check(s.myd.watchWakeCh, HasLen, 0)
187
188- // wireless on
189- wlanKillswitchStateCh <- wlanOn
190+ // connected
191+ nmStateCh <- connectedGlobal
192 c.Check(<-s.myd.watchWakeCh, Equals, true)
193
194- // wireless off
195- wlanKillswitchStateCh <- wlanOff
196+ // disconnected
197+ nmStateCh <- disconnectedGlobal
198 // pending wakeup was cleared
199 c.Check(<-s.myd.watchWakeCh, Equals, false)
200

Subscribers

People subscribed via source and target branches