Add missing attribute in MetricReport in RSD 2.2
Change-Id: I8772a284f2d911c3a3b016f797e5efc52903c95b
This commit is contained in:
parent
52d13897d0
commit
bb1396772d
@ -16,21 +16,27 @@
|
||||
from sushy.resources import base
|
||||
from sushy import utils
|
||||
|
||||
from rsd_lib import base as rsd_lib_base
|
||||
from rsd_lib import utils as rsd_lib_utils
|
||||
|
||||
|
||||
class MetricValuesField(base.ListField):
|
||||
metric_id = base.Field('MetricId')
|
||||
class MetricValueCollectionField(base.ListField):
|
||||
"""MetricValue field
|
||||
|
||||
A metric Value.
|
||||
"""
|
||||
|
||||
metric_id = base.Field("MetricId")
|
||||
"""The value shall be the MetricId of the source metric within the
|
||||
associated MetricDefinition
|
||||
"""
|
||||
|
||||
metric_value = base.Field('MetricValue')
|
||||
metric_value = base.Field("MetricValue")
|
||||
"""The value of the metric represented as a string. Its data type is
|
||||
specified in including MetricResult.MetricDefinition.
|
||||
"""
|
||||
|
||||
time_stamp = base.Field('TimeStamp')
|
||||
time_stamp = base.Field("TimeStamp")
|
||||
"""The value shall be an ISO 8601 date time for when the metric value was
|
||||
computed. Note that this may be different from the time when this
|
||||
instance is created. If Volatile is true for a given metric value
|
||||
@ -40,51 +46,44 @@ class MetricValuesField(base.ListField):
|
||||
according to their TimeStamp.
|
||||
"""
|
||||
|
||||
metric_property = base.Field('MetricProperty')
|
||||
metric_property = base.Field("MetricProperty")
|
||||
"""The value shall be a URI of a property contained in the scope of the
|
||||
MetricScope
|
||||
"""
|
||||
|
||||
metric_definition = base.Field(
|
||||
'MetricDefinition', adapter=rsd_lib_utils.get_resource_identity)
|
||||
"MetricDefinition", adapter=rsd_lib_utils.get_resource_identity
|
||||
)
|
||||
"""The value shall be a URI to the metric definition of the property"""
|
||||
|
||||
|
||||
class MetricReport(base.ResourceBase):
|
||||
identity = base.Field("Id")
|
||||
"""The metric report identity"""
|
||||
class MetricReport(rsd_lib_base.ResourceBase):
|
||||
"""MetricReport resource class
|
||||
|
||||
name = base.Field("Name")
|
||||
"""The metric report name"""
|
||||
A metric report resource that is output from Metric Report Definition.
|
||||
"""
|
||||
|
||||
description = base.Field("Description")
|
||||
"""The metric report description"""
|
||||
|
||||
metric_values = MetricValuesField("MetricValues")
|
||||
"""The metric report definition"""
|
||||
|
||||
def _get_metric_report_definition_path(self):
|
||||
"""Helper function to find the metric report definition path"""
|
||||
return utils.get_sub_resource_path_by(self, 'MetricReportDefinition')
|
||||
metric_values = MetricValueCollectionField("MetricValues")
|
||||
"""An array of metric values for the metered items of this Metric."""
|
||||
|
||||
@property
|
||||
@utils.cache_it
|
||||
def metric_report_definition(self):
|
||||
"""Property to provide reference to `MetricReportDefinition`
|
||||
"""Property to provide reference to `MetricReportDefinition` instance
|
||||
|
||||
It is calculated once the first time it is queried. On refresh,
|
||||
this property is reset.
|
||||
It is calculated once when it is queried for the first time. On
|
||||
refresh, this property is reset.
|
||||
"""
|
||||
# Avoid metric_report and metric_report_definition module mutually
|
||||
# import each other, move import to this function
|
||||
from rsd_lib.resources.v2_2.telemetry import metric_report_definition
|
||||
|
||||
return metric_report_definition.MetricReportDefinition(
|
||||
self._conn, self._get_metric_report_definition_path(),
|
||||
redfish_version=self.redfish_version)
|
||||
self._conn,
|
||||
utils.get_sub_resource_path_by(self, "MetricReportDefinition"),
|
||||
redfish_version=self.redfish_version,
|
||||
)
|
||||
|
||||
|
||||
class MetricReportCollection(base.ResourceCollectionBase):
|
||||
|
||||
class MetricReportCollection(rsd_lib_base.ResourceCollectionBase):
|
||||
@property
|
||||
def _resource_type(self):
|
||||
return MetricReport
|
||||
|
@ -17,173 +17,197 @@ import json
|
||||
import mock
|
||||
import testtools
|
||||
|
||||
from sushy import exceptions
|
||||
|
||||
from rsd_lib.resources.v2_2.telemetry import metric_report
|
||||
from rsd_lib.resources.v2_2.telemetry import metric_report_definition
|
||||
|
||||
|
||||
class MetricReportTestCase(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(MetricReportTestCase, self).setUp()
|
||||
self.conn = mock.Mock()
|
||||
with open(
|
||||
'rsd_lib/tests/unit/json_samples/v2_2/metric_report.json',
|
||||
'r') as f:
|
||||
"rsd_lib/tests/unit/json_samples/v2_2/metric_report.json", "r"
|
||||
) as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
|
||||
self.metric_report_inst = metric_report.MetricReport(
|
||||
self.conn,
|
||||
'/redfish/v1/TelemetryService/MetricReports/TransmitCPU1Metrics',
|
||||
redfish_version='1.1.0')
|
||||
"/redfish/v1/TelemetryService/MetricReports/TransmitCPU1Metrics",
|
||||
redfish_version="1.1.0",
|
||||
)
|
||||
|
||||
def test__parse_attributes(self):
|
||||
self.metric_report_inst._parse_attributes()
|
||||
self.assertEqual("TransmitCPU1Metrics",
|
||||
self.metric_report_inst.identity)
|
||||
self.assertEqual(
|
||||
"TransmitCPU1Metrics", self.metric_report_inst.identity
|
||||
)
|
||||
self.assertEqual("CPU1 Metric Report", self.metric_report_inst.name)
|
||||
self.assertEqual("description-as-string",
|
||||
self.metric_report_inst.description)
|
||||
self.assertEqual(
|
||||
"description-as-string", self.metric_report_inst.description
|
||||
)
|
||||
# metric_values section
|
||||
self.assertEqual(
|
||||
None, self.metric_report_inst.metric_values[0].metric_id)
|
||||
None, self.metric_report_inst.metric_values[0].metric_id
|
||||
)
|
||||
self.assertEqual(
|
||||
"29", self.metric_report_inst.metric_values[0].metric_value)
|
||||
"29", self.metric_report_inst.metric_values[0].metric_value
|
||||
)
|
||||
self.assertEqual(
|
||||
"2016-07-25T11:27:59.895513984+02:00",
|
||||
self.metric_report_inst.metric_values[0].time_stamp)
|
||||
self.metric_report_inst.metric_values[0].time_stamp,
|
||||
)
|
||||
self.assertEqual(
|
||||
"/redfish/v1/Systems/System1/Processors/CPU1/Metrics#/"
|
||||
"BandwidthPercent",
|
||||
self.metric_report_inst.metric_values[0].metric_property)
|
||||
self.metric_report_inst.metric_values[0].metric_property,
|
||||
)
|
||||
self.assertEqual(
|
||||
"/redfish/v1/TelemetryService/MetricDefinitions/CPUBandwidth",
|
||||
self.metric_report_inst.metric_values[0].metric_definition)
|
||||
self.metric_report_inst.metric_values[0].metric_definition,
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
None, self.metric_report_inst.metric_values[1].metric_id)
|
||||
None, self.metric_report_inst.metric_values[1].metric_id
|
||||
)
|
||||
self.assertEqual(
|
||||
"FRB1 BIST Failure",
|
||||
self.metric_report_inst.metric_values[1].metric_value)
|
||||
self.metric_report_inst.metric_values[1].metric_value,
|
||||
)
|
||||
self.assertEqual(
|
||||
"2016-07-25T11:27:59.795513984+02:00",
|
||||
self.metric_report_inst.metric_values[1].time_stamp)
|
||||
self.metric_report_inst.metric_values[1].time_stamp,
|
||||
)
|
||||
self.assertEqual(
|
||||
"/redfish/v1/Systems/System1/Processors/CPU1/Metrics#/CPUHealth",
|
||||
self.metric_report_inst.metric_values[1].metric_property)
|
||||
self.metric_report_inst.metric_values[1].metric_property,
|
||||
)
|
||||
self.assertEqual(
|
||||
"/redfish/v1/TelemetryService/MetricDefinitions/CPUHealth",
|
||||
self.metric_report_inst.metric_values[1].metric_definition)
|
||||
self.metric_report_inst.metric_values[1].metric_definition,
|
||||
)
|
||||
|
||||
self.assertEqual(
|
||||
None, self.metric_report_inst.metric_values[2].metric_id)
|
||||
None, self.metric_report_inst.metric_values[2].metric_id
|
||||
)
|
||||
self.assertEqual(
|
||||
"43", self.metric_report_inst.metric_values[2].metric_value)
|
||||
"43", self.metric_report_inst.metric_values[2].metric_value
|
||||
)
|
||||
self.assertEqual(
|
||||
"2016-07-25T11:27:59.595513984+02:00",
|
||||
self.metric_report_inst.metric_values[2].time_stamp)
|
||||
self.metric_report_inst.metric_values[2].time_stamp,
|
||||
)
|
||||
self.assertEqual(
|
||||
"/redfish/v1/Systems/System1/Processors/CPU1/Metrics#/"
|
||||
"TemperatureCelsius",
|
||||
self.metric_report_inst.metric_values[2].metric_property)
|
||||
self.metric_report_inst.metric_values[2].metric_property,
|
||||
)
|
||||
self.assertEqual(
|
||||
"/redfish/v1/TelemetryService/MetricDefinitions/CPUTemperature",
|
||||
self.metric_report_inst.metric_values[2].metric_definition)
|
||||
|
||||
def test__get_metric_report_definition_path_path(self):
|
||||
self.assertEqual(
|
||||
'/redfish/v1/TelemetryService/MetricReportDefinitions/CPU1Metrics',
|
||||
self.metric_report_inst._get_metric_report_definition_path())
|
||||
|
||||
def test__get_metric_report_definition_path_missing_attr(self):
|
||||
self.metric_report_inst._json.pop('MetricReportDefinition')
|
||||
with self.assertRaisesRegex(
|
||||
exceptions.MissingAttributeError,
|
||||
'attribute MetricReportDefinition'):
|
||||
self.metric_report_inst._get_metric_report_definition_path()
|
||||
self.metric_report_inst.metric_values[2].metric_definition,
|
||||
)
|
||||
|
||||
def test_metric_report_definition(self):
|
||||
# | GIVEN |
|
||||
self.conn.get.return_value.json.reset_mock()
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_2/'
|
||||
'metric_report_definition.json', 'r') as f:
|
||||
with open(
|
||||
"rsd_lib/tests/unit/json_samples/v2_2/"
|
||||
"metric_report_definition.json",
|
||||
"r",
|
||||
) as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
# | WHEN |
|
||||
actual_report_definition = \
|
||||
actual_report_definition = (
|
||||
self.metric_report_inst.metric_report_definition
|
||||
)
|
||||
# | THEN |
|
||||
self.assertIsInstance(
|
||||
actual_report_definition,
|
||||
metric_report_definition.MetricReportDefinition)
|
||||
metric_report_definition.MetricReportDefinition,
|
||||
)
|
||||
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_report_definition,
|
||||
self.metric_report_inst.metric_report_definition)
|
||||
self.assertIs(
|
||||
actual_report_definition,
|
||||
self.metric_report_inst.metric_report_definition,
|
||||
)
|
||||
self.conn.get.return_value.json.assert_not_called()
|
||||
|
||||
def test_metric_report_definitions_on_refresh(self):
|
||||
# | GIVEN |
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_2/'
|
||||
'metric_report_definition.json', 'r') as f:
|
||||
with open(
|
||||
"rsd_lib/tests/unit/json_samples/v2_2/"
|
||||
"metric_report_definition.json",
|
||||
"r",
|
||||
) as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
# | WHEN & THEN |
|
||||
self.assertIsInstance(
|
||||
self.metric_report_inst.metric_report_definition,
|
||||
metric_report_definition.MetricReportDefinition)
|
||||
metric_report_definition.MetricReportDefinition,
|
||||
)
|
||||
|
||||
# On refreshing the telemetry service instance...
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_2/'
|
||||
'metric_report.json', 'r') as f:
|
||||
with open(
|
||||
"rsd_lib/tests/unit/json_samples/v2_2/" "metric_report.json", "r"
|
||||
) as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
|
||||
self.metric_report_inst.invalidate()
|
||||
self.metric_report_inst.refresh(force=False)
|
||||
|
||||
# | GIVEN |
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_2/'
|
||||
'metric_report_definition.json', 'r') as f:
|
||||
with open(
|
||||
"rsd_lib/tests/unit/json_samples/v2_2/"
|
||||
"metric_report_definition.json",
|
||||
"r",
|
||||
) as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
# | WHEN & THEN |
|
||||
self.assertIsInstance(
|
||||
self.metric_report_inst.metric_report_definition,
|
||||
metric_report_definition.MetricReportDefinition)
|
||||
metric_report_definition.MetricReportDefinition,
|
||||
)
|
||||
|
||||
|
||||
class MetricReportCollectionTestCase(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(MetricReportCollectionTestCase, self).setUp()
|
||||
self.conn = mock.Mock()
|
||||
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_2/'
|
||||
'metric_report_collection.json', 'r') as f:
|
||||
with open(
|
||||
"rsd_lib/tests/unit/json_samples/v2_2/"
|
||||
"metric_report_collection.json",
|
||||
"r",
|
||||
) as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
|
||||
self.metric_report_col = metric_report.MetricReportCollection(
|
||||
self.conn, '/redfish/v1/TelemetryService/MetricReports',
|
||||
redfish_version='1.1.0')
|
||||
self.conn,
|
||||
"/redfish/v1/TelemetryService/MetricReports",
|
||||
redfish_version="1.1.0",
|
||||
)
|
||||
|
||||
def test_parse_attributes(self):
|
||||
self.metric_report_col._parse_attributes()
|
||||
self.assertEqual("MetricReports", self.metric_report_col.name)
|
||||
|
||||
@mock.patch.object(metric_report, 'MetricReport', autospec=True)
|
||||
@mock.patch.object(metric_report, "MetricReport", autospec=True)
|
||||
def test_get_member(self, mock_metric_report):
|
||||
self.metric_report_col.get_member(
|
||||
'/redfish/v1/TelemetryService/MetricReports/TransmitCPU1Metrics')
|
||||
"/redfish/v1/TelemetryService/MetricReports/TransmitCPU1Metrics"
|
||||
)
|
||||
|
||||
mock_metric_report.assert_called_once_with(
|
||||
self.metric_report_col._conn,
|
||||
'/redfish/v1/TelemetryService/MetricReports/TransmitCPU1Metrics',
|
||||
redfish_version=self.metric_report_col.redfish_version
|
||||
"/redfish/v1/TelemetryService/MetricReports/TransmitCPU1Metrics",
|
||||
redfish_version=self.metric_report_col.redfish_version,
|
||||
)
|
||||
|
||||
@mock.patch.object(metric_report, 'MetricReport', autospec=True)
|
||||
@mock.patch.object(metric_report, "MetricReport", autospec=True)
|
||||
def test_get_members(self, mock_metric_report):
|
||||
members = self.metric_report_col.get_members()
|
||||
self.assertEqual(mock_metric_report.call_count, 1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user