Merge "Adapt to the inspector api signature"
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
# Copyright 2015, 2017 IBM Corp.
|
# Copyright 2015, 2019 IBM Corp.
|
||||||
#
|
#
|
||||||
# All Rights Reserved.
|
# All Rights Reserved.
|
||||||
#
|
#
|
||||||
@@ -83,7 +83,7 @@ class PowerVMInspector(virt_inspector.Inspector):
|
|||||||
LOG.debug("Host UUID: %s" % hosts[0].uuid)
|
LOG.debug("Host UUID: %s" % hosts[0].uuid)
|
||||||
return hosts[0].uuid
|
return hosts[0].uuid
|
||||||
|
|
||||||
def inspect_instance(self, instance, duration=None):
|
def inspect_instance(self, instance, duration):
|
||||||
"""Inspect the statistics for an instance.
|
"""Inspect the statistics for an instance.
|
||||||
|
|
||||||
:param instance: the target instance
|
:param instance: the target instance
|
||||||
@@ -225,10 +225,15 @@ class PowerVMInspector(virt_inspector.Inspector):
|
|||||||
child_type=pvm_net.CNA.schema_type)
|
child_type=pvm_net.CNA.schema_type)
|
||||||
return pvm_net.CNA.wrap(client_cna_resp)
|
return pvm_net.CNA.wrap(client_cna_resp)
|
||||||
|
|
||||||
def inspect_vnics(self, instance):
|
def inspect_vnics(self, instance, duration):
|
||||||
"""Inspect the vNIC statistics for an instance.
|
"""Inspect the vNIC statistics for an instance.
|
||||||
|
|
||||||
:param instance: the target instance
|
:param instance: the target instance
|
||||||
|
:param duration: the last 'n' seconds, over which the value should be
|
||||||
|
inspected.
|
||||||
|
|
||||||
|
The PowerVM implementation does not make use of the duration
|
||||||
|
field.
|
||||||
:return: for each vNIC, the number of bytes & packets
|
:return: for each vNIC, the number of bytes & packets
|
||||||
received and transmitted
|
received and transmitted
|
||||||
"""
|
"""
|
||||||
@@ -277,7 +282,7 @@ class PowerVMInspector(virt_inspector.Inspector):
|
|||||||
tx_drop=0,
|
tx_drop=0,
|
||||||
tx_errors=0)
|
tx_errors=0)
|
||||||
|
|
||||||
def inspect_vnic_rates(self, instance, duration=None):
|
def inspect_vnic_rates(self, instance, duration):
|
||||||
"""Inspect the vNIC rate statistics for an instance.
|
"""Inspect the vNIC rate statistics for an instance.
|
||||||
|
|
||||||
:param instance: the target instance
|
:param instance: the target instance
|
||||||
@@ -358,12 +363,17 @@ class PowerVMInspector(virt_inspector.Inspector):
|
|||||||
mac=mac, fref=None, parameters=None,
|
mac=mac, fref=None, parameters=None,
|
||||||
rx_bytes_rate=rx_rate, tx_bytes_rate=tx_rate)
|
rx_bytes_rate=rx_rate, tx_bytes_rate=tx_rate)
|
||||||
|
|
||||||
def inspect_disks(self, instance):
|
def inspect_disks(self, instance, duration):
|
||||||
"""Inspect the disk statistics for an instance.
|
"""Inspect the disk statistics for an instance.
|
||||||
|
|
||||||
The response is a generator of the values.
|
The response is a generator of the values.
|
||||||
|
|
||||||
:param instance: the target instance
|
:param instance: the target instance
|
||||||
|
:param duration: the last 'n' seconds, over which the value should be
|
||||||
|
inspected.
|
||||||
|
|
||||||
|
The PowerVM implementation does not make use of the duration
|
||||||
|
field.
|
||||||
:return disk: The Disk indicating the device for the storage device.
|
:return disk: The Disk indicating the device for the storage device.
|
||||||
:return stats: The DiskStats indicating the read/write data to the
|
:return stats: The DiskStats indicating the read/write data to the
|
||||||
device.
|
device.
|
||||||
@@ -400,12 +410,17 @@ class PowerVMInspector(virt_inspector.Inspector):
|
|||||||
write_bytes=adpt.write_bytes, errors=0, wr_total_times=0,
|
write_bytes=adpt.write_bytes, errors=0, wr_total_times=0,
|
||||||
rd_total_times=0)
|
rd_total_times=0)
|
||||||
|
|
||||||
def inspect_disk_iops(self, instance):
|
def inspect_disk_iops(self, instance, duration):
|
||||||
"""Inspect the Disk Input/Output operations per second for an instance.
|
"""Inspect the Disk Input/Output operations per second for an instance.
|
||||||
|
|
||||||
The response is a generator of the values.
|
The response is a generator of the values.
|
||||||
|
|
||||||
:param instance: the target instance
|
:param instance: the target instance
|
||||||
|
:param duration: the last 'n' seconds, over which the value should be
|
||||||
|
inspected.
|
||||||
|
|
||||||
|
The PowerVM implementation does not make use of the duration
|
||||||
|
field.
|
||||||
:return disk: The Disk indicating the device for the storage device.
|
:return disk: The Disk indicating the device for the storage device.
|
||||||
:return stats: The DiskIOPSStats indicating the I/O operations per
|
:return stats: The DiskIOPSStats indicating the I/O operations per
|
||||||
second for the device.
|
second for the device.
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
# Copyright 2015, 2017 IBM Corp.
|
# Copyright 2015, 2019 IBM Corp.
|
||||||
#
|
#
|
||||||
# All Rights Reserved.
|
# All Rights Reserved.
|
||||||
#
|
#
|
||||||
@@ -85,7 +85,7 @@ class TestPowerVMInspector(base.BaseTestCase):
|
|||||||
# in the sample
|
# in the sample
|
||||||
self.mock_metrics.get_latest_metric.return_value = None, None
|
self.mock_metrics.get_latest_metric.return_value = None, None
|
||||||
self.assertRaises(virt_inspector.InstanceNotFoundException,
|
self.assertRaises(virt_inspector.InstanceNotFoundException,
|
||||||
self.inspector.inspect_instance, mock.Mock())
|
self.inspector.inspect_instance, mock.Mock(), None)
|
||||||
|
|
||||||
def mock_metric(util_cap, util_uncap, idle, donated, entitled):
|
def mock_metric(util_cap, util_uncap, idle, donated, entitled):
|
||||||
"""Helper method to create mock proc metrics."""
|
"""Helper method to create mock proc metrics."""
|
||||||
@@ -103,7 +103,7 @@ class TestPowerVMInspector(base.BaseTestCase):
|
|||||||
self.mock_metrics.get_latest_metric.return_value = (
|
self.mock_metrics.get_latest_metric.return_value = (
|
||||||
mock.Mock(), mock_metric(7000, 50, 1000, 5000, 10000))
|
mock.Mock(), mock_metric(7000, 50, 1000, 5000, 10000))
|
||||||
self.mock_metrics.get_previous_metric.return_value = None, None
|
self.mock_metrics.get_previous_metric.return_value = None, None
|
||||||
resp = self.inspector.inspect_instance(mock.Mock())
|
resp = self.inspector.inspect_instance(mock.Mock(), None)
|
||||||
self.assertEqual(7050, resp.cpu_time)
|
self.assertEqual(7050, resp.cpu_time)
|
||||||
self.assertEqual(12, resp.cpu_number)
|
self.assertEqual(12, resp.cpu_number)
|
||||||
|
|
||||||
@@ -114,7 +114,7 @@ class TestPowerVMInspector(base.BaseTestCase):
|
|||||||
self.mock_metrics.get_previous_metric.return_value = mock.Mock(), prev
|
self.mock_metrics.get_previous_metric.return_value = mock.Mock(), prev
|
||||||
|
|
||||||
# Execute and validate
|
# Execute and validate
|
||||||
resp = self.inspector.inspect_instance(mock.Mock())
|
resp = self.inspector.inspect_instance(mock.Mock(), None)
|
||||||
self.assertEqual(.5, resp.cpu_util)
|
self.assertEqual(.5, resp.cpu_util)
|
||||||
|
|
||||||
# Mock an instance with a dedicated processor, but idling and donating
|
# Mock an instance with a dedicated processor, but idling and donating
|
||||||
@@ -126,7 +126,7 @@ class TestPowerVMInspector(base.BaseTestCase):
|
|||||||
self.mock_metrics.get_previous_metric.return_value = mock.Mock(), prev
|
self.mock_metrics.get_previous_metric.return_value = mock.Mock(), prev
|
||||||
|
|
||||||
# Execute and validate
|
# Execute and validate
|
||||||
resp = self.inspector.inspect_instance(mock.Mock())
|
resp = self.inspector.inspect_instance(mock.Mock(), None)
|
||||||
self.assertEqual(51.0, resp.cpu_util)
|
self.assertEqual(51.0, resp.cpu_util)
|
||||||
|
|
||||||
# Mock an instance with a shared processor. By nature, this doesn't
|
# Mock an instance with a shared processor. By nature, this doesn't
|
||||||
@@ -138,7 +138,7 @@ class TestPowerVMInspector(base.BaseTestCase):
|
|||||||
self.mock_metrics.get_previous_metric.return_value = mock.Mock(), prev
|
self.mock_metrics.get_previous_metric.return_value = mock.Mock(), prev
|
||||||
|
|
||||||
# Execute and validate
|
# Execute and validate
|
||||||
resp = self.inspector.inspect_instance(mock.Mock())
|
resp = self.inspector.inspect_instance(mock.Mock(), None)
|
||||||
self.assertEqual(80.0, resp.cpu_util)
|
self.assertEqual(80.0, resp.cpu_util)
|
||||||
|
|
||||||
# Mock an instance with a shared processor - but using cycles from
|
# Mock an instance with a shared processor - but using cycles from
|
||||||
@@ -151,7 +151,7 @@ class TestPowerVMInspector(base.BaseTestCase):
|
|||||||
|
|
||||||
# Execute and validate. This should be running at 300% CPU
|
# Execute and validate. This should be running at 300% CPU
|
||||||
# utilization. Fast!
|
# utilization. Fast!
|
||||||
resp = self.inspector.inspect_instance(mock.Mock())
|
resp = self.inspector.inspect_instance(mock.Mock(), None)
|
||||||
self.assertEqual(300.0, resp.cpu_util)
|
self.assertEqual(300.0, resp.cpu_util)
|
||||||
|
|
||||||
# Mock an instance that hasn't been started yet.
|
# Mock an instance that hasn't been started yet.
|
||||||
@@ -161,7 +161,7 @@ class TestPowerVMInspector(base.BaseTestCase):
|
|||||||
self.mock_metrics.get_previous_metric.return_value = mock.Mock(), prev
|
self.mock_metrics.get_previous_metric.return_value = mock.Mock(), prev
|
||||||
|
|
||||||
# This should have 0% utilization
|
# This should have 0% utilization
|
||||||
resp = self.inspector.inspect_instance(mock.Mock())
|
resp = self.inspector.inspect_instance(mock.Mock(), None)
|
||||||
self.assertEqual(0.0, resp.cpu_util)
|
self.assertEqual(0.0, resp.cpu_util)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@@ -211,15 +211,16 @@ class TestPowerVMInspector(base.BaseTestCase):
|
|||||||
# Validate that an error is raised if the instance can't be found in
|
# Validate that an error is raised if the instance can't be found in
|
||||||
# the sample data.
|
# the sample data.
|
||||||
self.mock_metrics.get_latest_metric.return_value = None, None
|
self.mock_metrics.get_latest_metric.return_value = None, None
|
||||||
self.assertRaises(virt_inspector.InstanceNotFoundException,
|
self.assertRaises(virt_inspector.InstanceNotFoundException, list,
|
||||||
list, self.inspector.inspect_vnics(mock.Mock()))
|
self.inspector.inspect_vnics(mock.Mock(), None))
|
||||||
|
|
||||||
# Validate that no data is returned if there is a current metric,
|
# Validate that no data is returned if there is a current metric,
|
||||||
# just no network within it.
|
# just no network within it.
|
||||||
mock_empty_net = mock.MagicMock()
|
mock_empty_net = mock.MagicMock()
|
||||||
mock_empty_net.network = None
|
mock_empty_net.network = None
|
||||||
self.mock_metrics.get_latest_metric.return_value = None, mock_empty_net
|
self.mock_metrics.get_latest_metric.return_value = None, mock_empty_net
|
||||||
self.assertEqual([], list(self.inspector.inspect_vnics(mock.Mock())))
|
self.assertEqual(
|
||||||
|
[], list(self.inspector.inspect_vnics(mock.Mock(), None)))
|
||||||
|
|
||||||
# Build a couple CNAs and verify we get the proper list back
|
# Build a couple CNAs and verify we get the proper list back
|
||||||
mock_wrap.return_value = self._build_mock_cnas()
|
mock_wrap.return_value = self._build_mock_cnas()
|
||||||
@@ -227,7 +228,7 @@ class TestPowerVMInspector(base.BaseTestCase):
|
|||||||
mock_metrics = self._build_cur_mock_vnic_metrics()
|
mock_metrics = self._build_cur_mock_vnic_metrics()
|
||||||
self.mock_metrics.get_latest_metric.return_value = None, mock_metrics
|
self.mock_metrics.get_latest_metric.return_value = None, mock_metrics
|
||||||
|
|
||||||
resp = list(self.inspector.inspect_vnics(mock.Mock()))
|
resp = list(self.inspector.inspect_vnics(mock.Mock(), None))
|
||||||
self.assertEqual(3, len(resp))
|
self.assertEqual(3, len(resp))
|
||||||
|
|
||||||
stats1 = resp[0]
|
stats1 = resp[0]
|
||||||
@@ -249,16 +250,16 @@ class TestPowerVMInspector(base.BaseTestCase):
|
|||||||
# the sample data.
|
# the sample data.
|
||||||
self.mock_metrics.get_latest_metric.return_value = None, None
|
self.mock_metrics.get_latest_metric.return_value = None, None
|
||||||
self.mock_metrics.get_previous_metric.return_value = None, None
|
self.mock_metrics.get_previous_metric.return_value = None, None
|
||||||
self.assertRaises(virt_inspector.InstanceNotFoundException,
|
self.assertRaises(virt_inspector.InstanceNotFoundException, list,
|
||||||
list, self.inspector.inspect_vnic_rates(mock.Mock()))
|
self.inspector.inspect_vnic_rates(mock.Mock(), None))
|
||||||
|
|
||||||
# Validate that no data is returned if there is a current metric,
|
# Validate that no data is returned if there is a current metric,
|
||||||
# just no network within it.
|
# just no network within it.
|
||||||
mock_empty_net = mock.MagicMock()
|
mock_empty_net = mock.MagicMock()
|
||||||
mock_empty_net.network = None
|
mock_empty_net.network = None
|
||||||
self.mock_metrics.get_latest_metric.return_value = None, mock_empty_net
|
self.mock_metrics.get_latest_metric.return_value = None, mock_empty_net
|
||||||
self.assertEqual([],
|
self.assertEqual(
|
||||||
list(self.inspector.inspect_vnic_rates(mock.Mock())))
|
[], list(self.inspector.inspect_vnic_rates(mock.Mock(), None)))
|
||||||
|
|
||||||
# Build the response LPAR data
|
# Build the response LPAR data
|
||||||
mock_wrap.return_value = self._build_mock_cnas()
|
mock_wrap.return_value = self._build_mock_cnas()
|
||||||
@@ -276,7 +277,7 @@ class TestPowerVMInspector(base.BaseTestCase):
|
|||||||
mock_prev)
|
mock_prev)
|
||||||
|
|
||||||
# Execute
|
# Execute
|
||||||
resp = list(self.inspector.inspect_vnic_rates(mock.Mock()))
|
resp = list(self.inspector.inspect_vnic_rates(mock.Mock(), None))
|
||||||
self.assertEqual(3, len(resp))
|
self.assertEqual(3, len(resp))
|
||||||
|
|
||||||
# First metric. No delta
|
# First metric. No delta
|
||||||
@@ -335,15 +336,15 @@ class TestPowerVMInspector(base.BaseTestCase):
|
|||||||
# the sample data.
|
# the sample data.
|
||||||
self.mock_metrics.get_latest_metric.return_value = None, None
|
self.mock_metrics.get_latest_metric.return_value = None, None
|
||||||
self.mock_metrics.get_previous_metric.return_value = None, None
|
self.mock_metrics.get_previous_metric.return_value = None, None
|
||||||
self.assertRaises(virt_inspector.InstanceNotFoundException,
|
self.assertRaises(virt_inspector.InstanceNotFoundException, list,
|
||||||
list, self.inspector.inspect_disk_iops(mock.Mock()))
|
self.inspector.inspect_disk_iops(mock.Mock(), None))
|
||||||
|
|
||||||
# Validate that no data is returned if there is a current metric,
|
# Validate that no data is returned if there is a current metric,
|
||||||
# just no storage within it.
|
# just no storage within it.
|
||||||
mock_empty_st = mock.MagicMock(storage=None)
|
mock_empty_st = mock.MagicMock(storage=None)
|
||||||
self.mock_metrics.get_latest_metric.return_value = None, mock_empty_st
|
self.mock_metrics.get_latest_metric.return_value = None, mock_empty_st
|
||||||
self.assertEqual([],
|
self.assertEqual(
|
||||||
list(self.inspector.inspect_disk_iops(mock.Mock())))
|
[], list(self.inspector.inspect_disk_iops(mock.Mock(), None)))
|
||||||
|
|
||||||
# Current metric data
|
# Current metric data
|
||||||
mock_cur = self._build_cur_mock_stor_metrics()
|
mock_cur = self._build_cur_mock_stor_metrics()
|
||||||
@@ -351,8 +352,8 @@ class TestPowerVMInspector(base.BaseTestCase):
|
|||||||
self.mock_metrics.get_latest_metric.return_value = cur_date, mock_cur
|
self.mock_metrics.get_latest_metric.return_value = cur_date, mock_cur
|
||||||
|
|
||||||
# Validate that if there is no previous data, get no data back.
|
# Validate that if there is no previous data, get no data back.
|
||||||
self.assertEqual([],
|
self.assertEqual(
|
||||||
list(self.inspector.inspect_disk_iops(mock.Mock())))
|
[], list(self.inspector.inspect_disk_iops(mock.Mock(), None)))
|
||||||
|
|
||||||
# Build the previous
|
# Build the previous
|
||||||
mock_prev = self._build_prev_mock_stor_metrics()
|
mock_prev = self._build_prev_mock_stor_metrics()
|
||||||
@@ -361,7 +362,7 @@ class TestPowerVMInspector(base.BaseTestCase):
|
|||||||
mock_prev)
|
mock_prev)
|
||||||
|
|
||||||
# Execute
|
# Execute
|
||||||
resp = list(self.inspector.inspect_disk_iops(mock.Mock()))
|
resp = list(self.inspector.inspect_disk_iops(mock.Mock(), None))
|
||||||
self.assertEqual(3, len(resp))
|
self.assertEqual(3, len(resp))
|
||||||
|
|
||||||
# Two vSCSI's
|
# Two vSCSI's
|
||||||
@@ -383,15 +384,15 @@ class TestPowerVMInspector(base.BaseTestCase):
|
|||||||
# Validate that an error is raised if the instance can't be found in
|
# Validate that an error is raised if the instance can't be found in
|
||||||
# the sample data.
|
# the sample data.
|
||||||
self.mock_metrics.get_latest_metric.return_value = None, None
|
self.mock_metrics.get_latest_metric.return_value = None, None
|
||||||
self.assertRaises(virt_inspector.InstanceNotFoundException,
|
self.assertRaises(virt_inspector.InstanceNotFoundException, list,
|
||||||
list, self.inspector.inspect_disks(mock.Mock()))
|
self.inspector.inspect_disks(mock.Mock(), None))
|
||||||
|
|
||||||
# Validate that no data is returned if there is a current metric,
|
# Validate that no data is returned if there is a current metric,
|
||||||
# just no storage within it.
|
# just no storage within it.
|
||||||
mock_empty_st = mock.MagicMock(storage=None)
|
mock_empty_st = mock.MagicMock(storage=None)
|
||||||
self.mock_metrics.get_latest_metric.return_value = None, mock_empty_st
|
self.mock_metrics.get_latest_metric.return_value = None, mock_empty_st
|
||||||
self.assertEqual([],
|
self.assertEqual([],
|
||||||
list(self.inspector.inspect_disks(mock.Mock())))
|
list(self.inspector.inspect_disks(mock.Mock(), None)))
|
||||||
|
|
||||||
# Current metric data
|
# Current metric data
|
||||||
mock_cur = self._build_cur_mock_stor_metrics()
|
mock_cur = self._build_cur_mock_stor_metrics()
|
||||||
@@ -399,7 +400,7 @@ class TestPowerVMInspector(base.BaseTestCase):
|
|||||||
self.mock_metrics.get_latest_metric.return_value = cur_date, mock_cur
|
self.mock_metrics.get_latest_metric.return_value = cur_date, mock_cur
|
||||||
|
|
||||||
# Execute
|
# Execute
|
||||||
resp = list(self.inspector.inspect_disks(mock.Mock()))
|
resp = list(self.inspector.inspect_disks(mock.Mock(), None))
|
||||||
self.assertEqual(3, len(resp))
|
self.assertEqual(3, len(resp))
|
||||||
|
|
||||||
# Two vSCSIs.
|
# Two vSCSIs.
|
||||||
|
Reference in New Issue
Block a user