Add ethernet interface resource for RSD2.2

Change-Id: I3c303205f0b91ff3d279571458ddf9499d6305aa
This commit is contained in:
monokai 2019-01-16 16:33:24 +08:00
parent ec91d38ef4
commit 6bd83b5ea4
6 changed files with 237 additions and 2 deletions

View File

@ -0,0 +1,42 @@
# 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
from rsd_lib.resources.v2_1.manager import ethernet_interface as \
v2_1_ethernet_interface
class EthernetInterfaceCollection(v2_1_ethernet_interface.
EthernetInterfaceCollection):
description = base.Field("Description")
"""The ethernet interface description"""
def __init__(self, connector, path, redfish_version=None):
"""A class representing a EthernetInterface Collection
:param connector: A Connector instance
:param path: The canonical path to the EthernetInterface collection
resource
:param redfish_version: The version of RedFish. Used to construct
the object according to schema of the given version.
"""
super(EthernetInterfaceCollection, self).__init__(connector,
path,
redfish_version)

View File

@ -14,7 +14,11 @@
# under the License.
from rsd_lib.resources.v2_1.manager import manager as v2_1_manager
from rsd_lib.resources.v2_2.manager import ethernet_interface
from sushy.resources import base
from sushy import utils
class ManagerResetFiled(base.CompositeField):
@ -31,6 +35,22 @@ class Manager(v2_1_manager.Manager):
actions = ActionsField("Actions")
"""The manager actions"""
def _get_ethernet_interface_path(self):
"""Helper function to find the Ethernet Interface path"""
return utils.get_sub_resource_path_by(self, 'EthernetInterfaces')
@property
@utils.cache_it
def ethernet_interface(self):
"""Property to provide reference to `EthernetInterface` instance
It is calculated once when it is queried for the first time. On
refresh, this property is reset.
"""
return ethernet_interface.EthernetInterfaceCollection(
self._conn, self._get_ethernet_interface_path(),
redfish_version=self.redfish_version)
class ManagerCollection(base.ResourceCollectionBase):
description = base.Field("Description")

View File

@ -0,0 +1,61 @@
{
"@odata.context":"/redfish/v1/$metadata#EthernetInterface.EthernetInterface",
"@odata.id":"/redfish/v1/Systems/System1/EthernetInterfaces/LAN1",
"@odata.type":"#EthernetInterface.v1_1_0.EthernetInterface",
"Id":"LAN1",
"Name":"Ethernet Interface",
"Description":"System NIC 1",
"Status":{
"State":"Enabled",
"Health":"OK",
"HealthRollup":null
},
"InterfaceEnabled":true,
"PermanentMACAddress":"AA:BB:CC:DD:EE:FF",
"MACAddress":"AA:BB:CC:DD:EE:FF",
"SpeedMbps":100,
"AutoNeg":true,
"FullDuplex":true,
"MTUSize":1500,
"HostName":"web483",
"FQDN":"web483.redfishspecification.org",
"IPv6DefaultGateway":"fe80::3ed9:2bff:fe34:600",
"MaxIPv6StaticAddresses":null,
"NameServers":[
"names.redfishspecification.org"
],
"IPv4Addresses":[
{
"Address":"192.168.0.10",
"SubnetMask":"255.255.252.0",
"AddressOrigin":"Static",
"Gateway":"192.168.0.1"
}
],
"IPv6Addresses":[
{
"Address":"fe80::1ec1:deff:fe6f:1e24",
"PrefixLength":64,
"AddressOrigin":"Static",
"AddressState":"Preferred"
}
],
"IPv6StaticAddresses":[
],
"VLAN":null,
"VLANs":null,
"Oem":{
},
"Links":{
"Oem":{
"Intel_RackScale":{
"@odata.type":"#Intel.Oem.EthernetInterface",
"NeighborPort":{
"@odata.id":"/redfish/v1/EthernetSwitches/1/Ports/1"
}
}
}
}
}

View File

@ -0,0 +1,13 @@
{
"@odata.context":"/redfish/v1/$metadata#Managers/Members/1/EthernetInterfaces/$entity",
"@odata.id":"/redfish/v1/Managers/1/EthernetInterfaces",
"@odata.type":"#EthernetNetworkInterface.v1_0_0.EthernetNetworkInterfaceCollection",
"Name":"Ethernet Network Interface Collection",
"Description":"description-as-string",
"Members@odata.count":1,
"Members":[
{
"@odata.id":"/redfish/v1/Managers/1/EthernetInterfaces/1"
}
]
}

View File

@ -0,0 +1,52 @@
# 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
import testtools
from rsd_lib.resources.v2_2.manager import ethernet_interface
class EthernetInterface(testtools.TestCase):
def setUp(self):
super(EthernetInterface, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_2/'
'ethernet_interface.json', 'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.ethernet_interface_inst = ethernet_interface.EthernetInterface(
self.conn,
'/redfish/v1/Managers/1/EthernetInterfaces/1',
redfish_version='1.0.2')
class EthernetInterfaceCollectionTestCase(testtools.TestCase):
def setUp(self):
super(EthernetInterfaceCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_2/'
'ethernet_interface_collection.json', 'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.ethernet_interface_col = ethernet_interface.\
EthernetInterfaceCollection(self.conn,
'/redfish/v1/Managers/1/Ethernet'
'Interfaces/1',
redfish_version='1.0.2')
def test__parse_attributes(self):
self.assertEqual("description-as-string", self.ethernet_interface_col.
description)

View File

@ -17,10 +17,11 @@ import json
import mock
from sushy.tests.unit import base
from rsd_lib.resources.v2_2.manager import ethernet_interface
from rsd_lib.resources.v2_2.manager import manager
from sushy.tests.unit import base
class TestManager(base.TestCase):
@ -41,6 +42,52 @@ class TestManager(base.TestCase):
self.assertEqual('/redfish/v1/Managers/PSME/Actions/Manager.Reset',
self.manager_inst.actions.manager_reset.target)
def test_ethernet_interface(self):
# | GIVEN |
self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_2/'
'ethernet_interface.json', 'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN |
actual_ethernet_interface = self.manager_inst.ethernet_interface
# | THEN |
self.assertIsInstance(actual_ethernet_interface,
ethernet_interface.EthernetInterfaceCollection)
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_ethernet_interface,
self.manager_inst.ethernet_interface)
self.conn.get.return_value.json.assert_not_called()
def test_ethernet_interface_on_refresh(self):
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_2/'
'ethernet_interface.json', 'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.manager_inst.ethernet_interface,
ethernet_interface.EthernetInterfaceCollection)
# On refreshing the manager instance...
with open('rsd_lib/tests/unit/json_samples/v2_2/'
'manager.json', 'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.manager_inst.invalidate()
self.manager_inst.refresh(force=False)
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_2/'
'ethernet_interface.json', 'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.manager_inst.ethernet_interface,
ethernet_interface.EthernetInterfaceCollection)
class TestManagerCollection(base.TestCase):