]> xenbits.xensource.com Git - osstest/openstack-nova.git/commitdiff
Make parsing of usage stats from XS more robust.
authorMonsyne Dragon <mdragon@rackspace.com>
Tue, 31 Jan 2012 21:22:22 +0000 (21:22 +0000)
committerMonsyne Dragon <mdragon@rackspace.com>
Wed, 1 Feb 2012 20:47:07 +0000 (20:47 +0000)
Better handle odd values in parsing of usage data from xenserver.
Fixes bug 918490

Change-Id: Ie634ba6a740d0ea098d7fc4e13b4b46b5203ce79

nova/virt/xenapi/vm_utils.py

index 4c7ece9c525a7aac1f70ce3abbe20bb499b0d333..5978e745e3980ded7e6adfd09cd4f3860dadf158 100644 (file)
@@ -30,7 +30,7 @@ import tempfile
 import time
 import urllib
 import uuid
-from decimal import Decimal
+from decimal import Decimal, InvalidOperation
 from xml.dom import minidom
 
 from nova.common import cfg
@@ -1082,9 +1082,21 @@ def parse_rrd_update(doc, start, until=None):
 def average_series(data, col, start, until=None):
     vals = [row['values'][col] for row in data
             if (not until or (row['time'] <= until)) and
-                not row['values'][col].is_nan()]
+                row['values'][col].is_finite()]
     if vals:
-        return (sum(vals) / len(vals)).quantize(Decimal('1.0000'))
+        try:
+            return (sum(vals) / len(vals)).quantize(Decimal('1.0000'))
+        except InvalidOperation:
+            # (mdragon) Xenserver occasionally returns odd values in
+            # data that will throw an error on averaging (see bug 918490)
+            # These are hard to find, since, whatever those values are,
+            # Decimal seems to think they are a valid number, sortof.
+            # We *think* we've got the the cases covered, but just in
+            # case, log and return NaN, so we don't break reporting of
+            # other statistics.
+            LOG.error(_("Invalid statistics data from Xenserver: %s")
+                      % str(vals))
+            return Decimal('NaN')
     else:
         return Decimal('0.0000')