Add VolumeMetrics resource for RSD2.3
Change-Id: I74c5967f0a277ac10cd4920cc938d6a7bf62d65f
This commit is contained in:
parent
203df22a5e
commit
adf6991611
@ -20,6 +20,7 @@ from sushy import exceptions
|
||||
from sushy.resources import base
|
||||
from sushy import utils
|
||||
|
||||
from rsd_lib.resources.v2_3.storage_service import volume_metrics
|
||||
from rsd_lib.resources.v2_3.storage_service import volume_schemas
|
||||
from rsd_lib import utils as rsd_lib_utils
|
||||
|
||||
@ -194,6 +195,26 @@ class Volume(base.ResourceBase):
|
||||
"""Delete this volume"""
|
||||
self._conn.delete(self.path)
|
||||
|
||||
def _get_metrics_path(self):
|
||||
"""Helper function to find the Metrics path"""
|
||||
return utils.get_sub_resource_path_by(self,
|
||||
['Links',
|
||||
'Oem',
|
||||
'Intel_RackScale',
|
||||
'Metrics'])
|
||||
|
||||
@property
|
||||
@utils.cache_it
|
||||
def metrics(self):
|
||||
"""Property to provide reference to `Metrics` instance
|
||||
|
||||
It is calculated once when it is queried for the first time. On
|
||||
refresh, this property is reset.
|
||||
"""
|
||||
return volume_metrics.VolumeMetrics(
|
||||
self._conn, self._get_metrics_path(),
|
||||
redfish_version=self.redfish_version)
|
||||
|
||||
|
||||
class VolumeCollection(base.ResourceCollectionBase):
|
||||
|
||||
|
33
rsd_lib/resources/v2_3/storage_service/volume_metrics.py
Normal file
33
rsd_lib/resources/v2_3/storage_service/volume_metrics.py
Normal file
@ -0,0 +1,33 @@
|
||||
# Copyright (c) 2019 Intel, Corp.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from sushy.resources import base
|
||||
|
||||
from rsd_lib import utils as rsd_lib_utils
|
||||
|
||||
|
||||
class VolumeMetrics(base.ResourceBase):
|
||||
|
||||
name = base.Field('Name')
|
||||
"""The volume metrics name"""
|
||||
|
||||
description = base.Field('Description')
|
||||
"""The volume metrics description"""
|
||||
|
||||
identity = base.Field('Id', required=True)
|
||||
"""The volume metrics identity string"""
|
||||
|
||||
capacity_used_bytes = base.Field('CapacityUsedBytes',
|
||||
adapter=rsd_lib_utils.num_or_none)
|
||||
"""The capacity in bytes of the volume"""
|
9
rsd_lib/tests/unit/json_samples/v2_3/volume_metrics.json
Normal file
9
rsd_lib/tests/unit/json_samples/v2_3/volume_metrics.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"@odata.context": "/redfish/v1/$metadata#StorageServices/Members/1/Volume/Metrics/$entity",
|
||||
"@odata.id": "/redfish/v1/StorageServices/NVMeoE1/Volumes/1/Metrics",
|
||||
"@odata.type": "#VolumeMetrics.v1_0_0.VolumeMetrics",
|
||||
"Name": "Volume Metrics",
|
||||
"Description": "Metrics for Volume 1",
|
||||
"Id": "Metrics",
|
||||
"CapacityUsedBytes": 6799708160
|
||||
}
|
@ -21,6 +21,7 @@ import testtools
|
||||
from sushy import exceptions
|
||||
|
||||
from rsd_lib.resources.v2_3.storage_service import volume
|
||||
from rsd_lib.resources.v2_3.storage_service import volume_metrics
|
||||
from rsd_lib.tests.unit.fakes import request_fakes
|
||||
|
||||
|
||||
@ -158,6 +159,56 @@ class StorageServiceTestCase(testtools.TestCase):
|
||||
self.volume_inst.delete()
|
||||
self.volume_inst._conn.delete.assert_called_once()
|
||||
|
||||
def test_get_metrics_path(self):
|
||||
expected = '/redfish/v1/StorageServices/NVMeoE1/Volumes/1/Metrics'
|
||||
result = self.volume_inst._get_metrics_path()
|
||||
self.assertEqual(expected, result)
|
||||
|
||||
def test_volume_metrics(self):
|
||||
# | GIVEN |
|
||||
self.conn.get.return_value.json.reset_mock()
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_3/'
|
||||
'volume_metrics.json', 'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
# | WHEN |
|
||||
actual_volume_metrics = self.volume_inst.metrics
|
||||
# | THEN |
|
||||
self.assertIsInstance(actual_volume_metrics,
|
||||
volume_metrics.VolumeMetrics)
|
||||
self.conn.get.return_value.json.assert_called_once_with()
|
||||
# reset mock
|
||||
self.conn.get.return_value.json.reset_mock()
|
||||
# | WHEN & THEN |
|
||||
# tests for same object on invoking subsequently
|
||||
self.assertIs(actual_volume_metrics,
|
||||
self.volume_inst.metrics)
|
||||
self.conn.get.return_value.json.assert_not_called()
|
||||
|
||||
def test_volume_metrics_on_refresh(self):
|
||||
# | GIVEN |
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_3/'
|
||||
'volume_metrics.json', 'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
# | WHEN & THEN |
|
||||
self.assertIsInstance(self.volume_inst.metrics,
|
||||
volume_metrics.VolumeMetrics)
|
||||
|
||||
# On refreshing the volume instance...
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_3/'
|
||||
'volume.json', 'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
|
||||
self.volume_inst.invalidate()
|
||||
self.volume_inst.refresh(force=False)
|
||||
|
||||
# | GIVEN |
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_3/'
|
||||
'volume.json', 'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
# | WHEN & THEN |
|
||||
self.assertIsInstance(self.volume_inst.metrics,
|
||||
volume_metrics.VolumeMetrics)
|
||||
|
||||
|
||||
class VolumeCollectionTestCase(testtools.TestCase):
|
||||
|
||||
|
@ -0,0 +1,43 @@
|
||||
# Copyright 2019 Intel, Inc.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import json
|
||||
import mock
|
||||
import testtools
|
||||
|
||||
from rsd_lib.resources.v2_3.storage_service import volume_metrics
|
||||
|
||||
|
||||
class VolumeMetricsTestCase(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(VolumeMetricsTestCase, self).setUp()
|
||||
self.conn = mock.Mock()
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_3/volume_metrics.json',
|
||||
'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
|
||||
self.volume_metrics_inst = volume_metrics.VolumeMetrics(
|
||||
self.conn, '/redfish/v1/StorageServices/NVMeoE1/Volumes/1/Metrics',
|
||||
redfish_version='1.0.2')
|
||||
|
||||
def test__parse_attributes(self):
|
||||
self.volume_metrics_inst._parse_attributes()
|
||||
self.assertEqual('Volume Metrics', self.volume_metrics_inst.name)
|
||||
self.assertEqual('Metrics', self.volume_metrics_inst.identity)
|
||||
self.assertEqual('Metrics for Volume 1',
|
||||
self.volume_metrics_inst.description)
|
||||
self.assertEqual(6799708160,
|
||||
self.volume_metrics_inst.capacity_used_bytes)
|
Loading…
x
Reference in New Issue
Block a user