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 (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.

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
=== modified file 'tests/platform/linux/test_dbus.py'
--- tests/platform/linux/test_dbus.py 2011-11-30 19:30:00 +0000
+++ tests/platform/linux/test_dbus.py 2012-02-10 13:42:19 +0000
@@ -39,8 +39,8 @@
39 DBUS_IFACE_FOLDERS_NAME,39 DBUS_IFACE_FOLDERS_NAME,
40 DBUS_IFACE_PUBLIC_FILES_NAME,40 DBUS_IFACE_PUBLIC_FILES_NAME,
41 DBUS_IFACE_LAUNCHER_NAME,41 DBUS_IFACE_LAUNCHER_NAME,
42 NM_STATE_CONNECTED_GLOBAL,42# NM_STATE_CONNECTED_GLOBAL,
43 NM_STATE_DISCONNECTED,43# NM_STATE_DISCONNECTED,
44)44)
45from ubuntuone.platform.tools.linux import DBusClient45from ubuntuone.platform.tools.linux import DBusClient
4646
@@ -76,11 +76,11 @@
7676
77 def emit_connected(self):77 def emit_connected(self):
78 """ Emits the signal StateCganged(3). """78 """ Emits the signal StateCganged(3). """
79 self.StateChanged(NM_STATE_CONNECTED_GLOBAL)79 self.StateChanged(70)
8080
81 def emit_disconnected(self):81 def emit_disconnected(self):
82 """ Emits the signal StateCganged(4). """82 """ Emits the signal StateCganged(4). """
83 self.StateChanged(NM_STATE_DISCONNECTED)83 self.StateChanged(20)
8484
85 @dbus.service.method(dbus.PROPERTIES_IFACE,85 @dbus.service.method(dbus.PROPERTIES_IFACE,
86 in_signature='ss', out_signature='v',86 in_signature='ss', out_signature='v',
@@ -95,7 +95,7 @@
95 @dbus.service.method('org.freedesktop.NetworkManager')95 @dbus.service.method('org.freedesktop.NetworkManager')
96 def state(self):96 def state(self):
97 """Fake the state."""97 """Fake the state."""
98 return NM_STATE_CONNECTED_GLOBAL98 return 70
9999
100 # pylint: enable-msg=C0103100 # pylint: enable-msg=C0103
101101
@@ -208,40 +208,6 @@
208DBusTwistedTestCase = IPCTestCase # API compatibility208DBusTwistedTestCase = IPCTestCase # API compatibility
209209
210210
211class NetworkManagerIntegrationTests(IPCTestCase):
212 """Test case for our NetworkManager integration."""
213
214 def test_nm_signals(self):
215 """Test that NM signals are received and handled properly."""
216 result = None
217 d = defer.Deferred()
218
219 class Listener(object):
220 """Helper class."""
221
222 # class-closure, cannot use self, pylint: disable=E0213
223 def handle_SYS_NET_CONNECTED(innerself):
224 self.nm.emit_disconnected()
225
226 def handle_SYS_NET_DISCONNECTED(innerself):
227 self.assertTrue(result)
228
229 listener = Listener()
230 self.event_q.subscribe(listener)
231
232 def empty_queue_cb():
233 d.callback(True)
234
235 def callback(result):
236 self.event_q.unsubscribe(listener)
237 self.event_q.remove_empty_event_queue_callback(empty_queue_cb)
238 d.addCallback(callback)
239
240 self.nm.emit_connected()
241 self.event_q.add_empty_event_queue_callback(empty_queue_cb)
242 return d
243
244
245class StatusTestCase(IPCTestCase):211class StatusTestCase(IPCTestCase):
246 """Tests for the Status exposed object."""212 """Tests for the Status exposed object."""
247213
248214
=== modified file 'tests/platform/windows/test_ipc.py'
--- tests/platform/windows/test_ipc.py 2011-10-28 19:17:47 +0000
+++ tests/platform/windows/test_ipc.py 2012-02-10 13:42:19 +0000
@@ -652,10 +652,6 @@
652 'Remote object should not be None')652 'Remote object should not be None')
653 self.assertIsInstance(remote, RemoteReference)653 self.assertIsInstance(remote, RemoteReference)
654654
655 def test_daemonized(self):
656 """Check that the NM thread won't block the process."""
657 self.assertTrue(self.interface.network_manager_thread.daemon)
658
659655
660class IPCPortTestCase(TestCase):656class IPCPortTestCase(TestCase):
661 """Tests for the ipc port setup."""657 """Tests for the ipc port setup."""
662658
=== removed file 'tests/platform/windows/test_network_manager.py'
--- tests/platform/windows/test_network_manager.py 2011-10-28 18:43:23 +0000
+++ tests/platform/windows/test_network_manager.py 1970-01-01 00:00:00 +0000
@@ -1,71 +0,0 @@
1# -*- coding: utf-8 -*-
2#
3# Author: Manuel de la Pena<manuel@canonical.com>
4#
5# Copyright 2011 Canonical Ltd.
6#
7# This program is free software: you can redistribute it and/or modify it
8# under the terms of the GNU General Public License version 3, as published
9# by the Free Software Foundation.
10#
11# This program is distributed in the hope that it will be useful, but
12# WITHOUT ANY WARRANTY; without even the implied warranties of
13# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14# PURPOSE. See the GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License along
17# with this program. If not, see <http://www.gnu.org/licenses/>.
18
19"""Tests for the network manager."""
20
21from mocker import MockerTestCase
22
23from ubuntuone.platform.windows.network_manager import NetworkManager
24
25
26class TestNetworkManager(MockerTestCase):
27 """Test he Network Manager."""
28
29 def setUp(self):
30 super(TestNetworkManager, self).setUp()
31 self.connection_info = self.mocker.mock()
32 self.connection_no_info = self.mocker.mock()
33 self.disconnected = self.mocker.mock()
34 self.manager = NetworkManager(self.connection_no_info,
35 self.connection_info, self.disconnected)
36
37 def test_connection_made(self):
38 """Ensure db is called."""
39 self.connection_info()
40 self.mocker.replay()
41 self.manager.ConnectionMade()
42
43 def test_connection_made_no_cb(self):
44 """Ensure db is called."""
45 self.manager.connected_cb_info = None
46 self.mocker.replay()
47 self.manager.ConnectionMade()
48
49 def test_connection_made_no_info(self):
50 """Ensure db is called."""
51 self.connection_no_info()
52 self.mocker.replay()
53 self.manager.ConnectionMadeNoQOCInfo()
54
55 def test_connection_made_no_info_no_cb(self):
56 """Ensure db is called."""
57 self.manager.connected_cb = None
58 self.mocker.replay()
59 self.manager.ConnectionMadeNoQOCInfo()
60
61 def test_disconnection(self):
62 """Ensure db is called."""
63 self.disconnected()
64 self.mocker.replay()
65 self.manager.ConnectionLost()
66
67 def test_disconnection_no_cb(self):
68 """Ensure db is called."""
69 self.manager.disconnected_cb = None
70 self.mocker.replay()
71 self.manager.ConnectionLost()
720
=== modified file 'tests/syncdaemon/test_action_queue.py'
--- tests/syncdaemon/test_action_queue.py 2012-02-06 15:32:28 +0000
+++ tests/syncdaemon/test_action_queue.py 2012-02-10 13:42:19 +0000
@@ -58,7 +58,7 @@
58 protocol_pb2,58 protocol_pb2,
59 request,59 request,
60)60)
61from ubuntuone.syncdaemon import states, interfaces, config61from ubuntuone.syncdaemon import interfaces, config
62from ubuntuone.syncdaemon import action_queue62from ubuntuone.syncdaemon import action_queue
63from ubuntuone.syncdaemon.action_queue import (63from ubuntuone.syncdaemon.action_queue import (
64 ActionQueue, ActionQueueCommand, ChangePublicAccess, CreateUDF,64 ActionQueue, ActionQueueCommand, ChangePublicAccess, CreateUDF,
@@ -1295,109 +1295,6 @@
1295 "host 1.2.3.4", "port 4321"))1295 "host 1.2.3.4", "port 4321"))
12961296
12971297
1298class NetworkmanagerTestCase(FactoryBaseTestCase):
1299 """Base test case generating a connected factory."""
1300
1301 timeout = 15
1302
1303 @defer.inlineCallbacks
1304 def setUp(self):
1305 """Init."""
1306 yield super(NetworkmanagerTestCase, self).setUp()
1307 self.action_queue.event_queue.push('SYS_NET_CONNECTED')
1308 self.main.start()
1309
1310 @defer.inlineCallbacks
1311 def test_wrong_disconnect(self):
1312 """Test factory's connection when SYS_NET_DISCONNECTED."""
1313
1314 d1 = self.main.wait_for('SYS_CONNECTION_MADE')
1315 d2 = self.main.wait_for('SYS_CONNECTION_LOST')
1316
1317 self.server = self._start_sample_webserver()
1318 self.user_connect()
1319 yield d1
1320
1321 self.action_queue.event_queue.push('SYS_NET_DISCONNECTED')
1322 yield d2
1323
1324 @defer.inlineCallbacks
1325 def test_disconnect_twice(self):
1326 """Test connection when SYS_NET_DISCONNECTED is received twice."""
1327
1328 d1 = self.main.wait_for('SYS_CONNECTION_MADE')
1329 d2 = self.main.wait_for('SYS_CONNECTION_LOST')
1330
1331 self.server = self._start_sample_webserver()
1332 self.user_connect()
1333 yield d1
1334
1335 self.action_queue.event_queue.push('SYS_NET_DISCONNECTED')
1336 yield d2
1337
1338 self.action_queue.event_queue.events = []
1339 self.action_queue.event_queue.push('SYS_NET_DISCONNECTED')
1340 self.assertEqual([('SYS_NET_DISCONNECTED', {})],
1341 self.action_queue.event_queue.events,
1342 'No new events after a misplaced SYS_NET_DISCONNECTED')
1343
1344 @defer.inlineCallbacks
1345 def test_net_connected_if_already_connected(self):
1346 """Test connection when SYS_NET_CONNECTED is received twice."""
1347
1348 d1 = self.main.wait_for('SYS_CONNECTION_MADE')
1349
1350 self.server = self._start_sample_webserver()
1351 self.user_connect()
1352 yield d1
1353
1354 self.action_queue.event_queue.events = []
1355 self.action_queue.event_queue.push('SYS_NET_CONNECTED')
1356 self.assertEqual([('SYS_NET_CONNECTED', {})],
1357 self.action_queue.event_queue.events,
1358 'No new events after a misplaced SYS_NET_CONNECTED')
1359
1360 @defer.inlineCallbacks
1361 def test_messy_mix(self):
1362 """Test connection when a messy mix of events is received."""
1363 orig_waiting = states.MAX_WAITING
1364 states.MAX_WAITING = 1
1365
1366 self.action_queue.event_queue.events = []
1367 self.server = self._start_sample_webserver()
1368
1369 conn_made = self.main.wait_for('SYS_CONNECTION_MADE')
1370 self.user_connect()
1371 yield conn_made
1372
1373 events = ['SYS_NET_CONNECTED', 'SYS_NET_DISCONNECTED',
1374 'SYS_NET_CONNECTED', 'SYS_NET_CONNECTED',
1375 'SYS_NET_DISCONNECTED', 'SYS_NET_DISCONNECTED',
1376 'SYS_NET_CONNECTED']
1377
1378 for i in events:
1379 self.action_queue.event_queue.push(i)
1380
1381 yield self.main.wait_for_nirvana()
1382
1383 expected = ['SYS_NET_CONNECTED', # from the DBus fake NetworkManager
1384 'SYS_NET_CONNECTED', 'SYS_NET_DISCONNECTED',
1385 'SYS_CONNECTION_LOST', 'SYS_CONNECTION_RETRY',
1386 'SYS_NET_CONNECTED', 'SYS_NET_CONNECTED',
1387 'SYS_CONNECTION_MADE', 'SYS_NET_DISCONNECTED',
1388 'SYS_NET_DISCONNECTED']
1389
1390 avoid = ('SYS_STATE_CHANGED', 'SYS_LOCAL_RESCAN_DONE',
1391 'SYS_PROTOCOL_VERSION_OK', 'SYS_SET_CAPABILITIES_OK',
1392 'SYS_AUTH_OK', 'SYS_SERVER_RESCAN_DONE')
1393 actual = [event for (event, kwargs) in
1394 self.action_queue.event_queue.events
1395 if event not in avoid]
1396 self.assertEqual(sorted(expected), sorted(actual))
1397
1398 states.MAX_WAITING = orig_waiting
1399
1400
1401class ConnectedBaseTestCase(FactoryBaseTestCase):1298class ConnectedBaseTestCase(FactoryBaseTestCase):
1402 """Base test case generating a connected factory."""1299 """Base test case generating a connected factory."""
14031300
14041301
=== modified file 'tests/syncdaemon/test_interaction_interfaces.py'
--- tests/syncdaemon/test_interaction_interfaces.py 2012-01-17 20:00:44 +0000
+++ tests/syncdaemon/test_interaction_interfaces.py 2012-02-10 13:42:19 +0000
@@ -21,6 +21,7 @@
2121
22from twisted.internet import defer22from twisted.internet import defer
23from ubuntuone.devtools.handlers import MementoHandler23from ubuntuone.devtools.handlers import MementoHandler
24from ubuntu_sso.networkstate import ONLINE
2425
25from contrib.testing.testcase import (26from contrib.testing.testcase import (
26 FakeCommand,27 FakeCommand,
@@ -2208,7 +2209,21 @@
2208 def test_rescan_from_scratch_missing_volume(self):2209 def test_rescan_from_scratch_missing_volume(self):
2209 """Test for rescan_from_scratch with a non-existing volume."""2210 """Test for rescan_from_scratch with a non-existing volume."""
2210 volume_id = object()2211 volume_id = object()
2211 self.assertRaises(ValueError, self.sd_obj.rescan_from_scratch, volume_id)2212 self.assertRaises(ValueError,
2213 self.sd_obj.rescan_from_scratch, volume_id)
2214
2215 def test_network_state_changed_with_connection(self):
2216 """Test the network_state changed method with a connection."""
2217 self.sd_obj.network_state_changed(ONLINE)
2218
2219 self.assertEqual(self.events, [('SYS_NET_CONNECTED', {})])
2220
2221 def test_network_state_changed_without_connection(self):
2222 """Test the network_state changed method without a connection."""
2223 # Sending anything instead of ONLINE should be interpreted as OFFLINE
2224 self.sd_obj.network_state_changed(object())
2225
2226 self.assertEqual(self.events, [('SYS_NET_DISCONNECTED', {})])
22122227
2213 def test_network_connected(self):2228 def test_network_connected(self):
2214 """Test the network_connected method."""2229 """Test the network_connected method."""
22152230
=== modified file 'tests/syncdaemon/test_states.py'
--- tests/syncdaemon/test_states.py 2011-10-27 11:39:43 +0000
+++ tests/syncdaemon/test_states.py 2012-02-10 13:42:19 +0000
@@ -847,58 +847,6 @@
847 self.assertFalse(self.aq.queue.active)847 self.assertFalse(self.aq.queue.active)
848848
849849
850class TestStateManagerPassToNetworkManager(Base):
851 """All network events should go to NetworkManager."""
852
853 @defer.inlineCallbacks
854 def setUp(self):
855 yield super(TestStateManagerPassToNetworkManager,
856 self).setUp()
857
858 # put a function in the middle to log calls
859 self.called_events = []
860 orig_on_event = self.sm.connection.on_event
861 def fake_on_event(event):
862 """Log the call and call original."""
863 self.called_events.append(event)
864 orig_on_event(event)
865 self.sm.connection.on_event = fake_on_event
866
867 def _test(self, event):
868 """Generic test method."""
869 cnt = 0
870 for node in self.sm_nodes_ok:
871 cnt += 1
872 self.sm.state = node
873 self.sm.handle_default(event)
874 self.assertEqual(self.called_events, [event]*cnt)
875
876 def test_net_connected(self):
877 """SYS_NET_CONNECTED should go to Connection no matter where."""
878 self._test('SYS_NET_CONNECTED')
879
880 def test_user_connect(self):
881 """SYS_USER_CONNECT should go to Connection no matter where."""
882 self._test('SYS_USER_CONNECT')
883
884 def test_net_disconnected(self):
885 """SYS_NET_DISCONNECTED should go to Connection no matter where."""
886 self._test('SYS_NET_DISCONNECTED')
887
888 def test_user_disconnect(self):
889 """SYS_USER_DISCONNECT should go to Connection no matter where."""
890 self._test('SYS_USER_DISCONNECT')
891
892 def test_connection_lost(self):
893 """SYS_CONNECTION_LOST should go to Connection no matter where."""
894 self._test('SYS_CONNECTION_LOST')
895
896 def test_handshake_timeout(self):
897 """SYS_HANDSHAKE_TIMEOUT should go to Connection no matter where."""
898 self._test('SYS_HANDSHAKE_TIMEOUT')
899
900
901
902class TestStateManagerPassToQueueManager(Base):850class TestStateManagerPassToQueueManager(Base):
903 """All queue events should go to QueueManager."""851 """All queue events should go to QueueManager."""
904852
905853
=== modified file 'ubuntuone/platform/__init__.py'
--- ubuntuone/platform/__init__.py 2012-01-25 20:49:55 +0000
+++ ubuntuone/platform/__init__.py 2012-02-10 13:42:19 +0000
@@ -31,6 +31,7 @@
31 from ubuntuone.platform import linux31 from ubuntuone.platform import linux
32 source = linux32 source = linux
3333
34# This imports needs to be here in order to belongs to this namespace
34from ubuntuone.platform import credentials35from ubuntuone.platform import credentials
35from ubuntuone.platform import tools36from ubuntuone.platform import tools
3637
3738
=== modified file 'ubuntuone/platform/linux/dbus_interface.py'
--- ubuntuone/platform/linux/dbus_interface.py 2012-01-02 20:24:31 +0000
+++ ubuntuone/platform/linux/dbus_interface.py 2012-02-10 13:42:19 +0000
@@ -41,28 +41,6 @@
41DBUS_IFACE_PUBLIC_FILES_NAME = DBUS_IFACE_NAME + '.PublicFiles'41DBUS_IFACE_PUBLIC_FILES_NAME = DBUS_IFACE_NAME + '.PublicFiles'
42DBUS_IFACE_LAUNCHER_NAME = DBUS_IFACE_NAME + '.Launcher'42DBUS_IFACE_LAUNCHER_NAME = DBUS_IFACE_NAME + '.Launcher'
4343
44# NetworkManager State constants
45NM_STATE_UNKNOWN = 0
46NM_STATE_ASLEEP_OLD = 1
47NM_STATE_ASLEEP = 10
48NM_STATE_CONNECTING_OLD = 2
49NM_STATE_CONNECTING = 40
50NM_STATE_CONNECTED_OLD = 3
51NM_STATE_CONNECTED_LOCAL = 50
52NM_STATE_CONNECTED_SITE = 60
53NM_STATE_CONNECTED_GLOBAL = 70
54NM_STATE_DISCONNECTED_OLD = 4
55NM_STATE_DISCONNECTED = 20
56
57# NM state -> online/offline mapping
58# Note that the LOCAL and SITE mappings are *not* a typo. Local and site links
59# are not enough to connect to one.ubuntu.com, so we treat them as if we were
60# not connected.
61NM_STATE_ONLINE_EVENTS = [
62 NM_STATE_CONNECTED_OLD,
63 NM_STATE_CONNECTED_GLOBAL,
64]
65
66logger = logging.getLogger("ubuntuone.SyncDaemon.DBus")44logger = logging.getLogger("ubuntuone.SyncDaemon.DBus")
6745
6846
@@ -859,39 +837,6 @@
859 self.config = Config(self.busName, service)837 self.config = Config(self.busName, service)
860 self.service = service838 self.service = service
861839
862 def error_handler(error):
863 """Handle errors from NM."""
864 logger.error("Error while getting the NetworkManager state %s",
865 error)
866 # If we get an error back from NetworkManager, we should
867 # just try to connect anyway; it probably means that
868 # NetworkManager is down or broken or something.
869 self.connection_state_changed(NM_STATE_CONNECTED_GLOBAL)
870 try:
871 nm = self.system_bus.get_object(
872 'org.freedesktop.NetworkManager',
873 '/org/freedesktop/NetworkManager',
874 follow_name_owner_changes=True)
875 iface = dbus.Interface(nm, 'org.freedesktop.NetworkManager')
876 except dbus.DBusException, e:
877 if e.get_dbus_name() == \
878 'org.freedesktop.DBus.Error.ServiceUnknown':
879 # NetworkManager isn't running.
880 logger.warn("Unable to connect to NetworkManager. "
881 "Assuming we have network.")
882 self.connection_state_changed(NM_STATE_CONNECTED_GLOBAL)
883 else:
884 raise
885 else:
886 iface.state(reply_handler=self.connection_state_changed,
887 error_handler=error_handler)
888
889 # register a handler to NM StateChanged signal
890 self.system_bus.add_signal_receiver(self.connection_state_changed,
891 signal_name='StateChanged',
892 dbus_interface='org.freedesktop.NetworkManager',
893 path='/org/freedesktop/NetworkManager')
894
895 logger.info('DBusInterface initialized.')840 logger.info('DBusInterface initialized.')
896841
897 def shutdown(self, with_restart=False):842 def shutdown(self, with_restart=False):
@@ -905,11 +850,6 @@
905 self.config.remove_from_connection()850 self.config.remove_from_connection()
906 self.folders.remove_from_connection()851 self.folders.remove_from_connection()
907 self.launcher.remove_from_connection()852 self.launcher.remove_from_connection()
908 # remove the NM's StateChanged signal receiver
909 self.system_bus.remove_signal_receiver(self.connection_state_changed,
910 signal_name='StateChanged',
911 dbus_interface='org.freedesktop.NetworkManager',
912 path='/org/freedesktop/NetworkManager')
913 self.bus.release_name(self.busName.get_name())853 self.bus.release_name(self.busName.get_name())
914 if with_restart:854 if with_restart:
915 # this is what activate_name_owner boils down to, except that855 # this is what activate_name_owner boils down to, except that
@@ -931,10 +871,3 @@
931 not: there is nothing we can do about it.871 not: there is nothing we can do about it.
932 """872 """
933 _restart_error_handler = _restart_reply_handler873 _restart_error_handler = _restart_reply_handler
934
935 def connection_state_changed(self, state):
936 """Push a connection state changed event to the Event Queue."""
937 if state in NM_STATE_ONLINE_EVENTS:
938 self.service.network_connected()
939 else:
940 self.service.network_disconnected()
941874
=== modified file 'ubuntuone/platform/windows/ipc.py'
--- ubuntuone/platform/windows/ipc.py 2012-01-03 12:40:04 +0000
+++ ubuntuone/platform/windows/ipc.py 2012-02-10 13:42:19 +0000
@@ -21,7 +21,6 @@
2121
22from functools import wraps22from functools import wraps
23from collections import defaultdict23from collections import defaultdict
24from threading import Thread
2524
26from twisted.internet import defer, reactor25from twisted.internet import defer, reactor
27from twisted.spread.pb import (26from twisted.spread.pb import (
@@ -38,7 +37,6 @@
38 ActivationInstance,37 ActivationInstance,
39 AlreadyStartedError,38 AlreadyStartedError,
40)39)
41from ubuntuone.platform.windows.network_manager import NetworkManager
4240
43logger = logging.getLogger("ubuntuone.SyncDaemon.Pb")41logger = logging.getLogger("ubuntuone.SyncDaemon.Pb")
44LOCALHOST = "127.0.0.1"42LOCALHOST = "127.0.0.1"
@@ -933,19 +931,6 @@
933 self.factory = PBServerFactory(self)931 self.factory = PBServerFactory(self)
934 self.listener = ipc_server_listen(self.factory)932 self.listener = ipc_server_listen(self.factory)
935933
936 # register to future network changes
937 self.network_manager = NetworkManager(
938 connected_cb=service.network_connected,
939 disconnected_cb=service.network_disconnected)
940 self.network_manager_thread = Thread(
941 target=self.network_manager.register, name='Network changes')
942 self.network_manager_thread.daemon = True
943 self.network_manager_thread.start()
944
945 # XXX: the current network manager is not calling network_connected
946 # for now, let's fake it
947 service.network_connected()
948
949 logger.info('IPC initialized.')934 logger.info('IPC initialized.')
950935
951 def shutdown(self, with_restart=False):936 def shutdown(self, with_restart=False):
952937
=== removed file 'ubuntuone/platform/windows/network_manager.py'
--- ubuntuone/platform/windows/network_manager.py 2011-10-14 20:02:23 +0000
+++ ubuntuone/platform/windows/network_manager.py 1970-01-01 00:00:00 +0000
@@ -1,160 +0,0 @@
1# -*- coding: utf-8 -*-
2#
3# Author: Manuel de la Pena<manuel@canonical.com>
4#
5# Copyright 2011 Canonical Ltd.
6#
7# This program is free software: you can redistribute it and/or modify it
8# under the terms of the GNU General Public License version 3, as published
9# by the Free Software Foundation.
10#
11# This program is distributed in the hope that it will be useful, but
12# WITHOUT ANY WARRANTY; without even the implied warranties of
13# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
14# PURPOSE. See the GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License along
17# with this program. If not, see <http://www.gnu.org/licenses/>.
18"""Implementation of a Network Mnager using ISesNework in Python."""
19import logging
20
21import pythoncom
22
23from win32com.server.policy import DesignatedWrapPolicy
24from win32com.client import Dispatch
25
26# set te logging to store the data in the ubuntuone folder
27logger = logging.getLogger('ubuntuone.platform.windows.NetworkManager')
28
29## from EventSys.h
30PROGID_EventSystem = "EventSystem.EventSystem"
31PROGID_EventSubscription = "EventSystem.EventSubscription"
32
33# SENS (System Event Notification Service) values for the events,
34# this events contain the uuid of the event, the name of the event to be used
35# as well as the method name of the method in the ISesNetwork interface that
36# will be executed for the event.
37# For more ingo look at:
38# http://msdn.microsoft.com/en-us/library/aa377384(v=vs.85).aspx
39
40SUBSCRIPTION_NETALIVE = ('{cd1dcbd6-a14d-4823-a0d2-8473afde360f}',
41 'UbuntuOne Network Alive',
42 'ConnectionMade')
43
44SUBSCRIPTION_NETALIVE_NOQOC = ('{a82f0e80-1305-400c-ba56-375ae04264a1}',
45 'UbuntuOne Net Alive No Info',
46 'ConnectionMadeNoQOCInfo')
47
48SUBSCRIPTION_NETLOST = ('{45233130-b6c3-44fb-a6af-487c47cee611}',
49 'UbuntuOne Network Lost',
50 'ConnectionLost')
51
52SUBSCRIPTION_REACH = ('{4c6b2afa-3235-4185-8558-57a7a922ac7b}',
53 'UbuntuOne Network Reach',
54 'ConnectionMade')
55
56SUBSCRIPTION_REACH_NOQOC = ('{db62fa23-4c3e-47a3-aef2-b843016177cf}',
57 'UbuntuOne Network Reach No Info',
58 'ConnectionMadeNoQOCInfo')
59
60SUBSCRIPTION_REACH_NOQOC2 = ('{d4d8097a-60c6-440d-a6da-918b619ae4b7}',
61 'UbuntuOne Network Reach No Info 2',
62 'ConnectionMadeNoQOCInfo')
63
64SUBSCRIPTIONS = [SUBSCRIPTION_NETALIVE,
65 SUBSCRIPTION_NETALIVE_NOQOC,
66 SUBSCRIPTION_NETLOST,
67 SUBSCRIPTION_REACH,
68 SUBSCRIPTION_REACH_NOQOC,
69 SUBSCRIPTION_REACH_NOQOC2]
70
71SENSGUID_EVENTCLASS_NETWORK = '{d5978620-5b9f-11d1-8dd2-00aa004abd5e}'
72SENSGUID_PUBLISHER = "{5fee1bd6-5b9b-11d1-8dd2-00aa004abd5e}"
73
74# uuid of the implemented com interface
75IID_ISesNetwork = '{d597bab1-5b9f-11d1-8dd2-00aa004abd5e}'
76
77
78class NetworkManager(DesignatedWrapPolicy):
79 """Implement ISesNetwork to know about the network status."""
80
81 _com_interfaces_ = [IID_ISesNetwork]
82 _public_methods_ = ['ConnectionMade',
83 'ConnectionMadeNoQOCInfo',
84 'ConnectionLost']
85 _reg_clsid_ = '{41B032DA-86B5-4907-A7F7-958E59333010}'
86 _reg_progid_ = "UbuntuOne.NetworkManager"
87
88 def __init__(self, connected_cb=None, connected_cb_info=None,
89 disconnected_cb=None):
90 self._wrap_(self)
91 self.connected_cb = connected_cb
92 self.connected_cb_info = connected_cb_info
93 self.disconnected_cb = disconnected_cb
94
95 def ConnectionMade(self, *args):
96 """Tell that the connection is up again."""
97 logger.info('Connection was made.')
98 if self.connected_cb_info:
99 self.connected_cb_info()
100
101 def ConnectionMadeNoQOCInfo(self, *args):
102 """Tell that the connection is up again."""
103 logger.info('Connection was made no info.')
104 if self.connected_cb:
105 self.connected_cb()
106
107 def ConnectionLost(self, *args):
108 """Tell the connection was lost."""
109 logger.info('Connection was lost.')
110 if self.disconnected_cb:
111 self.disconnected_cb()
112
113 def register(self):
114 """Register to listen to network events."""
115 # call the CoInitialize to allow the registration to run in an other
116 # thread
117 pythoncom.CoInitialize()
118 # interface to be used by com
119 manager_interface = pythoncom.WrapObject(self)
120 event_system = Dispatch(PROGID_EventSystem)
121 # register to listent to each of the events to make sure that
122 # the code will work on all platforms.
123 for current_event in SUBSCRIPTIONS:
124 # create an event subscription and add it to the event
125 # service
126 event_subscription = Dispatch(PROGID_EventSubscription)
127 event_subscription.EventClassId = SENSGUID_EVENTCLASS_NETWORK
128 event_subscription.PublisherID = SENSGUID_PUBLISHER
129 event_subscription.SubscriptionID = current_event[0]
130 event_subscription.SubscriptionName = current_event[1]
131 event_subscription.MethodName = current_event[2]
132 event_subscription.SubscriberInterface = manager_interface
133 event_subscription.PerUser = True
134 # store the event
135 try:
136 event_system.Store(PROGID_EventSubscription,
137 event_subscription)
138 except pythoncom.com_error as e:
139 logger.error(
140 'Error registering %s to event %s', e, current_event[1])
141
142 pythoncom.PumpMessages()
143
144if __name__ == '__main__':
145 # Run an expample of the code so that the user can test the code in
146 # real life.
147 from threading import Thread
148
149 def connected():
150 print 'Connected'
151
152 def connected_info():
153 print 'Connected'
154
155 def disconnected():
156 print 'Disconnected'
157
158 manager = NetworkManager(connected, connected_info, disconnected)
159 p = Thread(target=manager.register)
160 p.start()
1610
=== modified file 'ubuntuone/syncdaemon/interaction_interfaces.py'
--- ubuntuone/syncdaemon/interaction_interfaces.py 2012-01-15 19:31:07 +0000
+++ ubuntuone/syncdaemon/interaction_interfaces.py 2012-02-10 13:42:19 +0000
@@ -36,6 +36,8 @@
3636
37from twisted.internet import defer37from twisted.internet import defer
3838
39from ubuntu_sso.networkstate import NetworkManagerState, ONLINE
40
39from ubuntuone.logger import log_call41from ubuntuone.logger import log_call
40from ubuntuone.platform import credentials, ExternalInterface42from ubuntuone.platform import credentials, ExternalInterface
41from ubuntuone.storageprotocol import request43from ubuntuone.storageprotocol import request
@@ -1150,6 +1152,9 @@
1150 super(SyncdaemonService, self).__init__(main, interface)1152 super(SyncdaemonService, self).__init__(main, interface)
11511153
1152 self.send_events = send_events1154 self.send_events = send_events
1155 self.network_manager = NetworkManagerState(
1156 result_cb=self.network_state_changed)
1157 self.network_manager.find_online_state()
11531158
1154 if interface is None:1159 if interface is None:
1155 self.interface = ExternalInterface(service=self)1160 self.interface = ExternalInterface(service=self)
@@ -1283,6 +1288,14 @@
1283 self.main.action_q.rescan_from_scratch(volume.volume_id)1288 self.main.action_q.rescan_from_scratch(volume.volume_id)
12841289
1285 @log_call(logger.debug)1290 @log_call(logger.debug)
1291 def network_state_changed(self, state):
1292 """Receive the connection state and call the proper function."""
1293 if state == ONLINE:
1294 self.network_connected()
1295 else:
1296 self.network_disconnected()
1297
1298 @log_call(logger.debug)
1286 def network_connected(self):1299 def network_connected(self):
1287 """Push the connected event."""1300 """Push the connected event."""
1288 self.main.event_q.push('SYS_NET_CONNECTED')1301 self.main.event_q.push('SYS_NET_CONNECTED')
12891302
=== modified file 'ubuntuone/syncdaemon/states.py'
--- ubuntuone/syncdaemon/states.py 2011-10-14 20:02:23 +0000
+++ ubuntuone/syncdaemon/states.py 2012-02-10 13:42:19 +0000
@@ -400,7 +400,7 @@
400 self._state_changed()400 self._state_changed()
401 return401 return
402402
403 # NetworkManager and User events403 # User events
404 if event in ('SYS_NET_CONNECTED', 'SYS_USER_CONNECT',404 if event in ('SYS_NET_CONNECTED', 'SYS_USER_CONNECT',
405 'SYS_NET_DISCONNECTED', 'SYS_USER_DISCONNECT',405 'SYS_NET_DISCONNECTED', 'SYS_USER_DISCONNECT',
406 'SYS_CONNECTION_LOST', 'SYS_HANDSHAKE_TIMEOUT'):406 'SYS_CONNECTION_LOST', 'SYS_HANDSHAKE_TIMEOUT'):

Subscribers

People subscribed via source and target branches