Add missing attributes in metric definition resource

Change-Id: If6cf07482b1c4b5ab331e553d41b434b79134ed0
This commit is contained in:
Lin Yang 2019-02-07 12:19:15 -08:00
parent a19db87420
commit 6a1041db3b
4 changed files with 78 additions and 33 deletions

View File

@ -15,6 +15,27 @@
from sushy.resources import base
from rsd_lib import utils as rsd_lib_utils
class WildcardsField(base.ListField):
name = base.Field("Name")
"""This property shall contain a name for a Wildcard for a key"""
keys = base.Field("Keys")
"""If the value is an empty string, then the server shall substitute every
current key. Each not empty key value shall be substituted for the
wildcard
"""
class CalculationParameterField(base.ListField):
source_metric = base.Field("SourceMetric")
"""The metric property used as the input into the calculation"""
result_metric = base.Field("ResultMetric")
"""The metric property used to store the results of the calculation"""
class MetricDefinition(base.ResourceBase):
@ -28,64 +49,88 @@ class MetricDefinition(base.ResourceBase):
"""The metric definition description"""
sensor_type = base.Field('SensorType')
"""The type of sensor"""
"""This property represents the type of sensor that this resource
represents
"""
metric_type = base.Field('MetricType')
"""The type of metric"""
"""Specifies the type of metric provided"""
implementation = base.Field('Implementation')
"""The implementation type of sensor"""
"""The value of this property shall designate how the sensor is implemented
"""
sensing_interval = base.Field('SensingInterval')
"""The sensing interval"""
"""This property specifies the time interval between when a metric or
sensor reading is updated
"""
physical_context = base.Field('PhysicalContext')
"""The physical context of this metric definition"""
"""Specifies the physical context of the sensor"""
units = base.Field('Units')
"""The units of the sensor"""
"""Units of measure for this metric"""
min_reading_range = base.Field('MinReadingRange')
"""The min reading range of this sensor"""
min_reading_range = base.Field(
'MinReadingRange', adapter=rsd_lib_utils.num_or_none)
"""Minimum value for Reading"""
max_reading_range = base.Field('MaxReadingRange')
"""The max reading range of this sensor"""
max_reading_range = base.Field(
'MaxReadingRange', adapter=rsd_lib_utils.num_or_none)
"""Maximum value for Reading"""
discrete_values = base.Field('DiscreteValues')
"""The allowed discrete values"""
"""This array property specifies possible values of a discrete metric"""
precision = base.Field('Precision')
"""The precision of the sensor"""
precision = base.Field('Precision', adapter=rsd_lib_utils.num_or_none)
"""Number of significant digits in the Reading described by
MetricProperties field
"""
calibration = base.Field('Calibration')
"""The calibration of the sensor"""
calibration = base.Field('Calibration', adapter=rsd_lib_utils.num_or_none)
"""Specifies the calibration offset added to the Reading to obtain an
accurate value
"""
isLinear = base.Field('IsLinear', adapter=bool)
"""The boolean indicate this sensor is linear or not"""
"""Indicates linear or non-linear values"""
calculable = base.Field('Calculable', adapter=bool)
"""The variable indicate this sensor is calculable or not"""
calculable = base.Field('Calculable')
"""The value shall define the caculatability of this metric"""
data_type = base.Field('DataType')
"""The type of the sensor data"""
"""The data type of the corresponding metric values"""
accuracy = base.Field('Accuracy')
"""The accuracy of the sensor"""
accuracy = base.Field('Accuracy', adapter=rsd_lib_utils.num_or_none)
"""Estimated percent error of measured vs. actual values"""
time_stamp_accuracy = base.Field('TimeStampAccuracy')
"""The time stamp accuracy of the sensor"""
"""Accuracy of the timestamp"""
calculation_time_interval = base.Field('CalculationTimeInterval')
"""The calculation time interval of the sensor"""
"""This property specifies the time interval over which a calculated
metric algorithm is performed
"""
calculation_algorithm = base.Field('CalculationAlgorithm')
"""The calculation algorithm of the sensor"""
"""This property specifies the calculation which is performed on a source
metric to obtain the metric being defined
"""
calculation_parameters = base.Field('CalculationParameters')
"""The calculation parameters of the sensor"""
calculation_parameters = CalculationParameterField('CalculationParameters')
"""Specifies the resource properties (metric) which are characterized by
this definition
"""
wildcards = base.Field('Wildcards')
"""The wildcards of the sensor"""
wildcards = WildcardsField("Wildcards")
"""The property shall contain an array of wildcards and their replacements
strings, which are to appliced to the MetricProperties array property
"""
metric_properties = base.Field('MetricProperties')
"""A collection of URI for the properties on which this metric definition
is defined
"""
class MetricDefinitionCollection(base.ResourceCollectionBase):

View File

@ -66,7 +66,7 @@ class MetricDefinitionTestCase(testtools.TestCase):
self.assertEqual(
True, self.metric_definition_inst.isLinear)
self.assertEqual(
False, self.metric_definition_inst.calculable)
None, self.metric_definition_inst.calculable)
self.assertEqual(
None, self.metric_definition_inst.data_type)
self.assertEqual(
@ -184,7 +184,7 @@ class MetricDefinitionsCollectionTestCase(testtools.TestCase):
super(MetricDefinitionsCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_2/'
'metric_definitions.json', 'r') as f:
'metric_definition_collection.json', 'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.metric_def_col = metric_definition.MetricDefinitionCollection(
self.conn, '/redfish/v1/TelemetryService/MetricDefinitions',

View File

@ -62,7 +62,7 @@ class TelemetryTestCase(testtools.TestCase):
# | GIVEN |
self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_2/'
'metric_definitions.json', 'r') as f:
'metric_definition_collection.json', 'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN |
actual_metric_definitions = self.telemetry_inst.metric_definitions
@ -82,7 +82,7 @@ class TelemetryTestCase(testtools.TestCase):
def test_metrics_definitions_on_refresh(self):
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_2/'
'metric_definitions.json', 'r') as f:
'metric_definition_collection.json', 'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.telemetry_inst.metric_definitions,
@ -98,7 +98,7 @@ class TelemetryTestCase(testtools.TestCase):
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_2/'
'metric_definitions.json', 'r') as f:
'metric_definition_collection.json', 'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.telemetry_inst.metric_definitions,