Merge lp:~diegosarmentero/ubuntuone-client/network-detect into lp:ubuntuone-client

Proposed by Diego Sarmentero
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
Reviewer Review Type Date Requested Status
Natalia Bidart 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.

To post a comment you must log in.
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

I can not branch this branch, I'm getting:

nessita@dali:~/canonical/client$ bzr branch lp:~diegosarmentero/ubuntuone-client/network-detect
bzr: ERROR: Not a branch: "bzr+ssh://bazaar.launchpad.net/~diegosarmentero/ubuntuone-client/network-detect/": location is a repository.
nessita@dali:~/canonical/client$

Also, this MP is empty, so... can you please check what happened?
Thanks!

review: Needs Fixing
Revision history for this message
Manuel de la Peña (mandel) wrote :
Download full text (4.8 KiB)

I'm getting the following when I run the tests on windows:

C:\Users\Mandel\Projects\Canonical\ubuntu-sso-client\gtk-ui-executable>run-tests

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\choose_sign_in.ui into ubuntu_sso\qt\choose_sign_in_ui.py
Compiled data\qt\current_user_sign_in.ui into ubuntu_sso\qt\current_user_sign_in
_ui.py
Compiled data\qt\email_verification.ui into ubuntu_sso\qt\email_verification_ui.
py
Compiled data\qt\error_message.ui into ubuntu_sso\qt\error_message_ui.py
Compiled data\qt\forgotten_password.ui into ubuntu_sso\qt\forgotten_password_ui.
py
Compiled data\qt\reset_password.ui into ubuntu_sso\qt\reset_password_ui.py
Compiled data\qt\setup_account.ui into ubuntu_sso\qt\setup_account_ui.py
Compiled data\qt\success_message.ui into ubuntu_sso\qt\success_message_ui.py
running build_py
creating build
creating build\lib
creating build\lib\ubuntu_sso
copying ubuntu_sso\account.py -> build\lib\ubuntu_sso
copying ubuntu_sso\credentials.py -> build\lib\ubuntu_sso
copying ubuntu_sso\logger.py -> build\lib\ubuntu_sso
copying ubuntu_sso\__init__.py -> build\lib\ubuntu_sso
creating build\lib\ubuntu_sso\utils
copying ubuntu_sso\utils\ipc.py -> build\lib\ubuntu_sso\utils
copying ubuntu_sso\utils\tcpactivation.py -> build\lib\ubuntu_sso\utils
copying ubuntu_sso\utils\txsecrets.py -> build\lib\ubuntu_sso\utils
copying ubuntu_sso\utils\ui.py -> build\lib\ubuntu_sso\utils
copying ubuntu_sso\utils\__init__.py -> build\lib\ubuntu_sso\utils
creating build\lib\ubuntu_sso\keyring
copying ubuntu_sso\keyring\linux.py -> build\lib\ubuntu_sso\keyring
copying ubuntu_sso\keyring\windows.py -> build\lib\ubuntu_sso\keyring
copying ubuntu_sso\keyring\__init__.py -> build\lib\ubuntu_sso\keyring
creating build\lib\ubuntu_sso\networkstate
copying ubuntu_sso\networkstate\linux.py -> build\lib\ubuntu_sso\networkstate
copying ubuntu_sso\networkstate\windows.py -> build\lib\ubuntu_sso\networkstate
copying ubuntu_sso\networkstate\__init__.py -> build\lib\ubuntu_sso\networkstate

creating build\lib\ubuntu_sso\main
copying ubuntu_sso\main\linux.py -> build\lib\ubuntu_sso\main
copying ubuntu_sso\main\windows.py -> build\lib\ubuntu_sso\main
copying ubuntu_sso\main\__init__.py -> build\lib\ubuntu_sso\main
creating build\lib\ubuntu_sso\gtk
copying ubuntu_sso\gtk\gui.py -> build\lib\ubuntu_sso\gtk
copying ubuntu_sso\gtk\main.py -> build\lib\ubuntu_sso\gtk
copying ubuntu_sso\gtk\__init__.py -> build\lib\ubuntu_sso\gtk
creating build\lib\ubuntu_sso\qt
copying ubuntu_sso\qt\choose_sign_in_ui.py -> build\lib\ubuntu_sso\qt
copying ubuntu_sso\qt\common.py -> build\lib\ubuntu_sso\qt
copying ubuntu_sso\qt\controllers.py -> build\lib\ubuntu_sso\qt
copying ubuntu_sso\qt\current_user_sign_in_ui.py -> build\lib\ubuntu_sso\qt
copying ubuntu_sso\qt\email_verification_ui.py -> build\lib\ubuntu_sso\qt
copying ubuntu_sso\qt\error_message_ui.py -> build\lib\ubuntu_sso\qt
copying ubun...

Read more...

review: Needs Fixing
Revision history for this message
Manuel de la Peña (mandel) wrote :

Ag, sorry wrong branch :(

Revision history for this message
Natalia Bidart (nataliabidart) wrote :

* This import:

from ubuntu_sso.networkstate import ONLINE

has to be in the same group as:

from twisted.internet import defer
from ubuntuone.devtools.handlers import MementoHandler

Same for from ubuntu_sso.networkstate import NetworkManagerState.

* "# 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_interfaces. So, remove the instance of NetworkManagerState in each windows/linux implementation, and add it to SyncdaemonService class, right after the send_events var is assigned.

review: Needs Fixing
Revision history for this message
Manuel de la Peña (mandel) wrote :

This is for this branch:

C:\Users\Mandel\Projects\Canonical\ubuntuone-client\network-detect>run-tests.bat
 >> 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\\Scripts\u1trial", line 325, in <module>
    main()
  File "C:\Python27\\Scripts\u1trial", line 305, in main
    suite = trial_runner.get_suite(config)
  File "C:\Python27\\Scripts\u1trial", line 184, in get_suite
    config['ignore-paths']))
  File "C:\Python27\\Scripts\u1trial", line 168, in _collect_tests
    module_suite = self._load_unittest(filepath)
  File "C:\Python27\\Scripts\u1trial", line 108, in _load_unittest
    module = __import__(modpath, None, None, [""])
  File "C:\Users\Mandel\Projects\Canonical\ubuntuone-client\network-detect\tests
\platform\windows\test_network_manager.py", line 23, in <module>
    from ubuntuone.platform.windows.network_manager import NetworkManager
ImportError: No module named network_manager

That is when trying to run the tests on Windows.

review: Needs Fixing
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Also, when trying to run tests on windows I'm getting:

  File "E:\client\review_network-detect\tests\platform\windows\test_network_mana
ger.py", line 23, in <module>
    from ubuntuone.platform.windows.network_manager import NetworkManager
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.

Revision history for this message
Manuel de la Peña (mandel) wrote :

All tests passed on Linux P and Windows.

review: Approve
Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Can you please also remove this bit from ubuntuone/platform/linux/dbus_interface.py?

        # remove the NM's StateChanged signal receiver
        self.system_bus.remove_signal_receiver(self.connection_state_changed,
                               signal_name='StateChanged',
                               dbus_interface='org.freedesktop.NetworkManager',
                               path='/org/freedesktop/NetworkManager')

The rest looks good, works OK on linux, and I'm setting up my windows VM to test it IRL there.

review: Needs Fixing
Revision history for this message
Diego Sarmentero (diegosarmentero) wrote :

> Can you please also remove this bit from
> ubuntuone/platform/linux/dbus_interface.py?
>
> # remove the NM's StateChanged signal receiver
> self.system_bus.remove_signal_receiver(self.connection_state_changed,
> signal_name='StateChanged',
> dbus_interface='org.freedesktop.NetworkManager',
> path='/org/freedesktop/NetworkManager')
>
> 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.

Revision history for this message
Natalia Bidart (nataliabidart) wrote :

Hum, I did not notice this before, but there are still some NM code:

nessita@dali:~/canonical/client/review_network-detect$ grep NetworkManager *
contrib/dbus-docs:36: FakeNetworkManager,
contrib/dbus-docs:171: nm = FakeNetworkManager(bus)
tests/syncdaemon/test_action_queue.py:1386: expected = ['SYS_NET_CONNECTED', # from the DBus fake NetworkManager
tests/platform/linux/test_dbus.py:48:class FakeNetworkManager(DBusExposedObject):
tests/platform/linux/test_dbus.py:49: """ A fake NetworkManager that only emits StatusChanged signal. """
tests/platform/linux/test_dbus.py:52: path = '/org/freedesktop/NetworkManager'
tests/platform/linux/test_dbus.py:57: self.bus.request_name('org.freedesktop.NetworkManager',
tests/platform/linux/test_dbus.py:61: self.busName = dbus.service.BusName('org.freedesktop.NetworkManager',
tests/platform/linux/test_dbus.py:67: """ Shutdown the fake NetworkManager """
tests/platform/linux/test_dbus.py:73: @dbus.service.signal('org.freedesktop.NetworkManager', signature='i')
tests/platform/linux/test_dbus.py:95: @dbus.service.method('org.freedesktop.NetworkManager')
tests/platform/linux/test_dbus.py:121: self.nm = FakeNetworkManager(self.bus)
tests/platform/linux/test_dbus.py:211:class NetworkManagerIntegrationTests(IPCTestCase):
tests/platform/linux/test_dbus.py:212: """Test case for our NetworkManager integration."""
ubuntuone/platform/linux/dbus_interface.py:44:# NetworkManager State constants
ubuntuone/platform/linux/dbus_interface.py:864: logger.error("Error while getting the NetworkManager state %s",
ubuntuone/platform/linux/dbus_interface.py:866: # If we get an error back from NetworkManager, we should
ubuntuone/platform/linux/dbus_interface.py:868: # NetworkManager is down or broken or something.

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

Revision history for this message
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!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
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 DBUS_IFACE_FOLDERS_NAME,
6 DBUS_IFACE_PUBLIC_FILES_NAME,
7 DBUS_IFACE_LAUNCHER_NAME,
8- NM_STATE_CONNECTED_GLOBAL,
9- NM_STATE_DISCONNECTED,
10+# NM_STATE_CONNECTED_GLOBAL,
11+# NM_STATE_DISCONNECTED,
12 )
13 from ubuntuone.platform.tools.linux import DBusClient
14
15@@ -76,11 +76,11 @@
16
17 def emit_connected(self):
18 """ Emits the signal StateCganged(3). """
19- self.StateChanged(NM_STATE_CONNECTED_GLOBAL)
20+ self.StateChanged(70)
21
22 def emit_disconnected(self):
23 """ Emits the signal StateCganged(4). """
24- self.StateChanged(NM_STATE_DISCONNECTED)
25+ self.StateChanged(20)
26
27 @dbus.service.method(dbus.PROPERTIES_IFACE,
28 in_signature='ss', out_signature='v',
29@@ -95,7 +95,7 @@
30 @dbus.service.method('org.freedesktop.NetworkManager')
31 def state(self):
32 """Fake the state."""
33- return NM_STATE_CONNECTED_GLOBAL
34+ return 70
35
36 # pylint: enable-msg=C0103
37
38@@ -208,40 +208,6 @@
39 DBusTwistedTestCase = IPCTestCase # API compatibility
40
41
42-class NetworkManagerIntegrationTests(IPCTestCase):
43- """Test case for our NetworkManager integration."""
44-
45- def test_nm_signals(self):
46- """Test that NM signals are received and handled properly."""
47- result = None
48- d = defer.Deferred()
49-
50- class Listener(object):
51- """Helper class."""
52-
53- # class-closure, cannot use self, pylint: disable=E0213
54- def handle_SYS_NET_CONNECTED(innerself):
55- self.nm.emit_disconnected()
56-
57- def handle_SYS_NET_DISCONNECTED(innerself):
58- self.assertTrue(result)
59-
60- listener = Listener()
61- self.event_q.subscribe(listener)
62-
63- def empty_queue_cb():
64- d.callback(True)
65-
66- def callback(result):
67- self.event_q.unsubscribe(listener)
68- self.event_q.remove_empty_event_queue_callback(empty_queue_cb)
69- d.addCallback(callback)
70-
71- self.nm.emit_connected()
72- self.event_q.add_empty_event_queue_callback(empty_queue_cb)
73- return d
74-
75-
76 class StatusTestCase(IPCTestCase):
77 """Tests for the Status exposed object."""
78
79
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 'Remote object should not be None')
85 self.assertIsInstance(remote, RemoteReference)
86
87- def test_daemonized(self):
88- """Check that the NM thread won't block the process."""
89- self.assertTrue(self.interface.network_manager_thread.daemon)
90-
91
92 class IPCPortTestCase(TestCase):
93 """Tests for the ipc port setup."""
94
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-# -*- coding: utf-8 -*-
100-#
101-# Author: Manuel de la Pena<manuel@canonical.com>
102-#
103-# Copyright 2011 Canonical Ltd.
104-#
105-# This program is free software: you can redistribute it and/or modify it
106-# under the terms of the GNU General Public License version 3, as published
107-# by the Free Software Foundation.
108-#
109-# This program is distributed in the hope that it will be useful, but
110-# WITHOUT ANY WARRANTY; without even the implied warranties of
111-# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
112-# PURPOSE. See the GNU General Public License for more details.
113-#
114-# You should have received a copy of the GNU General Public License along
115-# with this program. If not, see <http://www.gnu.org/licenses/>.
116-
117-"""Tests for the network manager."""
118-
119-from mocker import MockerTestCase
120-
121-from ubuntuone.platform.windows.network_manager import NetworkManager
122-
123-
124-class TestNetworkManager(MockerTestCase):
125- """Test he Network Manager."""
126-
127- def setUp(self):
128- super(TestNetworkManager, self).setUp()
129- self.connection_info = self.mocker.mock()
130- self.connection_no_info = self.mocker.mock()
131- self.disconnected = self.mocker.mock()
132- self.manager = NetworkManager(self.connection_no_info,
133- self.connection_info, self.disconnected)
134-
135- def test_connection_made(self):
136- """Ensure db is called."""
137- self.connection_info()
138- self.mocker.replay()
139- self.manager.ConnectionMade()
140-
141- def test_connection_made_no_cb(self):
142- """Ensure db is called."""
143- self.manager.connected_cb_info = None
144- self.mocker.replay()
145- self.manager.ConnectionMade()
146-
147- def test_connection_made_no_info(self):
148- """Ensure db is called."""
149- self.connection_no_info()
150- self.mocker.replay()
151- self.manager.ConnectionMadeNoQOCInfo()
152-
153- def test_connection_made_no_info_no_cb(self):
154- """Ensure db is called."""
155- self.manager.connected_cb = None
156- self.mocker.replay()
157- self.manager.ConnectionMadeNoQOCInfo()
158-
159- def test_disconnection(self):
160- """Ensure db is called."""
161- self.disconnected()
162- self.mocker.replay()
163- self.manager.ConnectionLost()
164-
165- def test_disconnection_no_cb(self):
166- """Ensure db is called."""
167- self.manager.disconnected_cb = None
168- self.mocker.replay()
169- self.manager.ConnectionLost()
170
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 protocol_pb2,
176 request,
177 )
178-from ubuntuone.syncdaemon import states, interfaces, config
179+from ubuntuone.syncdaemon import interfaces, config
180 from ubuntuone.syncdaemon import action_queue
181 from ubuntuone.syncdaemon.action_queue import (
182 ActionQueue, ActionQueueCommand, ChangePublicAccess, CreateUDF,
183@@ -1295,109 +1295,6 @@
184 "host 1.2.3.4", "port 4321"))
185
186
187-class NetworkmanagerTestCase(FactoryBaseTestCase):
188- """Base test case generating a connected factory."""
189-
190- timeout = 15
191-
192- @defer.inlineCallbacks
193- def setUp(self):
194- """Init."""
195- yield super(NetworkmanagerTestCase, self).setUp()
196- self.action_queue.event_queue.push('SYS_NET_CONNECTED')
197- self.main.start()
198-
199- @defer.inlineCallbacks
200- def test_wrong_disconnect(self):
201- """Test factory's connection when SYS_NET_DISCONNECTED."""
202-
203- d1 = self.main.wait_for('SYS_CONNECTION_MADE')
204- d2 = self.main.wait_for('SYS_CONNECTION_LOST')
205-
206- self.server = self._start_sample_webserver()
207- self.user_connect()
208- yield d1
209-
210- self.action_queue.event_queue.push('SYS_NET_DISCONNECTED')
211- yield d2
212-
213- @defer.inlineCallbacks
214- def test_disconnect_twice(self):
215- """Test connection when SYS_NET_DISCONNECTED is received twice."""
216-
217- d1 = self.main.wait_for('SYS_CONNECTION_MADE')
218- d2 = self.main.wait_for('SYS_CONNECTION_LOST')
219-
220- self.server = self._start_sample_webserver()
221- self.user_connect()
222- yield d1
223-
224- self.action_queue.event_queue.push('SYS_NET_DISCONNECTED')
225- yield d2
226-
227- self.action_queue.event_queue.events = []
228- self.action_queue.event_queue.push('SYS_NET_DISCONNECTED')
229- self.assertEqual([('SYS_NET_DISCONNECTED', {})],
230- self.action_queue.event_queue.events,
231- 'No new events after a misplaced SYS_NET_DISCONNECTED')
232-
233- @defer.inlineCallbacks
234- def test_net_connected_if_already_connected(self):
235- """Test connection when SYS_NET_CONNECTED is received twice."""
236-
237- d1 = self.main.wait_for('SYS_CONNECTION_MADE')
238-
239- self.server = self._start_sample_webserver()
240- self.user_connect()
241- yield d1
242-
243- self.action_queue.event_queue.events = []
244- self.action_queue.event_queue.push('SYS_NET_CONNECTED')
245- self.assertEqual([('SYS_NET_CONNECTED', {})],
246- self.action_queue.event_queue.events,
247- 'No new events after a misplaced SYS_NET_CONNECTED')
248-
249- @defer.inlineCallbacks
250- def test_messy_mix(self):
251- """Test connection when a messy mix of events is received."""
252- orig_waiting = states.MAX_WAITING
253- states.MAX_WAITING = 1
254-
255- self.action_queue.event_queue.events = []
256- self.server = self._start_sample_webserver()
257-
258- conn_made = self.main.wait_for('SYS_CONNECTION_MADE')
259- self.user_connect()
260- yield conn_made
261-
262- events = ['SYS_NET_CONNECTED', 'SYS_NET_DISCONNECTED',
263- 'SYS_NET_CONNECTED', 'SYS_NET_CONNECTED',
264- 'SYS_NET_DISCONNECTED', 'SYS_NET_DISCONNECTED',
265- 'SYS_NET_CONNECTED']
266-
267- for i in events:
268- self.action_queue.event_queue.push(i)
269-
270- yield self.main.wait_for_nirvana()
271-
272- expected = ['SYS_NET_CONNECTED', # from the DBus fake NetworkManager
273- 'SYS_NET_CONNECTED', 'SYS_NET_DISCONNECTED',
274- 'SYS_CONNECTION_LOST', 'SYS_CONNECTION_RETRY',
275- 'SYS_NET_CONNECTED', 'SYS_NET_CONNECTED',
276- 'SYS_CONNECTION_MADE', 'SYS_NET_DISCONNECTED',
277- 'SYS_NET_DISCONNECTED']
278-
279- avoid = ('SYS_STATE_CHANGED', 'SYS_LOCAL_RESCAN_DONE',
280- 'SYS_PROTOCOL_VERSION_OK', 'SYS_SET_CAPABILITIES_OK',
281- 'SYS_AUTH_OK', 'SYS_SERVER_RESCAN_DONE')
282- actual = [event for (event, kwargs) in
283- self.action_queue.event_queue.events
284- if event not in avoid]
285- self.assertEqual(sorted(expected), sorted(actual))
286-
287- states.MAX_WAITING = orig_waiting
288-
289-
290 class ConnectedBaseTestCase(FactoryBaseTestCase):
291 """Base test case generating a connected factory."""
292
293
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
299 from twisted.internet import defer
300 from ubuntuone.devtools.handlers import MementoHandler
301+from ubuntu_sso.networkstate import ONLINE
302
303 from contrib.testing.testcase import (
304 FakeCommand,
305@@ -2208,7 +2209,21 @@
306 def test_rescan_from_scratch_missing_volume(self):
307 """Test for rescan_from_scratch with a non-existing volume."""
308 volume_id = object()
309- self.assertRaises(ValueError, self.sd_obj.rescan_from_scratch, volume_id)
310+ self.assertRaises(ValueError,
311+ self.sd_obj.rescan_from_scratch, volume_id)
312+
313+ def test_network_state_changed_with_connection(self):
314+ """Test the network_state changed method with a connection."""
315+ self.sd_obj.network_state_changed(ONLINE)
316+
317+ self.assertEqual(self.events, [('SYS_NET_CONNECTED', {})])
318+
319+ def test_network_state_changed_without_connection(self):
320+ """Test the network_state changed method without a connection."""
321+ # Sending anything instead of ONLINE should be interpreted as OFFLINE
322+ self.sd_obj.network_state_changed(object())
323+
324+ self.assertEqual(self.events, [('SYS_NET_DISCONNECTED', {})])
325
326 def test_network_connected(self):
327 """Test the network_connected method."""
328
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 self.assertFalse(self.aq.queue.active)
334
335
336-class TestStateManagerPassToNetworkManager(Base):
337- """All network events should go to NetworkManager."""
338-
339- @defer.inlineCallbacks
340- def setUp(self):
341- yield super(TestStateManagerPassToNetworkManager,
342- self).setUp()
343-
344- # put a function in the middle to log calls
345- self.called_events = []
346- orig_on_event = self.sm.connection.on_event
347- def fake_on_event(event):
348- """Log the call and call original."""
349- self.called_events.append(event)
350- orig_on_event(event)
351- self.sm.connection.on_event = fake_on_event
352-
353- def _test(self, event):
354- """Generic test method."""
355- cnt = 0
356- for node in self.sm_nodes_ok:
357- cnt += 1
358- self.sm.state = node
359- self.sm.handle_default(event)
360- self.assertEqual(self.called_events, [event]*cnt)
361-
362- def test_net_connected(self):
363- """SYS_NET_CONNECTED should go to Connection no matter where."""
364- self._test('SYS_NET_CONNECTED')
365-
366- def test_user_connect(self):
367- """SYS_USER_CONNECT should go to Connection no matter where."""
368- self._test('SYS_USER_CONNECT')
369-
370- def test_net_disconnected(self):
371- """SYS_NET_DISCONNECTED should go to Connection no matter where."""
372- self._test('SYS_NET_DISCONNECTED')
373-
374- def test_user_disconnect(self):
375- """SYS_USER_DISCONNECT should go to Connection no matter where."""
376- self._test('SYS_USER_DISCONNECT')
377-
378- def test_connection_lost(self):
379- """SYS_CONNECTION_LOST should go to Connection no matter where."""
380- self._test('SYS_CONNECTION_LOST')
381-
382- def test_handshake_timeout(self):
383- """SYS_HANDSHAKE_TIMEOUT should go to Connection no matter where."""
384- self._test('SYS_HANDSHAKE_TIMEOUT')
385-
386-
387-
388 class TestStateManagerPassToQueueManager(Base):
389 """All queue events should go to QueueManager."""
390
391
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 from ubuntuone.platform import linux
397 source = linux
398
399+# This imports needs to be here in order to belongs to this namespace
400 from ubuntuone.platform import credentials
401 from ubuntuone.platform import tools
402
403
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 DBUS_IFACE_PUBLIC_FILES_NAME = DBUS_IFACE_NAME + '.PublicFiles'
409 DBUS_IFACE_LAUNCHER_NAME = DBUS_IFACE_NAME + '.Launcher'
410
411-# NetworkManager State constants
412-NM_STATE_UNKNOWN = 0
413-NM_STATE_ASLEEP_OLD = 1
414-NM_STATE_ASLEEP = 10
415-NM_STATE_CONNECTING_OLD = 2
416-NM_STATE_CONNECTING = 40
417-NM_STATE_CONNECTED_OLD = 3
418-NM_STATE_CONNECTED_LOCAL = 50
419-NM_STATE_CONNECTED_SITE = 60
420-NM_STATE_CONNECTED_GLOBAL = 70
421-NM_STATE_DISCONNECTED_OLD = 4
422-NM_STATE_DISCONNECTED = 20
423-
424-# NM state -> online/offline mapping
425-# Note that the LOCAL and SITE mappings are *not* a typo. Local and site links
426-# are not enough to connect to one.ubuntu.com, so we treat them as if we were
427-# not connected.
428-NM_STATE_ONLINE_EVENTS = [
429- NM_STATE_CONNECTED_OLD,
430- NM_STATE_CONNECTED_GLOBAL,
431-]
432-
433 logger = logging.getLogger("ubuntuone.SyncDaemon.DBus")
434
435
436@@ -859,39 +837,6 @@
437 self.config = Config(self.busName, service)
438 self.service = service
439
440- def error_handler(error):
441- """Handle errors from NM."""
442- logger.error("Error while getting the NetworkManager state %s",
443- error)
444- # If we get an error back from NetworkManager, we should
445- # just try to connect anyway; it probably means that
446- # NetworkManager is down or broken or something.
447- self.connection_state_changed(NM_STATE_CONNECTED_GLOBAL)
448- try:
449- nm = self.system_bus.get_object(
450- 'org.freedesktop.NetworkManager',
451- '/org/freedesktop/NetworkManager',
452- follow_name_owner_changes=True)
453- iface = dbus.Interface(nm, 'org.freedesktop.NetworkManager')
454- except dbus.DBusException, e:
455- if e.get_dbus_name() == \
456- 'org.freedesktop.DBus.Error.ServiceUnknown':
457- # NetworkManager isn't running.
458- logger.warn("Unable to connect to NetworkManager. "
459- "Assuming we have network.")
460- self.connection_state_changed(NM_STATE_CONNECTED_GLOBAL)
461- else:
462- raise
463- else:
464- iface.state(reply_handler=self.connection_state_changed,
465- error_handler=error_handler)
466-
467- # register a handler to NM StateChanged signal
468- self.system_bus.add_signal_receiver(self.connection_state_changed,
469- signal_name='StateChanged',
470- dbus_interface='org.freedesktop.NetworkManager',
471- path='/org/freedesktop/NetworkManager')
472-
473 logger.info('DBusInterface initialized.')
474
475 def shutdown(self, with_restart=False):
476@@ -905,11 +850,6 @@
477 self.config.remove_from_connection()
478 self.folders.remove_from_connection()
479 self.launcher.remove_from_connection()
480- # remove the NM's StateChanged signal receiver
481- self.system_bus.remove_signal_receiver(self.connection_state_changed,
482- signal_name='StateChanged',
483- dbus_interface='org.freedesktop.NetworkManager',
484- path='/org/freedesktop/NetworkManager')
485 self.bus.release_name(self.busName.get_name())
486 if with_restart:
487 # this is what activate_name_owner boils down to, except that
488@@ -931,10 +871,3 @@
489 not: there is nothing we can do about it.
490 """
491 _restart_error_handler = _restart_reply_handler
492-
493- def connection_state_changed(self, state):
494- """Push a connection state changed event to the Event Queue."""
495- if state in NM_STATE_ONLINE_EVENTS:
496- self.service.network_connected()
497- else:
498- self.service.network_disconnected()
499
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
505 from functools import wraps
506 from collections import defaultdict
507-from threading import Thread
508
509 from twisted.internet import defer, reactor
510 from twisted.spread.pb import (
511@@ -38,7 +37,6 @@
512 ActivationInstance,
513 AlreadyStartedError,
514 )
515-from ubuntuone.platform.windows.network_manager import NetworkManager
516
517 logger = logging.getLogger("ubuntuone.SyncDaemon.Pb")
518 LOCALHOST = "127.0.0.1"
519@@ -933,19 +931,6 @@
520 self.factory = PBServerFactory(self)
521 self.listener = ipc_server_listen(self.factory)
522
523- # register to future network changes
524- self.network_manager = NetworkManager(
525- connected_cb=service.network_connected,
526- disconnected_cb=service.network_disconnected)
527- self.network_manager_thread = Thread(
528- target=self.network_manager.register, name='Network changes')
529- self.network_manager_thread.daemon = True
530- self.network_manager_thread.start()
531-
532- # XXX: the current network manager is not calling network_connected
533- # for now, let's fake it
534- service.network_connected()
535-
536 logger.info('IPC initialized.')
537
538 def shutdown(self, with_restart=False):
539
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-# -*- coding: utf-8 -*-
545-#
546-# Author: Manuel de la Pena<manuel@canonical.com>
547-#
548-# Copyright 2011 Canonical Ltd.
549-#
550-# This program is free software: you can redistribute it and/or modify it
551-# under the terms of the GNU General Public License version 3, as published
552-# by the Free Software Foundation.
553-#
554-# This program is distributed in the hope that it will be useful, but
555-# WITHOUT ANY WARRANTY; without even the implied warranties of
556-# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
557-# PURPOSE. See the GNU General Public License for more details.
558-#
559-# You should have received a copy of the GNU General Public License along
560-# with this program. If not, see <http://www.gnu.org/licenses/>.
561-"""Implementation of a Network Mnager using ISesNework in Python."""
562-import logging
563-
564-import pythoncom
565-
566-from win32com.server.policy import DesignatedWrapPolicy
567-from win32com.client import Dispatch
568-
569-# set te logging to store the data in the ubuntuone folder
570-logger = logging.getLogger('ubuntuone.platform.windows.NetworkManager')
571-
572-## from EventSys.h
573-PROGID_EventSystem = "EventSystem.EventSystem"
574-PROGID_EventSubscription = "EventSystem.EventSubscription"
575-
576-# SENS (System Event Notification Service) values for the events,
577-# this events contain the uuid of the event, the name of the event to be used
578-# as well as the method name of the method in the ISesNetwork interface that
579-# will be executed for the event.
580-# For more ingo look at:
581-# http://msdn.microsoft.com/en-us/library/aa377384(v=vs.85).aspx
582-
583-SUBSCRIPTION_NETALIVE = ('{cd1dcbd6-a14d-4823-a0d2-8473afde360f}',
584- 'UbuntuOne Network Alive',
585- 'ConnectionMade')
586-
587-SUBSCRIPTION_NETALIVE_NOQOC = ('{a82f0e80-1305-400c-ba56-375ae04264a1}',
588- 'UbuntuOne Net Alive No Info',
589- 'ConnectionMadeNoQOCInfo')
590-
591-SUBSCRIPTION_NETLOST = ('{45233130-b6c3-44fb-a6af-487c47cee611}',
592- 'UbuntuOne Network Lost',
593- 'ConnectionLost')
594-
595-SUBSCRIPTION_REACH = ('{4c6b2afa-3235-4185-8558-57a7a922ac7b}',
596- 'UbuntuOne Network Reach',
597- 'ConnectionMade')
598-
599-SUBSCRIPTION_REACH_NOQOC = ('{db62fa23-4c3e-47a3-aef2-b843016177cf}',
600- 'UbuntuOne Network Reach No Info',
601- 'ConnectionMadeNoQOCInfo')
602-
603-SUBSCRIPTION_REACH_NOQOC2 = ('{d4d8097a-60c6-440d-a6da-918b619ae4b7}',
604- 'UbuntuOne Network Reach No Info 2',
605- 'ConnectionMadeNoQOCInfo')
606-
607-SUBSCRIPTIONS = [SUBSCRIPTION_NETALIVE,
608- SUBSCRIPTION_NETALIVE_NOQOC,
609- SUBSCRIPTION_NETLOST,
610- SUBSCRIPTION_REACH,
611- SUBSCRIPTION_REACH_NOQOC,
612- SUBSCRIPTION_REACH_NOQOC2]
613-
614-SENSGUID_EVENTCLASS_NETWORK = '{d5978620-5b9f-11d1-8dd2-00aa004abd5e}'
615-SENSGUID_PUBLISHER = "{5fee1bd6-5b9b-11d1-8dd2-00aa004abd5e}"
616-
617-# uuid of the implemented com interface
618-IID_ISesNetwork = '{d597bab1-5b9f-11d1-8dd2-00aa004abd5e}'
619-
620-
621-class NetworkManager(DesignatedWrapPolicy):
622- """Implement ISesNetwork to know about the network status."""
623-
624- _com_interfaces_ = [IID_ISesNetwork]
625- _public_methods_ = ['ConnectionMade',
626- 'ConnectionMadeNoQOCInfo',
627- 'ConnectionLost']
628- _reg_clsid_ = '{41B032DA-86B5-4907-A7F7-958E59333010}'
629- _reg_progid_ = "UbuntuOne.NetworkManager"
630-
631- def __init__(self, connected_cb=None, connected_cb_info=None,
632- disconnected_cb=None):
633- self._wrap_(self)
634- self.connected_cb = connected_cb
635- self.connected_cb_info = connected_cb_info
636- self.disconnected_cb = disconnected_cb
637-
638- def ConnectionMade(self, *args):
639- """Tell that the connection is up again."""
640- logger.info('Connection was made.')
641- if self.connected_cb_info:
642- self.connected_cb_info()
643-
644- def ConnectionMadeNoQOCInfo(self, *args):
645- """Tell that the connection is up again."""
646- logger.info('Connection was made no info.')
647- if self.connected_cb:
648- self.connected_cb()
649-
650- def ConnectionLost(self, *args):
651- """Tell the connection was lost."""
652- logger.info('Connection was lost.')
653- if self.disconnected_cb:
654- self.disconnected_cb()
655-
656- def register(self):
657- """Register to listen to network events."""
658- # call the CoInitialize to allow the registration to run in an other
659- # thread
660- pythoncom.CoInitialize()
661- # interface to be used by com
662- manager_interface = pythoncom.WrapObject(self)
663- event_system = Dispatch(PROGID_EventSystem)
664- # register to listent to each of the events to make sure that
665- # the code will work on all platforms.
666- for current_event in SUBSCRIPTIONS:
667- # create an event subscription and add it to the event
668- # service
669- event_subscription = Dispatch(PROGID_EventSubscription)
670- event_subscription.EventClassId = SENSGUID_EVENTCLASS_NETWORK
671- event_subscription.PublisherID = SENSGUID_PUBLISHER
672- event_subscription.SubscriptionID = current_event[0]
673- event_subscription.SubscriptionName = current_event[1]
674- event_subscription.MethodName = current_event[2]
675- event_subscription.SubscriberInterface = manager_interface
676- event_subscription.PerUser = True
677- # store the event
678- try:
679- event_system.Store(PROGID_EventSubscription,
680- event_subscription)
681- except pythoncom.com_error as e:
682- logger.error(
683- 'Error registering %s to event %s', e, current_event[1])
684-
685- pythoncom.PumpMessages()
686-
687-if __name__ == '__main__':
688- # Run an expample of the code so that the user can test the code in
689- # real life.
690- from threading import Thread
691-
692- def connected():
693- print 'Connected'
694-
695- def connected_info():
696- print 'Connected'
697-
698- def disconnected():
699- print 'Disconnected'
700-
701- manager = NetworkManager(connected, connected_info, disconnected)
702- p = Thread(target=manager.register)
703- p.start()
704
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
710 from twisted.internet import defer
711
712+from ubuntu_sso.networkstate import NetworkManagerState, ONLINE
713+
714 from ubuntuone.logger import log_call
715 from ubuntuone.platform import credentials, ExternalInterface
716 from ubuntuone.storageprotocol import request
717@@ -1150,6 +1152,9 @@
718 super(SyncdaemonService, self).__init__(main, interface)
719
720 self.send_events = send_events
721+ self.network_manager = NetworkManagerState(
722+ result_cb=self.network_state_changed)
723+ self.network_manager.find_online_state()
724
725 if interface is None:
726 self.interface = ExternalInterface(service=self)
727@@ -1283,6 +1288,14 @@
728 self.main.action_q.rescan_from_scratch(volume.volume_id)
729
730 @log_call(logger.debug)
731+ def network_state_changed(self, state):
732+ """Receive the connection state and call the proper function."""
733+ if state == ONLINE:
734+ self.network_connected()
735+ else:
736+ self.network_disconnected()
737+
738+ @log_call(logger.debug)
739 def network_connected(self):
740 """Push the connected event."""
741 self.main.event_q.push('SYS_NET_CONNECTED')
742
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 self._state_changed()
748 return
749
750- # NetworkManager and User events
751+ # User events
752 if event in ('SYS_NET_CONNECTED', 'SYS_USER_CONNECT',
753 'SYS_NET_DISCONNECTED', 'SYS_USER_DISCONNECT',
754 'SYS_CONNECTION_LOST', 'SYS_HANDSHAKE_TIMEOUT'):

Subscribers

People subscribed via source and target branches