Merge lp:~diegosarmentero/ubuntuone-client/network-detect into lp:ubuntuone-client
- network-detect
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Natalia Bidart |
Approved revision: | 1187 |
Merged at revision: | 1196 |
Proposed branch: | lp:~diegosarmentero/ubuntuone-client/network-detect |
Merge into: | lp:ubuntuone-client |
Diff against target: |
754 lines (+37/-514) 12 files modified
tests/platform/linux/test_dbus.py (+5/-39) tests/platform/windows/test_ipc.py (+0/-4) tests/platform/windows/test_network_manager.py (+0/-71) tests/syncdaemon/test_action_queue.py (+1/-104) tests/syncdaemon/test_interaction_interfaces.py (+16/-1) tests/syncdaemon/test_states.py (+0/-52) ubuntuone/platform/__init__.py (+1/-0) ubuntuone/platform/linux/dbus_interface.py (+0/-67) ubuntuone/platform/windows/ipc.py (+0/-15) ubuntuone/platform/windows/network_manager.py (+0/-160) ubuntuone/syncdaemon/interaction_interfaces.py (+13/-0) ubuntuone/syncdaemon/states.py (+1/-1) |
To merge this branch: | bzr merge lp:~diegosarmentero/ubuntuone-client/network-detect |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Natalia Bidart (community) | Approve | ||
Manuel de la Peña (community) | Approve | ||
Review via email: mp+88545@code.launchpad.net |
Commit message
- The current network manager is now calling network_connected properly (LP: #885292).
Description of the change
To test it IRL you can execute syncdaemon, and you can see the logs for online/offline if you connect and disconnect the computer.
Manuel de la Peña (mandel) wrote : | # |
I'm getting the following when I run the tests on windows:
C:\Users\
Checking if python 2.7 is in the system
ERROR: The system was unable to find the specified registry key or value.
Checking if python 2.6 is in the system
ERROR: The system was unable to find the specified registry key or value.
Checking if python 2.7 32 is in the system
Python found, building auto-generated modules...
running build
Compiled data\qt\
Compiled data\qt\
_ui.py
Compiled data\qt\
py
Compiled data\qt\
Compiled data\qt\
py
Compiled data\qt\
Compiled data\qt\
Compiled data\qt\
running build_py
creating build
creating build\lib
creating build\lib\
copying ubuntu_
copying ubuntu_
copying ubuntu_
copying ubuntu_
creating build\lib\
copying ubuntu_
copying ubuntu_
copying ubuntu_
copying ubuntu_
copying ubuntu_
creating build\lib\
copying ubuntu_
copying ubuntu_
copying ubuntu_
creating build\lib\
copying ubuntu_
copying ubuntu_
copying ubuntu_
creating build\lib\
copying ubuntu_
copying ubuntu_
copying ubuntu_
creating build\lib\
copying ubuntu_
copying ubuntu_
copying ubuntu_
creating build\lib\
copying ubuntu_
copying ubuntu_
copying ubuntu_
copying ubuntu_
copying ubuntu_
copying ubuntu_
copying ubun...
Manuel de la Peña (mandel) wrote : | # |
Ag, sorry wrong branch :(
Natalia Bidart (nataliabidart) wrote : | # |
* This import:
from ubuntu_
has to be in the same group as:
from twisted.internet import defer
from ubuntuone.
Same for from ubuntu_
* "# This imports needs to be here in order to belongs to this namespace" -> "# These imports needs to be here in order to belongs to this namespace"
* Since now NetworkManagerState is multiplatform, you should move it to intercation_
Manuel de la Peña (mandel) wrote : | # |
This is for this branch:
C:\Users\
>> test.out
ERROR: The system was unable to find the specified registry key or value.
ERROR: The system was unable to find the specified registry key or value.
Traceback (most recent call last):
File "C:\Python27\
main()
File "C:\Python27\
suite = trial_runner.
File "C:\Python27\
config[
File "C:\Python27\
module_suite = self._load_
File "C:\Python27\
module = __import__(modpath, None, None, [""])
File "C:\Users\
\platform\
from ubuntuone.
ImportError: No module named network_manager
That is when trying to run the tests on Windows.
Natalia Bidart (nataliabidart) wrote : | # |
Also, when trying to run tests on windows I'm getting:
File "E:\client\
ger.py", line 23, in <module>
from ubuntuone.
ImportError: No module named network_manager
- 1180. By Diego Sarmentero
-
Merge.
Move Network Manager State to interaction interfaces. - 1181. By Diego Sarmentero
-
removed test network manager file.
Manuel de la Peña (mandel) wrote : | # |
All tests passed on Linux P and Windows.
Natalia Bidart (nataliabidart) wrote : | # |
Can you please also remove this bit from ubuntuone/
# remove the NM's StateChanged signal receiver
The rest looks good, works OK on linux, and I'm setting up my windows VM to test it IRL there.
Diego Sarmentero (diegosarmentero) wrote : | # |
> Can you please also remove this bit from
> ubuntuone/
>
> # remove the NM's StateChanged signal receiver
> self.system_
> signal_
> dbus_interface=
> path='/
>
> The rest looks good, works OK on linux, and I'm setting up my windows VM to
> test it IRL there.
Done!
- 1182. By Diego Sarmentero
-
merge
- 1183. By Diego Sarmentero
-
merge
- 1184. By Diego Sarmentero
-
Removing dbus code for network detect.
Natalia Bidart (nataliabidart) wrote : | # |
Hum, I did not notice this before, but there are still some NM code:
nessita@
contrib/
contrib/
tests/syncdaemo
tests/platform/
tests/platform/
tests/platform/
tests/platform/
tests/platform/
tests/platform/
tests/platform/
tests/platform/
tests/platform/
tests/platform/
tests/platform/
ubuntuone/
ubuntuone/
ubuntuone/
ubuntuone/
Can you also remove those?
- 1185. By Diego Sarmentero
-
merge
- 1186. By Diego Sarmentero
-
run-tests.bat reverted
- 1187. By Diego Sarmentero
-
Remove some references to NetworkManager
Natalia Bidart (nataliabidart) wrote : | # |
Looks good. Still we have a FakedNetworkManager in test_dbus, so I filled bug #935389 so we can land this branch.
Tested IRL, works as expected!
Preview Diff
1 | === modified file 'tests/platform/linux/test_dbus.py' | |||
2 | --- tests/platform/linux/test_dbus.py 2011-11-30 19:30:00 +0000 | |||
3 | +++ tests/platform/linux/test_dbus.py 2012-02-10 13:42:19 +0000 | |||
4 | @@ -39,8 +39,8 @@ | |||
5 | 39 | DBUS_IFACE_FOLDERS_NAME, | 39 | DBUS_IFACE_FOLDERS_NAME, |
6 | 40 | DBUS_IFACE_PUBLIC_FILES_NAME, | 40 | DBUS_IFACE_PUBLIC_FILES_NAME, |
7 | 41 | DBUS_IFACE_LAUNCHER_NAME, | 41 | DBUS_IFACE_LAUNCHER_NAME, |
10 | 42 | NM_STATE_CONNECTED_GLOBAL, | 42 | # NM_STATE_CONNECTED_GLOBAL, |
11 | 43 | NM_STATE_DISCONNECTED, | 43 | # NM_STATE_DISCONNECTED, |
12 | 44 | ) | 44 | ) |
13 | 45 | from ubuntuone.platform.tools.linux import DBusClient | 45 | from ubuntuone.platform.tools.linux import DBusClient |
14 | 46 | 46 | ||
15 | @@ -76,11 +76,11 @@ | |||
16 | 76 | 76 | ||
17 | 77 | def emit_connected(self): | 77 | def emit_connected(self): |
18 | 78 | """ Emits the signal StateCganged(3). """ | 78 | """ Emits the signal StateCganged(3). """ |
20 | 79 | self.StateChanged(NM_STATE_CONNECTED_GLOBAL) | 79 | self.StateChanged(70) |
21 | 80 | 80 | ||
22 | 81 | def emit_disconnected(self): | 81 | def emit_disconnected(self): |
23 | 82 | """ Emits the signal StateCganged(4). """ | 82 | """ Emits the signal StateCganged(4). """ |
25 | 83 | self.StateChanged(NM_STATE_DISCONNECTED) | 83 | self.StateChanged(20) |
26 | 84 | 84 | ||
27 | 85 | @dbus.service.method(dbus.PROPERTIES_IFACE, | 85 | @dbus.service.method(dbus.PROPERTIES_IFACE, |
28 | 86 | in_signature='ss', out_signature='v', | 86 | in_signature='ss', out_signature='v', |
29 | @@ -95,7 +95,7 @@ | |||
30 | 95 | @dbus.service.method('org.freedesktop.NetworkManager') | 95 | @dbus.service.method('org.freedesktop.NetworkManager') |
31 | 96 | def state(self): | 96 | def state(self): |
32 | 97 | """Fake the state.""" | 97 | """Fake the state.""" |
34 | 98 | return NM_STATE_CONNECTED_GLOBAL | 98 | return 70 |
35 | 99 | 99 | ||
36 | 100 | # pylint: enable-msg=C0103 | 100 | # pylint: enable-msg=C0103 |
37 | 101 | 101 | ||
38 | @@ -208,40 +208,6 @@ | |||
39 | 208 | DBusTwistedTestCase = IPCTestCase # API compatibility | 208 | DBusTwistedTestCase = IPCTestCase # API compatibility |
40 | 209 | 209 | ||
41 | 210 | 210 | ||
42 | 211 | class NetworkManagerIntegrationTests(IPCTestCase): | ||
43 | 212 | """Test case for our NetworkManager integration.""" | ||
44 | 213 | |||
45 | 214 | def test_nm_signals(self): | ||
46 | 215 | """Test that NM signals are received and handled properly.""" | ||
47 | 216 | result = None | ||
48 | 217 | d = defer.Deferred() | ||
49 | 218 | |||
50 | 219 | class Listener(object): | ||
51 | 220 | """Helper class.""" | ||
52 | 221 | |||
53 | 222 | # class-closure, cannot use self, pylint: disable=E0213 | ||
54 | 223 | def handle_SYS_NET_CONNECTED(innerself): | ||
55 | 224 | self.nm.emit_disconnected() | ||
56 | 225 | |||
57 | 226 | def handle_SYS_NET_DISCONNECTED(innerself): | ||
58 | 227 | self.assertTrue(result) | ||
59 | 228 | |||
60 | 229 | listener = Listener() | ||
61 | 230 | self.event_q.subscribe(listener) | ||
62 | 231 | |||
63 | 232 | def empty_queue_cb(): | ||
64 | 233 | d.callback(True) | ||
65 | 234 | |||
66 | 235 | def callback(result): | ||
67 | 236 | self.event_q.unsubscribe(listener) | ||
68 | 237 | self.event_q.remove_empty_event_queue_callback(empty_queue_cb) | ||
69 | 238 | d.addCallback(callback) | ||
70 | 239 | |||
71 | 240 | self.nm.emit_connected() | ||
72 | 241 | self.event_q.add_empty_event_queue_callback(empty_queue_cb) | ||
73 | 242 | return d | ||
74 | 243 | |||
75 | 244 | |||
76 | 245 | class StatusTestCase(IPCTestCase): | 211 | class StatusTestCase(IPCTestCase): |
77 | 246 | """Tests for the Status exposed object.""" | 212 | """Tests for the Status exposed object.""" |
78 | 247 | 213 | ||
79 | 248 | 214 | ||
80 | === modified file 'tests/platform/windows/test_ipc.py' | |||
81 | --- tests/platform/windows/test_ipc.py 2011-10-28 19:17:47 +0000 | |||
82 | +++ tests/platform/windows/test_ipc.py 2012-02-10 13:42:19 +0000 | |||
83 | @@ -652,10 +652,6 @@ | |||
84 | 652 | 'Remote object should not be None') | 652 | 'Remote object should not be None') |
85 | 653 | self.assertIsInstance(remote, RemoteReference) | 653 | self.assertIsInstance(remote, RemoteReference) |
86 | 654 | 654 | ||
87 | 655 | def test_daemonized(self): | ||
88 | 656 | """Check that the NM thread won't block the process.""" | ||
89 | 657 | self.assertTrue(self.interface.network_manager_thread.daemon) | ||
90 | 658 | |||
91 | 659 | 655 | ||
92 | 660 | class IPCPortTestCase(TestCase): | 656 | class IPCPortTestCase(TestCase): |
93 | 661 | """Tests for the ipc port setup.""" | 657 | """Tests for the ipc port setup.""" |
94 | 662 | 658 | ||
95 | === removed file 'tests/platform/windows/test_network_manager.py' | |||
96 | --- tests/platform/windows/test_network_manager.py 2011-10-28 18:43:23 +0000 | |||
97 | +++ tests/platform/windows/test_network_manager.py 1970-01-01 00:00:00 +0000 | |||
98 | @@ -1,71 +0,0 @@ | |||
99 | 1 | # -*- coding: utf-8 -*- | ||
100 | 2 | # | ||
101 | 3 | # Author: Manuel de la Pena<manuel@canonical.com> | ||
102 | 4 | # | ||
103 | 5 | # Copyright 2011 Canonical Ltd. | ||
104 | 6 | # | ||
105 | 7 | # This program is free software: you can redistribute it and/or modify it | ||
106 | 8 | # under the terms of the GNU General Public License version 3, as published | ||
107 | 9 | # by the Free Software Foundation. | ||
108 | 10 | # | ||
109 | 11 | # This program is distributed in the hope that it will be useful, but | ||
110 | 12 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
111 | 13 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
112 | 14 | # PURPOSE. See the GNU General Public License for more details. | ||
113 | 15 | # | ||
114 | 16 | # You should have received a copy of the GNU General Public License along | ||
115 | 17 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
116 | 18 | |||
117 | 19 | """Tests for the network manager.""" | ||
118 | 20 | |||
119 | 21 | from mocker import MockerTestCase | ||
120 | 22 | |||
121 | 23 | from ubuntuone.platform.windows.network_manager import NetworkManager | ||
122 | 24 | |||
123 | 25 | |||
124 | 26 | class TestNetworkManager(MockerTestCase): | ||
125 | 27 | """Test he Network Manager.""" | ||
126 | 28 | |||
127 | 29 | def setUp(self): | ||
128 | 30 | super(TestNetworkManager, self).setUp() | ||
129 | 31 | self.connection_info = self.mocker.mock() | ||
130 | 32 | self.connection_no_info = self.mocker.mock() | ||
131 | 33 | self.disconnected = self.mocker.mock() | ||
132 | 34 | self.manager = NetworkManager(self.connection_no_info, | ||
133 | 35 | self.connection_info, self.disconnected) | ||
134 | 36 | |||
135 | 37 | def test_connection_made(self): | ||
136 | 38 | """Ensure db is called.""" | ||
137 | 39 | self.connection_info() | ||
138 | 40 | self.mocker.replay() | ||
139 | 41 | self.manager.ConnectionMade() | ||
140 | 42 | |||
141 | 43 | def test_connection_made_no_cb(self): | ||
142 | 44 | """Ensure db is called.""" | ||
143 | 45 | self.manager.connected_cb_info = None | ||
144 | 46 | self.mocker.replay() | ||
145 | 47 | self.manager.ConnectionMade() | ||
146 | 48 | |||
147 | 49 | def test_connection_made_no_info(self): | ||
148 | 50 | """Ensure db is called.""" | ||
149 | 51 | self.connection_no_info() | ||
150 | 52 | self.mocker.replay() | ||
151 | 53 | self.manager.ConnectionMadeNoQOCInfo() | ||
152 | 54 | |||
153 | 55 | def test_connection_made_no_info_no_cb(self): | ||
154 | 56 | """Ensure db is called.""" | ||
155 | 57 | self.manager.connected_cb = None | ||
156 | 58 | self.mocker.replay() | ||
157 | 59 | self.manager.ConnectionMadeNoQOCInfo() | ||
158 | 60 | |||
159 | 61 | def test_disconnection(self): | ||
160 | 62 | """Ensure db is called.""" | ||
161 | 63 | self.disconnected() | ||
162 | 64 | self.mocker.replay() | ||
163 | 65 | self.manager.ConnectionLost() | ||
164 | 66 | |||
165 | 67 | def test_disconnection_no_cb(self): | ||
166 | 68 | """Ensure db is called.""" | ||
167 | 69 | self.manager.disconnected_cb = None | ||
168 | 70 | self.mocker.replay() | ||
169 | 71 | self.manager.ConnectionLost() | ||
170 | 72 | 0 | ||
171 | === modified file 'tests/syncdaemon/test_action_queue.py' | |||
172 | --- tests/syncdaemon/test_action_queue.py 2012-02-06 15:32:28 +0000 | |||
173 | +++ tests/syncdaemon/test_action_queue.py 2012-02-10 13:42:19 +0000 | |||
174 | @@ -58,7 +58,7 @@ | |||
175 | 58 | protocol_pb2, | 58 | protocol_pb2, |
176 | 59 | request, | 59 | request, |
177 | 60 | ) | 60 | ) |
179 | 61 | from ubuntuone.syncdaemon import states, interfaces, config | 61 | from ubuntuone.syncdaemon import interfaces, config |
180 | 62 | from ubuntuone.syncdaemon import action_queue | 62 | from ubuntuone.syncdaemon import action_queue |
181 | 63 | from ubuntuone.syncdaemon.action_queue import ( | 63 | from ubuntuone.syncdaemon.action_queue import ( |
182 | 64 | ActionQueue, ActionQueueCommand, ChangePublicAccess, CreateUDF, | 64 | ActionQueue, ActionQueueCommand, ChangePublicAccess, CreateUDF, |
183 | @@ -1295,109 +1295,6 @@ | |||
184 | 1295 | "host 1.2.3.4", "port 4321")) | 1295 | "host 1.2.3.4", "port 4321")) |
185 | 1296 | 1296 | ||
186 | 1297 | 1297 | ||
187 | 1298 | class NetworkmanagerTestCase(FactoryBaseTestCase): | ||
188 | 1299 | """Base test case generating a connected factory.""" | ||
189 | 1300 | |||
190 | 1301 | timeout = 15 | ||
191 | 1302 | |||
192 | 1303 | @defer.inlineCallbacks | ||
193 | 1304 | def setUp(self): | ||
194 | 1305 | """Init.""" | ||
195 | 1306 | yield super(NetworkmanagerTestCase, self).setUp() | ||
196 | 1307 | self.action_queue.event_queue.push('SYS_NET_CONNECTED') | ||
197 | 1308 | self.main.start() | ||
198 | 1309 | |||
199 | 1310 | @defer.inlineCallbacks | ||
200 | 1311 | def test_wrong_disconnect(self): | ||
201 | 1312 | """Test factory's connection when SYS_NET_DISCONNECTED.""" | ||
202 | 1313 | |||
203 | 1314 | d1 = self.main.wait_for('SYS_CONNECTION_MADE') | ||
204 | 1315 | d2 = self.main.wait_for('SYS_CONNECTION_LOST') | ||
205 | 1316 | |||
206 | 1317 | self.server = self._start_sample_webserver() | ||
207 | 1318 | self.user_connect() | ||
208 | 1319 | yield d1 | ||
209 | 1320 | |||
210 | 1321 | self.action_queue.event_queue.push('SYS_NET_DISCONNECTED') | ||
211 | 1322 | yield d2 | ||
212 | 1323 | |||
213 | 1324 | @defer.inlineCallbacks | ||
214 | 1325 | def test_disconnect_twice(self): | ||
215 | 1326 | """Test connection when SYS_NET_DISCONNECTED is received twice.""" | ||
216 | 1327 | |||
217 | 1328 | d1 = self.main.wait_for('SYS_CONNECTION_MADE') | ||
218 | 1329 | d2 = self.main.wait_for('SYS_CONNECTION_LOST') | ||
219 | 1330 | |||
220 | 1331 | self.server = self._start_sample_webserver() | ||
221 | 1332 | self.user_connect() | ||
222 | 1333 | yield d1 | ||
223 | 1334 | |||
224 | 1335 | self.action_queue.event_queue.push('SYS_NET_DISCONNECTED') | ||
225 | 1336 | yield d2 | ||
226 | 1337 | |||
227 | 1338 | self.action_queue.event_queue.events = [] | ||
228 | 1339 | self.action_queue.event_queue.push('SYS_NET_DISCONNECTED') | ||
229 | 1340 | self.assertEqual([('SYS_NET_DISCONNECTED', {})], | ||
230 | 1341 | self.action_queue.event_queue.events, | ||
231 | 1342 | 'No new events after a misplaced SYS_NET_DISCONNECTED') | ||
232 | 1343 | |||
233 | 1344 | @defer.inlineCallbacks | ||
234 | 1345 | def test_net_connected_if_already_connected(self): | ||
235 | 1346 | """Test connection when SYS_NET_CONNECTED is received twice.""" | ||
236 | 1347 | |||
237 | 1348 | d1 = self.main.wait_for('SYS_CONNECTION_MADE') | ||
238 | 1349 | |||
239 | 1350 | self.server = self._start_sample_webserver() | ||
240 | 1351 | self.user_connect() | ||
241 | 1352 | yield d1 | ||
242 | 1353 | |||
243 | 1354 | self.action_queue.event_queue.events = [] | ||
244 | 1355 | self.action_queue.event_queue.push('SYS_NET_CONNECTED') | ||
245 | 1356 | self.assertEqual([('SYS_NET_CONNECTED', {})], | ||
246 | 1357 | self.action_queue.event_queue.events, | ||
247 | 1358 | 'No new events after a misplaced SYS_NET_CONNECTED') | ||
248 | 1359 | |||
249 | 1360 | @defer.inlineCallbacks | ||
250 | 1361 | def test_messy_mix(self): | ||
251 | 1362 | """Test connection when a messy mix of events is received.""" | ||
252 | 1363 | orig_waiting = states.MAX_WAITING | ||
253 | 1364 | states.MAX_WAITING = 1 | ||
254 | 1365 | |||
255 | 1366 | self.action_queue.event_queue.events = [] | ||
256 | 1367 | self.server = self._start_sample_webserver() | ||
257 | 1368 | |||
258 | 1369 | conn_made = self.main.wait_for('SYS_CONNECTION_MADE') | ||
259 | 1370 | self.user_connect() | ||
260 | 1371 | yield conn_made | ||
261 | 1372 | |||
262 | 1373 | events = ['SYS_NET_CONNECTED', 'SYS_NET_DISCONNECTED', | ||
263 | 1374 | 'SYS_NET_CONNECTED', 'SYS_NET_CONNECTED', | ||
264 | 1375 | 'SYS_NET_DISCONNECTED', 'SYS_NET_DISCONNECTED', | ||
265 | 1376 | 'SYS_NET_CONNECTED'] | ||
266 | 1377 | |||
267 | 1378 | for i in events: | ||
268 | 1379 | self.action_queue.event_queue.push(i) | ||
269 | 1380 | |||
270 | 1381 | yield self.main.wait_for_nirvana() | ||
271 | 1382 | |||
272 | 1383 | expected = ['SYS_NET_CONNECTED', # from the DBus fake NetworkManager | ||
273 | 1384 | 'SYS_NET_CONNECTED', 'SYS_NET_DISCONNECTED', | ||
274 | 1385 | 'SYS_CONNECTION_LOST', 'SYS_CONNECTION_RETRY', | ||
275 | 1386 | 'SYS_NET_CONNECTED', 'SYS_NET_CONNECTED', | ||
276 | 1387 | 'SYS_CONNECTION_MADE', 'SYS_NET_DISCONNECTED', | ||
277 | 1388 | 'SYS_NET_DISCONNECTED'] | ||
278 | 1389 | |||
279 | 1390 | avoid = ('SYS_STATE_CHANGED', 'SYS_LOCAL_RESCAN_DONE', | ||
280 | 1391 | 'SYS_PROTOCOL_VERSION_OK', 'SYS_SET_CAPABILITIES_OK', | ||
281 | 1392 | 'SYS_AUTH_OK', 'SYS_SERVER_RESCAN_DONE') | ||
282 | 1393 | actual = [event for (event, kwargs) in | ||
283 | 1394 | self.action_queue.event_queue.events | ||
284 | 1395 | if event not in avoid] | ||
285 | 1396 | self.assertEqual(sorted(expected), sorted(actual)) | ||
286 | 1397 | |||
287 | 1398 | states.MAX_WAITING = orig_waiting | ||
288 | 1399 | |||
289 | 1400 | |||
290 | 1401 | class ConnectedBaseTestCase(FactoryBaseTestCase): | 1298 | class ConnectedBaseTestCase(FactoryBaseTestCase): |
291 | 1402 | """Base test case generating a connected factory.""" | 1299 | """Base test case generating a connected factory.""" |
292 | 1403 | 1300 | ||
293 | 1404 | 1301 | ||
294 | === modified file 'tests/syncdaemon/test_interaction_interfaces.py' | |||
295 | --- tests/syncdaemon/test_interaction_interfaces.py 2012-01-17 20:00:44 +0000 | |||
296 | +++ tests/syncdaemon/test_interaction_interfaces.py 2012-02-10 13:42:19 +0000 | |||
297 | @@ -21,6 +21,7 @@ | |||
298 | 21 | 21 | ||
299 | 22 | from twisted.internet import defer | 22 | from twisted.internet import defer |
300 | 23 | from ubuntuone.devtools.handlers import MementoHandler | 23 | from ubuntuone.devtools.handlers import MementoHandler |
301 | 24 | from ubuntu_sso.networkstate import ONLINE | ||
302 | 24 | 25 | ||
303 | 25 | from contrib.testing.testcase import ( | 26 | from contrib.testing.testcase import ( |
304 | 26 | FakeCommand, | 27 | FakeCommand, |
305 | @@ -2208,7 +2209,21 @@ | |||
306 | 2208 | def test_rescan_from_scratch_missing_volume(self): | 2209 | def test_rescan_from_scratch_missing_volume(self): |
307 | 2209 | """Test for rescan_from_scratch with a non-existing volume.""" | 2210 | """Test for rescan_from_scratch with a non-existing volume.""" |
308 | 2210 | volume_id = object() | 2211 | volume_id = object() |
310 | 2211 | self.assertRaises(ValueError, self.sd_obj.rescan_from_scratch, volume_id) | 2212 | self.assertRaises(ValueError, |
311 | 2213 | self.sd_obj.rescan_from_scratch, volume_id) | ||
312 | 2214 | |||
313 | 2215 | def test_network_state_changed_with_connection(self): | ||
314 | 2216 | """Test the network_state changed method with a connection.""" | ||
315 | 2217 | self.sd_obj.network_state_changed(ONLINE) | ||
316 | 2218 | |||
317 | 2219 | self.assertEqual(self.events, [('SYS_NET_CONNECTED', {})]) | ||
318 | 2220 | |||
319 | 2221 | def test_network_state_changed_without_connection(self): | ||
320 | 2222 | """Test the network_state changed method without a connection.""" | ||
321 | 2223 | # Sending anything instead of ONLINE should be interpreted as OFFLINE | ||
322 | 2224 | self.sd_obj.network_state_changed(object()) | ||
323 | 2225 | |||
324 | 2226 | self.assertEqual(self.events, [('SYS_NET_DISCONNECTED', {})]) | ||
325 | 2212 | 2227 | ||
326 | 2213 | def test_network_connected(self): | 2228 | def test_network_connected(self): |
327 | 2214 | """Test the network_connected method.""" | 2229 | """Test the network_connected method.""" |
328 | 2215 | 2230 | ||
329 | === modified file 'tests/syncdaemon/test_states.py' | |||
330 | --- tests/syncdaemon/test_states.py 2011-10-27 11:39:43 +0000 | |||
331 | +++ tests/syncdaemon/test_states.py 2012-02-10 13:42:19 +0000 | |||
332 | @@ -847,58 +847,6 @@ | |||
333 | 847 | self.assertFalse(self.aq.queue.active) | 847 | self.assertFalse(self.aq.queue.active) |
334 | 848 | 848 | ||
335 | 849 | 849 | ||
336 | 850 | class TestStateManagerPassToNetworkManager(Base): | ||
337 | 851 | """All network events should go to NetworkManager.""" | ||
338 | 852 | |||
339 | 853 | @defer.inlineCallbacks | ||
340 | 854 | def setUp(self): | ||
341 | 855 | yield super(TestStateManagerPassToNetworkManager, | ||
342 | 856 | self).setUp() | ||
343 | 857 | |||
344 | 858 | # put a function in the middle to log calls | ||
345 | 859 | self.called_events = [] | ||
346 | 860 | orig_on_event = self.sm.connection.on_event | ||
347 | 861 | def fake_on_event(event): | ||
348 | 862 | """Log the call and call original.""" | ||
349 | 863 | self.called_events.append(event) | ||
350 | 864 | orig_on_event(event) | ||
351 | 865 | self.sm.connection.on_event = fake_on_event | ||
352 | 866 | |||
353 | 867 | def _test(self, event): | ||
354 | 868 | """Generic test method.""" | ||
355 | 869 | cnt = 0 | ||
356 | 870 | for node in self.sm_nodes_ok: | ||
357 | 871 | cnt += 1 | ||
358 | 872 | self.sm.state = node | ||
359 | 873 | self.sm.handle_default(event) | ||
360 | 874 | self.assertEqual(self.called_events, [event]*cnt) | ||
361 | 875 | |||
362 | 876 | def test_net_connected(self): | ||
363 | 877 | """SYS_NET_CONNECTED should go to Connection no matter where.""" | ||
364 | 878 | self._test('SYS_NET_CONNECTED') | ||
365 | 879 | |||
366 | 880 | def test_user_connect(self): | ||
367 | 881 | """SYS_USER_CONNECT should go to Connection no matter where.""" | ||
368 | 882 | self._test('SYS_USER_CONNECT') | ||
369 | 883 | |||
370 | 884 | def test_net_disconnected(self): | ||
371 | 885 | """SYS_NET_DISCONNECTED should go to Connection no matter where.""" | ||
372 | 886 | self._test('SYS_NET_DISCONNECTED') | ||
373 | 887 | |||
374 | 888 | def test_user_disconnect(self): | ||
375 | 889 | """SYS_USER_DISCONNECT should go to Connection no matter where.""" | ||
376 | 890 | self._test('SYS_USER_DISCONNECT') | ||
377 | 891 | |||
378 | 892 | def test_connection_lost(self): | ||
379 | 893 | """SYS_CONNECTION_LOST should go to Connection no matter where.""" | ||
380 | 894 | self._test('SYS_CONNECTION_LOST') | ||
381 | 895 | |||
382 | 896 | def test_handshake_timeout(self): | ||
383 | 897 | """SYS_HANDSHAKE_TIMEOUT should go to Connection no matter where.""" | ||
384 | 898 | self._test('SYS_HANDSHAKE_TIMEOUT') | ||
385 | 899 | |||
386 | 900 | |||
387 | 901 | |||
388 | 902 | class TestStateManagerPassToQueueManager(Base): | 850 | class TestStateManagerPassToQueueManager(Base): |
389 | 903 | """All queue events should go to QueueManager.""" | 851 | """All queue events should go to QueueManager.""" |
390 | 904 | 852 | ||
391 | 905 | 853 | ||
392 | === modified file 'ubuntuone/platform/__init__.py' | |||
393 | --- ubuntuone/platform/__init__.py 2012-01-25 20:49:55 +0000 | |||
394 | +++ ubuntuone/platform/__init__.py 2012-02-10 13:42:19 +0000 | |||
395 | @@ -31,6 +31,7 @@ | |||
396 | 31 | from ubuntuone.platform import linux | 31 | from ubuntuone.platform import linux |
397 | 32 | source = linux | 32 | source = linux |
398 | 33 | 33 | ||
399 | 34 | # This imports needs to be here in order to belongs to this namespace | ||
400 | 34 | from ubuntuone.platform import credentials | 35 | from ubuntuone.platform import credentials |
401 | 35 | from ubuntuone.platform import tools | 36 | from ubuntuone.platform import tools |
402 | 36 | 37 | ||
403 | 37 | 38 | ||
404 | === modified file 'ubuntuone/platform/linux/dbus_interface.py' | |||
405 | --- ubuntuone/platform/linux/dbus_interface.py 2012-01-02 20:24:31 +0000 | |||
406 | +++ ubuntuone/platform/linux/dbus_interface.py 2012-02-10 13:42:19 +0000 | |||
407 | @@ -41,28 +41,6 @@ | |||
408 | 41 | DBUS_IFACE_PUBLIC_FILES_NAME = DBUS_IFACE_NAME + '.PublicFiles' | 41 | DBUS_IFACE_PUBLIC_FILES_NAME = DBUS_IFACE_NAME + '.PublicFiles' |
409 | 42 | DBUS_IFACE_LAUNCHER_NAME = DBUS_IFACE_NAME + '.Launcher' | 42 | DBUS_IFACE_LAUNCHER_NAME = DBUS_IFACE_NAME + '.Launcher' |
410 | 43 | 43 | ||
411 | 44 | # NetworkManager State constants | ||
412 | 45 | NM_STATE_UNKNOWN = 0 | ||
413 | 46 | NM_STATE_ASLEEP_OLD = 1 | ||
414 | 47 | NM_STATE_ASLEEP = 10 | ||
415 | 48 | NM_STATE_CONNECTING_OLD = 2 | ||
416 | 49 | NM_STATE_CONNECTING = 40 | ||
417 | 50 | NM_STATE_CONNECTED_OLD = 3 | ||
418 | 51 | NM_STATE_CONNECTED_LOCAL = 50 | ||
419 | 52 | NM_STATE_CONNECTED_SITE = 60 | ||
420 | 53 | NM_STATE_CONNECTED_GLOBAL = 70 | ||
421 | 54 | NM_STATE_DISCONNECTED_OLD = 4 | ||
422 | 55 | NM_STATE_DISCONNECTED = 20 | ||
423 | 56 | |||
424 | 57 | # NM state -> online/offline mapping | ||
425 | 58 | # Note that the LOCAL and SITE mappings are *not* a typo. Local and site links | ||
426 | 59 | # are not enough to connect to one.ubuntu.com, so we treat them as if we were | ||
427 | 60 | # not connected. | ||
428 | 61 | NM_STATE_ONLINE_EVENTS = [ | ||
429 | 62 | NM_STATE_CONNECTED_OLD, | ||
430 | 63 | NM_STATE_CONNECTED_GLOBAL, | ||
431 | 64 | ] | ||
432 | 65 | |||
433 | 66 | logger = logging.getLogger("ubuntuone.SyncDaemon.DBus") | 44 | logger = logging.getLogger("ubuntuone.SyncDaemon.DBus") |
434 | 67 | 45 | ||
435 | 68 | 46 | ||
436 | @@ -859,39 +837,6 @@ | |||
437 | 859 | self.config = Config(self.busName, service) | 837 | self.config = Config(self.busName, service) |
438 | 860 | self.service = service | 838 | self.service = service |
439 | 861 | 839 | ||
440 | 862 | def error_handler(error): | ||
441 | 863 | """Handle errors from NM.""" | ||
442 | 864 | logger.error("Error while getting the NetworkManager state %s", | ||
443 | 865 | error) | ||
444 | 866 | # If we get an error back from NetworkManager, we should | ||
445 | 867 | # just try to connect anyway; it probably means that | ||
446 | 868 | # NetworkManager is down or broken or something. | ||
447 | 869 | self.connection_state_changed(NM_STATE_CONNECTED_GLOBAL) | ||
448 | 870 | try: | ||
449 | 871 | nm = self.system_bus.get_object( | ||
450 | 872 | 'org.freedesktop.NetworkManager', | ||
451 | 873 | '/org/freedesktop/NetworkManager', | ||
452 | 874 | follow_name_owner_changes=True) | ||
453 | 875 | iface = dbus.Interface(nm, 'org.freedesktop.NetworkManager') | ||
454 | 876 | except dbus.DBusException, e: | ||
455 | 877 | if e.get_dbus_name() == \ | ||
456 | 878 | 'org.freedesktop.DBus.Error.ServiceUnknown': | ||
457 | 879 | # NetworkManager isn't running. | ||
458 | 880 | logger.warn("Unable to connect to NetworkManager. " | ||
459 | 881 | "Assuming we have network.") | ||
460 | 882 | self.connection_state_changed(NM_STATE_CONNECTED_GLOBAL) | ||
461 | 883 | else: | ||
462 | 884 | raise | ||
463 | 885 | else: | ||
464 | 886 | iface.state(reply_handler=self.connection_state_changed, | ||
465 | 887 | error_handler=error_handler) | ||
466 | 888 | |||
467 | 889 | # register a handler to NM StateChanged signal | ||
468 | 890 | self.system_bus.add_signal_receiver(self.connection_state_changed, | ||
469 | 891 | signal_name='StateChanged', | ||
470 | 892 | dbus_interface='org.freedesktop.NetworkManager', | ||
471 | 893 | path='/org/freedesktop/NetworkManager') | ||
472 | 894 | |||
473 | 895 | logger.info('DBusInterface initialized.') | 840 | logger.info('DBusInterface initialized.') |
474 | 896 | 841 | ||
475 | 897 | def shutdown(self, with_restart=False): | 842 | def shutdown(self, with_restart=False): |
476 | @@ -905,11 +850,6 @@ | |||
477 | 905 | self.config.remove_from_connection() | 850 | self.config.remove_from_connection() |
478 | 906 | self.folders.remove_from_connection() | 851 | self.folders.remove_from_connection() |
479 | 907 | self.launcher.remove_from_connection() | 852 | self.launcher.remove_from_connection() |
480 | 908 | # remove the NM's StateChanged signal receiver | ||
481 | 909 | self.system_bus.remove_signal_receiver(self.connection_state_changed, | ||
482 | 910 | signal_name='StateChanged', | ||
483 | 911 | dbus_interface='org.freedesktop.NetworkManager', | ||
484 | 912 | path='/org/freedesktop/NetworkManager') | ||
485 | 913 | self.bus.release_name(self.busName.get_name()) | 853 | self.bus.release_name(self.busName.get_name()) |
486 | 914 | if with_restart: | 854 | if with_restart: |
487 | 915 | # this is what activate_name_owner boils down to, except that | 855 | # this is what activate_name_owner boils down to, except that |
488 | @@ -931,10 +871,3 @@ | |||
489 | 931 | not: there is nothing we can do about it. | 871 | not: there is nothing we can do about it. |
490 | 932 | """ | 872 | """ |
491 | 933 | _restart_error_handler = _restart_reply_handler | 873 | _restart_error_handler = _restart_reply_handler |
492 | 934 | |||
493 | 935 | def connection_state_changed(self, state): | ||
494 | 936 | """Push a connection state changed event to the Event Queue.""" | ||
495 | 937 | if state in NM_STATE_ONLINE_EVENTS: | ||
496 | 938 | self.service.network_connected() | ||
497 | 939 | else: | ||
498 | 940 | self.service.network_disconnected() | ||
499 | 941 | 874 | ||
500 | === modified file 'ubuntuone/platform/windows/ipc.py' | |||
501 | --- ubuntuone/platform/windows/ipc.py 2012-01-03 12:40:04 +0000 | |||
502 | +++ ubuntuone/platform/windows/ipc.py 2012-02-10 13:42:19 +0000 | |||
503 | @@ -21,7 +21,6 @@ | |||
504 | 21 | 21 | ||
505 | 22 | from functools import wraps | 22 | from functools import wraps |
506 | 23 | from collections import defaultdict | 23 | from collections import defaultdict |
507 | 24 | from threading import Thread | ||
508 | 25 | 24 | ||
509 | 26 | from twisted.internet import defer, reactor | 25 | from twisted.internet import defer, reactor |
510 | 27 | from twisted.spread.pb import ( | 26 | from twisted.spread.pb import ( |
511 | @@ -38,7 +37,6 @@ | |||
512 | 38 | ActivationInstance, | 37 | ActivationInstance, |
513 | 39 | AlreadyStartedError, | 38 | AlreadyStartedError, |
514 | 40 | ) | 39 | ) |
515 | 41 | from ubuntuone.platform.windows.network_manager import NetworkManager | ||
516 | 42 | 40 | ||
517 | 43 | logger = logging.getLogger("ubuntuone.SyncDaemon.Pb") | 41 | logger = logging.getLogger("ubuntuone.SyncDaemon.Pb") |
518 | 44 | LOCALHOST = "127.0.0.1" | 42 | LOCALHOST = "127.0.0.1" |
519 | @@ -933,19 +931,6 @@ | |||
520 | 933 | self.factory = PBServerFactory(self) | 931 | self.factory = PBServerFactory(self) |
521 | 934 | self.listener = ipc_server_listen(self.factory) | 932 | self.listener = ipc_server_listen(self.factory) |
522 | 935 | 933 | ||
523 | 936 | # register to future network changes | ||
524 | 937 | self.network_manager = NetworkManager( | ||
525 | 938 | connected_cb=service.network_connected, | ||
526 | 939 | disconnected_cb=service.network_disconnected) | ||
527 | 940 | self.network_manager_thread = Thread( | ||
528 | 941 | target=self.network_manager.register, name='Network changes') | ||
529 | 942 | self.network_manager_thread.daemon = True | ||
530 | 943 | self.network_manager_thread.start() | ||
531 | 944 | |||
532 | 945 | # XXX: the current network manager is not calling network_connected | ||
533 | 946 | # for now, let's fake it | ||
534 | 947 | service.network_connected() | ||
535 | 948 | |||
536 | 949 | logger.info('IPC initialized.') | 934 | logger.info('IPC initialized.') |
537 | 950 | 935 | ||
538 | 951 | def shutdown(self, with_restart=False): | 936 | def shutdown(self, with_restart=False): |
539 | 952 | 937 | ||
540 | === removed file 'ubuntuone/platform/windows/network_manager.py' | |||
541 | --- ubuntuone/platform/windows/network_manager.py 2011-10-14 20:02:23 +0000 | |||
542 | +++ ubuntuone/platform/windows/network_manager.py 1970-01-01 00:00:00 +0000 | |||
543 | @@ -1,160 +0,0 @@ | |||
544 | 1 | # -*- coding: utf-8 -*- | ||
545 | 2 | # | ||
546 | 3 | # Author: Manuel de la Pena<manuel@canonical.com> | ||
547 | 4 | # | ||
548 | 5 | # Copyright 2011 Canonical Ltd. | ||
549 | 6 | # | ||
550 | 7 | # This program is free software: you can redistribute it and/or modify it | ||
551 | 8 | # under the terms of the GNU General Public License version 3, as published | ||
552 | 9 | # by the Free Software Foundation. | ||
553 | 10 | # | ||
554 | 11 | # This program is distributed in the hope that it will be useful, but | ||
555 | 12 | # WITHOUT ANY WARRANTY; without even the implied warranties of | ||
556 | 13 | # MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR | ||
557 | 14 | # PURPOSE. See the GNU General Public License for more details. | ||
558 | 15 | # | ||
559 | 16 | # You should have received a copy of the GNU General Public License along | ||
560 | 17 | # with this program. If not, see <http://www.gnu.org/licenses/>. | ||
561 | 18 | """Implementation of a Network Mnager using ISesNework in Python.""" | ||
562 | 19 | import logging | ||
563 | 20 | |||
564 | 21 | import pythoncom | ||
565 | 22 | |||
566 | 23 | from win32com.server.policy import DesignatedWrapPolicy | ||
567 | 24 | from win32com.client import Dispatch | ||
568 | 25 | |||
569 | 26 | # set te logging to store the data in the ubuntuone folder | ||
570 | 27 | logger = logging.getLogger('ubuntuone.platform.windows.NetworkManager') | ||
571 | 28 | |||
572 | 29 | ## from EventSys.h | ||
573 | 30 | PROGID_EventSystem = "EventSystem.EventSystem" | ||
574 | 31 | PROGID_EventSubscription = "EventSystem.EventSubscription" | ||
575 | 32 | |||
576 | 33 | # SENS (System Event Notification Service) values for the events, | ||
577 | 34 | # this events contain the uuid of the event, the name of the event to be used | ||
578 | 35 | # as well as the method name of the method in the ISesNetwork interface that | ||
579 | 36 | # will be executed for the event. | ||
580 | 37 | # For more ingo look at: | ||
581 | 38 | # http://msdn.microsoft.com/en-us/library/aa377384(v=vs.85).aspx | ||
582 | 39 | |||
583 | 40 | SUBSCRIPTION_NETALIVE = ('{cd1dcbd6-a14d-4823-a0d2-8473afde360f}', | ||
584 | 41 | 'UbuntuOne Network Alive', | ||
585 | 42 | 'ConnectionMade') | ||
586 | 43 | |||
587 | 44 | SUBSCRIPTION_NETALIVE_NOQOC = ('{a82f0e80-1305-400c-ba56-375ae04264a1}', | ||
588 | 45 | 'UbuntuOne Net Alive No Info', | ||
589 | 46 | 'ConnectionMadeNoQOCInfo') | ||
590 | 47 | |||
591 | 48 | SUBSCRIPTION_NETLOST = ('{45233130-b6c3-44fb-a6af-487c47cee611}', | ||
592 | 49 | 'UbuntuOne Network Lost', | ||
593 | 50 | 'ConnectionLost') | ||
594 | 51 | |||
595 | 52 | SUBSCRIPTION_REACH = ('{4c6b2afa-3235-4185-8558-57a7a922ac7b}', | ||
596 | 53 | 'UbuntuOne Network Reach', | ||
597 | 54 | 'ConnectionMade') | ||
598 | 55 | |||
599 | 56 | SUBSCRIPTION_REACH_NOQOC = ('{db62fa23-4c3e-47a3-aef2-b843016177cf}', | ||
600 | 57 | 'UbuntuOne Network Reach No Info', | ||
601 | 58 | 'ConnectionMadeNoQOCInfo') | ||
602 | 59 | |||
603 | 60 | SUBSCRIPTION_REACH_NOQOC2 = ('{d4d8097a-60c6-440d-a6da-918b619ae4b7}', | ||
604 | 61 | 'UbuntuOne Network Reach No Info 2', | ||
605 | 62 | 'ConnectionMadeNoQOCInfo') | ||
606 | 63 | |||
607 | 64 | SUBSCRIPTIONS = [SUBSCRIPTION_NETALIVE, | ||
608 | 65 | SUBSCRIPTION_NETALIVE_NOQOC, | ||
609 | 66 | SUBSCRIPTION_NETLOST, | ||
610 | 67 | SUBSCRIPTION_REACH, | ||
611 | 68 | SUBSCRIPTION_REACH_NOQOC, | ||
612 | 69 | SUBSCRIPTION_REACH_NOQOC2] | ||
613 | 70 | |||
614 | 71 | SENSGUID_EVENTCLASS_NETWORK = '{d5978620-5b9f-11d1-8dd2-00aa004abd5e}' | ||
615 | 72 | SENSGUID_PUBLISHER = "{5fee1bd6-5b9b-11d1-8dd2-00aa004abd5e}" | ||
616 | 73 | |||
617 | 74 | # uuid of the implemented com interface | ||
618 | 75 | IID_ISesNetwork = '{d597bab1-5b9f-11d1-8dd2-00aa004abd5e}' | ||
619 | 76 | |||
620 | 77 | |||
621 | 78 | class NetworkManager(DesignatedWrapPolicy): | ||
622 | 79 | """Implement ISesNetwork to know about the network status.""" | ||
623 | 80 | |||
624 | 81 | _com_interfaces_ = [IID_ISesNetwork] | ||
625 | 82 | _public_methods_ = ['ConnectionMade', | ||
626 | 83 | 'ConnectionMadeNoQOCInfo', | ||
627 | 84 | 'ConnectionLost'] | ||
628 | 85 | _reg_clsid_ = '{41B032DA-86B5-4907-A7F7-958E59333010}' | ||
629 | 86 | _reg_progid_ = "UbuntuOne.NetworkManager" | ||
630 | 87 | |||
631 | 88 | def __init__(self, connected_cb=None, connected_cb_info=None, | ||
632 | 89 | disconnected_cb=None): | ||
633 | 90 | self._wrap_(self) | ||
634 | 91 | self.connected_cb = connected_cb | ||
635 | 92 | self.connected_cb_info = connected_cb_info | ||
636 | 93 | self.disconnected_cb = disconnected_cb | ||
637 | 94 | |||
638 | 95 | def ConnectionMade(self, *args): | ||
639 | 96 | """Tell that the connection is up again.""" | ||
640 | 97 | logger.info('Connection was made.') | ||
641 | 98 | if self.connected_cb_info: | ||
642 | 99 | self.connected_cb_info() | ||
643 | 100 | |||
644 | 101 | def ConnectionMadeNoQOCInfo(self, *args): | ||
645 | 102 | """Tell that the connection is up again.""" | ||
646 | 103 | logger.info('Connection was made no info.') | ||
647 | 104 | if self.connected_cb: | ||
648 | 105 | self.connected_cb() | ||
649 | 106 | |||
650 | 107 | def ConnectionLost(self, *args): | ||
651 | 108 | """Tell the connection was lost.""" | ||
652 | 109 | logger.info('Connection was lost.') | ||
653 | 110 | if self.disconnected_cb: | ||
654 | 111 | self.disconnected_cb() | ||
655 | 112 | |||
656 | 113 | def register(self): | ||
657 | 114 | """Register to listen to network events.""" | ||
658 | 115 | # call the CoInitialize to allow the registration to run in an other | ||
659 | 116 | # thread | ||
660 | 117 | pythoncom.CoInitialize() | ||
661 | 118 | # interface to be used by com | ||
662 | 119 | manager_interface = pythoncom.WrapObject(self) | ||
663 | 120 | event_system = Dispatch(PROGID_EventSystem) | ||
664 | 121 | # register to listent to each of the events to make sure that | ||
665 | 122 | # the code will work on all platforms. | ||
666 | 123 | for current_event in SUBSCRIPTIONS: | ||
667 | 124 | # create an event subscription and add it to the event | ||
668 | 125 | # service | ||
669 | 126 | event_subscription = Dispatch(PROGID_EventSubscription) | ||
670 | 127 | event_subscription.EventClassId = SENSGUID_EVENTCLASS_NETWORK | ||
671 | 128 | event_subscription.PublisherID = SENSGUID_PUBLISHER | ||
672 | 129 | event_subscription.SubscriptionID = current_event[0] | ||
673 | 130 | event_subscription.SubscriptionName = current_event[1] | ||
674 | 131 | event_subscription.MethodName = current_event[2] | ||
675 | 132 | event_subscription.SubscriberInterface = manager_interface | ||
676 | 133 | event_subscription.PerUser = True | ||
677 | 134 | # store the event | ||
678 | 135 | try: | ||
679 | 136 | event_system.Store(PROGID_EventSubscription, | ||
680 | 137 | event_subscription) | ||
681 | 138 | except pythoncom.com_error as e: | ||
682 | 139 | logger.error( | ||
683 | 140 | 'Error registering %s to event %s', e, current_event[1]) | ||
684 | 141 | |||
685 | 142 | pythoncom.PumpMessages() | ||
686 | 143 | |||
687 | 144 | if __name__ == '__main__': | ||
688 | 145 | # Run an expample of the code so that the user can test the code in | ||
689 | 146 | # real life. | ||
690 | 147 | from threading import Thread | ||
691 | 148 | |||
692 | 149 | def connected(): | ||
693 | 150 | print 'Connected' | ||
694 | 151 | |||
695 | 152 | def connected_info(): | ||
696 | 153 | print 'Connected' | ||
697 | 154 | |||
698 | 155 | def disconnected(): | ||
699 | 156 | print 'Disconnected' | ||
700 | 157 | |||
701 | 158 | manager = NetworkManager(connected, connected_info, disconnected) | ||
702 | 159 | p = Thread(target=manager.register) | ||
703 | 160 | p.start() | ||
704 | 161 | 0 | ||
705 | === modified file 'ubuntuone/syncdaemon/interaction_interfaces.py' | |||
706 | --- ubuntuone/syncdaemon/interaction_interfaces.py 2012-01-15 19:31:07 +0000 | |||
707 | +++ ubuntuone/syncdaemon/interaction_interfaces.py 2012-02-10 13:42:19 +0000 | |||
708 | @@ -36,6 +36,8 @@ | |||
709 | 36 | 36 | ||
710 | 37 | from twisted.internet import defer | 37 | from twisted.internet import defer |
711 | 38 | 38 | ||
712 | 39 | from ubuntu_sso.networkstate import NetworkManagerState, ONLINE | ||
713 | 40 | |||
714 | 39 | from ubuntuone.logger import log_call | 41 | from ubuntuone.logger import log_call |
715 | 40 | from ubuntuone.platform import credentials, ExternalInterface | 42 | from ubuntuone.platform import credentials, ExternalInterface |
716 | 41 | from ubuntuone.storageprotocol import request | 43 | from ubuntuone.storageprotocol import request |
717 | @@ -1150,6 +1152,9 @@ | |||
718 | 1150 | super(SyncdaemonService, self).__init__(main, interface) | 1152 | super(SyncdaemonService, self).__init__(main, interface) |
719 | 1151 | 1153 | ||
720 | 1152 | self.send_events = send_events | 1154 | self.send_events = send_events |
721 | 1155 | self.network_manager = NetworkManagerState( | ||
722 | 1156 | result_cb=self.network_state_changed) | ||
723 | 1157 | self.network_manager.find_online_state() | ||
724 | 1153 | 1158 | ||
725 | 1154 | if interface is None: | 1159 | if interface is None: |
726 | 1155 | self.interface = ExternalInterface(service=self) | 1160 | self.interface = ExternalInterface(service=self) |
727 | @@ -1283,6 +1288,14 @@ | |||
728 | 1283 | self.main.action_q.rescan_from_scratch(volume.volume_id) | 1288 | self.main.action_q.rescan_from_scratch(volume.volume_id) |
729 | 1284 | 1289 | ||
730 | 1285 | @log_call(logger.debug) | 1290 | @log_call(logger.debug) |
731 | 1291 | def network_state_changed(self, state): | ||
732 | 1292 | """Receive the connection state and call the proper function.""" | ||
733 | 1293 | if state == ONLINE: | ||
734 | 1294 | self.network_connected() | ||
735 | 1295 | else: | ||
736 | 1296 | self.network_disconnected() | ||
737 | 1297 | |||
738 | 1298 | @log_call(logger.debug) | ||
739 | 1286 | def network_connected(self): | 1299 | def network_connected(self): |
740 | 1287 | """Push the connected event.""" | 1300 | """Push the connected event.""" |
741 | 1288 | self.main.event_q.push('SYS_NET_CONNECTED') | 1301 | self.main.event_q.push('SYS_NET_CONNECTED') |
742 | 1289 | 1302 | ||
743 | === modified file 'ubuntuone/syncdaemon/states.py' | |||
744 | --- ubuntuone/syncdaemon/states.py 2011-10-14 20:02:23 +0000 | |||
745 | +++ ubuntuone/syncdaemon/states.py 2012-02-10 13:42:19 +0000 | |||
746 | @@ -400,7 +400,7 @@ | |||
747 | 400 | self._state_changed() | 400 | self._state_changed() |
748 | 401 | return | 401 | return |
749 | 402 | 402 | ||
751 | 403 | # NetworkManager and User events | 403 | # User events |
752 | 404 | if event in ('SYS_NET_CONNECTED', 'SYS_USER_CONNECT', | 404 | if event in ('SYS_NET_CONNECTED', 'SYS_USER_CONNECT', |
753 | 405 | 'SYS_NET_DISCONNECTED', 'SYS_USER_DISCONNECT', | 405 | 'SYS_NET_DISCONNECTED', 'SYS_USER_DISCONNECT', |
754 | 406 | 'SYS_CONNECTION_LOST', 'SYS_HANDSHAKE_TIMEOUT'): | 406 | 'SYS_CONNECTION_LOST', 'SYS_HANDSHAKE_TIMEOUT'): |
I can not branch this branch, I'm getting:
nessita@ dali:~/ canonical/ client$ bzr branch lp:~diegosarmentero/ubuntuone-client/network-detect //bazaar. launchpad. net/~diegosarme ntero/ubuntuone -client/ network- detect/ ": location is a repository. dali:~/ canonical/ client$
bzr: ERROR: Not a branch: "bzr+ssh:
nessita@
Also, this MP is empty, so... can you please check what happened?
Thanks!