Add Ethernet Interface in RSD 2.3 system

Change-Id: Iffe5358c6800d0ea622fdf620e2abf979d991775
This commit is contained in:
Lin Yang
2019-02-05 12:12:33 -08:00
parent bf81ec72f8
commit bbdb7c48df
13 changed files with 738 additions and 73 deletions

View File

@@ -52,8 +52,6 @@ class System(system.System):
self._conn, self._get_processor_collection_path(),
redfish_version=self.redfish_version)
return self._processors
@property
@utils.cache_it
def memory(self):

View File

@@ -0,0 +1,90 @@
# 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.system import ethernet_interface
from rsd_lib import utils as rsd_lib_utils
class IntelRackScaleField(base.CompositeField):
supported_protocols = base.Field("SupportedProtocols")
""""This property shall represent an array of supported protocol types
by the Ethernet interface.
"""
class OemField(base.CompositeField):
intel_rackscale = IntelRackScaleField("Intel_RackScale")
"""The Oem Intel_RackScale"""
class LinksIntelRackScaleField(base.CompositeField):
neighbor_port = base.Field("NeighborPort",
adapter=rsd_lib_utils.get_resource_identity)
"""The neighbor port of Rack ScaleIntel"""
class LinksOemField(base.CompositeField):
intel_rackscale = LinksIntelRackScaleField("Intel_RackScale")
"""The Oem Intel_RackScale"""
class LinksField(base.CompositeField):
oem = LinksOemField("Oem")
""""The oem of Links"""
endpoints = base.Field(
"Endpoints", adapter=rsd_lib_utils.get_resource_identity)
"""The value of this property shall be a reference to the resources that
this ethernet interface is associated with and shall reference a
resource of type Endpoint.
"""
class EthernetInterface(ethernet_interface.EthernetInterface):
uefi_device_path = base.Field('UefiDevicePath')
"""The value of the property shall be the UEFI device path to the device
that implements the interface (port).
"""
oem = OemField("Oem")
""""The oem fields of Ethernet Interface"""
links = LinksField("Links")
"""The EthernetInterface links"""
class EthernetInterfaceCollection(ethernet_interface.
EthernetInterfaceCollection):
@property
def _resource_type(self):
return EthernetInterface
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

@@ -0,0 +1,41 @@
# 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 utils
from rsd_lib.resources.v2_2.system import system
from rsd_lib.resources.v2_3.system import ethernet_interface
class System(system.System):
@property
@utils.cache_it
def ethernet_interface(self):
"""Property to provide reference to `EthernetInterface` instance
It is calculated once the first time it is queried. On refresh,
this property is reset.
"""
return ethernet_interface.EthernetInterfaceCollection(
self._conn, self._get_ethernet_interface_collection_path(),
redfish_version=self.redfish_version)
class SystemCollection(system.SystemCollection):
@property
def _resource_type(self):
return System

View File

@@ -0,0 +1,136 @@
{
"@odata.type": "#ComputerSystem.v1_1_0.ComputerSystem",
"Id": "437XR1138R2",
"Name": "WebFrontEnd483",
"SystemType": "Physical",
"AssetTag": "Chicago-45Z-2381",
"Manufacturer": "Contoso",
"Model": "3500RX",
"SKU": "8675309",
"SerialNumber": "437XR1138R2",
"PartNumber": "224071-J23",
"Description": "Web Front End node",
"UUID": "38947555-7742-3448-3784-823347823834",
"HostName": "web483",
"Status": {
"State": "Enabled",
"Health": "OK",
"HealthRollup": "OK"
},
"IndicatorLED": "Off",
"PowerState": "On",
"Boot": {
"BootSourceOverrideEnabled": "Once",
"BootSourceOverrideTarget": "Pxe",
"BootSourceOverrideTarget@Redfish.AllowableValues": [
"None",
"Pxe",
"Cd",
"Usb",
"Hdd",
"BiosSetup",
"Utilities",
"Diags",
"SDCard",
"UefiTarget"
],
"BootSourceOverrideMode": "UEFI",
"UefiTargetBootSourceOverride": "/0x31/0x33/0x01/0x01"
},
"TrustedModules": [
{
"FirmwareVersion": "1.13b",
"InterfaceType": "TPM1_2",
"Status": {
"State": "Enabled",
"Health": "OK"
}
}
],
"Oem": {
"Contoso": {
"@odata.type": "http://Contoso.com/Schema#Contoso.ComputerSystem",
"ProductionLocation": {
"FacilityName": "PacWest Production Facility",
"Country": "USA"
}
},
"Chipwise": {
"@odata.type": "http://Chipwise.com/Schema#Chipwise.ComputerSystem",
"Style": "Executive"
}
},
"BiosVersion": "P79 v1.33 (02/28/2015)",
"ProcessorSummary": {
"Count": 2,
"ProcessorFamily": "Multi-Core Intel(R) Xeon(R) processor 7xxx Series",
"Status": {
"State": "Enabled",
"Health": "OK",
"HealthRollup": "OK"
}
},
"MemorySummary": {
"TotalSystemMemoryGiB": 96,
"Status": {
"State": "Enabled",
"Health": "OK",
"HealthRollup": "OK"
}
},
"Bios": {
"@odata.id": "/redfish/v1/Systems/437XR1138R2/BIOS"
},
"Processors": {
"@odata.id": "/redfish/v1/Systems/437XR1138R2/Processors"
},
"Memory": {
"@odata.id": "/redfish/v1/Systems/437XR1138R2/Memory"
},
"EthernetInterfaces": {
"@odata.id": "/redfish/v1/Systems/437XR1138R2/EthernetInterfaces"
},
"SimpleStorage": {
"@odata.id": "/redfish/v1/Systems/437XR1138R2/SimpleStorage"
},
"Storage": {
"@odata.id": "/redfish/v1/Systems/1/Storage"
},
"LogServices": {
"@odata.id": "/redfish/v1/Systems/437XR1138R2/LogServices"
},
"Links": {
"Chassis": [
{
"@odata.id": "/redfish/v1/Chassis/1U"
}
],
"ManagedBy": [
{
"@odata.id": "/redfish/v1/Managers/BMC"
}
]
},
"Actions": {
"#ComputerSystem.Reset": {
"target": "/redfish/v1/Systems/437XR1138R2/Actions/ComputerSystem.Reset",
"ResetType@Redfish.AllowableValues": [
"On",
"ForceOff",
"GracefulShutdown",
"GracefulRestart",
"ForceRestart",
"Nmi",
"ForceOn"
]
},
"Oem": {
"#Contoso.Reset": {
"target": "/redfish/v1/Systems/437XR1138R2/Oem/Contoso/Actions/Contoso.Reset"
}
}
},
"@odata.context": "/redfish/v1/$metadata#ComputerSystem.ComputerSystem",
"@odata.id": "/redfish/v1/Systems/437XR1138R2",
"@Redfish.Copyright": "Copyright 2014-2016 Distributed Management Task Force, Inc. (DMTF). For the full DMTF copyright policy, see http://www.dmtf.org/about/policies/copyright."
}

View File

@@ -0,0 +1,15 @@
{
"@odata.context": "/redfish/v1/$metadata#ComputerSystemCollection.ComputerSystemCollection",
"@odata.id": "/redfish/v1/Systems",
"@odata.type": "#ComputerSystemCollection.ComputerSystemCollection",
"Name": "Computer System Collection",
"Members@odata.count": 2,
"Members": [
{
"@odata.id": "/redfish/v1/Systems/System1"
},
{
"@odata.id": "/redfish/v1/Systems/System2"
}
]
}

View File

@@ -0,0 +1,67 @@
{
"@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
},
"UefiDevicePath": "UefiDevicePath string",
"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": {
"Intel_RackScale" : {
"SupportedProtocols": [
"RoCEv2",
"iWARP",
"iSCSI"
]
}
},
"Links": {
"Oem" : {
"Intel_RackScale" : {
"@odata.type" : "#Intel.Oem.EthernetInterface",
"NeighborPort" : {
"@odata.id" : "/redfish/v1/EthernetSwitches/1/Ports/1"
}
}
}
}
}

View File

@@ -0,0 +1,12 @@
{
"@odata.context": "/redfish/v1/$metadata#Systems/Members/1/EthernetInterfaces/$entity",
"@odata.type": "#EthernetInterfaceCollection.EthernetInterfaceCollection",
"@odata.id": "/redfish/v1/Systems/System1/EthernetInterfaces",
"Name": "Ethernet Interface Collection",
"Members@odata.count": 1,
"Members": [
{
"@odata.id": "/redfish/v1/Systems/System1/EthernetInterfaces/LAN1"
}
]
}

View File

@@ -39,66 +39,68 @@ class EthernetInterface(testtools.TestCase):
def test_parse_attributes(self):
self.ethernet_interface_inst._parse_attributes()
self.assertEqual("LAN1", self.ethernet_interface_inst.identity)
self.assertEqual("Ethernet Interface", self.
ethernet_interface_inst.name)
self.assertEqual("System NIC 1", self.
ethernet_interface_inst.description)
self.assertEqual("Enabled", self.
ethernet_interface_inst.status.state)
self.assertEqual("Ethernet Interface",
self.ethernet_interface_inst.name)
self.assertEqual("System NIC 1",
self.ethernet_interface_inst.description)
self.assertEqual("Enabled",
self.ethernet_interface_inst.status.state)
self.assertEqual("OK", self.ethernet_interface_inst.status.health)
self.assertEqual(None, self.
ethernet_interface_inst.status.health_rollup)
self.assertEqual(True, self.
ethernet_interface_inst.interface_enabled)
self.assertEqual("AA:BB:CC:DD:EE:FF", self.
ethernet_interface_inst.
permanent_mac_address)
self.assertEqual("AA:BB:CC:DD:EE:FF", self.
ethernet_interface_inst.
mac_address)
self.assertEqual(100, self.
ethernet_interface_inst.speed_mbps)
self.assertEqual(None,
self.ethernet_interface_inst.status.health_rollup)
self.assertEqual(True,
self.ethernet_interface_inst.interface_enabled)
self.assertEqual(
"AA:BB:CC:DD:EE:FF",
self.ethernet_interface_inst.permanent_mac_address)
self.assertEqual(
"AA:BB:CC:DD:EE:FF",
self.ethernet_interface_inst.mac_address)
self.assertEqual(100, self.ethernet_interface_inst.speed_mbps)
self.assertEqual(True, self.ethernet_interface_inst.auto_neg)
self.assertEqual(True, self.ethernet_interface_inst.full_duplex)
self.assertEqual(1500, self.ethernet_interface_inst.mtu_size)
self.assertEqual("web483", self.
ethernet_interface_inst.host_name)
self.assertEqual("web483.redfishspecification.org", self.
ethernet_interface_inst.fqdn)
self.assertEqual("fe80::3ed9:2bff:fe34:600", self.
ethernet_interface_inst.ipv6_default_gateway)
self.assertEqual(None, self.
ethernet_interface_inst.max_ipv6_static_addresses)
self.assertEqual((['names.redfishspecification.org']), self.
ethernet_interface_inst.name_servers)
self.assertEqual("192.168.0.10", self.ethernet_interface_inst.
ipv4_addresses[0].address)
self.assertEqual("255.255.252.0", self.ethernet_interface_inst.
ipv4_addresses[0].subnet_mask)
self.assertEqual("Static", self.
ethernet_interface_inst.ipv4_addresses[0].
address_origin)
self.assertEqual("192.168.0.1", self.ethernet_interface_inst.
ipv4_addresses[0].gateway)
self.assertEqual("fe80::1ec1:deff:fe6f:1e24", self.
ethernet_interface_inst.ipv6_addresses[0].address)
self.assertEqual(64, self.ethernet_interface_inst.ipv6_addresses[0].
prefix_length)
self.assertEqual("Static", self.
ethernet_interface_inst.ipv6_addresses[0].
address_origin)
self.assertEqual("Preferred", self.
ethernet_interface_inst.ipv6_addresses[0].
address_state)
self.assertEqual("web483", self.ethernet_interface_inst.host_name)
self.assertEqual("web483.redfishspecification.org",
self.ethernet_interface_inst.fqdn)
self.assertEqual("fe80::3ed9:2bff:fe34:600",
self.ethernet_interface_inst.ipv6_default_gateway)
self.assertEqual(
None, self.ethernet_interface_inst.max_ipv6_static_addresses)
self.assertEqual((['names.redfishspecification.org']),
self.ethernet_interface_inst.name_servers)
self.assertEqual(
"192.168.0.10",
self.ethernet_interface_inst.ipv4_addresses[0].address)
self.assertEqual(
"255.255.252.0",
self.ethernet_interface_inst.ipv4_addresses[0].subnet_mask)
self.assertEqual(
"Static",
self.ethernet_interface_inst.ipv4_addresses[0].address_origin)
self.assertEqual(
"192.168.0.1",
self.ethernet_interface_inst.ipv4_addresses[0].gateway)
self.assertEqual(
"fe80::1ec1:deff:fe6f:1e24",
self.ethernet_interface_inst.ipv6_addresses[0].address)
self.assertEqual(
64, self.ethernet_interface_inst.ipv6_addresses[0].prefix_length)
self.assertEqual(
"Static",
self.ethernet_interface_inst.ipv6_addresses[0].address_origin)
self.assertEqual(
"Preferred",
self.ethernet_interface_inst.ipv6_addresses[0].address_state)
self.assertEqual(None, self.ethernet_interface_inst.vlan)
self.assertEqual([],
self.ethernet_interface_inst.ipv6_static_addresses)
self.assertEqual(None,
self.ethernet_interface_inst.
ipv6_address_policy_table)
self.assertEqual("/redfish/v1/EthernetSwitches/1/Ports/1", self.
ethernet_interface_inst.
links.oem.intel_rackScale.neighbor_port)
self.assertEqual(
[], self.ethernet_interface_inst.ipv6_static_addresses)
self.assertEqual(
None, self.ethernet_interface_inst.ipv6_address_policy_table)
self.assertEqual(
"/redfish/v1/EthernetSwitches/1/Ports/1",
self.ethernet_interface_inst.links.oem.intel_rackScale.
neighbor_port)
def test__get_vlan_collection_path(self):
actual_path = self.ethernet_interface_inst._get_vlan_collection_path()
@@ -168,10 +170,9 @@ class EthernetInterfaceCollectionTestCase(testtools.TestCase):
'manager_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')
EthernetInterfaceCollection(
self.conn, '/redfish/v1/Managers/1/EthernetInterfaces',
redfish_version='1.0.2')
def test__parse_attributes(self):
self.ethernet_interface_col._parse_attributes()

View File

@@ -65,24 +65,23 @@ class EthernetInterfaceTestCase(testtools.TestCase):
self.assertEqual(
'192.168.0.10',
self.ethernet_interface_inst.ipv4_addresses[0].address)
self.assertEqual('255.255.252.0',
self.ethernet_interface_inst.ipv4_addresses[0].
subnet_mask)
self.assertEqual(
'255.255.252.0',
self.ethernet_interface_inst.ipv4_addresses[0].subnet_mask)
self.assertEqual(
'192.168.0.1',
self.ethernet_interface_inst.ipv4_addresses[0].gateway)
self.assertEqual(
'fe80::1ec1:deff:fe6f:1e24',
self.ethernet_interface_inst.ipv6_addresses[0].address)
self.assertEqual(64,
self.ethernet_interface_inst.ipv6_addresses[0].
prefix_length)
self.assertEqual('Static',
self.ethernet_interface_inst.ipv6_addresses[0].
address_origin)
self.assertEqual('Preferred',
self.ethernet_interface_inst.ipv6_addresses[0].
address_state)
self.assertEqual(
64, self.ethernet_interface_inst.ipv6_addresses[0].prefix_length)
self.assertEqual(
'Static',
self.ethernet_interface_inst.ipv6_addresses[0].address_origin)
self.assertEqual(
'Preferred',
self.ethernet_interface_inst.ipv6_addresses[0].address_state)
self.assertEqual(
[], self.ethernet_interface_inst.ipv6_static_addresses)
self.assertEqual(None, self.ethernet_interface_inst.vlan)

View File

@@ -0,0 +1,161 @@
# 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 sushy import exceptions
from rsd_lib.resources.v2_3.system 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_3/'
'system_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')
def test_parse_attributes(self):
self.ethernet_interface_inst._parse_attributes()
self.assertEqual("LAN1", self.ethernet_interface_inst.identity)
self.assertEqual("Ethernet Interface",
self.ethernet_interface_inst.name)
self.assertEqual("System NIC 1",
self.ethernet_interface_inst.description)
self.assertEqual("Enabled",
self.ethernet_interface_inst.status.state)
self.assertEqual("OK", self.ethernet_interface_inst.status.health)
self.assertEqual(None,
self.ethernet_interface_inst.status.health_rollup)
self.assertEqual(True,
self.ethernet_interface_inst.interface_enabled)
self.assertEqual("AA:BB:CC:DD:EE:FF",
self.ethernet_interface_inst.permanent_mac_address)
self.assertEqual("AA:BB:CC:DD:EE:FF",
self.ethernet_interface_inst.mac_address)
self.assertEqual(100, self.ethernet_interface_inst.speed_mbps)
self.assertEqual(True, self.ethernet_interface_inst.auto_neg)
self.assertEqual(True, self.ethernet_interface_inst.full_duplex)
self.assertEqual(1500, self.ethernet_interface_inst.mtu_size)
self.assertEqual("web483", self.ethernet_interface_inst.host_name)
self.assertEqual("web483.redfishspecification.org",
self.ethernet_interface_inst.fqdn)
self.assertEqual("fe80::3ed9:2bff:fe34:600",
self.ethernet_interface_inst.ipv6_default_gateway)
self.assertEqual(
None, self.ethernet_interface_inst.max_ipv6_static_addresses)
self.assertEqual((['names.redfishspecification.org']),
self.ethernet_interface_inst.name_servers)
self.assertEqual(
"192.168.0.10",
self.ethernet_interface_inst.ipv4_addresses[0].address)
self.assertEqual(
"255.255.252.0",
self.ethernet_interface_inst.ipv4_addresses[0].subnet_mask)
self.assertEqual(
"Static",
self.ethernet_interface_inst.ipv4_addresses[0].address_origin)
self.assertEqual(
"192.168.0.1",
self.ethernet_interface_inst.ipv4_addresses[0].gateway)
self.assertEqual(
"fe80::1ec1:deff:fe6f:1e24",
self.ethernet_interface_inst.ipv6_addresses[0].address)
self.assertEqual(
64, self.ethernet_interface_inst.ipv6_addresses[0].prefix_length)
self.assertEqual(
"Static",
self.ethernet_interface_inst.ipv6_addresses[0].address_origin)
self.assertEqual(
"Preferred",
self.ethernet_interface_inst.ipv6_addresses[0].address_state)
self.assertEqual(None, self.ethernet_interface_inst.vlan)
self.assertEqual([],
self.ethernet_interface_inst.ipv6_static_addresses)
self.assertEqual(None,
self.ethernet_interface_inst.
ipv6_address_policy_table)
self.assertEqual(
"/redfish/v1/EthernetSwitches/1/Ports/1",
self.ethernet_interface_inst.links.oem.intel_rackscale.
neighbor_port)
# New attributes in RSD 2.3
self.assertEqual(
"UefiDevicePath string",
self.ethernet_interface_inst.uefi_device_path)
self.assertEqual(
["RoCEv2", "iWARP", "iSCSI"],
self.ethernet_interface_inst.oem.intel_rackscale.
supported_protocols)
self.assertEqual(
None, self.ethernet_interface_inst.links.endpoints)
def test__get_vlan_collection_path_without_vlans(self):
with self.assertRaisesRegex(
exceptions.MissingAttributeError, 'attribute VLANs'):
self.ethernet_interface_inst._get_vlan_collection_path()
class EthernetInterfaceCollectionTestCase(testtools.TestCase):
def setUp(self):
super(EthernetInterfaceCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'system_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/Systems/System1/EthernetInterfaces',
redfish_version='1.0.2')
def test__parse_attributes(self):
self.ethernet_interface_col._parse_attributes()
self.assertEqual('1.0.2', self.ethernet_interface_col.redfish_version)
self.assertEqual(
('/redfish/v1/Systems/System1/EthernetInterfaces/LAN1',),
self.ethernet_interface_col.members_identities)
@mock.patch.object(ethernet_interface, 'EthernetInterface', autospec=True)
def test_get_member(self, mock_ethernet_interface):
self.ethernet_interface_col.get_member(
'/redfish/v1/Systems/System1/EthernetInterfaces/LAN1')
mock_ethernet_interface.assert_called_once_with(
self.ethernet_interface_col._conn,
'/redfish/v1/Systems/System1/EthernetInterfaces/LAN1',
redfish_version=self.ethernet_interface_col.redfish_version
)
@mock.patch.object(ethernet_interface, 'EthernetInterface', autospec=True)
def test_get_members(self, mock_ethernet_interface):
members = self.ethernet_interface_col.get_members()
calls = [
mock.call(
self.ethernet_interface_col._conn,
'/redfish/v1/Systems/System1/EthernetInterfaces/LAN1',
redfish_version=self.ethernet_interface_col.redfish_version)
]
mock_ethernet_interface.assert_has_calls(calls)
self.assertIsInstance(members, list)
self.assertEqual(1, len(members))

View File

@@ -0,0 +1,145 @@
# 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 sushy.resources.system import system as sushy_system
from rsd_lib.resources.v2_2.system import system as v2_2_system
from rsd_lib.resources.v2_3.system import ethernet_interface
from rsd_lib.resources.v2_3.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_3/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/437XR1138R2',
redfish_version='1.1.0')
def test_class_inherit(self):
self.assertIsInstance(self.system_inst, system.System)
self.assertIsInstance(self.system_inst, v2_2_system.System)
self.assertIsInstance(self.system_inst, sushy_system.System)
def test__get_ethernet_interface_collection_path(self):
self.assertEqual(
'/redfish/v1/Systems/437XR1138R2/EthernetInterfaces',
self.system_inst._get_ethernet_interface_collection_path())
def test__get_ethernet_interface_collection_path_missing_attr(self):
self.system_inst._json.pop('EthernetInterfaces')
with self.assertRaisesRegex(
exceptions.MissingAttributeError, 'attribute EthernetInterfaces'):
self.system_inst._get_ethernet_interface_collection_path()
def test_ethernet_interface(self):
# | GIVEN |
self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'system_ethernet_interface_collection.json', 'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN |
actual_ethernet_interface_col = self.system_inst.ethernet_interface
# | THEN |
self.assertIsInstance(actual_ethernet_interface_col,
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_col,
self.system_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_3/'
'system_ethernet_interface_collection.json', 'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.system_inst.ethernet_interface,
ethernet_interface.EthernetInterfaceCollection)
# on refreshing the system instance...
with open('rsd_lib/tests/unit/json_samples/v2_3/system.json',
'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.system_inst.invalidate()
self.system_inst.refresh(force=False)
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'system_ethernet_interface_collection.json', 'r') as f:
self.conn.get.return_value.son.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.system_inst.ethernet_interface,
ethernet_interface.EthernetInterfaceCollection)
class SystemCollectionTestCase(testtools.TestCase):
def setUp(self):
super(SystemCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'system_collection.json', 'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.system_col = system.SystemCollection(
self.conn, '/redfish/v1/Systems',
redfish_version='1.1.0')
def test__parse_attributes(self):
self.system_col._parse_attributes()
self.assertEqual('1.1.0', self.system_col.redfish_version)
self.assertEqual(('/redfish/v1/Systems/System1',
'/redfish/v1/Systems/System2'),
self.system_col.members_identities)
@mock.patch.object(system, 'System', autospec=True)
def test_get_member(self, mock_system):
self.system_col.get_member(
'/redfish/v1/Systems/System1')
mock_system.assert_called_once_with(
self.system_col._conn,
'/redfish/v1/Systems/System1',
redfish_version=self.system_col.redfish_version)
@mock.patch.object(system, 'System', autospec=True)
def test_get_members(self, mock_system):
members = self.system_col.get_members()
calls = [
mock.call(self.system_col._conn,
'/redfish/v1/Systems/System1',
redfish_version=self.system_col.redfish_version),
mock.call(self.system_col._conn,
'/redfish/v1/Systems/System2',
redfish_version=self.system_col.redfish_version)
]
mock_system.assert_has_calls(calls)
self.assertIsInstance(members, list)
self.assertEqual(2, len(members))