[NEW PATCH] Related to BZ#719516 vdsClient: avoid possible race in list table. (via gerrit-bot)

David Naori dnaori at redhat.com
Thu Jul 7 14:31:10 UTC 2011


New patch submitted by David Naori (dnaori at redhat.com)

You can review this change at: http://gerrit.usersys.redhat.com/671

commit adf44e8372158e45481bb1e8015e32edb9e69991
Author: David Naori <dnaori at redhat.com>
Date:   Thu Jul 7 09:24:20 2011 +0300

    Related to BZ#719516 vdsClient: avoid possible race in list table.
    
    Change-Id: I7fc52ac0428fd0a2128376a97d56df0fc41ff8ac

diff --git a/vdsm_cli/vdsClient.py b/vdsm_cli/vdsClient.py
index 903dc46..a2c5d94 100755
--- a/vdsm_cli/vdsClient.py
+++ b/vdsm_cli/vdsClient.py
@@ -173,34 +173,37 @@ class service:
         return self.ExecAndExit(self.s.changeFloppy(vmId, file))
 
     def do_list(self, args):
-        table=False
-        if len(args):
-            if args[0] == 'table':
-                table=True
         response = self.s.list(True)
-        if response['status']['code'] != 0:
-            print response['status']['message']
-        else:
-            if table:
-                allStats = {}
+        if response['status']['code']:
+            return response['status']['code'], response['status']['message']
+
+        table = {}
+
+        if args:
+            if args[0] == 'table':
                 for s in self.s.getAllVmStats()['statsList']:
-                    allStats[s['vmId']] = s
-            for conf in response['vmList']:
-                if table:
-                    id = conf['vmId']
-                    status = conf['status']
-                    if allStats[id].get('monitorResponse') == '-1':
-                        status += '*'
-                    print "%-36s %6s  %-20s %-20s %-20s" % (id,
-                        conf.get('pid', 'none'),
-                        conf.get('vmName', '<< NO NAME >>'),
-                        status, allStats[id].get('guestIPs', '') )
-                else:
-                    if 'sysprepInf' in conf:
-                        conf['sysprepInf'] = '<<exists>>'
-                    printConf(conf)
-        sys.exit(response['status']['code'])
+                    table[ s['vmId'] ] = s
+            else:
+                raise ValueError
 
+        for conf in response['vmList']:
+            if table:
+                vmId = conf['vmId']
+                if vmId not in table:
+                    continue
+                status = conf['status']
+                if table[vmId].get('monitorResponse') == '-1':
+                    status += '*'
+                print "%-36s %6s  %-20s %-20s %-20s" % ( vmId,
+                    conf.get('pid', 'none'),
+                    conf.get('vmName', '<< NO NAME >>'),
+                    status, table[vmId].get('guestIPs', '') )
+            else:
+                if 'sysprepInf' in conf:
+                    conf['sysprepInf'] = '<<exists>>'
+                printConf(conf)
+
+        sys.exit(response['status']['code'])
 
     def do_listNames(self, args):
         response = self.s.list()




More information about the vdsm-patches mailing list