Add NetworkInterface class in RSD 2.1

Change-Id: Ib7492fa0e447b60c27facbea03bb1da9d06ed32a
This commit is contained in:
Lin Yang 2019-02-05 21:35:35 -08:00
parent 3ca930a682
commit 519b4c4043
9 changed files with 801 additions and 4 deletions

View File

@ -113,10 +113,10 @@ class Memory(base.ResourceBase):
"""The memory status"""
def __init__(self, connector, identity, redfish_version=None):
"""A class representing a Processor
"""A class representing a Memory
:param connector: A Connector instance
:param identity: The identity of the processor
:param identity: The identity of the memory
:param redfish_version: The version of RedFish. Used to construct
the object according to schema of the given version.
"""
@ -130,10 +130,10 @@ class MemoryCollection(base.ResourceCollectionBase):
return Memory
def __init__(self, connector, path, redfish_version=None):
"""A class representing a ProcessorCollection
"""A class representing a MemoryCollection
:param connector: A Connector instance
:param path: The canonical path to the Processor collection resource
:param path: The canonical path to the Memory collection resource
:param redfish_version: The version of RedFish. Used to construct
the object according to schema of the given version.
"""

View File

@ -0,0 +1,249 @@
# 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 import utils as rsd_lib_utils
class EthernetField(base.CompositeField):
macaddress = base.Field('MACAddress')
"""This is the currently configured MAC address of the (logical port)
network device function
"""
class iSCSIBootField(base.CompositeField):
ip_address_type = base.Field('IPAddressType')
"""The type of IP address (IPv6 or IPv4) being populated in the iSCSIBoot
IP address fields
"""
initiator_ip_address = base.Field('InitiatorIPAddress')
"""The IPv6 or IPv4 address of the iSCSI initiator"""
initiator_name = base.Field('InitiatorName')
"""The value of this property shall be the iSCSI boot initiator name"""
initiator_default_gateway = base.Field('InitiatorDefaultGateway')
"""The value of this property shall be the IPv6 or IPv4 iSCSI boot default
gateway
"""
initiator_netmask = base.Field('InitiatorNetmask')
"""The value of this property shall be the IPv6 or IPv4 netmask of the
iSCSI boot initiator
"""
target_info_via_dhcp = base.Field('TargetInfoViaDHCP', adapter=bool)
"""The value of this property shall be a boolean indicating whether the
iSCSI boot target name, LUN, IP address, and netmask should be obtained
from DHCP
"""
primary_target_name = base.Field('PrimaryTargetName')
"""The value of this property shall be the name of the primary iSCSI boot
target (iSCSI Qualified Name, IQN)
"""
primary_target_ip_address = base.Field('PrimaryTargetIPAddress')
"""The value of this property shall be the IP address (IPv6 or IPv4) for
the primary iSCSI boot target
"""
primary_target_tcp_port = base.Field(
'PrimaryTargetTCPPort', adapter=rsd_lib_utils.num_or_none)
"""The value of this property shall be the TCP port for the primary iSCSI
boot target
"""
primary_lun = base.Field('PrimaryLUN', adapter=rsd_lib_utils.num_or_none)
"""The value of this property shall be the logical unit number (LUN) for
the primary iSCSI boot target
"""
primary_vlan_enable = base.Field('PrimaryVLANEnable', adapter=bool)
"""The value of this property shall be used to indicate if PrimaryVLANId
is enabled for the primary iSCSI boot target
"""
primary_vlan_id = base.Field(
'PrimaryVLANId', adapter=rsd_lib_utils.num_or_none)
"""The value of this property shall be the 802.1q VLAN ID to use for iSCSI
boot from the primary target. This VLAN ID is only used if
PrimaryVLANEnable is true.
"""
primary_dns = base.Field('PrimaryDNS')
"""The value of this property shall be the IPv6 or IPv4 address of the
primary DNS server for the iSCSI boot initiator
"""
secondary_target_name = base.Field('SecondaryTargetName')
"""The value of this property shall be the name of the secondary iSCSI
boot target (iSCSI Qualified Name, IQN)
"""
secondary_target_ip_address = base.Field('SecondaryTargetIPAddress')
"""The value of this property shall be the IP address (IPv6 or IPv4) for
the secondary iSCSI boot target
"""
secondary_target_tcp_port = base.Field(
'SecondaryTargetTCPPort', adapter=rsd_lib_utils.num_or_none)
"""The value of this property shall be the TCP port for the secondary
iSCSI boot target
"""
secondary_lun = base.Field(
'SecondaryLUN', adapter=rsd_lib_utils.num_or_none)
"""The value of this property shall be the logical unit number (LUN) for
the secondary iSCSI boot target
"""
secondary_vlan_enable = base.Field('SecondaryVLANEnable', adapter=bool)
"""The value of this property shall be used to indicate if this VLAN is
enabled for the secondary iSCSI boot target
"""
secondary_vlan_id = base.Field(
'SecondaryVLANId', adapter=rsd_lib_utils.num_or_none)
"""The value of this property shall be the 802.1q VLAN ID to use for iSCSI
boot from the secondary target. This VLAN ID is only used if
SecondaryVLANEnable is true.
"""
secondary_dns = base.Field('SecondaryDNS')
"""The value of this property shall be the IPv6 or IPv4 address of the
secondary DNS server for the iSCSI boot initiator
"""
ip_mask_dns_via_dhcp = base.Field('IPMaskDNSViaDHCP', adapter=bool)
"""The value of this property shall be a boolean indicating whether the
iSCSI boot initiator uses DHCP to obtain the iniator name, IP address,
and netmask
"""
router_advertisement_enabled = base.Field(
'RouterAdvertisementEnabled', adapter=bool)
"""The value of this property shall be a boolean indicating whether IPv6
router advertisement is enabled for the iSCSI boot target. This
setting shall only apply to IPv6 configurations.
"""
authentication_method = base.Field('AuthenticationMethod')
"""The value of this property shall be the iSCSI boot authentication
method for this network device function
"""
chap_username = base.Field('CHAPUsername')
"""The value of this property shall be username for CHAP authentication"""
chap_secret = base.Field('CHAPSecret')
"""The value of this property shall be the shared secret for CHAP
authentication
"""
mutual_chap_username = base.Field('MutualCHAPUsername')
"""The value of this property shall be the CHAP Username for 2-way CHAP
authentication
"""
mutual_chap_secret = base.Field('MutualCHAPSecret')
"""The value of this property shall be the CHAP Secret for 2-way CHAP
authentication
"""
class StatusField(base.CompositeField):
state = base.Field('State')
health = base.Field('Health')
health_rollup = base.Field('HealthRollup')
class NetworkDeviceFunction(base.ResourceBase):
name = base.Field('Name')
"""The NetworkDeviceFunction name"""
identity = base.Field('Id', required=True)
"""The NetworkDeviceFunction identity string"""
description = base.Field('Description')
"""The description of NetworkDeviceFunction"""
device_enabled = base.Field('DeviceEnabled', adapter=bool)
"""Whether the network device function is enabled"""
ethernet = EthernetField('Ethernet')
"""This object shall contain Ethernet capabilities for this network
device function
"""
iscsi_boot = iSCSIBootField('iSCSIBoot')
"""This object shall contain iSCSI boot capabilities, status, and
configuration values for this network device function
"""
status = StatusField('Status')
"""The NetworkDeviceFunction status"""
links = base.Field('Links')
"""Links for this NetworkDeviceFunction"""
def __init__(self, connector, identity, redfish_version=None):
"""A class representing a NetworkDeviceFunction
:param connector: A Connector instance
:param identity: The identity of the NetworkDeviceFunction
:param redfish_version: The version of RedFish. Used to construct
the object according to schema of the given version.
"""
super(NetworkDeviceFunction, self).__init__(
connector, identity, redfish_version)
def update(self, ethernet=None, iscsi_boot=None):
"""Enable iSCSI boot of compute node
:param ethernet: Ethernet capabilities for this network device function
:param iscsi_boot: iSCSI boot capabilities, status, and configuration
values for this network device function
"""
data = {}
if ethernet is not None:
data['Ethernet'] = ethernet
if iscsi_boot is not None:
data['iSCSIBoot'] = iscsi_boot
self._conn.patch(self.path, data=data)
class NetworkDeviceFunctionCollection(base.ResourceCollectionBase):
@property
def _resource_type(self):
return NetworkDeviceFunction
def __init__(self, connector, path, redfish_version=None):
"""A class representing a NetworkDeviceFunctionCollection
:param connector: A Connector instance
:param path: The canonical path to the NetworkDeviceFunction collection
resource
:param redfish_version: The version of RedFish. Used to construct
the object according to schema of the given version.
"""
super(NetworkDeviceFunctionCollection, self).__init__(
connector, path, redfish_version)

View File

@ -0,0 +1,89 @@
# 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 sushy import utils
from rsd_lib.resources.v2_1.system import network_device_function
class StatusField(base.CompositeField):
state = base.Field('State')
health = base.Field('Health')
health_rollup = base.Field('HealthRollup')
class NetworkInterface(base.ResourceBase):
name = base.Field('Name')
"""The NetworkDeviceFunction name"""
identity = base.Field('Id', required=True)
"""The NetworkDeviceFunction identity string"""
description = base.Field('Description')
"""The description of NetworkDeviceFunction"""
status = StatusField('Status')
"""The NetworkDeviceFunction status"""
links = base.Field('Links')
"""Links for this NetworkDeviceFunction"""
def __init__(self, connector, identity, redfish_version=None):
"""A class representing a NetworkInterface
:param connector: A Connector instance
:param identity: The identity of the NetworkInterface
:param redfish_version: The version of RedFish. Used to construct
the object according to schema of the given version.
"""
super(NetworkInterface, self).__init__(connector, identity,
redfish_version)
def _get_network_device_functions_path(self):
"""Helper function to find the NetworkDeviceFunctions path"""
return utils.get_sub_resource_path_by(self, 'NetworkDeviceFunctions')
@property
@utils.cache_it
def network_device_functions(self):
"""Property to provide reference to `NetworkDeviceFunctionCollection`
It is calculated once when it is queried for the first time. On
refresh, this property is reset.
"""
return network_device_function.NetworkDeviceFunctionCollection(
self._conn, self._get_network_device_functions_path(),
redfish_version=self.redfish_version)
class NetworkInterfaceCollection(base.ResourceCollectionBase):
@property
def _resource_type(self):
return NetworkInterface
def __init__(self, connector, path, redfish_version=None):
"""A class representing a NetworkInterfaceCollection
:param connector: A Connector instance
:param path: The canonical path to the NetworkInterface collection
resource
:param redfish_version: The version of RedFish. Used to construct
the object according to schema of the given version.
"""
super(NetworkInterfaceCollection, self).__init__(connector, path,
redfish_version)

View File

@ -0,0 +1,48 @@
{
"@odata.context": "/redfish/v1/$metadata#NetworkDeviceFunction.NetworkDeviceFunction",
"@odata.id": "/redfish/v1/Systems/System1/NetworkInterfaces/1/NetworkDeviceFunctions/1",
"@odata.type": "#NetworkDeviceFunction.v1_0_0.NetworkDeviceFunction",
"Id": "1",
"Name": "Network Device Function View",
"Description": "Network Device Function View",
"Status": {
"State": "Enabled",
"Health": "OK",
"HealthRollup": "OK"
},
"DeviceEnabled": true,
"Ethernet": {
"MACAddress": "00:0C:29:9A:98:ED"
},
"iSCSIBoot": {
"IPAddressType": "IPv4",
"InitiatorIPAddress": "10.0.10.10",
"InitiatorName": "iqn.2017-03.com.intel:workload-server",
"InitiatorDefaultGateway": "10.0.10.1",
"InitiatorNetmask": "255.255.255.0",
"TargetInfoViaDHCP": false,
"PrimaryTargetName": "iqn.2017-03.com.intel:image-server",
"PrimaryTargetIPAddress": "10.0.10.254",
"PrimaryTargetTCPPort": 3260,
"PrimaryLUN": 1,
"PrimaryVLANEnable": true,
"PrimaryVLANId": 4088,
"PrimaryDNS": null,
"SecondaryTargetName": null,
"SecondaryTargetIPAddress": null,
"SecondaryTargetTCPPort": null,
"SecondaryLUN": null,
"SecondaryVLANEnable": null,
"SecondaryVLANId": null,
"SecondaryDNS": null,
"IPMaskDNSViaDHCP": false,
"RouterAdvertisementEnabled": false,
"AuthenticationMethod": "CHAP",
"CHAPUsername": "user",
"CHAPSecret": null,
"MutualCHAPUsername": "mutualuser",
"MutualCHAPSecret": null
},
"Links": {},
"Oem": {}
}

View File

@ -0,0 +1,12 @@
{
"@odata.context": "/redfish/v1/$metadata#NetworkDeviceFunctionCollection. NetworkDeviceFunctionCollection",
"@odata.id": "/redfish/v1/Systems/System1/NetworkInterfaces/1/NetworkDeviceFunctions",
"@odata.type": "#NetworkDeviceFunctionCollection.NetworkDeviceFunctionCollection",
"Name": "Network Device Function Collection",
"Members@odata.count": 1,
"Members": [
{
"@odata.id": "/redfish/v1/Systems/System1/NetworkInterfaces/1/NetworkDeviceFunctions/1"
}
]
}

View File

@ -0,0 +1,18 @@
{
"@odata.context": "/redfish/v1/$metadata#NetworkInterface.NetworkInterface",
"@odata.id": "/redfish/v1/Systems/System1/NetworkInterfaces/1",
"@odata.type": "# NetworkInterface.v1_0_0.NetworkInterface",
"Id": "1",
"Name": "Network Device View",
"Description": "Network Device View",
"Status": {
"State": "Enabled",
"Health": "OK",
"HealthRollup": "OK"
},
"NetworkDeviceFunctions": {
"@odata.id": "/redfish/v1/Systems/System1/NetworkInterfaces/1/NetworkDeviceFunctions"
},
"Links": {},
"Oem": {}
}

View File

@ -0,0 +1,12 @@
{
"@odata.context": "/redfish/v1/$metadata#NetworkInterfaceCollection.NetworkInterfaceCollection",
"@odata.id": "/redfish/v1/Systems/System1/NetworkInterfaces",
"@odata.type": "# NetworkInterfaceCollection.NetworkInterfaceCollection",
"Name": "Network Interface Collection",
"Members@odata.count": 1,
"Members": [
{
"@odata.id": "/redfish/v1/Systems/System1/NetworkInterfaces/1"
}
]
}

View File

@ -0,0 +1,222 @@
# 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_1.system import network_device_function
class NetworkDeviceFunctionTestCase(testtools.TestCase):
def setUp(self):
super(NetworkDeviceFunctionTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_1/'
'network_device_function.json', 'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.network_device_function_inst = network_device_function.\
NetworkDeviceFunction(
self.conn,
'/redfish/v1/Systems/System1/NetworkInterfaces/1/'
'NetworkDeviceFunctions/1',
redfish_version='1.1.0')
def test__parse_attributes(self):
self.network_device_function_inst._parse_attributes()
self.assertEqual(
'1.1.0', self.network_device_function_inst.redfish_version)
self.assertEqual('Network Device Function View',
self.network_device_function_inst.name)
self.assertEqual('1', self.network_device_function_inst.identity)
self.assertEqual('Network Device Function View',
self.network_device_function_inst.description)
self.assertEqual(
True, self.network_device_function_inst.device_enabled)
self.assertEqual(
'Enabled', self.network_device_function_inst.status.state)
self.assertEqual('OK', self.network_device_function_inst.status.health)
self.assertEqual(
'OK', self.network_device_function_inst.status.health_rollup)
self.assertEqual('00:0C:29:9A:98:ED',
self.network_device_function_inst.ethernet.macaddress)
self.assertEqual({}, self.network_device_function_inst.links)
# iSCSIBoot section
self.assertEqual(
'IPv4',
self.network_device_function_inst.iscsi_boot.ip_address_type)
self.assertEqual(
'10.0.10.10',
self.network_device_function_inst.iscsi_boot.initiator_ip_address)
self.assertEqual(
'iqn.2017-03.com.intel:workload-server',
self.network_device_function_inst.iscsi_boot.initiator_name)
self.assertEqual(
'10.0.10.1',
self.network_device_function_inst.iscsi_boot.
initiator_default_gateway)
self.assertEqual(
'255.255.255.0',
self.network_device_function_inst.iscsi_boot.initiator_netmask)
self.assertEqual(
False,
self.network_device_function_inst.iscsi_boot.target_info_via_dhcp)
self.assertEqual(
'iqn.2017-03.com.intel:image-server',
self.network_device_function_inst.iscsi_boot.primary_target_name)
self.assertEqual(
'10.0.10.254',
self.network_device_function_inst.iscsi_boot.
primary_target_ip_address)
self.assertEqual(
3260,
self.network_device_function_inst.iscsi_boot.
primary_target_tcp_port)
self.assertEqual(
1, self.network_device_function_inst.iscsi_boot.primary_lun)
self.assertEqual(
True,
self.network_device_function_inst.iscsi_boot.primary_vlan_enable)
self.assertEqual(
4088,
self.network_device_function_inst.iscsi_boot.primary_vlan_id)
self.assertEqual(
None,
self.network_device_function_inst.iscsi_boot.primary_dns)
self.assertEqual(
None,
self.network_device_function_inst.iscsi_boot.secondary_target_name)
self.assertEqual(
None,
self.network_device_function_inst.iscsi_boot.
secondary_target_ip_address)
self.assertEqual(
None,
self.network_device_function_inst.iscsi_boot.
secondary_target_tcp_port)
self.assertEqual(
None,
self.network_device_function_inst.iscsi_boot.secondary_lun)
self.assertEqual(
False,
self.network_device_function_inst.iscsi_boot.secondary_vlan_enable)
self.assertEqual(
None,
self.network_device_function_inst.iscsi_boot.secondary_vlan_id)
self.assertEqual(
None,
self.network_device_function_inst.iscsi_boot.secondary_dns)
self.assertEqual(
False,
self.network_device_function_inst.iscsi_boot.ip_mask_dns_via_dhcp)
self.assertEqual(
False,
self.network_device_function_inst.iscsi_boot.
router_advertisement_enabled)
self.assertEqual(
'CHAP',
self.network_device_function_inst.iscsi_boot.authentication_method)
self.assertEqual(
'user',
self.network_device_function_inst.iscsi_boot.chap_username)
self.assertEqual(
None,
self.network_device_function_inst.iscsi_boot.chap_secret)
self.assertEqual(
'mutualuser',
self.network_device_function_inst.iscsi_boot.mutual_chap_username)
self.assertEqual(
None,
self.network_device_function_inst.iscsi_boot.mutual_chap_secret)
def test_update(self):
self.network_device_function_inst.update(
ethernet={"MACAddress": "00:0C:29:9A:98:ED"})
self.network_device_function_inst._conn.patch.assert_called_once_with(
'/redfish/v1/Systems/System1/NetworkInterfaces/1/'
'NetworkDeviceFunctions/1',
data={"Ethernet": {"MACAddress": "00:0C:29:9A:98:ED"}})
self.network_device_function_inst._conn.patch.reset_mock()
self.network_device_function_inst.update(
iscsi_boot={"IPAddressType": "IPv4"})
self.network_device_function_inst._conn.patch.assert_called_once_with(
'/redfish/v1/Systems/System1/NetworkInterfaces/1/'
'NetworkDeviceFunctions/1',
data={"iSCSIBoot": {"IPAddressType": "IPv4"}})
self.network_device_function_inst._conn.patch.reset_mock()
self.network_device_function_inst.update(
ethernet={"MACAddress": "00:0C:29:9A:98:ED"},
iscsi_boot={"IPAddressType": "IPv4"})
self.network_device_function_inst._conn.patch.assert_called_once_with(
'/redfish/v1/Systems/System1/NetworkInterfaces/1/'
'NetworkDeviceFunctions/1',
data={"Ethernet": {"MACAddress": "00:0C:29:9A:98:ED"},
"iSCSIBoot": {"IPAddressType": "IPv4"}})
class NetworkDeviceFunctionCollectionTestCase(testtools.TestCase):
def setUp(self):
super(NetworkDeviceFunctionCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_1/'
'network_device_function_collection.json', 'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.network_device_function_col = network_device_function.\
NetworkDeviceFunctionCollection(
self.conn,
'/redfish/v1/Systems/System1/NetworkInterfaces/1/'
'NetworkDeviceFunctions',
redfish_version='1.1.0')
def test__parse_attributes(self):
self.network_device_function_col._parse_attributes()
self.assertEqual(
'1.1.0', self.network_device_function_col.redfish_version)
self.assertEqual(
('/redfish/v1/Systems/System1/NetworkInterfaces/1/'
'NetworkDeviceFunctions/1',),
self.network_device_function_col.members_identities)
@mock.patch.object(
network_device_function, 'NetworkDeviceFunction',
autospec=True)
def test_get_member(self, mock_network_device_function):
self.network_device_function_col.get_member(
'/redfish/v1/Systems/System1/NetworkInterfaces/1/'
'NetworkDeviceFunctions/1')
mock_network_device_function.assert_called_once_with(
self.network_device_function_col._conn,
'/redfish/v1/Systems/System1/NetworkInterfaces/1/'
'NetworkDeviceFunctions/1',
redfish_version=self.network_device_function_col.redfish_version)
@mock.patch.object(
network_device_function, 'NetworkDeviceFunction',
autospec=True)
def test_get_members(self, mock_network_device_function):
members = self.network_device_function_col.get_members()
mock_network_device_function.assert_called_once_with(
self.network_device_function_col._conn,
'/redfish/v1/Systems/System1/NetworkInterfaces/1/'
'NetworkDeviceFunctions/1',
redfish_version=self.network_device_function_col.redfish_version)
self.assertIsInstance(members, list)
self.assertEqual(1, len(members))

View File

@ -0,0 +1,147 @@
# 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_1.system import network_device_function
from rsd_lib.resources.v2_1.system import network_interface
class NetworkInterface(testtools.TestCase):
def setUp(self):
super(NetworkInterface, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_1/'
'network_interface.json', 'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.network_interface_inst = network_interface.NetworkInterface(
self.conn, '/redfish/v1/Systems/System1/NetworkInterfaces/1/',
redfish_version='1.1.0')
def test__parse_attributes(self):
self.network_interface_inst._parse_attributes()
self.assertEqual('1.1.0', self.network_interface_inst.redfish_version)
self.assertEqual('Network Device View',
self.network_interface_inst.name)
self.assertEqual('1', self.network_interface_inst.identity)
self.assertEqual('Network Device View',
self.network_interface_inst.description)
self.assertEqual('Enabled', self.network_interface_inst.status.state)
self.assertEqual('OK', self.network_interface_inst.status.health)
self.assertEqual(
'OK', self.network_interface_inst.status.health_rollup)
self.assertEqual({}, self.network_interface_inst.links)
def test__get_network_device_functions_path(self):
expected = '/redfish/v1/Systems/System1/NetworkInterfaces/1/'\
'NetworkDeviceFunctions'
result = self.network_interface_inst.\
_get_network_device_functions_path()
self.assertEqual(expected, result)
def test_network_device_functions(self):
# | GIVEN |
self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_1/'
'network_device_function_collection.json', 'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN |
actual_network_device_functions = self.network_interface_inst.\
network_device_functions
# | THEN |
self.assertIsInstance(
actual_network_device_functions,
network_device_function.NetworkDeviceFunctionCollection)
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_network_device_functions,
self.network_interface_inst.network_device_functions)
self.conn.get.return_value.json.assert_not_called()
def test_network_device_functions_on_refresh(self):
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_1/'
'network_device_function_collection.json', 'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(
self.network_interface_inst.network_device_functions,
network_device_function.NetworkDeviceFunctionCollection)
# On refreshing the network_interface instance...
with open('rsd_lib/tests/unit/json_samples/v2_1/'
'network_interface.json', 'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.network_interface_inst.invalidate()
self.network_interface_inst.refresh(force=False)
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_1/'
'network_device_function_collection.json', 'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(
self.network_interface_inst.network_device_functions,
network_device_function.NetworkDeviceFunctionCollection)
class NetworkInterfaceCollectionTestCase(testtools.TestCase):
def setUp(self):
super(NetworkInterfaceCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_1/'
'network_interface_collection.json', 'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.network_interface_col = network_interface.\
NetworkInterfaceCollection(
self.conn,
'/redfish/v1/Systems/System1/NetworkInterfaces/1',
redfish_version='1.1.0')
def test__parse_attributes(self):
self.network_interface_col._parse_attributes()
self.assertEqual(
'1.1.0', self.network_interface_col.redfish_version)
self.assertEqual(
('/redfish/v1/Systems/System1/NetworkInterfaces/1',),
self.network_interface_col.members_identities)
@mock.patch.object(network_interface, 'NetworkInterface', autospec=True)
def test_get_member(self, mock_network_interface):
self.network_interface_col.get_member(
'/redfish/v1/Systems/System1/NetworkInterfaces/1')
mock_network_interface.assert_called_once_with(
self.network_interface_col._conn,
'/redfish/v1/Systems/System1/NetworkInterfaces/1',
redfish_version=self.network_interface_col.redfish_version)
@mock.patch.object(network_interface, 'NetworkInterface', autospec=True)
def test_get_members(self, mock_network_interface):
members = self.network_interface_col.get_members()
mock_network_interface.assert_called_once_with(
self.network_interface_col._conn,
'/redfish/v1/Systems/System1/NetworkInterfaces/1',
redfish_version=self.network_interface_col.redfish_version)
self.assertIsInstance(members, list)
self.assertEqual(1, len(members))