Merge "Add metrics resource for RSD 2.2"
This commit is contained in:
commit
9b0309c5b3
@ -1,4 +1,4 @@
|
||||
# Copyright 2018 Intel, Inc.
|
||||
# Copyright 2019 Intel, Inc.
|
||||
# All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
@ -13,13 +13,14 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from sushy.resources import base
|
||||
from sushy import utils
|
||||
|
||||
from rsd_lib.resources.v2_1.ethernet_switch import ethernet_switch \
|
||||
as v2_1_ethernet_switch
|
||||
from rsd_lib.resources.v2_2.ethernet_switch import metrics
|
||||
from rsd_lib.resources.v2_2.ethernet_switch import port
|
||||
|
||||
from sushy.resources import base
|
||||
from sushy import utils
|
||||
|
||||
|
||||
class EthernetSwitch(v2_1_ethernet_switch.EthernetSwitch):
|
||||
|
||||
@ -35,6 +36,22 @@ class EthernetSwitch(v2_1_ethernet_switch.EthernetSwitch):
|
||||
self._conn, self._get_port_collection_path(),
|
||||
redfish_version=self.redfish_version)
|
||||
|
||||
def _get_metrics_path(self):
|
||||
"""Helper function to find the Metrics path"""
|
||||
return utils.get_sub_resource_path_by(self, '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 metrics.Metrics(
|
||||
self._conn, self._get_metrics_path(),
|
||||
redfish_version=self.redfish_version)
|
||||
|
||||
|
||||
class EthernetSwitchCollection(base.ResourceCollectionBase):
|
||||
|
||||
|
30
rsd_lib/resources/v2_2/ethernet_switch/metrics.py
Normal file
30
rsd_lib/resources/v2_2/ethernet_switch/metrics.py
Normal file
@ -0,0 +1,30 @@
|
||||
# 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.
|
||||
|
||||
from sushy.resources import base
|
||||
|
||||
|
||||
class Metrics(base.ResourceBase):
|
||||
name = base.Field("Name")
|
||||
"""The metrics name"""
|
||||
|
||||
description = base.Field("Description")
|
||||
"""The description of metrics"""
|
||||
|
||||
identity = base.Field("Id")
|
||||
"""The id of metrics"""
|
||||
|
||||
health = base.Field("Health")
|
||||
"""The health status of metrics"""
|
@ -0,0 +1,9 @@
|
||||
{
|
||||
"@odata.context": "/redfish/v1/$metadata#EthernetSwitchMetrics.EthernetSwitchMetrics",
|
||||
"@odata.id": "/redfish/v1/EthernetSwitches/Switch1/Metrics",
|
||||
"@odata.type": "#EthernetSwitchMetrics.v1_0_0.EthernetSwitchMetrics",
|
||||
"Name": "EthernetSwitch Metrics for Switch1",
|
||||
"Description": "description-as-string",
|
||||
"Id": "Metrics for Switch1",
|
||||
"Health": "OK"
|
||||
}
|
@ -15,11 +15,13 @@
|
||||
|
||||
import json
|
||||
import mock
|
||||
import testtools
|
||||
|
||||
from rsd_lib.resources.v2_2.ethernet_switch import ethernet_switch
|
||||
from rsd_lib.resources.v2_2.ethernet_switch import metrics
|
||||
from rsd_lib.resources.v2_2.ethernet_switch import port
|
||||
|
||||
import testtools
|
||||
|
||||
|
||||
class EthernetSwitchTestCase(testtools.TestCase):
|
||||
|
||||
@ -80,6 +82,52 @@ class EthernetSwitchTestCase(testtools.TestCase):
|
||||
self.assertIsInstance(self.ethernet_switch_inst.ports,
|
||||
port.PortCollection)
|
||||
|
||||
def test_metrics(self):
|
||||
# | GIVEN |
|
||||
self.conn.get.return_value.json.reset_mock()
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_2/'
|
||||
'ethernet_switch_metrics.json', 'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
# | WHEN |
|
||||
actual_metrics = self.ethernet_switch_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.ethernet_switch_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/'
|
||||
'ethernet_switch_metrics.json', 'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
# | WHEN & THEN |
|
||||
self.assertIsInstance(self.ethernet_switch_inst.metrics,
|
||||
metrics.Metrics)
|
||||
|
||||
# On refreshing the metrics instance...
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_2/'
|
||||
'ethernet_switch.json', 'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
|
||||
self.ethernet_switch_inst.invalidate()
|
||||
self.ethernet_switch_inst.refresh(force=False)
|
||||
|
||||
# | GIVEN |
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_2/'
|
||||
'ethernet_switch_metrics.json', 'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
# | WHEN & THEN |
|
||||
self.assertIsInstance(self.ethernet_switch_inst.metrics,
|
||||
metrics.Metrics)
|
||||
|
||||
|
||||
class EthernetSwitchCollectionTestCase(testtools.TestCase):
|
||||
|
||||
|
@ -0,0 +1,45 @@
|
||||
# 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
|
||||
from rsd_lib.resources.v2_2.ethernet_switch import metrics
|
||||
import testtools
|
||||
|
||||
|
||||
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/'
|
||||
'ethernet_switch_metrics.json',
|
||||
'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
|
||||
self.metrics_inst = metrics.Metrics(self.conn,
|
||||
'/redfish/v1/EthernetSwitches/'
|
||||
'Switch1/Metrics',
|
||||
redfish_version='1.0.2')
|
||||
|
||||
def test__parse_attributes(self):
|
||||
self.metrics_inst._parse_attributes()
|
||||
self.assertEqual('EthernetSwitch Metrics for Switch1',
|
||||
self.metrics_inst.name)
|
||||
self.assertEqual('description-as-string',
|
||||
self.metrics_inst.description)
|
||||
self.assertEqual('Metrics for Switch1', self.metrics_inst.identity)
|
||||
self.assertEqual('OK', self.metrics_inst.health)
|
Loading…
x
Reference in New Issue
Block a user