From 66a1bb3816abfa154982c6d80d88b851cefd9800 Mon Sep 17 00:00:00 2001 From: Monsyne Dragon Date: Tue, 31 Jan 2012 21:22:22 +0000 Subject: [PATCH] Make parsing of usage stats from XS more robust. Better handle odd values in parsing of usage data from xenserver. Fixes bug 918490 Change-Id: Ie634ba6a740d0ea098d7fc4e13b4b46b5203ce79 --- nova/virt/xenapi/vm_utils.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/nova/virt/xenapi/vm_utils.py b/nova/virt/xenapi/vm_utils.py index 4c7ece9c525..5978e745e39 100644 --- a/nova/virt/xenapi/vm_utils.py +++ b/nova/virt/xenapi/vm_utils.py @@ -30,7 +30,7 @@ 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')