Add system metrics for RSD 2.2

RSD 2.2 add more metrics information for System resource in URI
/redfish/v1/Systems/{systemID}/Metrics. Added corresponding interface
to retrieve such information back.

Change-Id: Iba7d9a164a12805e1e4c325bcc8f7815806ea306
This commit is contained in:
Lin Yang 2018-02-12 19:40:47 -08:00
parent 61d491c73a
commit d01f675d8b
13 changed files with 640 additions and 1 deletions

View File

@ -0,0 +1,39 @@
# 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
from rsd_lib.resources import v2_1
from rsd_lib.resources.v2_2.system import system
class RSDLibV2_2(v2_1.RSDLibV2_1):
_nodes_path = base.Field(['Oem', 'Intel_RackScale', 'Nodes', '@odata.id'],
required=True)
"""NodeCollection path"""
_storage_service_path = base.Field(['Oem', 'Intel_RackScale', 'Services',
'@odata.id'], required=True)
"""StorageServiceCollection path"""
def get_system(self, identity):
"""Given the identity return a System object
:param identity: The identity of the System resource
:returns: The System object
"""
return system.System(self._conn, identity,
redfish_version=self.redfish_version)

View File

@ -0,0 +1,51 @@
# 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 Metrics(base.ResourceBase):
name = base.Field('Name')
"""The metrics name"""
description = base.Field('Description')
"""The metrics description"""
identity = base.Field('Id')
"""The metrics identity"""
processor_bandwidth_percent = base.Field('ProcessorBandwidthPercent',
adapter=int)
"""The processor bandwidth percent"""
memory_bandwidth_percent = base.Field('MemoryBandwidthPercent',
adapter=int)
"""The memory bandwidth percent"""
memory_throttled_cycles_percent = base.Field(
'MemoryThrottledCyclesPercent', adapter=int)
"""The memory throttled cycles percent"""
processor_power_watt = base.Field('ProcessorPowerWatt', adapter=int)
"""The processor power watt"""
memory_power_watt = base.Field('MemoryPowerWatt', adapter=int)
"""The memory power watt"""
io_bandwidth_gbps = base.Field('IOBandwidthGBps', adapter=int)
"""The io bandwidth GBps"""
health = base.Field('Health', adapter=list)
"""The detail health information"""

View File

@ -0,0 +1,51 @@
# 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 import exceptions
from sushy.resources.system import system
from rsd_lib.resources.v2_2.system import metrics
from rsd_lib import utils
class System(system.System):
_metrics = None # ref to System instance
def _get_metrics_path(self):
"""Helper function to find the System path"""
system_col = self.json.get('Oem').get('Intel_RackScale').get('Metrics')
if not system_col:
raise exceptions.MissingAttributeError(attribute='Metrics',
resource=self._path)
return utils.get_resource_identity(system_col)
@property
def metrics(self):
"""Property to provide reference to `Metrics` instance
It is calculated once the first time it is queried. On refresh,
this property is reset.
"""
if self._metrics is None:
self._metrics = metrics.Metrics(
self._conn, self._get_metrics_path(),
redfish_version=self.redfish_version)
return self._metrics
def refresh(self):
super(System, self).refresh()
self._metrics = None

View File

@ -0,0 +1,44 @@
{
"@odata.context": "/redfish/v1/$metadata#ServiceRoot.ServiceRoot",
"@odata.id": "/redfish/v1/",
"@odata.type": "#ServiceRoot.v1_1_1.ServiceRoot",
"Id": "RootService",
"Name": "Root Service",
"Description": "description-as-string",
"RedfishVersion": "1.1.0",
"UUID": "92384634-2938-2342-8820-489239905423",
"Systems": {
"@odata.id": "/redfish/v1/Systems"
},
"Chassis": {
"@odata.id": "/redfish/v1/Chassis"
},
"Managers": {
"@odata.id": "/redfish/v1/Managers"
},
"EventService": {
"@odata.id": "/redfish/v1/EventService"
},
"Fabrics": {
"@odata.id": "/redfish/v1/Fabrics"
},
"TelemetryService": {
"@odata.id": "/redfish/v1/TelemetryService"
},
"Oem": {
"Intel_RackScale": {
"@odata.type": "#Intel.Oem.ServiceRoot",
"ApiVersion": "2.2.0",
"Services": {
"@odata.id": "/redfish/v1/Services"
},
"Nodes": {
"@odata.id": "/redfish/v1/Nodes"
},
"EthernetSwitches": {
"@odata.id": "/redfish/v1/EthernetSwitches"
}
}
},
"Links": {}
}

View File

@ -0,0 +1,123 @@
{
"@odata.context": "/redfish/v1/$metadata#ComputerSystem.ComputerSystem", "@odata.id": "/redfish/v1/Systems/System2",
"@odata.type": "#ComputerSystem.v1_3_0.ComputerSystem",
"Id": "System2",
"Name": "My Computer System",
"Description": "Description of server",
"SystemType": "Physical",
"AssetTag": "free form asset tag",
"Manufacturer": "Manufacturer Name",
"Model": "Model Name",
"SKU": "SKU",
"SerialNumber": "2M220100SL",
"PartNumber": "Computer1",
"UUID": "00000000-0000-0000-0000-000000000000",
"HostName": null,
"Status": {
"State": "Enabled",
"Health": "OK",
"HealthRollup": "OK"
},
"IndicatorLED": null,
"PowerState": "On",
"Boot": {
"@odata.type": "#ComputerSystem.v1_1_0.Boot",
"BootSourceOverrideEnabled": "Disabled",
"BootSourceOverrideTarget": "None",
"BootSourceOverrideTarget@Redfish.AllowableValues": ["None"],
"BootSourceOverrideMode": null,
"BootSourceOverrideMode@Redfish.AllowableValues": []
},
"BiosVersion": null,
"ProcessorSummary": {
"Count": 0,
"Model": null,
"Status": {
"State": null,
"Health": null,
"HealthRollup": null
}
},
"MemorySummary": {
"TotalSystemMemoryGiB": 0,
"Status": {
"State": null,
"Health": null,
"HealthRollup": null
}
},
"Processors": {
"@odata.id": "/redfish/v1/Systems/System2/Processors"
},
"EthernetInterfaces": {
"@odata.id": "/redfish/v1/Systems/System2/EthernetInterfaces"
},
"SimpleStorage": {},
"Storage": {
"@odata.id": "/redfish/v1/Systems/System2/Storage"
},
"Memory": {
"@odata.id": "/redfish/v1/Systems/System1/Memory"
},
"PCIeDevices": [
{
"@odata.id": "/redfish/v1/Chassis/PCIeSwitch1/PCIeDevices/Device1"
}
],
"PCIeFunctions": [],
"TrustedModules": [],
"Links": {
"@odata.type": "#ComputerSystem.v1_2_0.Links",
"Chassis": [{
"@odata.id": "/redfish/v1/Chassis/4"
}],
"ManagedBy": [{
"@odata.id": "/redfish/v1/Managers/1"
}],
"Endpoints": [],
"Oem": {}
},
"Actions": {
"#ComputerSystem.Reset": {
"target": "/redfish/v1/Systems/System1/Actions/ComputerSystem.Reset",
"ResetType@Redfish.AllowableValues": ["On",
"ForceOff",
"GracefulShutdown",
"ForceRestart",
"Nmi",
"GracefulRestart",
"ForceOn",
"PushPowerButton"]
},
"Oem": {
"#Intel.Oem.StartDeepDiscovery": {
"target": "/redfish/v1/Systems/System1/Actions/Oem/Intel.Oem.StartDeepDiscovery"
},
"#Intel.Oem.StartDiscoveryOnDemand": {
"target": "/redfish/v1/Systems/System1/Actions/Oem/Intel.Oem.StartDiscoveryOnDemand"
},
"#Intel.Oem.ChangeTPMState": {
"target": "/redfish/v1/Systems/System1/Actions/Oem/Intel.Oem.ChangeTPMState",
"InterfaceType@Redfish.AllowableValues": [
"TPM1_2",
"TPM2_0"
]
}
}
},
"Oem": {
"Intel_RackScale": {
"@odata.type": "#Intel.Oem.ComputerSystem",
"PciDevices": [],
"DiscoveryState": "Basic",
"ProcessorSockets": null,
"MemorySockets": null,
"PCIeConnectionId": [],
"UserModeEnabled": false,
"TrustedExecutionTechnologyEnabled": false,
"Metrics": {
"@odata.id": "/redfish/v1/Systems/System2/Metrics"
}
}
}
}

View File

@ -0,0 +1,15 @@
{
"@odata.context": "/redfish/v1/$metadata#ComputerSystemMetricsComputerSystemMetrics",
"@odata.id": "/redfish/v1/Systems/System1/Metrics",
"@odata.type": "#ComputerSystemMetrics.v1_0_0.ComputerSystemMetrics",
"Name": "Computer System Metrics for System1",
"Description": "description-as-string",
"Id": "Metrics for System1",
"ProcessorBandwidthPercent": 17,
"MemoryBandwidthPercent": 23,
"MemoryThrottledCyclesPercent": 13,
"ProcessorPowerWatt": 120,
"MemoryPowerWatt": 48,
"IOBandwidthGBps": 4,
"Health": ["OK"]
}

View File

@ -14,13 +14,16 @@
# under the License. # under the License.
import json import json
import mock import mock
import testtools import testtools
from sushy.resources.system import system
from rsd_lib.resources import v2_1 from rsd_lib.resources import v2_1
from rsd_lib.resources.v2_1.chassis import chassis
from rsd_lib.resources.v2_1.fabric import fabric from rsd_lib.resources.v2_1.fabric import fabric
from rsd_lib.resources.v2_1.node import node from rsd_lib.resources.v2_1.node import node
from rsd_lib.resources.v2_1.storage_service import storage_service
class RSDLibV2_1TestCase(testtools.TestCase): class RSDLibV2_1TestCase(testtools.TestCase):
@ -43,6 +46,20 @@ class RSDLibV2_1TestCase(testtools.TestCase):
self.rsd._storage_service_path) self.rsd._storage_service_path)
self.assertEqual("/redfish/v1/Fabrics", self.rsd._fabrics_path) self.assertEqual("/redfish/v1/Fabrics", self.rsd._fabrics_path)
@mock.patch.object(system, 'SystemCollection', autospec=True)
def test_get_system_collection(self, mock_system_collection):
self.rsd.get_system_collection()
mock_system_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Systems',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(system, 'System', autospec=True)
def test_get_system(self, mock_system):
self.rsd.get_system('fake-system-id')
mock_system.assert_called_once_with(
self.rsd._conn, 'fake-system-id',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(node, 'NodeCollection', autospec=True) @mock.patch.object(node, 'NodeCollection', autospec=True)
def test_get_node_collection(self, mock_node_collection): def test_get_node_collection(self, mock_node_collection):
self.rsd.get_node_collection() self.rsd.get_node_collection()
@ -70,3 +87,33 @@ class RSDLibV2_1TestCase(testtools.TestCase):
mock_fabric.assert_called_once_with( mock_fabric.assert_called_once_with(
self.rsd._conn, 'fake-fabric-id', self.rsd._conn, 'fake-fabric-id',
redfish_version=self.rsd.redfish_version) redfish_version=self.rsd.redfish_version)
@mock.patch.object(chassis, 'ChassisCollection', autospec=True)
def test_get_chassis_collection(self, mock_chassis_collection):
self.rsd.get_chassis_collection()
mock_chassis_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Chassis',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(chassis, 'Chassis', autospec=True)
def test_get_chassis(self, mock_chassis):
self.rsd.get_chassis('fake-chassis-id')
mock_chassis.assert_called_once_with(
self.rsd._conn, 'fake-chassis-id',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(storage_service, 'StorageServiceCollection',
autospec=True)
def test_get_storage_service_collection(self,
mock_storage_service_collection):
self.rsd.get_storage_service_collection()
mock_storage_service_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Services',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(storage_service, 'StorageService', autospec=True)
def test_get_storage_service(self, mock_storage_service):
self.rsd.get_storage_service('fake-storage-service-id')
mock_storage_service.assert_called_once_with(
self.rsd._conn, 'fake-storage-service-id',
redfish_version=self.rsd.redfish_version)

View File

@ -0,0 +1,54 @@
# 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.system import metrics
class MetricsTestCase(testtools.TestCase):
def setUp(self):
super(MetricsTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_2/system_metrics.json',
'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.system_metrics_inst = metrics.Metrics(
self.conn, '/redfish/v1/Systems/System1/Metrics',
redfish_version='1.0.2')
def test__parse_attributes(self):
self.system_metrics_inst._parse_attributes()
self.assertEqual('1.0.2', self.system_metrics_inst.redfish_version)
self.assertEqual('Computer System Metrics for System1',
self.system_metrics_inst.name)
self.assertEqual('description-as-string',
self.system_metrics_inst.description)
self.assertEqual('Metrics for System1',
self.system_metrics_inst.identity)
self.assertEqual(
17, self.system_metrics_inst.processor_bandwidth_percent)
self.assertEqual(23, self.system_metrics_inst.memory_bandwidth_percent)
self.assertEqual(
13, self.system_metrics_inst.memory_throttled_cycles_percent)
self.assertEqual(120, self.system_metrics_inst.processor_power_watt)
self.assertEqual(48, self.system_metrics_inst.memory_power_watt)
self.assertEqual(4, self.system_metrics_inst.io_bandwidth_gbps)
self.assertEqual(["OK"], self.system_metrics_inst.health)

View File

@ -0,0 +1,95 @@
# 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 sushy import exceptions
from rsd_lib.resources.v2_2.system import metrics
from rsd_lib.resources.v2_2.system import system
class SystemTestCase(testtools.TestCase):
def setUp(self):
super(SystemTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_2/system.json',
'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.system_inst = system.System(
self.conn, '/redfish/v1/Systems/System2',
redfish_version='1.0.2')
def test__get_metrics_path(self):
self.assertEqual('/redfish/v1/Systems/System2/Metrics',
self.system_inst._get_metrics_path())
def test__get_metrics_path_missing_systems_attr(self):
self.system_inst._json.get('Oem').get('Intel_RackScale').pop('Metrics')
with self.assertRaisesRegex(
exceptions.MissingAttributeError, 'attribute Metrics'):
self.system_inst._get_metrics_path()
def test_metrics(self):
# check for the underneath variable value
self.assertIsNone(self.system_inst._metrics)
# | GIVEN |
self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_2/system_metrics.json',
'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN |
actual_metrics = self.system_inst.metrics
# | THEN |
self.assertIsInstance(actual_metrics,
metrics.Metrics)
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_metrics,
self.system_inst.metrics)
self.conn.get.return_value.json.assert_not_called()
def test_metrics_on_refresh(self):
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_2/system_metrics.json',
'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.system_inst.metrics,
metrics.Metrics)
# On refreshing the system instance...
with open('rsd_lib/tests/unit/json_samples/v2_2/system.json',
'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.system_inst.refresh()
# | WHEN & THEN |
self.assertIsNone(self.system_inst._metrics)
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_2/system_metrics.json',
'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.system_inst.metrics,
metrics.Metrics)

View File

@ -0,0 +1,120 @@
# 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 sushy.resources.system import system
from rsd_lib.resources.v2_1.chassis import chassis
from rsd_lib.resources.v2_1.fabric import fabric
from rsd_lib.resources.v2_1.node import node
from rsd_lib.resources.v2_1.storage_service import storage_service
from rsd_lib.resources import v2_2
from rsd_lib.resources.v2_2.system import system as v2_2_system
class RSDLibV2_2TestCase(testtools.TestCase):
def setUp(self):
super(RSDLibV2_2TestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_2/root.json', 'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.rsd = v2_2.RSDLibV2_2(self.conn)
def test__parse_attributes(self):
self.rsd._parse_attributes()
self.assertEqual("2.2.0", self.rsd._rsd_api_version)
self.assertEqual("1.1.0", self.rsd._redfish_version)
self.assertEqual("/redfish/v1/Systems", self.rsd._systems_path)
self.assertEqual("/redfish/v1/Nodes", self.rsd._nodes_path)
self.assertEqual("/redfish/v1/Chassis", self.rsd._chassis_path)
self.assertEqual("/redfish/v1/Services",
self.rsd._storage_service_path)
self.assertEqual("/redfish/v1/Fabrics", self.rsd._fabrics_path)
@mock.patch.object(system, 'SystemCollection', autospec=True)
def test_get_system_collection(self, mock_system_collection):
self.rsd.get_system_collection()
mock_system_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Systems',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(v2_2_system, 'System', autospec=True)
def test_get_system(self, mock_system):
self.rsd.get_system('fake-system-id')
mock_system.assert_called_once_with(
self.rsd._conn, 'fake-system-id',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(node, 'NodeCollection', autospec=True)
def test_get_node_collection(self, mock_node_collection):
self.rsd.get_node_collection()
mock_node_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Nodes',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(node, 'Node', autospec=True)
def test_get_node(self, mock_node):
self.rsd.get_node('fake-node-id')
mock_node.assert_called_once_with(
self.rsd._conn, 'fake-node-id',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(fabric, 'FabricCollection', autospec=True)
def test_get_fabric_collection(self, mock_fabric_collection):
self.rsd.get_fabric_collection()
mock_fabric_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Fabrics',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(fabric, 'Fabric', autospec=True)
def test_get_fabric(self, mock_fabric):
self.rsd.get_fabric('fake-fabric-id')
mock_fabric.assert_called_once_with(
self.rsd._conn, 'fake-fabric-id',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(chassis, 'ChassisCollection', autospec=True)
def test_get_chassis_collection(self, mock_chassis_collection):
self.rsd.get_chassis_collection()
mock_chassis_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Chassis',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(chassis, 'Chassis', autospec=True)
def test_get_chassis(self, mock_chassis):
self.rsd.get_chassis('fake-chassis-id')
mock_chassis.assert_called_once_with(
self.rsd._conn, 'fake-chassis-id',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(storage_service, 'StorageServiceCollection',
autospec=True)
def test_get_storage_service_collection(self,
mock_storage_service_collection):
self.rsd.get_storage_service_collection()
mock_storage_service_collection.assert_called_once_with(
self.rsd._conn, '/redfish/v1/Services',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(storage_service, 'StorageService', autospec=True)
def test_get_storage_service(self, mock_storage_service):
self.rsd.get_storage_service('fake-storage-service-id')
mock_storage_service.assert_called_once_with(
self.rsd._conn, 'fake-storage-service-id',
redfish_version=self.rsd.redfish_version)