Commit 601fb4b4 authored by Jenkins's avatar Jenkins Committed by Gerrit Code Review

Merge "XenAPI support: Disk rates"

parents 83573da5 edee5d42
......@@ -167,3 +167,27 @@ class XenapiInspector(virt_inspector.Inspector):
tx_rate = float(vif_metrics_rec['io_write_kbs']) * units.Ki
stats = virt_inspector.InterfaceRateStats(rx_rate, tx_rate)
yield (interface, stats)
def inspect_disk_rates(self, instance, duration=None):
instance_name = util.instance_name(instance)
vm_ref = self._lookup_by_name(instance_name)
vbd_refs = self._call_xenapi("VM.get_VBDs", vm_ref)
if vbd_refs:
for vbd_ref in vbd_refs:
vbd_rec = self._call_xenapi("VBD.get_record", vbd_ref)
vbd_metrics_ref = self._call_xenapi("VBD.get_metrics",
vbd_ref)
vbd_metrics_rec = self._call_xenapi("VBD_metrics.get_record",
vbd_metrics_ref)
disk = virt_inspector.Disk(device=vbd_rec['device'])
# Stats provided from XenServer are in KB/s,
# converting it to B/s.
read_rate = float(vbd_metrics_rec['io_read_kbs']) * units.Ki
write_rate = float(vbd_metrics_rec['io_write_kbs']) * units.Ki
disk_rate_info = virt_inspector.DiskRateStats(
read_bytes_rate=read_rate,
read_requests_rate=0,
write_bytes_rate=write_rate,
write_requests_rate=0)
yield(disk, disk_rate_info)
......@@ -139,3 +139,40 @@ class TestXenapiInspection(base.BaseTestCase):
self.assertEqual('vif_mac', vnic0.mac)
self.assertEqual(1024, info0.rx_bytes_rate)
self.assertEqual(2048, info0.tx_bytes_rate)
def test_inspect_disk_rates(self):
fake_instance = {'OS-EXT-SRV-ATTR:instance_name': 'fake_instance_name',
'id': 'fake_instance_id'}
def fake_xenapi_request(method, args):
vbd_rec = {
'device': 'xvdd'
}
vbd_metrics_rec = {
'io_read_kbs': '1',
'io_write_kbs': '2'
}
if method == 'VM.get_by_name_label':
return ['vm_ref']
elif method == 'VM.get_VBDs':
return ['vbd_ref']
elif method == 'VBD.get_record':
return vbd_rec
elif method == 'VBD.get_metrics':
return 'vbd_metrics_ref'
elif method == 'VBD_metrics.get_record':
return vbd_metrics_rec
else:
return None
session = self.inspector.session
with mock.patch.object(session, 'xenapi_request',
side_effect=fake_xenapi_request):
disks = list(self.inspector.inspect_disk_rates(fake_instance))
self.assertEqual(1, len(disks))
disk0, info0 = disks[0]
self.assertEqual('xvdd', disk0.device)
self.assertEqual(1024, info0.read_bytes_rate)
self.assertEqual(2048, info0.write_bytes_rate)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment