Move pcie device from chassis to system
Change-Id: I68ce17f8951305e008ea9cfa261a896ac7e4b054
This commit is contained in:
parent
731994050a
commit
0b29ff0628
@ -16,7 +16,6 @@
|
||||
from sushy.resources import base
|
||||
from sushy import utils
|
||||
|
||||
from rsd_lib.resources.v2_1.chassis import pcie_device
|
||||
from rsd_lib.resources.v2_1.chassis import power
|
||||
from rsd_lib.resources.v2_1.chassis import power_zone
|
||||
from rsd_lib.resources.v2_1.chassis import thermal
|
||||
@ -225,21 +224,6 @@ class Chassis(base.ResourceBase):
|
||||
|
||||
self._conn.patch(self.path, data=data)
|
||||
|
||||
@property
|
||||
@utils.cache_it
|
||||
def pcie_devices(self):
|
||||
"""Property to provide reference to a list of `PCIeDevice` instances
|
||||
|
||||
It is calculated once when it is queried for the first time. On
|
||||
refresh, this property is reset.
|
||||
"""
|
||||
pcie_device_paths = rsd_lib_utils.get_sub_resource_path_list_by(
|
||||
self, ['Links', 'PCIeDevices'])
|
||||
return [
|
||||
pcie_device.PCIeDevice(
|
||||
self._conn, path, redfish_version=self.redfish_version
|
||||
) for path in pcie_device_paths]
|
||||
|
||||
|
||||
class ChassisCollection(base.ResourceCollectionBase):
|
||||
@property
|
||||
|
@ -85,3 +85,20 @@ class PCIeDevice(base.ResourceBase):
|
||||
data = {'AssetTag': asset_tag}
|
||||
|
||||
self._conn.patch(self.path, data=data)
|
||||
|
||||
|
||||
class PCIeDeviceCollection(base.ResourceCollectionBase):
|
||||
@property
|
||||
def _resource_type(self):
|
||||
return PCIeDevice
|
||||
|
||||
def __init__(self, connector, path, redfish_version=None):
|
||||
"""A class representing a PCIeDeviceCollection
|
||||
|
||||
:param connector: A Connector instance
|
||||
:param path: The canonical path to the PCIeDevice collection resource
|
||||
:param redfish_version: The version of RedFish. Used to construct
|
||||
the object according to schema of the given version.
|
||||
"""
|
||||
super(PCIeDeviceCollection, self).__init__(connector, path,
|
||||
redfish_version)
|
@ -19,6 +19,7 @@ from sushy import utils
|
||||
from rsd_lib.resources.v2_1.system import ethernet_interface
|
||||
from rsd_lib.resources.v2_1.system import memory
|
||||
from rsd_lib.resources.v2_1.system import network_interface
|
||||
from rsd_lib.resources.v2_1.system import pcie_device
|
||||
from rsd_lib.resources.v2_1.system import storage_subsystem
|
||||
|
||||
|
||||
@ -88,6 +89,22 @@ class System(system.System):
|
||||
self._conn, self._get_network_interfaces_collection_path(),
|
||||
redfish_version=self.redfish_version)
|
||||
|
||||
def _get_pcie_device_collection_path(self):
|
||||
"""Helper function to find the pcie device collection path"""
|
||||
return utils.get_sub_resource_path_by(self, 'PCIeDevices')
|
||||
|
||||
@property
|
||||
@utils.cache_it
|
||||
def pcie_devices(self):
|
||||
"""Property to provide reference to `PCIeDevice` collection
|
||||
|
||||
It is calculated once when it is queried for the first time. On
|
||||
refresh, this property is reset.
|
||||
"""
|
||||
return pcie_device.PCIeDeviceCollection(
|
||||
self._conn, self._get_pcie_device_collection_path(),
|
||||
redfish_version=self.redfish_version)
|
||||
|
||||
|
||||
class SystemCollection(system.SystemCollection):
|
||||
|
||||
|
@ -0,0 +1,12 @@
|
||||
{
|
||||
"@odata.context": "/redfish/v1/$metadata#PCIeDeviceCollection.PCIeDeviceCollection",
|
||||
"@odata.id": "/redfish/v1/Chassis/1/PCIeDevices",
|
||||
"@odata.type": "#PCIeDeviceCollection.PCIeDeviceCollection",
|
||||
"Name": "PCIe Device Collection",
|
||||
"Members@odata.count": 1,
|
||||
"Members": [
|
||||
{
|
||||
"@odata.id": "/redfish/v1/Chassis/1/PCIeDevices/Device1"
|
||||
}
|
||||
]
|
||||
}
|
@ -90,6 +90,9 @@
|
||||
"EthernetInterfaces": {
|
||||
"@odata.id": "/redfish/v1/Systems/437XR1138R2/EthernetInterfaces"
|
||||
},
|
||||
"PCIeDevices": {
|
||||
"@odata.id": "/redfish/v1/Systems/437XR1138R2/PCIeDevices"
|
||||
},
|
||||
"SimpleStorage": {
|
||||
"@odata.id": "/redfish/v1/Systems/437XR1138R2/SimpleStorage"
|
||||
},
|
||||
|
@ -17,7 +17,6 @@ from sushy import exceptions
|
||||
from sushy.tests.unit import base
|
||||
|
||||
from rsd_lib.resources.v2_1.chassis import chassis
|
||||
from rsd_lib.resources.v2_1.chassis import pcie_device
|
||||
from rsd_lib.resources.v2_1.chassis import power
|
||||
from rsd_lib.resources.v2_1.chassis import power_zone
|
||||
from rsd_lib.resources.v2_1.chassis import thermal
|
||||
@ -331,55 +330,6 @@ class TestChassis(base.TestCase):
|
||||
"Location": {
|
||||
"Id": "1234"}}}})
|
||||
|
||||
def test_pcie_devices(self):
|
||||
# | GIVEN |
|
||||
self.conn.get.return_value.json.reset_mock()
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_1/'
|
||||
'pcie_device.json', 'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
# | WHEN |
|
||||
actual_pcie_devices = self.chassis_inst.pcie_devices
|
||||
# | THEN |
|
||||
self.assertEqual(2, len(actual_pcie_devices))
|
||||
for pcie in actual_pcie_devices:
|
||||
self.assertIsInstance(pcie, pcie_device.PCIeDevice)
|
||||
self.assertEqual(2, self.conn.get.return_value.json.call_count)
|
||||
|
||||
# reset mock
|
||||
self.conn.get.return_value.json.reset_mock()
|
||||
# | WHEN & THEN |
|
||||
# tests for same object on invoking subsequently
|
||||
self.assertIs(actual_pcie_devices,
|
||||
self.chassis_inst.pcie_devices)
|
||||
self.conn.get.return_value.json.assert_not_called()
|
||||
|
||||
def test_pcie_devices_on_fresh(self):
|
||||
# | GIVEN |
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_1/'
|
||||
'pcie_device.json', 'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
# | WHEN & THEN |
|
||||
for pcie in self.chassis_inst.pcie_devices:
|
||||
self.assertIsInstance(pcie,
|
||||
pcie_device.PCIeDevice)
|
||||
|
||||
# On refreshing the chassis instance...
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_1/'
|
||||
'chassis.json', 'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
|
||||
self.chassis_inst.invalidate()
|
||||
self.chassis_inst.refresh(force=False)
|
||||
|
||||
# | GIVEN |
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_1/'
|
||||
'pcie_device.json', 'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
# | WHEN & THEN |
|
||||
for pcie in self.chassis_inst.pcie_devices:
|
||||
self.assertIsInstance(pcie,
|
||||
pcie_device.PCIeDevice)
|
||||
|
||||
|
||||
class TestChassisCollection(base.TestCase):
|
||||
|
||||
|
@ -17,7 +17,7 @@ import json
|
||||
import mock
|
||||
import testtools
|
||||
|
||||
from rsd_lib.resources.v2_1.chassis import pcie_device
|
||||
from rsd_lib.resources.v2_1.system import pcie_device
|
||||
|
||||
|
||||
class PCIeDeviceTestCase(testtools.TestCase):
|
@ -23,6 +23,7 @@ from sushy.resources.system import system as sushy_system
|
||||
from rsd_lib.resources.v2_1.system import ethernet_interface
|
||||
from rsd_lib.resources.v2_1.system import memory
|
||||
from rsd_lib.resources.v2_1.system import network_interface
|
||||
from rsd_lib.resources.v2_1.system import pcie_device
|
||||
from rsd_lib.resources.v2_1.system import storage_subsystem
|
||||
from rsd_lib.resources.v2_1.system import system
|
||||
|
||||
@ -51,7 +52,7 @@ class SystemTestCase(testtools.TestCase):
|
||||
def test__get_memory_collection_path_missing_attr(self):
|
||||
self.system_inst._json.pop('Memory')
|
||||
with self.assertRaisesRegex(
|
||||
exceptions.MissingAttributeError, 'attribute Memory'):
|
||||
exceptions.MissingAttributeError, 'attribute Memory'):
|
||||
self.system_inst._get_memory_collection_path()
|
||||
|
||||
def test_memory(self):
|
||||
@ -108,7 +109,7 @@ class SystemTestCase(testtools.TestCase):
|
||||
def test__get_storage_collection_path_missing_attr(self):
|
||||
self.system_inst._json.pop('Storage')
|
||||
with self.assertRaisesRegex(
|
||||
exceptions.MissingAttributeError, 'attribute Storage'):
|
||||
exceptions.MissingAttributeError, 'attribute Storage'):
|
||||
self.system_inst._get_storage_subsystem_collection_path()
|
||||
|
||||
def test_storage_subsystem(self):
|
||||
@ -165,7 +166,8 @@ class SystemTestCase(testtools.TestCase):
|
||||
def test__get_ethernet_interfaces_collection_path_missing_attr(self):
|
||||
self.system_inst._json.pop('EthernetInterfaces')
|
||||
with self.assertRaisesRegex(
|
||||
exceptions.MissingAttributeError, 'attribute EthernetInterfaces'):
|
||||
exceptions.MissingAttributeError,
|
||||
'attribute EthernetInterfaces'):
|
||||
self.system_inst._get_ethernet_interfaces_collection_path()
|
||||
|
||||
def test_ethernet_interfaces(self):
|
||||
@ -222,7 +224,8 @@ class SystemTestCase(testtools.TestCase):
|
||||
def test__get_network_interfaces_collection_path_missing_attr(self):
|
||||
self.system_inst._json.pop('NetworkInterfaces')
|
||||
with self.assertRaisesRegex(
|
||||
exceptions.MissingAttributeError, 'attribute NetworkInterfaces'):
|
||||
exceptions.MissingAttributeError,
|
||||
'attribute NetworkInterfaces'):
|
||||
self.system_inst._get_network_interfaces_collection_path()
|
||||
|
||||
def test_network_interfaces(self):
|
||||
@ -271,6 +274,62 @@ class SystemTestCase(testtools.TestCase):
|
||||
self.assertIsInstance(self.system_inst.network_interfaces,
|
||||
network_interface.NetworkInterfaceCollection)
|
||||
|
||||
def test__get_pcie_device_collection_path(self):
|
||||
self.assertEqual('/redfish/v1/Systems/437XR1138R2/PCIeDevices',
|
||||
self.system_inst._get_pcie_device_collection_path())
|
||||
|
||||
def test__get_pcie_device_collection_path_missing_attr(self):
|
||||
self.system_inst._json.pop('PCIeDevices')
|
||||
with self.assertRaisesRegex(
|
||||
exceptions.MissingAttributeError, 'attribute PCIeDevices'):
|
||||
self.system_inst._get_pcie_device_collection_path()
|
||||
|
||||
def test_pcie_devices(self):
|
||||
# | GIVEN |
|
||||
self.conn.get.return_value.json.reset_mock()
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_1/'
|
||||
'pcie_device_collection.json', 'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
# | WHEN |
|
||||
actual_pcie_devices = self.system_inst.pcie_devices
|
||||
# | THEN |
|
||||
self.assertIsInstance(actual_pcie_devices,
|
||||
pcie_device.PCIeDeviceCollection)
|
||||
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_pcie_devices,
|
||||
self.system_inst.pcie_devices)
|
||||
self.conn.get.return_value.json.assert_not_called()
|
||||
|
||||
def test_pcie_devices_on_fresh(self):
|
||||
# | GIVEN |
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_1/'
|
||||
'pcie_device_collection.json', 'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
# | WHEN & THEN |
|
||||
self.assertIsInstance(self.system_inst.pcie_devices,
|
||||
pcie_device.PCIeDeviceCollection)
|
||||
|
||||
# On refreshing the chassis instance...
|
||||
with open('rsd_lib/tests/unit/json_samples/v2_1/'
|
||||
'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_1/'
|
||||
'pcie_device_collection.json', 'r') as f:
|
||||
self.conn.get.return_value.json.return_value = json.loads(f.read())
|
||||
# | WHEN & THEN |
|
||||
self.assertIsInstance(self.system_inst.pcie_devices,
|
||||
pcie_device.PCIeDeviceCollection)
|
||||
|
||||
|
||||
class SystemCollectionTestCase(testtools.TestCase):
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user