Permalink
Browse files

taskOwner: only return False when we are sure the task isn't ours

There's a race between receiving the task URI and the call to
taskOwner.ping: solve this by returning True when we aren't sure
which task URI we own.

Improve debugability by adding a taskOwner.tasks property.

Signed-off-by: David Scott <dave.scott@eu.citrix.com>
  • Loading branch information...
1 parent 5dfdda3 commit 06541001866ec17f70fd88ddf155e04e658aed80 David Scott committed Feb 11, 2014
Showing with 26 additions and 4 deletions.
  1. +16 −3 dbus/vm/python/dbus-call.py
  2. +10 −1 dbus/vm/taskOwner.xml
@@ -77,25 +77,35 @@ def __init__(self):
self.path = "/org/xenserver/task/owner"
scheme = self.bus.get_unique_name()[1:] #remove : prefix
self.uri = scheme + "://" + self.path
+ self.owned_uris = []
info("TaskOwner registered at %s" % self.uri)
dbus.service.Object.__init__(self, self.bus, self.path)
@dbus.service.method(dbus_interface=TASKOWNER_INTERFACE, in_signature="as", out_signature="ab")
def ping(self, uris):
results = []
for uri in uris:
- debug("%s: I own dat" % uri)
- results.append(True)
+ if self.owned_uris == []:
+ debug("%s: I might own that" % uri)
+ results.append(True)
+ elif uri in self.owned_uris:
+ debug("%s: I definitely own that" % uri)
+ else:
+ debug("%s: I do not own that" % uri)
+ results.append(False)
return results
+ def add(self, uri):
+ self.owned_uris.append(uri)
+
@dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE, in_signature='ss', out_signature='v')
def Get(self, interface_name, property_name):
return self.GetAll(interface_name)[property_name]
@dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE, in_signature='s', out_signature='a{sv}')
def GetAll(self, interface_name):
if interface_name == TASKOWNER_INTERFACE:
- return { }
+ return { "tasks": self.owned_uris }
else:
raise dbus.exceptions.DBusException(
'com.example.UnknownInterface',
@@ -116,14 +126,17 @@ def GetAll(self, interface_name):
else:
print "Unknown command %s, expected either 'attach' or 'detach'" % command
sys.exit(2)
+taskOwner.add(task)
info("%s: created" % task)
+
uri = urlparse.urlparse(task)
task_proxy = bus.get_object(uri.scheme, uri.path)
def handler():
info("%s: got Completed signal" % task)
result = task_proxy.getResult(dbus_interface=TASK_INTERFACE)
info("%s: result = %s" % (task, result))
+ print result
task_proxy.destroy(dbus_interface=TASK_INTERFACE)
loop.quit()
View
@@ -7,5 +7,14 @@
<arg name="tasks" type="as" direction="in"/>
<arg name="alive" type="ab" direction="out"/>
</method>
- </interface>
+ <property name="tasks" type="as" access="read">
+ <doc:doc>
+ <doc:description>
+ <doc:para>
+ A list of task URIs which this owner is responsible for.
+ </doc:para>
+ </doc:description>
+ </doc:doc>
+ </property>
+</interface>
</node>

0 comments on commit 0654100

Please sign in to comment.