Merge lp:~verterok/ubuntuone-client/waiting-meta into lp:ubuntuone-client

Proposed by Guillermo Gonzalez
Status: Merged
Approved by: Eric Casteleijn
Approved revision: 416
Merged at revision: not available
Proposed branch: lp:~verterok/ubuntuone-client/waiting-meta
Merge into: lp:ubuntuone-client
Diff against target: 171 lines (+85/-9)
5 files modified
tests/syncdaemon/test_dbus.py (+31/-0)
tests/syncdaemon/test_tools.py (+19/-9)
ubuntuone/syncdaemon/action_queue.py (+16/-0)
ubuntuone/syncdaemon/dbus_interface.py (+9/-0)
ubuntuone/syncdaemon/tools.py (+10/-0)
To merge this branch: bzr merge lp:~verterok/ubuntuone-client/waiting-meta
Reviewer Review Type Date Requested Status
Eric Casteleijn (community) Approve
Rick McBride (community) Approve
Review via email: mp+21004@code.launchpad.net

Commit message

Expose waiting metadata commands via DBus and add waiting_metadata method to SyncDaemonTool.

Description of the change

Expose list of waiting metadata commands via DBus and add the method to SyncDaemonTool.

To post a comment you must log in.
Revision history for this message
Rick McBride (rmcbride) wrote :

+1

review: Approve
Revision history for this message
Eric Casteleijn (thisfred) wrote :

Looks good, tests green!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/syncdaemon/test_dbus.py'
2--- tests/syncdaemon/test_dbus.py 2010-03-09 17:29:18 +0000
3+++ tests/syncdaemon/test_dbus.py 2010-03-09 22:18:13 +0000
4@@ -63,6 +63,12 @@
5 """Just succeed."""
6 return defer.succeed(None)
7
8+ def __str__(self):
9+ name = self.__class__.__name__
10+ tmpl = name + "(" + "share_id=%s, node_id=%s" + ")"
11+ return tmpl % (self.share_id,
12+ self.node_id)
13+
14
15 class DBusInterfaceTests(DBusTwistedTestCase):
16 """ Basic tests to the objects exposed with D-Bus"""
17@@ -253,6 +259,31 @@
18 error_handler=self.error_handler)
19 return d
20
21+ def test_waiting_metadata(self):
22+ """Test Status.waiting_metadata with fake data in the AQ."""
23+ # inject the fake data
24+ self.action_q.meta_queue.waiting.extend([
25+ FakeCommand("node_a_foo", "node_a_bar"),
26+ FakeCommand("node_b_foo", "node_b_bar")])
27+ # OK, testing time
28+ client = DBusClient(self.bus, '/status', DBUS_IFACE_STATUS_NAME)
29+ d = defer.Deferred()
30+ def waiting_handler(result):
31+ """waiting_metadata reply handler."""
32+ self.assertEquals(2, len(result))
33+ # the second time we're called, the result should be reversed
34+ node_a, node_b = result
35+ self.assertEquals(str(FakeCommand("node_a_foo", "node_a_bar")),
36+ node_a)
37+ self.assertEquals(str(FakeCommand("node_b_foo", "node_b_bar")),
38+ node_b)
39+ d.callback(True)
40+ client.call_method('waiting_metadata',
41+ reply_handler=waiting_handler,
42+ error_handler=self.error_handler)
43+ return d
44+
45+
46 def test_contq_changed(self):
47 """Test the Status.ContentQueueChanged signal."""
48 # prepare the VM so it lies for us
49
50=== modified file 'tests/syncdaemon/test_tools.py'
51--- tests/syncdaemon/test_tools.py 2010-03-03 15:04:02 +0000
52+++ tests/syncdaemon/test_tools.py 2010-03-09 22:18:13 +0000
53@@ -26,6 +26,7 @@
54 volume_manager,
55 states,
56 )
57+from tests.syncdaemon.test_dbus import FakeCommand
58 from contrib.testing.testcase import (
59 DBusTwistedTestCase,
60 )
61@@ -298,17 +299,26 @@
62 d.addCallbacks(handler, self.fail)
63 return d
64
65+ def test_waiting_metadata(self):
66+ """Test SyncDaemonTool.waiting_metadata."""
67+ # inject the fake data
68+ self.action_q.meta_queue.waiting.extend([
69+ FakeCommand("node_a_foo", "node_a_bar"),
70+ FakeCommand("node_b_foo", "node_b_bar")])
71+ d = self.tool.waiting_metadata()
72+ def check(result):
73+ """waiting_metadata reply handler."""
74+ self.assertEquals(2, len(result))
75+ # the second time we're called, the result should be reversed
76+ node_a, node_b = result
77+ self.assertEquals(str(FakeCommand("node_a_foo", "node_a_bar")),
78+ node_a)
79+ self.assertEquals(str(FakeCommand("node_b_foo", "node_b_bar")),
80+ node_b)
81+ return d
82+
83 def test_waiting_content_schedule_next(self):
84 """Test waiting_content and schedule_next"""
85- class FakeCommand(object):
86- """A fake command"""
87- def __init__(self, share_id, node_id):
88- """create it"""
89- self.share_id = share_id
90- self.node_id = node_id
91- def is_runnable(self):
92- """is runnable"""
93- return True
94 path = os.path.join(self.root_dir, "foo")
95 self.fs_manager.create(path, "")
96 self.fs_manager.set_node_id(path, "node_id")
97
98=== modified file 'ubuntuone/syncdaemon/action_queue.py'
99--- ubuntuone/syncdaemon/action_queue.py 2010-03-09 15:42:50 +0000
100+++ ubuntuone/syncdaemon/action_queue.py 2010-03-09 22:18:13 +0000
101@@ -1419,6 +1419,17 @@
102 """Returns the action queue."""
103 return self._queue.action_queue
104
105+ def __str__(self, str_attrs=None):
106+ """Return a str representation of the instance."""
107+ if str_attrs is None:
108+ str_attrs = self.logged_attrs
109+ name = self.__class__.__name__
110+ if len(str_attrs) == 0:
111+ return name
112+ attrs = [str(attr) + '=' + str(getattr(self, attr, None) or 'None') \
113+ for attr in str_attrs]
114+ return ''.join([name, '(', ', '.join([attr for attr in attrs]), ')'])
115+
116
117 class WaitForCondition(ActionQueueCommand):
118 """A command which waits for some condition to be satisfied."""
119@@ -2257,6 +2268,11 @@
120
121 is_dir = True
122
123+ def __str__(self):
124+ """Return a str representation of the instance."""
125+ to_show = ('share_id', 'node_id', 'server_hash')
126+ return super(ListDir, self).__str__(str_attrs=to_show)
127+
128
129 class Download(GetContentMixin, ActionQueueCommand):
130 """Get the contents of a file."""
131
132=== modified file 'ubuntuone/syncdaemon/dbus_interface.py'
133--- ubuntuone/syncdaemon/dbus_interface.py 2010-03-09 21:11:16 +0000
134+++ ubuntuone/syncdaemon/dbus_interface.py 2010-03-09 22:18:13 +0000
135@@ -191,6 +191,15 @@
136 current_downloads.append(entry)
137 return current_downloads
138
139+ @dbus.service.method(DBUS_IFACE_STATUS_NAME, out_signature='as')
140+ def waiting_metadata(self):
141+ """Return a list of the operations in the meta-queue."""
142+ logger.debug('called waiting_metadata')
143+ waiting_metadata = []
144+ for cmd in self.action_queue.meta_queue.waiting:
145+ waiting_metadata.append(str(cmd))
146+ return waiting_metadata
147+
148 @dbus.service.method(DBUS_IFACE_STATUS_NAME, out_signature='aa{ss}')
149 def waiting_content(self):
150 """
151
152=== modified file 'ubuntuone/syncdaemon/tools.py'
153--- ubuntuone/syncdaemon/tools.py 2010-03-09 15:45:46 +0000
154+++ ubuntuone/syncdaemon/tools.py 2010-03-09 22:18:13 +0000
155@@ -593,6 +593,16 @@
156 error_handler=d.errback)
157 return d
158
159+ def waiting_metadata(self):
160+ """Return a description of the waiting metadata queue elements."""
161+ d = defer.Deferred()
162+ status_client = DBusClient(self.bus, '/status',
163+ DBUS_IFACE_STATUS_NAME)
164+ status_client.call_method('waiting_metadata',
165+ reply_handler=d.callback,
166+ error_handler=d.errback)
167+ return d
168+
169 def waiting_content(self):
170 """Returns the waiting content queue elements."""
171 d = defer.Deferred()

Subscribers

People subscribed via source and target branches