bug 929462: compile_diagnostics in xenapi erronously catch XenAPI.Failure

ensure we catch the right exception. Plus turn test_diagnostics into a
more thorough unit test.

Change-Id: I1aae28b9b3b942f08e419cd9cfa48dea003e96d9
This commit is contained in:
Armando Migliaccio 2012-02-09 15:53:50 +00:00
parent 2471629733
commit 8297a1bed0
5 changed files with 11320 additions and 5 deletions

View File

@ -38,6 +38,7 @@ include nova/tests/api/ec2/public_key/*
include nova/tests/db/nova.austin.sqlite
include nova/tests/image/*.tar.gz
include nova/tests/policy.json
include nova/tests/xenapi/vm_rrd.xml
include plugins/xenapi/README
include plugins/xenapi/etc/xapi.d/plugins/objectstore
include plugins/xenapi/etc/xapi.d/plugins/pluginlib_nova.py

View File

@ -243,8 +243,25 @@ class XenAPIVMTestCase(test.TestCase):
self.assertEqual(server_info[1], 'myaddress')
def test_get_diagnostics(self):
def fake_get_rrd(host, vm_uuid):
with open('xenapi/vm_rrd.xml') as f:
return re.sub(r'\s', '', f.read())
self.stubs.Set(vm_utils, 'get_rrd', fake_get_rrd)
fake_diagnostics = {
'vbd_xvdb_write': '0.0',
'memory_target': '10961792000.0000',
'memory_internal_free': '3612860.6020',
'memory': '10961792000.0000',
'vbd_xvda_write': '0.0',
'cpu0': '0.0110',
'vif_0_tx': '752.4007',
'vbd_xvda_read': '0.0',
'vif_0_rx': '4837.8805'
}
instance = self._create_instance()
self.conn.get_diagnostics(instance)
expected = self.conn.get_diagnostics(instance)
self.assertDictMatch(fake_diagnostics, expected)
def test_instance_snapshot_fails_with_no_primary_vdi(self):
def create_bad_vbd(vm_ref, vdi_ref):

11293
nova/tests/xenapi/vm_rrd.xml Normal file

File diff suppressed because it is too large Load Diff

View File

@ -98,9 +98,11 @@ def create_pool(name_label):
{'name_label': name_label})
def create_host(name_label):
def create_host(name_label, hostname='fake_name', address='fake_addr'):
return _create_object('host',
{'name_label': name_label})
{'name_label': name_label,
'hostname': hostname,
'address': address})
def create_network(name_label, bridge):

View File

@ -1037,7 +1037,8 @@ class VMHelper(HelperBase):
"""Compile VM diagnostics data"""
try:
diags = {}
xml = get_rrd(get_rrd_server(), record["uuid"])
vm_uuid = record["uuid"]
xml = get_rrd(get_rrd_server(), vm_uuid)
if xml:
rrd = minidom.parseString(xml)
for i, node in enumerate(rrd.firstChild.childNodes):
@ -1049,7 +1050,8 @@ class VMHelper(HelperBase):
_ref_zero = ref[0].firstChild.data
diags[_ref_zero] = ref[6].firstChild.data
return diags
except cls.XenAPI.Failure as e:
except expat.ExpatError as e:
LOG.exception(_('Unable to parse rrd of %(vm_uuid)s') % locals())
return {"Unable to retrieve diagnostics": e}
@classmethod