Add PCIeDevice resource for RSD 2.1

Change-Id: I73c3f510974c743f24467ed33606a3f25aed5914
This commit is contained in:
Lin Yang 2018-12-19 13:54:07 -08:00
parent 91774d44e2
commit aca4e4fef2
3 changed files with 189 additions and 0 deletions

View File

@ -0,0 +1,87 @@
# 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
class StatusField(base.CompositeField):
state = base.Field('State')
health = base.Field('Health')
health_rollup = base.Field('HealthRollup')
class LinksField(base.CompositeField):
chassis = base.Field('Chassis', adapter=utils.get_members_identities)
"""The value of this property shall reference a resource of type Chassis
that represents the physical container associated with this resource.
"""
pcie_functions = base.Field(
'PCIeFunctions', adapter=utils.get_members_identities)
"""The value of this property shall be a reference to the resources that
this device exposes and shall reference a resource of type PCIeFunction.
"""
class PCIeDevice(base.ResourceBase):
identity = base.Field('Id', required=True)
"""The PCIe device identity string"""
name = base.Field('Name')
"""The PCIe device name"""
description = base.Field('Description')
"""The PCIe device description"""
manufacturer = base.Field('Manufacturer')
"""The PCIe device manufacturer"""
model = base.Field('Model')
"""The PCIe device Model"""
sku = base.Field('SKU')
"""The PCIe device stock-keeping unit"""
serial_number = base.Field('SerialNumber')
"""The PCIe device serial number"""
part_number = base.Field('PartNumber')
"""The PCIe device part number"""
asset_tag = base.Field('AssetTag')
"""The user assigned asset tag for this PCIe device"""
device_type = base.Field('DeviceType')
"""The device type for this PCIe device"""
firmware_version = base.Field('FirmwareVersion')
"""The version of firmware for this PCIe device"""
status = StatusField('Status')
"""The PCIe device status"""
links = LinksField('Links')
"""The link section of PCIe device"""
def update(self, asset_tag=None):
"""Update AssetTag properties
:param asset_tag: The user assigned asset tag for this PCIe device
"""
data = {'AssetTag': asset_tag}
self._conn.patch(self.path, data=data)

View File

@ -0,0 +1,35 @@
{
"@odata.context": "/redfish/v1/$metadata#PCIeDevice.PCIeDevice",
"@odata.id": "/redfish/v1/Chassis/1/PCIeDevices/Device1",
"@odata.type": "#PCIeDevice.v1_0_0.PCIeDevice",
"Id": "Device1",
"Name": "NVMe SSD Drive",
"Description": "Simple NVMe Drive",
"AssetTag": "free form asset tag",
"Manufacturer": "Intel",
"Model": "Model Name",
"SKU": "sku string",
"SerialNumber": "SN123456",
"PartNumber": "partnumber string",
"DeviceType": "SingleFunction",
"FirmwareVersion": "XYZ1234",
"Status": {
"State": "Enabled",
"Health": "OK",
"HealthRollup": "OK"
},
"Links": {
"Chassis": [
{
"@odata.id": "/redfish/v1/Chassis/1"
}
],
"PCIeFunctions": [
{
"@odata.id": "/redfish/v1/Chassis/1/PCIeDevices/Device1/Functions/1"
}
],
"Oem": {}
},
"Oem": {}
}

View File

@ -0,0 +1,67 @@
# 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.chassis import pcie_device
class PCIeDeviceTestCase(testtools.TestCase):
def setUp(self):
super(PCIeDeviceTestCase, self).setUp()
self.conn = mock.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())
self.pcie_device_inst = pcie_device.PCIeDevice(
self.conn, '/redfish/v1/Chassis/1/PCIeDevices/Device1',
redfish_version='1.1.0')
def test__parse_attributes(self):
self.pcie_device_inst._parse_attributes()
self.assertEqual('Device1', self.pcie_device_inst.identity)
self.assertEqual('NVMe SSD Drive', self.pcie_device_inst.name)
self.assertEqual('Simple NVMe Drive',
self.pcie_device_inst.description)
self.assertEqual(
'Enabled', self.pcie_device_inst.status.state)
self.assertEqual('OK', self.pcie_device_inst.status.health)
self.assertEqual(
'OK', self.pcie_device_inst.status.health_rollup)
self.assertEqual('Intel', self.pcie_device_inst.manufacturer)
self.assertEqual('Model Name', self.pcie_device_inst.model)
self.assertEqual('sku string', self.pcie_device_inst.sku)
self.assertEqual('SN123456', self.pcie_device_inst.serial_number)
self.assertEqual(
'partnumber string', self.pcie_device_inst.part_number)
self.assertEqual(
'free form asset tag', self.pcie_device_inst.asset_tag)
self.assertEqual('SingleFunction', self.pcie_device_inst.device_type)
self.assertEqual('XYZ1234', self.pcie_device_inst.firmware_version)
self.assertEqual(
('/redfish/v1/Chassis/1',), self.pcie_device_inst.links.chassis)
self.assertEqual(
('/redfish/v1/Chassis/1/PCIeDevices/Device1/Functions/1',),
self.pcie_device_inst.links.pcie_functions)
def test_update(self):
self.pcie_device_inst.update(asset_tag='Rack#1')
self.pcie_device_inst._conn.patch.assert_called_once_with(
'/redfish/v1/Chassis/1/PCIeDevices/Device1',
data={"AssetTag": "Rack#1"})