Merge lp:~alecu/ubuntuone-client/use-staggered-sso-ports into lp:ubuntuone-client

Proposed by Alejandro J. Cura
Status: Merged
Approved by: Natalia Bidart
Approved revision: 1070
Merged at revision: 1073
Proposed branch: lp:~alecu/ubuntuone-client/use-staggered-sso-ports
Merge into: lp:ubuntuone-client
Diff against target: 292 lines (+103/-36)
6 files modified
bin/ubuntuone-syncdaemon (+34/-14)
tests/platform/windows/test_ipc.py (+31/-3)
tests/platform/windows/test_tools.py (+3/-3)
ubuntuone/platform/linux/__init__.py (+5/-1)
ubuntuone/platform/windows/__init__.py (+6/-7)
ubuntuone/platform/windows/ipc.py (+24/-8)
To merge this branch: bzr merge lp:~alecu/ubuntuone-client/use-staggered-sso-ports
Reviewer Review Type Date Requested Status
Natalia Bidart (community) Approve
Roberto Alsina (community) Approve
Review via email: mp+68922@code.launchpad.net

Commit message

Calculate the pb port number from the user id and use tcpactivation to only start one instance.

Description of the change

Calculate the pb port number from the user id and use tcpactivation to only start one instance.

To post a comment you must log in.
1067. By Alejandro J. Cura

merged trunk in

Revision history for this message
Roberto Alsina (ralsina) wrote :

+1 IRL and code review

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

Text conflict in ubuntuone/platform/windows/__init__.py
1 conflicts encountered.

review: Needs Fixing
1068. By Alejandro J. Cura

merged trunk in

1069. By Alejandro J. Cura

merged with trunk

1070. By Alejandro J. Cura

ugly workaround for the circular import on the windows platform modules (see LP: #817559)

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

All good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bin/ubuntuone-syncdaemon'
--- bin/ubuntuone-syncdaemon 2011-07-26 02:26:33 +0000
+++ bin/ubuntuone-syncdaemon 2011-07-28 14:37:29 +0000
@@ -45,17 +45,28 @@
4545
46from ubuntuone.syncdaemon.main import Main46from ubuntuone.syncdaemon.main import Main
4747
48from twisted.internet import reactor48from twisted.internet import reactor, defer
49from ubuntuone.platform.xdg_base_directory import (49from ubuntuone.platform.xdg_base_directory import (
50 xdg_cache_home,50 xdg_cache_home,
51 xdg_data_home,51 xdg_data_home,
52)52)
5353
5454
55class DeathException(Exception):
56 """The process has commited seppuku."""
57
58
55def die(msg):59def die(msg):
60 """Write the error message an die."""
56 logger.root_logger.warning(msg)61 logger.root_logger.warning(msg)
57 sys.stderr.write(msg + '\n')62 sys.stderr.write(msg + '\n')
58 sys.exit(1)63 raise DeathException()
64
65
66def check_death(failure):
67 """Stop the reactor and exit the process."""
68 failure.trap(DeathException)
69 reactor.callWhenRunning(reactor.stop)
5970
6071
61def main(argv):72def main(argv):
@@ -69,7 +80,24 @@
69 configs.extend(get_config_files())80 configs.extend(get_config_files())
70 (parser, options, argv) = config.configglue(file(configs[0]), *configs[1:],81 (parser, options, argv) = config.configglue(file(configs[0]), *configs[1:],
71 args=args, usage=usage)82 args=args, usage=usage)
7283 d = async_main(parser, options, argv)
84 d.addErrback(check_death)
85
86 if options.debug_lsprof_file:
87 try:
88 from bzrlib.lsprof import profile
89 ret, stats = profile(reactor.run)
90 stats.save(options.debug_lsprof_file)
91 except ImportError:
92 logger.root_logger.warning('bzrlib.lsprof not available')
93 reactor.run()
94 else:
95 reactor.run()
96
97
98@defer.inlineCallbacks
99def async_main(parser, options, argv):
100 """The client entry point that can yield."""
73 logger.init()101 logger.init()
74 if options.debug:102 if options.debug:
75 logger.set_debug('stdout file')103 logger.set_debug('stdout file')
@@ -92,7 +120,9 @@
92 die('Files synchronization is disabled.')120 die('Files synchronization is disabled.')
93121
94 # check if there is another instance running122 # check if there is another instance running
95 if is_already_running():123 is_running = yield is_already_running()
124
125 if is_running:
96 die('Another instance is running')126 die('Another instance is running')
97127
98 # check if we are using xdg_data_home and it doesn't exists128 # check if we are using xdg_data_home and it doesn't exists
@@ -173,16 +203,6 @@
173 guppy.heapy.RM.on()203 guppy.heapy.RM.on()
174204
175 main.start()205 main.start()
176 if options.debug_lsprof_file:
177 try:
178 from bzrlib.lsprof import profile
179 ret, stats = profile(reactor.run)
180 stats.save(options.debug_lsprof_file)
181 except ImportError:
182 logger.root_logger.warning('bzrlib.lsprof not available')
183 reactor.run()
184 else:
185 reactor.run()
186206
187207
188if __name__ == '__main__':208if __name__ == '__main__':
189209
=== modified file 'tests/platform/windows/test_ipc.py'
--- tests/platform/windows/test_ipc.py 2011-07-27 20:38:16 +0000
+++ tests/platform/windows/test_ipc.py 2011-07-28 14:37:29 +0000
@@ -61,7 +61,7 @@
61 SharesClient61 SharesClient
62)62)
6363
64TEST_HOST_PORT = "127.0.0.1", 4040464TEST_PORT = 40404
6565
6666
67class FakeActivationClient(object):67class FakeActivationClient(object):
@@ -95,7 +95,7 @@
9595
96 def setUp(self):96 def setUp(self):
97 """Initialize this test instance."""97 """Initialize this test instance."""
98 self.patch(ipc, "HOST_PORT", TEST_HOST_PORT)98 self.patch(ipc, "get_sd_pb_port", lambda: TEST_PORT)
99 self.patch(ipc, "ActivationClient", FakeActivationClient)99 self.patch(ipc, "ActivationClient", FakeActivationClient)
100100
101101
@@ -756,7 +756,7 @@
756 yield ipc_client_connect(fake_factory)756 yield ipc_client_connect(fake_factory)
757 self.assertEqual(len(fake_reactor.connections), 1)757 self.assertEqual(len(fake_reactor.connections), 1)
758 c = fake_reactor.connections[0]758 c = fake_reactor.connections[0]
759 self.assertEqual(c.port, TEST_HOST_PORT[1])759 self.assertEqual(c.port, TEST_PORT)
760 self.assertEqual(c.factory, fake_factory)760 self.assertEqual(c.factory, fake_factory)
761761
762762
@@ -3377,3 +3377,31 @@
3377 """Test the connect method when autoconnecting fails."""3377 """Test the connect method when autoconnecting fails."""
3378 d = self.ipc.connect(autoconnecting=True)3378 d = self.ipc.connect(autoconnecting=True)
3379 yield self.assertFailure(d, ipc.NoAccessToken)3379 yield self.assertFailure(d, ipc.NoAccessToken)
3380
3381
3382class IPCPortTestCase(TestCase):
3383 """Tests for the ipc port setup."""
3384
3385 def test_get_sd_pb_port(self):
3386 """A test for the get_sd_pb_port function."""
3387 sso_port = 50001
3388 self.patch(ipc, "get_sso_pb_port", lambda: sso_port)
3389 result = ipc.get_sd_pb_port()
3390 expected = sso_port + ipc.SD_SSO_PORT_OFFSET
3391 self.assertEqual(result, expected)
3392
3393 @defer.inlineCallbacks
3394 def test_is_already_running_no(self):
3395 """Test the is_already_running function."""
3396 self.patch(ipc.ActivationInstance, "get_port",
3397 lambda _: defer.succeed(TEST_PORT))
3398 is_running = yield ipc.is_already_running()
3399 self.assertFalse(is_running, "Should not be running.")
3400
3401 @defer.inlineCallbacks
3402 def test_is_already_running_yes(self):
3403 """Test the is_already_running function."""
3404 self.patch(ipc.ActivationInstance, "get_port",
3405 lambda _: defer.fail(ipc.AlreadyStartedError()))
3406 is_running = yield ipc.is_already_running()
3407 self.assertTrue(is_running, "Should be running by now.")
33803408
=== modified file 'tests/platform/windows/test_tools.py'
--- tests/platform/windows/test_tools.py 2011-07-27 20:38:16 +0000
+++ tests/platform/windows/test_tools.py 2011-07-28 14:37:29 +0000
@@ -43,7 +43,7 @@
43 SyncDaemonTool,43 SyncDaemonTool,
44)44)
4545
46TEST_TOOLS_HOST_PORT = "127.0.0.1", 4040546TEST_TOOLS_PORT = 40405
4747
4848
49class SaveProtocolServerFactory(PBServerFactory):49class SaveProtocolServerFactory(PBServerFactory):
@@ -136,9 +136,9 @@
136 self.folders, self.files)136 self.folders, self.files)
137 self.server_factory = SaveProtocolServerFactory(self.syncdaemon_root)137 self.server_factory = SaveProtocolServerFactory(self.syncdaemon_root)
138 # pylint: disable=E1101138 # pylint: disable=E1101
139 self.patch(ipc, "HOST_PORT", TEST_TOOLS_HOST_PORT)139 self.patch(ipc, "get_sd_pb_port", lambda: TEST_TOOLS_PORT)
140 self.patch(ipc.ActivationClient, "get_active_port",140 self.patch(ipc.ActivationClient, "get_active_port",
141 lambda _: defer.succeed(TEST_TOOLS_HOST_PORT[1]))141 lambda _: defer.succeed(TEST_TOOLS_PORT))
142 self.listener = ipc_server_listen(self.server_factory)142 self.listener = ipc_server_listen(self.server_factory)
143 self.sdtool = SyncDaemonTool()143 self.sdtool = SyncDaemonTool()
144144
145145
=== modified file 'ubuntuone/platform/linux/__init__.py'
--- ubuntuone/platform/linux/__init__.py 2011-07-27 20:38:16 +0000
+++ ubuntuone/platform/linux/__init__.py 2011-07-28 14:37:29 +0000
@@ -24,6 +24,7 @@
2424
25import dbus25import dbus
26from dbus.mainloop.glib import DBusGMainLoop26from dbus.mainloop.glib import DBusGMainLoop
27from twisted.internet import defer
2728
28from ubuntuone.platform.linux.os_helper import (29from ubuntuone.platform.linux.os_helper import (
29 access,30 access,
@@ -101,4 +102,7 @@
101 bus = dbus.SessionBus()102 bus = dbus.SessionBus()
102 request = bus.request_name(dbus_interface.DBUS_IFACE_NAME,103 request = bus.request_name(dbus_interface.DBUS_IFACE_NAME,
103 dbus.bus.NAME_FLAG_DO_NOT_QUEUE)104 dbus.bus.NAME_FLAG_DO_NOT_QUEUE)
104 return request == dbus.bus.REQUEST_NAME_REPLY_EXISTS105 if request == dbus.bus.REQUEST_NAME_REPLY_EXISTS:
106 return defer.succeed(True)
107 else:
108 return defer.succeed(False)
105109
=== modified file 'ubuntuone/platform/windows/__init__.py'
--- ubuntuone/platform/windows/__init__.py 2011-07-27 20:38:16 +0000
+++ ubuntuone/platform/windows/__init__.py 2011-07-28 14:37:29 +0000
@@ -63,6 +63,12 @@
63from ubuntuone.platform.windows.notification import Notification63from ubuntuone.platform.windows.notification import Notification
6464
6565
66def is_already_running():
67 """An ugly workaround for circular imports, see bug #817559."""
68 from ubuntuone.platform.windows.ipc import is_already_running
69 return is_already_running()
70
71
66class ExternalInterface(object):72class ExternalInterface(object):
67 """An ExternalInterface implemented with a IPC interface."""73 """An ExternalInterface implemented with a IPC interface."""
6874
@@ -92,10 +98,3 @@
9298
93 def connect(self, *args, **kwargs):99 def connect(self, *args, **kwargs):
94 self.dbus_iface.connect(*args, **kwargs)100 self.dbus_iface.connect(*args, **kwargs)
95
96
97def is_already_running():
98 """Return if the sd is running by asking the named pipe."""
99 #TODO: Do not start two instances of this process
100 # https://launchpad.net/bugs/803672
101 return False
102101
=== modified file 'ubuntuone/platform/windows/ipc.py'
--- ubuntuone/platform/windows/ipc.py 2011-07-21 14:54:14 +0000
+++ ubuntuone/platform/windows/ipc.py 2011-07-28 14:37:29 +0000
@@ -29,8 +29,13 @@
29 Referenceable,29 Referenceable,
30 Root,30 Root,
31)31)
32from ubuntu_sso.main.windows import get_activation_cmdline32from ubuntu_sso.main.windows import get_activation_cmdline, get_sso_pb_port
33from ubuntu_sso.utils.tcpactivation import ActivationClient, ActivationConfig33from ubuntu_sso.utils.tcpactivation import (
34 ActivationClient,
35 ActivationConfig,
36 ActivationInstance,
37 AlreadyStartedError,
38)
34from ubuntuone.syncdaemon.interfaces import IMarker39from ubuntuone.syncdaemon.interfaces import IMarker
35from ubuntuone.platform.windows import CredentialsManagementTool40from ubuntuone.platform.windows import CredentialsManagementTool
36from ubuntuone.platform.windows.network_manager import NetworkManager41from ubuntuone.platform.windows.network_manager import NetworkManager
@@ -51,19 +56,19 @@
5156
52logger = logging.getLogger("ubuntuone.SyncDaemon.Pb")57logger = logging.getLogger("ubuntuone.SyncDaemon.Pb")
53LOCALHOST = "127.0.0.1"58LOCALHOST = "127.0.0.1"
54HOST_PORT = LOCALHOST, 5000259SD_SSO_PORT_OFFSET = 1
55SD_SERVICE_NAME = "ubuntuone-syncdaemon"60SD_SERVICE_NAME = "ubuntuone-syncdaemon"
56CLIENT_NOT_PROCESSED = -161CLIENT_NOT_PROCESSED = -1
5762
5863
59def get_sd_pb_hostport():64def get_sd_pb_port():
60 """Returns the host and port for this user."""65 """Returns the host and port for this user."""
61 return HOST_PORT66 return get_sso_pb_port() + SD_SSO_PORT_OFFSET
6267
6368
64def get_activation_config():69def get_activation_config():
65 """Get the configuration to activate the sso service."""70 """Get the configuration to activate the sso service."""
66 _, port = get_sd_pb_hostport()71 port = get_sd_pb_port()
67 service_name = SD_SERVICE_NAME72 service_name = SD_SERVICE_NAME
68 cmdline = get_activation_cmdline(service_name)73 cmdline = get_activation_cmdline(service_name)
69 return ActivationConfig(service_name, cmdline, port)74 return ActivationConfig(service_name, cmdline, port)
@@ -71,9 +76,20 @@
7176
72def ipc_server_listen(server_factory):77def ipc_server_listen(server_factory):
73 """Connect the IPC server factory."""78 """Connect the IPC server factory."""
74 host, port = get_sd_pb_hostport()79 port = get_sd_pb_port()
75 # pylint: disable=E110180 # pylint: disable=E1101
76 return reactor.listenTCP(port, server_factory, interface=host)81 return reactor.listenTCP(port, server_factory, interface=LOCALHOST)
82
83
84@defer.inlineCallbacks
85def is_already_running():
86 """Return if the sd is running by trying to get the port."""
87 ai = ActivationInstance(get_activation_config())
88 try:
89 yield ai.get_port()
90 defer.returnValue(False)
91 except AlreadyStartedError:
92 defer.returnValue(True)
7793
7894
79@defer.inlineCallbacks95@defer.inlineCallbacks

Subscribers

People subscribed via source and target branches