Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@sugarlabs.org>2013-05-24 00:32:40 (GMT)
committer Aleksey Lim <alsroot@sugarlabs.org>2013-05-24 00:32:40 (GMT)
commit70514d40be33c04fa5519fd815c69e31ac2308f6 (patch)
treed63d2ef51b594fc98baf16f34162b59030a2b2f1
parent0f9a19da6d7e536c5cd390e4bb96c9feeab74949 (diff)
Use app level API access for webui on node side
-rwxr-xr-xsugar-network3
-rwxr-xr-xsugar-network-client2
-rwxr-xr-xsugar-network-node10
-rw-r--r--sugar_network/client/commands.py38
-rw-r--r--tests/__init__.py4
-rwxr-xr-xtests/units/client/commands.py14
-rwxr-xr-xtests/units/client/offline_commands.py2
-rwxr-xr-xtests/units/client/online_commands.py2
-rwxr-xr-xtests/units/client/server_commands.py6
9 files changed, 43 insertions, 38 deletions
diff --git a/sugar-network b/sugar-network
index 60b09e1..6a6d45f 100755
--- a/sugar-network
+++ b/sugar-network
@@ -155,7 +155,8 @@ class Application(application.Application):
if not client.anonymous.value:
util.ensure_key(client.key_path())
home = Volume(client.path('db'))
- cp = ClientCommands(home, offline=offline.value,
+ cp = ClientCommands(home,
+ client.api_url.value if not offline.value else None,
no_subscription=True)
if not offline.value:
for __ in cp.subscribe(event='inline', state='online'):
diff --git a/sugar-network-client b/sugar-network-client
index 284fa0e..2bbdd5b 100755
--- a/sugar-network-client
+++ b/sugar-network-client
@@ -106,7 +106,7 @@ class Application(application.Daemon):
util.ensure_key(client.key_path())
volume = Volume(client.path('db'), lazy_open=client.lazy_open.value)
commands = CachedClientCommands(volume,
- server_mode=client.server_mode.value)
+ client.api_url.value if not client.server_mode.value else None)
logging.info('Listening for IPC requests on %s port',
client.ipc_port.value)
diff --git a/sugar-network-node b/sugar-network-node
index 05538ad..835859b 100755
--- a/sugar-network-node
+++ b/sugar-network-node
@@ -88,12 +88,14 @@ class Application(application.Daemon):
client.sugar_uid = lambda: 'demo'
# Point client API to volume directly
client.mounts_root.value = None
- client_commands = _ClientCommands(volume, offline=True)
-
+ home_volume = Volume(join(application.rundir.value, 'db'))
+ client_commands = _ClientCommands(home_volume,
+ api_url='http://localhost:%s' % node.port.value,
+ static_prefix=client.api_url.value)
host = (node.host.value, webui.webui_port.value)
logging.info('Start Web server on %s:%s port', *host)
server = coroutine.WSGIServer(host,
- webui.get_app(client_commands, client.api_url.value))
+ webui.get_app(client_commands, client.api_url.value, True))
self.jobs.spawn(server.serve_forever)
try:
@@ -121,7 +123,7 @@ class Application(application.Daemon):
def _ensure_instance(self):
enforce(self.check_for_instance(), 'Node is not started')
- return Client('http://localhost:%s' % node.port.value)
+ return Client('http://localhost:%s' % node.port.value, trust_env=False)
# Let toolkit.http work in concurrence
diff --git a/sugar_network/client/commands.py b/sugar_network/client/commands.py
index e99235c..6352956 100644
--- a/sugar_network/client/commands.py
+++ b/sugar_network/client/commands.py
@@ -40,8 +40,8 @@ _logger = logging.getLogger('client.commands')
class ClientCommands(db.CommandsProcessor, Commands, journal.Commands):
- def __init__(self, home_volume, server_mode=False, offline=False,
- no_subscription=False):
+ def __init__(self, home_volume, api_url=None, no_subscription=False,
+ static_prefix=None):
db.CommandsProcessor.__init__(self)
Commands.__init__(self)
if not client.no_dbus.value:
@@ -53,23 +53,24 @@ class ClientCommands(db.CommandsProcessor, Commands, journal.Commands):
self._node = None
self._node_job = coroutine.Pool()
self._jobs = coroutine.Pool()
- self._static_prefix = 'http://localhost:%s' % client.ipc_port.value
- self._offline = offline
self._no_subscription = no_subscription
- self._server_mode = server_mode
+ self._server_mode = not api_url
+
+ if not static_prefix:
+ static_prefix = 'http://localhost:%s' % client.ipc_port.value
+ self._static_prefix = static_prefix
home_volume.connect(self._home_event_cb)
- if not offline:
- if server_mode:
- mountpoints.connect(_SN_DIRNAME,
- self._found_mount, self._lost_mount)
+ if self._server_mode:
+ mountpoints.connect(_SN_DIRNAME,
+ self._found_mount, self._lost_mount)
+ else:
+ if client.discover_server.value:
+ self._jobs.spawn(self._discover_node)
else:
- if client.discover_server.value:
- self._jobs.spawn(self._discover_node)
- else:
- self._remote_urls.append(client.api_url.value)
- self._jobs.spawn(self._wait_for_connectivity)
+ self._remote_urls.append(api_url)
+ self._jobs.spawn(self._wait_for_connectivity)
def close(self):
self._jobs.kill()
@@ -114,8 +115,7 @@ class ClientCommands(db.CommandsProcessor, Commands, journal.Commands):
@db.volume_command(method='GET', cmd='inline',
mime_type='application/json')
def inline(self):
- if not self._offline and not self._server_mode and \
- not self._inline.is_set():
+ if not self._server_mode and not self._inline.is_set():
self._remote_connect()
return self._inline.is_set()
@@ -539,8 +539,10 @@ class ClientCommands(db.CommandsProcessor, Commands, journal.Commands):
class CachedClientCommands(ClientCommands):
- def __init__(self, home_volume, server_mode=False, offline=False):
- ClientCommands.__init__(self, home_volume, server_mode, offline)
+ def __init__(self, home_volume, api_url=None, no_subscription=False,
+ static_prefix=None):
+ ClientCommands.__init__(self, home_volume, api_url, no_subscription,
+ static_prefix)
self._push_seq = util.PersistentSequence(
join(home_volume.root, 'push.sequence'), [1, None])
self._push_job = coroutine.Pool()
diff --git a/tests/__init__.py b/tests/__init__.py
index 52e5706..014f628 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -266,7 +266,7 @@ class Test(unittest.TestCase):
classes = [User, Context, Implementation]
self.start_master(classes)
volume = Volume('client', classes)
- commands = ClientCommands(volume)
+ commands = ClientCommands(volume, client.api_url.value)
self.wait_for_events(commands, event='inline', state='online').wait()
self.client = coroutine.WSGIServer(
('localhost', client.ipc_port.value), IPCRouter(commands))
@@ -278,7 +278,7 @@ class Test(unittest.TestCase):
if classes is None:
classes = [User, Context, Implementation]
volume = Volume('client', classes)
- commands = ClientCommands(volume, server_mode=True)
+ commands = ClientCommands(volume)
self.client = coroutine.WSGIServer(
('localhost', client.ipc_port.value), IPCRouter(commands))
coroutine.spawn(self.client.serve_forever)
diff --git a/tests/units/client/commands.py b/tests/units/client/commands.py
index 39ace93..3459ed6 100755
--- a/tests/units/client/commands.py
+++ b/tests/units/client/commands.py
@@ -21,7 +21,7 @@ class CommandsTest(tests.Test):
def test_Hub(self):
volume = Volume('db')
- cp = ClientCommands(volume, offline=True)
+ cp = ClientCommands(volume)
server = coroutine.WSGIServer(
('localhost', client.ipc_port.value), IPCRouter(cp))
coroutine.spawn(server.serve_forever)
@@ -46,7 +46,7 @@ class CommandsTest(tests.Test):
def test_launch(self):
self.override(injector, 'launch', lambda *args, **kwargs: [{'args': args, 'kwargs': kwargs}])
volume = Volume('db')
- cp = ClientCommands(volume, offline=True)
+ cp = ClientCommands(volume)
self.assertRaises(RuntimeError, cp.launch, 'fake-document', 'app', [])
@@ -60,7 +60,7 @@ class CommandsTest(tests.Test):
self.override(injector, 'launch', lambda *args, **kwargs: [{'args': args, 'kwargs': kwargs}])
self.override(journal, 'exists', lambda *args: True)
volume = Volume('db')
- cp = ClientCommands(volume, offline=True)
+ cp = ClientCommands(volume)
trigger = self.wait_for_events(cp, event='launch')
cp.launch('context', 'app', [], object_id='object_id')
@@ -166,7 +166,7 @@ class CommandsTest(tests.Test):
def test_SetLocalLayerInOffline(self):
volume = Volume('client')
- cp = ClientCommands(volume)
+ cp = ClientCommands(volume, client.api_url.value)
post = db.Request(method='POST', document='context')
post.content_type = 'application/json'
post.content = {
@@ -189,7 +189,7 @@ class CommandsTest(tests.Test):
def test_CachedClientCommands(self):
volume = Volume('client')
- cp = CachedClientCommands(volume)
+ cp = CachedClientCommands(volume, client.api_url.value)
post = db.Request(method='POST', document='context')
post.content_type = 'application/json'
@@ -234,7 +234,7 @@ class CommandsTest(tests.Test):
def test_CachedClientCommands_WipeReports(self):
volume = Volume('client')
- cp = CachedClientCommands(volume)
+ cp = CachedClientCommands(volume, client.api_url.value)
post = db.Request(method='POST', document='report')
post.content_type = 'application/json'
@@ -255,7 +255,7 @@ class CommandsTest(tests.Test):
def test_SwitchToOfflineForAbsentOnlineProps(self):
volume = Volume('client')
- cp = ClientCommands(volume)
+ cp = ClientCommands(volume, client.api_url.value)
post = db.Request(method='POST', document='context')
post.content_type = 'application/json'
diff --git a/tests/units/client/offline_commands.py b/tests/units/client/offline_commands.py
index 9f19f3a..3303a5c 100755
--- a/tests/units/client/offline_commands.py
+++ b/tests/units/client/offline_commands.py
@@ -18,7 +18,7 @@ class OfflineCommandsTest(tests.Test):
def setUp(self):
tests.Test.setUp(self)
self.home_volume = Volume('db')
- commands = ClientCommands(self.home_volume, offline=True)
+ commands = ClientCommands(self.home_volume)
server = coroutine.WSGIServer(('localhost', client.ipc_port.value), IPCRouter(commands))
coroutine.spawn(server.serve_forever)
coroutine.dispatch()
diff --git a/tests/units/client/online_commands.py b/tests/units/client/online_commands.py
index f0d1c77..d6a7510 100755
--- a/tests/units/client/online_commands.py
+++ b/tests/units/client/online_commands.py
@@ -24,7 +24,7 @@ import requests
class OnlineCommandsTest(tests.Test):
def test_inline(self):
- cp = ClientCommands(Volume('client'))
+ cp = ClientCommands(Volume('client'), client.api_url.value)
assert not cp.inline()
trigger = self.wait_for_events(cp, event='inline', state='online')
diff --git a/tests/units/client/server_commands.py b/tests/units/client/server_commands.py
index 7e3e577..59be857 100755
--- a/tests/units/client/server_commands.py
+++ b/tests/units/client/server_commands.py
@@ -20,7 +20,7 @@ class ServerCommandsTest(tests.Test):
def start_node(self):
os.makedirs('disk/sugar-network')
self.node_volume = Volume('db')
- cp = ClientCommands(self.node_volume, server_mode=True)
+ cp = ClientCommands(self.node_volume)
trigger = self.wait_for_events(cp, event='inline', state='online')
coroutine.spawn(mountpoints.monitor, tests.tmpdir)
trigger.wait()
@@ -32,7 +32,7 @@ class ServerCommandsTest(tests.Test):
def test_PopulateNode(self):
os.makedirs('disk/sugar-network')
volume = Volume('db')
- cp = ClientCommands(volume, server_mode=True)
+ cp = ClientCommands(volume)
assert not cp.inline()
trigger = self.wait_for_events(cp, event='inline', state='online')
@@ -42,7 +42,7 @@ class ServerCommandsTest(tests.Test):
def test_MountNode(self):
volume = Volume('db')
- cp = ClientCommands(volume, server_mode=True)
+ cp = ClientCommands(volume)
trigger = self.wait_for_events(cp, event='inline', state='online')
mountpoints.populate('.')