python client: add retries

Handle busy responses from the server with a retry.

Change-Id: I3b9f6746c7eedb5c7421e032539b15e241eb872e
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
diff --git a/obmc/mapper/bindings.py b/obmc/mapper/bindings.py
index 1f4139a..f77ba46 100644
--- a/obmc/mapper/bindings.py
+++ b/obmc/mapper/bindings.py
@@ -33,17 +33,41 @@
         self.iface = dbus.Interface(
             obj, dbus_interface=MAPPER_IFACE)
 
-    def get_object(self, path):
-        return self.iface.GetObject(path)
+    @staticmethod
+    def retry(func, retries):
+        e = None
+        count = 0
+        while count < retries:
+            try:
+                return func()
+            except dbus.exceptions.DBusException, e:
+                if e.get_dbus_name() is not \
+                        'org.freedesktop.DBus.Error.ObjectPathInUse':
+                    raise
 
-    def get_subtree_paths(self, path='/', depth=0):
-        return self.iface.GetSubTreePaths(path, depth)
+                count += 1
+        if e:
+            raise e
 
-    def get_subtree(self, path='/', depth=0):
-        return self.iface.GetSubTree(path, depth)
+    def get_object(self, path, retries=5):
+        return self.retry(
+            lambda: self.iface.GetObject(path),
+            retries)
 
-    def get_ancestors(self, path):
-        return self.iface.GetAncestors(path)
+    def get_subtree_paths(self, path='/', depth=0, retries=5):
+        return self.retry(
+            lambda: self.iface.GetSubTreePaths(path, depth),
+            retries)
+
+    def get_subtree(self, path='/', depth=0, retries=5):
+        return self.retry(
+            lambda: self.iface.GetSubTree(path, depth),
+            retries)
+
+    def get_ancestors(self, path, retries=5):
+        return self.retry(
+            lambda: self.iface.GetAncestors(path),
+            retries)
 
     @staticmethod
     def __try_properties_interface(f, *a):