From 36145b12ccc6ca8d7c6a4e31686729392ef8e1c3 Mon Sep 17 00:00:00 2001
From: Michael Hanselmann <hansmi@google.com>
Date: Tue, 4 Aug 2009 18:22:27 +0200
Subject: [PATCH] Use objects for blockdev_getmirrorstatus RPC call result

This patch changes the return type for backend.BlockdevGetmirrorstatus from
a list of tuples to a list of objects.BlockDevStatus instances.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Iustin Pop <iustin@google.com>
---
 daemons/ganeti-noded |  5 +++--
 lib/backend.py       |  5 +----
 lib/cmdlib.py        | 16 ++++++++--------
 lib/rpc.py           |  8 ++++++--
 4 files changed, 18 insertions(+), 16 deletions(-)

diff --git a/daemons/ganeti-noded b/daemons/ganeti-noded
index 95a334039..941a25fc3 100755
--- a/daemons/ganeti-noded
+++ b/daemons/ganeti-noded
@@ -202,8 +202,9 @@ class NodeHttpServer(http.server.HttpServer):
 
     """
     disks = [objects.Disk.FromDict(dsk_s)
-            for dsk_s in params]
-    return backend.BlockdevGetmirrorstatus(disks)
+             for dsk_s in params]
+    return [status.ToDict()
+            for status in backend.BlockdevGetmirrorstatus(disks)]
 
   @staticmethod
   def perspective_blockdev_find(params):
diff --git a/lib/backend.py b/lib/backend.py
index 05198f399..af741ff02 100644
--- a/lib/backend.py
+++ b/lib/backend.py
@@ -1385,10 +1385,7 @@ def BlockdevGetmirrorstatus(disks):
     if rbd is None:
       _Fail("Can't find device %s", dsk)
 
-    dstatus = rbd.CombinedSyncStatus()
-
-    stats.append((dstatus.sync_percent, dstatus.estimated_time,
-                  dstatus.is_degraded, dstatus.ldisk_degraded))
+    stats.append(rbd.CombinedSyncStatus())
 
   return stats
 
diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index 23d4ae1c0..9ef79ede9 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -1833,18 +1833,18 @@ def _WaitForSync(lu, instance, oneshot=False, unlock=False):
         lu.LogWarning("Can't compute data for node %s/%s",
                            node, instance.disks[i].iv_name)
         continue
-      # we ignore the ldisk parameter
-      perc_done, est_time, is_degraded, _ = mstat
-      cumul_degraded = cumul_degraded or (is_degraded and perc_done is None)
-      if perc_done is not None:
+
+      cumul_degraded = (cumul_degraded or
+                        (mstat.is_degraded and mstat.sync_percent is None))
+      if mstat.sync_percent is not None:
         done = False
-        if est_time is not None:
-          rem_time = "%d estimated seconds remaining" % est_time
-          max_time = est_time
+        if mstat.estimated_time is not None:
+          rem_time = "%d estimated seconds remaining" % mstat.estimated_time
+          max_time = mstat.estimated_time
         else:
           rem_time = "no time estimate"
         lu.proc.LogInfo("- device %s: %5.2f%% done, %s" %
-                        (instance.disks[i].iv_name, perc_done, rem_time))
+                        (instance.disks[i].iv_name, mstat.sync_percent, rem_time))
 
     # if we're done but degraded, let's do a few small retries, to
     # make sure we see a stable and not transient situation; therefore
diff --git a/lib/rpc.py b/lib/rpc.py
index bb665bfb8..289b9fb2a 100644
--- a/lib/rpc.py
+++ b/lib/rpc.py
@@ -799,8 +799,12 @@ class RpcRunner(object):
     This is a single-node call.
 
     """
-    return self._SingleNodeCall(node, "blockdev_getmirrorstatus",
-                                [dsk.ToDict() for dsk in disks])
+    result = self._SingleNodeCall(node, "blockdev_getmirrorstatus",
+                                  [dsk.ToDict() for dsk in disks])
+    if not result.failed:
+      result.payload = [objects.BlockDevStatus.FromDict(i)
+                        for i in result.payload]
+    return result
 
   def call_blockdev_find(self, node, disk):
     """Request identification of a given block device.
-- 
GitLab