Allow enabling metrics per virtual disk

This change will allow enabling metrics for individual virtual disks.
The Nova Hyper-V driver will use it when attaching Cinder volumes.

Note that Hyper-V does not support collecting metrics for passthrough
disks at the moment.

Change-Id: Iaba32ca94b2c09661f150fa4b12b2c7eb83ff6d9
Partial-Bug: #1794456
This commit is contained in:
Lucian Petrut 2018-09-27 12:48:17 +03:00
parent c73b074042
commit a0b64b6544
2 changed files with 37 additions and 0 deletions

View File

@ -18,7 +18,9 @@ import mock
from os_win import exceptions
from os_win.tests.unit import test_base
from os_win.utils import _wqlutils
from os_win.utils.compute import vmutils
from os_win.utils.metrics import metricsutils
from os_win import utilsfactory
class MetricsUtilsTestCase(test_base.OsWinBaseTestCase):
@ -27,8 +29,16 @@ class MetricsUtilsTestCase(test_base.OsWinBaseTestCase):
_FAKE_RET_VAL = 0
_FAKE_PORT = "fake's port name"
_autospec_classes = [
vmutils.VMUtils,
]
def setUp(self):
super(MetricsUtilsTestCase, self).setUp()
mock.patch.object(utilsfactory, 'get_vmutils',
mock.Mock(return_value=vmutils.VMUtils)).start()
self.utils = metricsutils.MetricsUtils()
self.utils._conn_attr = mock.MagicMock()
@ -58,6 +68,22 @@ class MetricsUtilsTestCase(test_base.OsWinBaseTestCase):
mock_enable_metrics.assert_has_calls(
[mock.call(mock_disk), mock.call(mock_vm, metrics_names)])
@mock.patch.object(metricsutils.MetricsUtils, '_enable_metrics')
def test_enable_disk_metrics_collection(self, mock_enable_metrics):
mock_get_disk = (
self.utils._vmutils._get_mounted_disk_resource_from_path)
self.utils.enable_disk_metrics_collection(
mock.sentinel.disk_path,
mock.sentinel.is_physical,
mock.sentinel.serial)
mock_get_disk.assert_called_once_with(
mock.sentinel.disk_path,
is_physical=mock.sentinel.is_physical,
serial=mock.sentinel.serial)
mock_enable_metrics.assert_called_once_with(mock_get_disk.return_value)
@mock.patch.object(metricsutils.MetricsUtils, '_enable_metrics')
@mock.patch.object(metricsutils.MetricsUtils, '_get_switch_port')
def test_enable_switch_port_metrics_collection(self, mock_get_port,

View File

@ -57,6 +57,10 @@ class MetricsUtils(baseutils.BaseUtilsVirt):
self._metrics_svc_obj = None
self._metrics_defs_obj = {}
# We need to avoid a circular dependency.
from os_win import utilsfactory
self._vmutils = utilsfactory.get_vmutils(host)
@property
def _metrics_svc(self):
if not self._metrics_svc_obj:
@ -87,6 +91,13 @@ class MetricsUtils(baseutils.BaseUtilsVirt):
metrics_names = [self._CPU_METRICS, self._MEMORY_METRICS]
self._enable_metrics(vm, metrics_names)
def enable_disk_metrics_collection(self, attached_disk_path=None,
is_physical=False,
serial=None):
disk = self._vmutils._get_mounted_disk_resource_from_path(
attached_disk_path, is_physical=is_physical, serial=serial)
self._enable_metrics(disk)
def enable_port_metrics_collection(self, switch_port_name):
port = self._get_switch_port(switch_port_name)
metrics_names = [self._NET_IN_METRICS, self._NET_OUT_METRICS]