Refactor telemetry definition
Merged all kinds of telemetry definition variables into one single class instead of separate files. Change-Id: Id772b370019af958413390484e1a0166c34ebfef
This commit is contained in:
parent
ee5fd7db53
commit
3a1ba6be7a
@ -1,46 +0,0 @@
|
||||
# Copyright 2018 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.
|
||||
|
||||
from sushy.resources import base
|
||||
|
||||
|
||||
class CPUBandwidth(base.ResourceBase):
|
||||
|
||||
name = base.Field('Name')
|
||||
"""The CPUHealth metric definition name"""
|
||||
|
||||
identity = base.Field('Id', required=True)
|
||||
"""The CPUHealth metric definition identity string"""
|
||||
|
||||
metric_type = base.Field('MetricType')
|
||||
"""The type of metric"""
|
||||
|
||||
implementation = base.Field('Implementation')
|
||||
"""The implementation type of sensor"""
|
||||
|
||||
sensing_interval = base.Field('SensingInterval')
|
||||
"""The sensing interval"""
|
||||
|
||||
physical_context = base.Field('PhysicalContext')
|
||||
"""The physical context of this metric definition"""
|
||||
|
||||
units = base.Field('Units')
|
||||
"""The units of the sensor"""
|
||||
|
||||
min_reading_range = base.Field('MinReadingRange')
|
||||
"""The min reading range of this sensor"""
|
||||
|
||||
max_reading_range = base.Field('MaxReadingRange')
|
||||
"""The max reading range of this sensor"""
|
@ -1,43 +0,0 @@
|
||||
# Copyright 2018 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.
|
||||
|
||||
from sushy.resources import base
|
||||
|
||||
|
||||
class CPUHealth(base.ResourceBase):
|
||||
|
||||
name = base.Field('Name')
|
||||
"""The CPUHealth metric definition name"""
|
||||
|
||||
identity = base.Field('Id', required=True)
|
||||
"""The CPUHealth metric definition identity string"""
|
||||
|
||||
metric_type = base.Field('MetricType')
|
||||
"""The type of metric"""
|
||||
|
||||
sensor_type = base.Field('SensorType')
|
||||
"""The type of sensor"""
|
||||
|
||||
implementation = base.Field('Implementation')
|
||||
"""The implementation type of sensor"""
|
||||
|
||||
sensing_interval = base.Field('SensingInterval')
|
||||
"""The sensing interval"""
|
||||
|
||||
physical_context = base.Field('PhysicalContext')
|
||||
"""The physical context of this metric definition"""
|
||||
|
||||
discrete_values = base.Field('DiscreteValues', adapter=list)
|
||||
"""The allowed discrete values"""
|
@ -1,55 +0,0 @@
|
||||
# Copyright 2018 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.
|
||||
|
||||
from sushy.resources import base
|
||||
|
||||
|
||||
class CPUTemperature(base.ResourceBase):
|
||||
|
||||
name = base.Field('Name')
|
||||
"""The CPUHealth metric definition name"""
|
||||
|
||||
identity = base.Field('Id', required=True)
|
||||
"""The CPUHealth metric definition identity string"""
|
||||
|
||||
metric_type = base.Field('MetricType')
|
||||
"""The type of metric"""
|
||||
|
||||
sensor_type = base.Field('SensorType')
|
||||
"""The type of sensor"""
|
||||
|
||||
implementation = base.Field('Implementation')
|
||||
"""The implementation type of sensor"""
|
||||
|
||||
sensing_interval = base.Field('SensingInterval')
|
||||
"""The sensing interval"""
|
||||
|
||||
physical_context = base.Field('PhysicalContext')
|
||||
"""The physical context of this metric definition"""
|
||||
|
||||
units = base.Field('Units')
|
||||
"""The units of the sensor"""
|
||||
|
||||
min_reading_range = base.Field('MinReadingRange', adapter=int)
|
||||
"""The min reading range of this sensor"""
|
||||
|
||||
max_reading_range = base.Field('MaxReadingRange', adapter=int)
|
||||
"""The max reading range of this sensor"""
|
||||
|
||||
precision = base.Field('Precision', adapter=int)
|
||||
"""The precision of this sensor"""
|
||||
|
||||
calibration = base.Field('Calibration', adapter=int)
|
||||
"""The calibration of this sensor"""
|
@ -13,61 +13,80 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import os
|
||||
|
||||
from sushy.resources import base
|
||||
|
||||
from rsd_lib.resources.v2_2.telemetry.metric_definitions import cpu_bandwidth
|
||||
from rsd_lib.resources.v2_2.telemetry.metric_definitions import cpu_health
|
||||
from rsd_lib.resources.v2_2.telemetry.metric_definitions import cpu_temperature
|
||||
|
||||
class MetricDefinition(base.ResourceBase):
|
||||
|
||||
name = base.Field('Name')
|
||||
"""The CPUHealth metric definition name"""
|
||||
|
||||
identity = base.Field('Id', required=True)
|
||||
"""The CPUHealth metric definition identity string"""
|
||||
|
||||
sensor_type = base.Field('SensorType')
|
||||
"""The type of sensor"""
|
||||
|
||||
metric_type = base.Field('MetricType')
|
||||
"""The type of metric"""
|
||||
|
||||
implementation = base.Field('Implementation')
|
||||
"""The implementation type of sensor"""
|
||||
|
||||
sensing_interval = base.Field('SensingInterval')
|
||||
"""The sensing interval"""
|
||||
|
||||
physical_context = base.Field('PhysicalContext')
|
||||
"""The physical context of this metric definition"""
|
||||
|
||||
units = base.Field('Units')
|
||||
"""The units of the sensor"""
|
||||
|
||||
min_reading_range = base.Field('MinReadingRange')
|
||||
"""The min reading range of this sensor"""
|
||||
|
||||
max_reading_range = base.Field('MaxReadingRange')
|
||||
"""The max reading range of this sensor"""
|
||||
|
||||
discrete_values = base.Field('DiscreteValues', adapter=list)
|
||||
"""The allowed discrete values"""
|
||||
|
||||
precision = base.Field('Precision')
|
||||
"""The precision of the sensor"""
|
||||
|
||||
calibration = base.Field('Calibration')
|
||||
"""The calibration of the sensor"""
|
||||
|
||||
isLinear = base.Field('IsLinear', adapter=bool)
|
||||
"""The boolean indicate this sensor is linear or not"""
|
||||
|
||||
calculable = base.Field('Calculable', adapter=bool)
|
||||
"""The variable indicate this sensor is calculable or not"""
|
||||
|
||||
data_type = base.Field('DataType')
|
||||
"""The type of the sensor data"""
|
||||
|
||||
accuracy = base.Field('Accuracy')
|
||||
"""The accuracy of the sensor"""
|
||||
|
||||
time_stamp_accuracy = base.Field('TimeStampAccuracy')
|
||||
"""The time stamp accuracy of the sensor"""
|
||||
|
||||
calculation_time_interval = base.Field('CalculationTimeInterval')
|
||||
"""The calculation time interval of the sensor"""
|
||||
|
||||
calculation_algorithm = base.Field('CalculationAlgorithm')
|
||||
"""The calculation algorithm of the sensor"""
|
||||
|
||||
calculation_parameters = base.Field('CalculationParameters', adapter=list)
|
||||
"""The calculation parameters of the sensor"""
|
||||
|
||||
wildcards = base.Field('Wildcards', adapter=list)
|
||||
"""The wildcards of the sensor"""
|
||||
|
||||
|
||||
class MetricDefinitionsCollection(base.ResourceCollectionBase):
|
||||
|
||||
def __init__(self, connector, path, redfish_version=None):
|
||||
"""A class representing a MetricDefinitionsCollection
|
||||
|
||||
:param connector: A Connector instance
|
||||
:param path: The canonical path to the MetricDefinitions
|
||||
collection resource
|
||||
:param redfish_version: The version of RedFish. Used to construct
|
||||
the object according to schema of the given version.
|
||||
"""
|
||||
super(MetricDefinitionsCollection, self).__init__(
|
||||
connector, path, redfish_version)
|
||||
|
||||
def _get_metric_definition_type(self, identity):
|
||||
"""Get metric definition class
|
||||
|
||||
:param identity: The identity of the metric definition
|
||||
:returns: The corresponding metric definition class
|
||||
"""
|
||||
metric_def_name = os.path.basename(identity)
|
||||
|
||||
if metric_def_name == 'CPUTemperature':
|
||||
return cpu_temperature.CPUTemperature
|
||||
elif metric_def_name == 'CPUHealth':
|
||||
return cpu_health.CPUHealth
|
||||
elif metric_def_name == 'CPUBandwidth':
|
||||
return cpu_bandwidth.CPUBandwidth
|
||||
else:
|
||||
raise NotImplementedError(
|
||||
'Metric definition {0} is not supported yet.'
|
||||
.format(metric_def_name))
|
||||
|
||||
def get_member(self, identity):
|
||||
"""Given the identity return a metric definition object
|
||||
|
||||
:param identity: The identity of the metric definition
|
||||
:returns: The metric definition object
|
||||
:raises: ResourceNotFoundError
|
||||
"""
|
||||
# return cpu_temperature.CPUTemperature(
|
||||
# self._conn, identity, redfish_version=self.redfish_version)
|
||||
metric_definition_type = self._get_metric_definition_type(identity)
|
||||
return metric_definition_type(self._conn, identity,
|
||||
redfish_version=self.redfish_version)
|
||||
|
||||
@property
|
||||
def _resource_type(self):
|
||||
pass
|
||||
return MetricDefinition
|
||||
|
36
rsd_lib/tests/unit/json_samples/v2_2/metric_definition.json
Normal file
36
rsd_lib/tests/unit/json_samples/v2_2/metric_definition.json
Normal file
@ -0,0 +1,36 @@
|
||||
{
|
||||
"@odata.context" : "/redfish/v1/$metadata#MetricDefinition.MetricDefinition",
|
||||
"@odata.id" : "/redfish/v1/TelemetryService/MetricDefinitions/1-md-6",
|
||||
"@odata.type" : "#MetricDefinition.v1_0_0.MetricDefinition",
|
||||
"Id" : "1-md-6",
|
||||
"Name" : "memoryTemperature",
|
||||
"Description" : "Metric Definition description",
|
||||
"SensorType" : "Temperature",
|
||||
"Implementation" : "PhysicalSensor",
|
||||
"SensingInterval" : "10.0s",
|
||||
"MetricType" : "Numeric",
|
||||
"PhysicalContext" : "SystemBoard",
|
||||
"Units" : "Celsius",
|
||||
"MinReadingRange" : null,
|
||||
"MaxReadingRange" : null,
|
||||
"MetricProperties" : [ "/redfish/v1/Systems/1-s-2/Memory/1-s-2-mm-4/Metrics"],
|
||||
"Precision" : null,
|
||||
"Calibration" : null,
|
||||
"IsLinear" : true,
|
||||
"Calculable" : null,
|
||||
"DataType" : null,
|
||||
"Accuracy" : null,
|
||||
"TimeStampAccuracy" : null,
|
||||
"CalculationTimeInterval" : null,
|
||||
"CalculationAlgorithm" : null,
|
||||
"DiscreteValues" : [ ],
|
||||
"CalculationParameters" : [ ],
|
||||
"Wildcards" : [ ],
|
||||
"Oem" : {
|
||||
"Intel_RackScale" : {
|
||||
"@odata.type" : "#Intel.Oem.MetricDefinition",
|
||||
"CalculationPrecision" : null,
|
||||
"DiscreteMetricType" : null
|
||||
}
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
"@odata.type": "#MetricDefinitionCollection.MetricDefinitionCollection",
|
||||
"Name": "Metric Definitions Collection",
|
||||
"Description": "description-as-string",
|
||||
"Members@odata.count": 5,
|
||||
"Members@odata.count": 3,
|
||||
"Members": [
|
||||
{
|
||||
"@odata.id":"/redfish/v1/TelemetryService/MetricDefinitions/CPUTemperature"
|
||||
|
@ -1,57 +0,0 @@
|
||||
# Copyright 2018 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_2.telemetry.metric_definitions import cpu_bandwidth
|
||||
|
||||
|
||||
class CPUBandwidthTestCase(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(CPUBandwidthTestCase, self).setUp()
|
||||
self.conn = mock.Mock()
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_2/'
|
||||
'cpu_bandwidth_metric_def.json', 'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
|
||||
self.cpu_bandwidth_metric_def_inst = cpu_bandwidth.CPUBandwidth(
|
||||
self.conn,
|
||||
'/redfish/v1/TelemetryService/MetricDefinitions/CPUBandwidth',
|
||||
redfish_version='1.1.0')
|
||||
|
||||
def test__parse_attributes(self):
|
||||
self.cpu_bandwidth_metric_def_inst._parse_attributes()
|
||||
self.assertEqual('1.1.0',
|
||||
self.cpu_bandwidth_metric_def_inst.redfish_version)
|
||||
self.assertEqual('CPU Bandwidth type',
|
||||
self.cpu_bandwidth_metric_def_inst.name)
|
||||
self.assertEqual('CPUBandwidth',
|
||||
self.cpu_bandwidth_metric_def_inst.identity)
|
||||
self.assertEqual('Numeric',
|
||||
self.cpu_bandwidth_metric_def_inst.metric_type)
|
||||
self.assertEqual('DigitalMeter',
|
||||
self.cpu_bandwidth_metric_def_inst.implementation)
|
||||
self.assertEqual('PT1S',
|
||||
self.cpu_bandwidth_metric_def_inst.sensing_interval)
|
||||
self.assertEqual('CPU',
|
||||
self.cpu_bandwidth_metric_def_inst.physical_context)
|
||||
self.assertEqual('%', self.cpu_bandwidth_metric_def_inst.units)
|
||||
self.assertEqual(
|
||||
0, self.cpu_bandwidth_metric_def_inst.min_reading_range)
|
||||
self.assertEqual(
|
||||
100, self.cpu_bandwidth_metric_def_inst.max_reading_range)
|
@ -1,73 +0,0 @@
|
||||
# Copyright 2018 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_2.telemetry.metric_definitions import cpu_health
|
||||
|
||||
|
||||
class CPUHealthTestCase(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(CPUHealthTestCase, self).setUp()
|
||||
self.conn = mock.Mock()
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_2/'
|
||||
'cpu_health_metric_def.json', 'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
|
||||
self.cpu_health_metric_def_inst = cpu_health.CPUHealth(
|
||||
self.conn,
|
||||
'/redfish/v1/TelemetryService/MetricDefinitions/CPUHealth',
|
||||
redfish_version='1.1.0')
|
||||
|
||||
def test__parse_attributes(self):
|
||||
self.cpu_health_metric_def_inst._parse_attributes()
|
||||
self.assertEqual('1.1.0',
|
||||
self.cpu_health_metric_def_inst.redfish_version)
|
||||
self.assertEqual('CPU1 IPMI Health Sensor',
|
||||
self.cpu_health_metric_def_inst.name)
|
||||
self.assertEqual('CPUHealth1',
|
||||
self.cpu_health_metric_def_inst.identity)
|
||||
self.assertEqual('Discrete',
|
||||
self.cpu_health_metric_def_inst.metric_type)
|
||||
self.assertEqual('PhysicalSensor',
|
||||
self.cpu_health_metric_def_inst.sensor_type)
|
||||
self.assertEqual('PhysicalSensor',
|
||||
self.cpu_health_metric_def_inst.implementation)
|
||||
self.assertEqual('PT1S',
|
||||
self.cpu_health_metric_def_inst.sensing_interval)
|
||||
self.assertEqual('CPU',
|
||||
self.cpu_health_metric_def_inst.physical_context)
|
||||
|
||||
expected = [
|
||||
"OK",
|
||||
"Internal Error",
|
||||
"Thermal Trip",
|
||||
"FRB1 BIST Failure",
|
||||
"FRB2 Hang in Post",
|
||||
"FRB3 Startup Failure",
|
||||
"Config Error",
|
||||
"SMBIOS Uncorrectable Error",
|
||||
"Processor Presence Detected",
|
||||
"Processor Disabled",
|
||||
"Terminator Presence Detected",
|
||||
"Processor Throttled",
|
||||
"Machine Check Exception",
|
||||
"Correctable Machine Check Error"
|
||||
]
|
||||
self.assertEqual(expected,
|
||||
self.cpu_health_metric_def_inst.discrete_values)
|
@ -1,61 +0,0 @@
|
||||
# Copyright 2018 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_2.telemetry.metric_definitions import cpu_temperature
|
||||
|
||||
|
||||
class CPUTemperatureTestCase(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(CPUTemperatureTestCase, self).setUp()
|
||||
self.conn = mock.Mock()
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_2/'
|
||||
'cpu_temperature_metric_def.json', 'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
|
||||
self.cpu_temperature_metric_def_inst = cpu_temperature.CPUTemperature(
|
||||
self.conn,
|
||||
'/redfish/v1/TelemetryService/MetricDefinitions/CPUTemperature',
|
||||
redfish_version='1.1.0')
|
||||
|
||||
def test__parse_attributes(self):
|
||||
self.cpu_temperature_metric_def_inst._parse_attributes()
|
||||
self.assertEqual('1.1.0',
|
||||
self.cpu_temperature_metric_def_inst.redfish_version)
|
||||
self.assertEqual('Temperature MetricDefinition',
|
||||
self.cpu_temperature_metric_def_inst.name)
|
||||
self.assertEqual('TEMP1',
|
||||
self.cpu_temperature_metric_def_inst.identity)
|
||||
self.assertEqual('Numeric',
|
||||
self.cpu_temperature_metric_def_inst.metric_type)
|
||||
self.assertEqual('Temperature',
|
||||
self.cpu_temperature_metric_def_inst.sensor_type)
|
||||
self.assertEqual('Physical',
|
||||
self.cpu_temperature_metric_def_inst.implementation)
|
||||
self.assertEqual('PT1S',
|
||||
self.cpu_temperature_metric_def_inst.sensing_interval)
|
||||
self.assertEqual('CPU',
|
||||
self.cpu_temperature_metric_def_inst.physical_context)
|
||||
self.assertEqual('Cel', self.cpu_temperature_metric_def_inst.units)
|
||||
self.assertEqual(
|
||||
0, self.cpu_temperature_metric_def_inst.min_reading_range)
|
||||
self.assertEqual(
|
||||
80, self.cpu_temperature_metric_def_inst.max_reading_range)
|
||||
self.assertEqual(1, self.cpu_temperature_metric_def_inst.precision)
|
||||
self.assertEqual(2, self.cpu_temperature_metric_def_inst.calibration)
|
@ -17,13 +17,168 @@ import json
|
||||
import mock
|
||||
import testtools
|
||||
|
||||
from rsd_lib.resources.v2_2.telemetry.metric_definitions import cpu_bandwidth
|
||||
from rsd_lib.resources.v2_2.telemetry.metric_definitions import cpu_health
|
||||
from rsd_lib.resources.v2_2.telemetry.metric_definitions import cpu_temperature
|
||||
from rsd_lib.resources.v2_2.telemetry.metric_definitions \
|
||||
import metric_definitions
|
||||
|
||||
|
||||
class MetricDefinitionTestCase(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(MetricDefinitionTestCase, self).setUp()
|
||||
self.conn = mock.Mock()
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_2/'
|
||||
'metric_definition.json', 'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
|
||||
self.metric_definition_inst = metric_definitions.MetricDefinition(
|
||||
self.conn,
|
||||
'/redfish/v1/TelemetryService/MetricDefinitions/1-md-6',
|
||||
redfish_version='1.1.0')
|
||||
|
||||
def test__parse_attributes(self):
|
||||
self.metric_definition_inst._parse_attributes()
|
||||
self.assertEqual('1.1.0',
|
||||
self.metric_definition_inst.redfish_version)
|
||||
self.assertEqual('memoryTemperature',
|
||||
self.metric_definition_inst.name)
|
||||
self.assertEqual('1-md-6',
|
||||
self.metric_definition_inst.identity)
|
||||
self.assertEqual('Numeric',
|
||||
self.metric_definition_inst.metric_type)
|
||||
self.assertEqual('Temperature',
|
||||
self.metric_definition_inst.sensor_type)
|
||||
self.assertEqual('PhysicalSensor',
|
||||
self.metric_definition_inst.implementation)
|
||||
self.assertEqual('10.0s',
|
||||
self.metric_definition_inst.sensing_interval)
|
||||
self.assertEqual('SystemBoard',
|
||||
self.metric_definition_inst.physical_context)
|
||||
self.assertEqual('Celsius',
|
||||
self.metric_definition_inst.units)
|
||||
self.assertEqual(
|
||||
None, self.metric_definition_inst.min_reading_range)
|
||||
self.assertEqual(
|
||||
None, self.metric_definition_inst.max_reading_range)
|
||||
self.assertEqual([], self.metric_definition_inst.discrete_values)
|
||||
self.assertEqual(
|
||||
None, self.metric_definition_inst.precision)
|
||||
self.assertEqual(
|
||||
None, self.metric_definition_inst.calibration)
|
||||
self.assertEqual(
|
||||
True, self.metric_definition_inst.isLinear)
|
||||
self.assertEqual(
|
||||
False, self.metric_definition_inst.calculable)
|
||||
self.assertEqual(
|
||||
None, self.metric_definition_inst.data_type)
|
||||
self.assertEqual(
|
||||
None, self.metric_definition_inst.accuracy)
|
||||
self.assertEqual(
|
||||
None, self.metric_definition_inst.time_stamp_accuracy)
|
||||
self.assertEqual(
|
||||
None, self.metric_definition_inst.calculation_time_interval)
|
||||
self.assertEqual(
|
||||
None, self.metric_definition_inst.calculation_algorithm)
|
||||
self.assertEqual(
|
||||
[], self.metric_definition_inst.calculation_parameters)
|
||||
self.assertEqual(
|
||||
[], self.metric_definition_inst.wildcards)
|
||||
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_2/'
|
||||
'cpu_bandwidth_metric_def.json', 'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
|
||||
self.metric_definition_inst.refresh()
|
||||
self.assertEqual('1.1.0',
|
||||
self.metric_definition_inst.redfish_version)
|
||||
self.assertEqual('CPU Bandwidth type',
|
||||
self.metric_definition_inst.name)
|
||||
self.assertEqual('CPUBandwidth',
|
||||
self.metric_definition_inst.identity)
|
||||
self.assertEqual('Numeric',
|
||||
self.metric_definition_inst.metric_type)
|
||||
self.assertEqual('DigitalMeter',
|
||||
self.metric_definition_inst.implementation)
|
||||
self.assertEqual('PT1S',
|
||||
self.metric_definition_inst.sensing_interval)
|
||||
self.assertEqual('CPU',
|
||||
self.metric_definition_inst.physical_context)
|
||||
self.assertEqual('%', self.metric_definition_inst.units)
|
||||
self.assertEqual(
|
||||
0, self.metric_definition_inst.min_reading_range)
|
||||
self.assertEqual(
|
||||
100, self.metric_definition_inst.max_reading_range)
|
||||
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_2/'
|
||||
'cpu_health_metric_def.json', 'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
|
||||
self.metric_definition_inst.refresh()
|
||||
self.assertEqual('1.1.0',
|
||||
self.metric_definition_inst.redfish_version)
|
||||
self.assertEqual('CPU1 IPMI Health Sensor',
|
||||
self.metric_definition_inst.name)
|
||||
self.assertEqual('CPUHealth1',
|
||||
self.metric_definition_inst.identity)
|
||||
self.assertEqual('Discrete',
|
||||
self.metric_definition_inst.metric_type)
|
||||
self.assertEqual('PhysicalSensor',
|
||||
self.metric_definition_inst.sensor_type)
|
||||
self.assertEqual('PhysicalSensor',
|
||||
self.metric_definition_inst.implementation)
|
||||
self.assertEqual('PT1S',
|
||||
self.metric_definition_inst.sensing_interval)
|
||||
self.assertEqual('CPU',
|
||||
self.metric_definition_inst.physical_context)
|
||||
|
||||
expected = [
|
||||
"OK",
|
||||
"Internal Error",
|
||||
"Thermal Trip",
|
||||
"FRB1 BIST Failure",
|
||||
"FRB2 Hang in Post",
|
||||
"FRB3 Startup Failure",
|
||||
"Config Error",
|
||||
"SMBIOS Uncorrectable Error",
|
||||
"Processor Presence Detected",
|
||||
"Processor Disabled",
|
||||
"Terminator Presence Detected",
|
||||
"Processor Throttled",
|
||||
"Machine Check Exception",
|
||||
"Correctable Machine Check Error"
|
||||
]
|
||||
self.assertEqual(expected,
|
||||
self.metric_definition_inst.discrete_values)
|
||||
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_2/'
|
||||
'cpu_temperature_metric_def.json', 'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
|
||||
self.metric_definition_inst.refresh()
|
||||
self.assertEqual('1.1.0',
|
||||
self.metric_definition_inst.redfish_version)
|
||||
self.assertEqual('Temperature MetricDefinition',
|
||||
self.metric_definition_inst.name)
|
||||
self.assertEqual('TEMP1',
|
||||
self.metric_definition_inst.identity)
|
||||
self.assertEqual('Numeric',
|
||||
self.metric_definition_inst.metric_type)
|
||||
self.assertEqual('Temperature',
|
||||
self.metric_definition_inst.sensor_type)
|
||||
self.assertEqual('Physical',
|
||||
self.metric_definition_inst.implementation)
|
||||
self.assertEqual('PT1S',
|
||||
self.metric_definition_inst.sensing_interval)
|
||||
self.assertEqual('CPU',
|
||||
self.metric_definition_inst.physical_context)
|
||||
self.assertEqual('Cel', self.metric_definition_inst.units)
|
||||
self.assertEqual(
|
||||
0, self.metric_definition_inst.min_reading_range)
|
||||
self.assertEqual(
|
||||
80, self.metric_definition_inst.max_reading_range)
|
||||
self.assertEqual(1, self.metric_definition_inst.precision)
|
||||
self.assertEqual(2, self.metric_definition_inst.calibration)
|
||||
|
||||
|
||||
class MetricDefinitionsCollectionTestCase(testtools.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
@ -45,50 +200,34 @@ class MetricDefinitionsCollectionTestCase(testtools.TestCase):
|
||||
'/redfish/v1/TelemetryService/MetricDefinitions/CPUBandwidth'),
|
||||
self.metric_def_col.members_identities)
|
||||
|
||||
@mock.patch.object(cpu_bandwidth, 'CPUBandwidth', autospec=True)
|
||||
@mock.patch.object(cpu_health, 'CPUHealth', autospec=True)
|
||||
@mock.patch.object(cpu_temperature, 'CPUTemperature', autospec=True)
|
||||
def test_get_member(self, mock_cpu_temperature, mock_cpu_health,
|
||||
mock_cpu_bandwidth):
|
||||
@mock.patch.object(metric_definitions, 'MetricDefinition', autospec=True)
|
||||
def test_get_member(self, mock_metric_definition):
|
||||
self.metric_def_col.get_member(
|
||||
'/redfish/v1/TelemetryService/MetricDefinitions/CPUTemperature')
|
||||
mock_cpu_temperature.assert_called_once_with(
|
||||
mock_metric_definition.assert_called_once_with(
|
||||
self.metric_def_col._conn,
|
||||
'/redfish/v1/TelemetryService/MetricDefinitions/CPUTemperature',
|
||||
redfish_version=self.metric_def_col.redfish_version)
|
||||
|
||||
self.metric_def_col.get_member(
|
||||
'/redfish/v1/TelemetryService/MetricDefinitions/CPUHealth')
|
||||
mock_cpu_health.assert_called_once_with(
|
||||
self.metric_def_col._conn,
|
||||
'/redfish/v1/TelemetryService/MetricDefinitions/CPUHealth',
|
||||
redfish_version=self.metric_def_col.redfish_version)
|
||||
|
||||
self.metric_def_col.get_member(
|
||||
'/redfish/v1/TelemetryService/MetricDefinitions/CPUBandwidth')
|
||||
mock_cpu_bandwidth.assert_called_once_with(
|
||||
self.metric_def_col._conn,
|
||||
'/redfish/v1/TelemetryService/MetricDefinitions/CPUBandwidth',
|
||||
redfish_version=self.metric_def_col.redfish_version)
|
||||
|
||||
@mock.patch.object(cpu_bandwidth, 'CPUBandwidth', autospec=True)
|
||||
@mock.patch.object(cpu_health, 'CPUHealth', autospec=True)
|
||||
@mock.patch.object(cpu_temperature, 'CPUTemperature', autospec=True)
|
||||
def test_get_members(self, mock_cpu_temperature, mock_cpu_health,
|
||||
mock_cpu_bandwidth):
|
||||
@mock.patch.object(metric_definitions, 'MetricDefinition', autospec=True)
|
||||
def test_get_members(self, mock_metric_definition):
|
||||
members = self.metric_def_col.get_members()
|
||||
|
||||
mock_cpu_temperature.assert_called_once_with(
|
||||
self.metric_def_col._conn,
|
||||
'/redfish/v1/TelemetryService/MetricDefinitions/CPUTemperature',
|
||||
redfish_version=self.metric_def_col.redfish_version)
|
||||
mock_cpu_health.assert_called_once_with(
|
||||
self.metric_def_col._conn,
|
||||
'/redfish/v1/TelemetryService/MetricDefinitions/CPUHealth',
|
||||
redfish_version=self.metric_def_col.redfish_version)
|
||||
mock_cpu_bandwidth.assert_called_once_with(
|
||||
self.metric_def_col._conn,
|
||||
'/redfish/v1/TelemetryService/MetricDefinitions/CPUBandwidth',
|
||||
redfish_version=self.metric_def_col.redfish_version)
|
||||
calls = [
|
||||
mock.call(
|
||||
self.metric_def_col._conn,
|
||||
'/redfish/v1/TelemetryService/MetricDefinitions/'
|
||||
'CPUTemperature',
|
||||
redfish_version=self.metric_def_col.redfish_version),
|
||||
mock.call(
|
||||
self.metric_def_col._conn,
|
||||
'/redfish/v1/TelemetryService/MetricDefinitions/CPUHealth',
|
||||
redfish_version=self.metric_def_col.redfish_version),
|
||||
mock.call(
|
||||
self.metric_def_col._conn,
|
||||
'/redfish/v1/TelemetryService/MetricDefinitions/CPUBandwidth',
|
||||
redfish_version=self.metric_def_col.redfish_version)
|
||||
]
|
||||
mock_metric_definition.assert_has_calls(calls)
|
||||
self.assertIsInstance(members, list)
|
||||
self.assertEqual(3, len(members))
|
||||
|
Loading…
x
Reference in New Issue
Block a user