Add trusted_modules property in System in RSD 2.2

Change-Id: Ic6d37054e2e0fcb9a828f58c4ed88792b16bfc0f
This commit is contained in:
HeyIns 2019-05-14 09:24:37 +08:00 committed by Lin Yang
parent f98599c640
commit 80d6b36b86
3 changed files with 232 additions and 89 deletions

View File

@ -13,20 +13,80 @@
# License for the specific language governing permissions and limitations
# under the License.
from sushy.resources import base
from sushy import utils
from rsd_lib import base as rsd_lib_base
from rsd_lib.resources.v2_1.system import system
from rsd_lib.resources.v2_2.system import memory
from rsd_lib.resources.v2_2.system import metrics
from rsd_lib.resources.v2_2.system import processor
from rsd_lib import utils as rsd_lib_utils
class IntelRackScaleField(system.IntelRackScaleField):
user_mode_enabled = base.Field("UserModeEnabled", adapter=bool)
"""This indicates if platform user mode is enabled"""
trusted_execution_technology_enabled = base.Field(
"TrustedExecutionTechnologyEnabled", adapter=bool
)
"""This indicates if TXT mode is enabled"""
metrics = base.Field(
"Metrics", adapter=rsd_lib_utils.get_resource_identity
)
"""A reference to the Metrics associated with this ComputerSystem"""
class OemField(base.CompositeField):
intel_rackscale = IntelRackScaleField("Intel_RackScale")
"""Intel Rack Scale Design specific properties."""
class TrustedModulesCollectionField(base.ListField):
"""TrustedModules field
This object describes the inventory of a Trusted Modules installed in
the system.
"""
firmware_version = base.Field("FirmwareVersion")
"""The firmware version of this Trusted Module."""
interface_type = base.Field("InterfaceType")
"""This property indicates the interface type of the Trusted Module."""
status = rsd_lib_base.StatusField("Status")
"""This indicates the known state of the resource, such as if it is
enabled.
"""
oem = base.Field("Oem")
"""The trusted_modules oem"""
firmware_version2 = base.Field("FirmwareVersion2")
"""The 2nd firmware version of this Trusted Module, if applicable."""
interface_type_selection = base.Field("InterfaceTypeSelection")
"""The Interface Type selection supported by this Trusted Module."""
class System(system.System):
trusted_modules = TrustedModulesCollectionField("TrustedModules")
"""This object describes the array of Trusted Modules in the system."""
oem = OemField("Oem")
"""Oem specific properties."""
def _get_metrics_path(self):
"""Helper function to find the System metrics path"""
return utils.get_sub_resource_path_by(
self, ['Oem', 'Intel_RackScale', 'Metrics'])
self, ["Oem", "Intel_RackScale", "Metrics"]
)
@property
@utils.cache_it
@ -37,8 +97,10 @@ class System(system.System):
this property is reset.
"""
return metrics.Metrics(
self._conn, self._get_metrics_path(),
redfish_version=self.redfish_version)
self._conn,
self._get_metrics_path(),
redfish_version=self.redfish_version,
)
@property
@utils.cache_it
@ -70,7 +132,6 @@ class System(system.System):
class SystemCollection(system.SystemCollection):
@property
def _resource_type(self):
return System

View File

@ -68,7 +68,21 @@
}
],
"PCIeFunctions": [],
"TrustedModules": [],
"TrustedModules": [
{
"@odata.type": "#ComputerSystem.v1_3_0.TrustedModules",
"FirmwareVersion": "0.001",
"InterfaceType": "TPM2_0",
"Status": {
"State": "Enabled",
"Health": null,
"HealthRollup": null
},
"Oem": {},
"FirmwareVersion2": null,
"InterfaceTypeSelection": "OemMethod"
}
],
"Links": {
"@odata.type": "#ComputerSystem.v1_2_0.Links",
"Chassis": [{
@ -111,15 +125,22 @@
"Oem": {
"Intel_RackScale": {
"@odata.type": "#Intel.Oem.ComputerSystem",
"PciDevices": [],
"PciDevices": [
{
"VendorId": "0x8086",
"DeviceId": "0x1234"
}
],
"DiscoveryState": "Basic",
"ProcessorSockets": null,
"MemorySockets": null,
"PCIeConnectionId": [],
"ProcessorSockets": 8,
"MemorySockets": 8,
"PCIeConnectionId": [
"XYZ1234567890"
],
"UserModeEnabled": false,
"TrustedExecutionTechnologyEnabled": false,
"Metrics": {
"@odata.id": "/redfish/v1/Systems/System2/Metrics"
"@odata.id": "/redfish/v1/Systems/System1/Metrics"
}
}
}

View File

@ -27,209 +27,270 @@ from rsd_lib.resources.v2_2.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_2/system.json',
'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_2/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/System2',
redfish_version='1.0.2')
self.conn, "/redfish/v1/Systems/System2", redfish_version="1.0.2"
)
def test_class_inherit(self):
self.assertIsInstance(self.system_inst, system.System)
self.assertIsInstance(self.system_inst, v2_1_system.System)
def test__parse_attributes(self):
self.system_inst._parse_attributes()
self.assertEqual(
"0.001", self.system_inst.trusted_modules[0].firmware_version
)
self.assertEqual(
"TPM2_0", self.system_inst.trusted_modules[0].interface_type
)
self.assertEqual(
"Enabled", self.system_inst.trusted_modules[0].status.state
)
self.assertEqual(
None, self.system_inst.trusted_modules[0].status.health
)
self.assertEqual(
None, self.system_inst.trusted_modules[0].status.health_rollup
)
self.assertEqual({}, self.system_inst.trusted_modules[0].oem)
self.assertEqual(
None, self.system_inst.trusted_modules[0].firmware_version2
)
self.assertEqual(
"OemMethod",
self.system_inst.trusted_modules[0].interface_type_selection,
)
self.assertEqual(
False, self.system_inst.oem.intel_rackscale.user_mode_enabled
)
self.assertEqual(
False,
self.system_inst.oem.intel_rackscale.
trusted_execution_technology_enabled,
)
self.assertEqual(
"/redfish/v1/Systems/System1/Metrics",
self.system_inst.oem.intel_rackscale.metrics,
)
def test__get_metrics_path(self):
self.assertEqual('/redfish/v1/Systems/System2/Metrics',
self.system_inst._get_metrics_path())
self.assertEqual(
"/redfish/v1/Systems/System1/Metrics",
self.system_inst._get_metrics_path(),
)
def test__get_metrics_path_missing_attr(self):
self.system_inst._json.get('Oem').get('Intel_RackScale').pop('Metrics')
with self.assertRaisesRegex(exceptions.MissingAttributeError,
'attribute Oem/Intel_RackScale/Metrics'):
self.system_inst._json.get("Oem").get("Intel_RackScale").pop("Metrics")
with self.assertRaisesRegex(
exceptions.MissingAttributeError,
"attribute Oem/Intel_RackScale/Metrics",
):
self.system_inst._get_metrics_path()
def test_metrics(self):
# | GIVEN |
self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_2/system_metrics.json',
'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_2/system_metrics.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN |
actual_metrics = self.system_inst.metrics
# | THEN |
self.assertIsInstance(actual_metrics,
metrics.Metrics)
self.assertIsInstance(actual_metrics, metrics.Metrics)
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_metrics,
self.system_inst.metrics)
self.assertIs(actual_metrics, self.system_inst.metrics)
self.conn.get.return_value.json.assert_not_called()
def test_metrics_on_refresh(self):
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_2/system_metrics.json',
'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_2/system_metrics.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.system_inst.metrics,
metrics.Metrics)
self.assertIsInstance(self.system_inst.metrics, metrics.Metrics)
# On refreshing the system instance...
with open('rsd_lib/tests/unit/json_samples/v2_2/system.json',
'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_2/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_2/system_metrics.json',
'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_2/system_metrics.json", "r"
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.system_inst.metrics,
metrics.Metrics)
self.assertIsInstance(self.system_inst.metrics, metrics.Metrics)
def test_processors(self):
# | GIVEN |
self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_2/'
'processor_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_2/"
"processor_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN |
actual_processors = self.system_inst.processors
# | THEN |
self.assertIsInstance(actual_processors,
processor.ProcessorCollection)
self.assertIsInstance(actual_processors, processor.ProcessorCollection)
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_processors,
self.system_inst.processors)
self.assertIs(actual_processors, self.system_inst.processors)
self.conn.get.return_value.json.assert_not_called()
def test_processors_on_refresh(self):
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_2/'
'processor_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_2/"
"processor_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.system_inst.processors,
processor.ProcessorCollection)
self.assertIsInstance(
self.system_inst.processors, processor.ProcessorCollection
)
# On refreshing the system instance...
with open('rsd_lib/tests/unit/json_samples/v2_2/system.json',
'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_2/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_2/'
'processor_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_2/"
"processor_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.system_inst.processors,
processor.ProcessorCollection)
self.assertIsInstance(
self.system_inst.processors, processor.ProcessorCollection
)
def test_memory(self):
# | GIVEN |
self.conn.get.return_value.json.reset_mock()
with open('rsd_lib/tests/unit/json_samples/v2_2/'
'memory_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_2/" "memory_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN |
actual_memory_col = self.system_inst.memory
# | THEN |
self.assertIsInstance(actual_memory_col,
memory.MemoryCollection)
self.assertIsInstance(actual_memory_col, memory.MemoryCollection)
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_memory_col,
self.system_inst.memory)
self.assertIs(actual_memory_col, self.system_inst.memory)
self.conn.get.return_value.json.assert_not_called()
def test_memory_on_refresh(self):
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_2/'
'memory_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_2/" "memory_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.system_inst.memory,
memory.MemoryCollection)
self.assertIsInstance(self.system_inst.memory, memory.MemoryCollection)
# On refreshing the system instance...
with open('rsd_lib/tests/unit/json_samples/v2_2/system.json',
'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_2/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_2/'
'memory_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_2/" "memory_collection.json",
"r",
) as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertIsInstance(self.system_inst.memory,
memory.MemoryCollection)
self.assertIsInstance(self.system_inst.memory, memory.MemoryCollection)
class SystemCollectionTestCase(testtools.TestCase):
def setUp(self):
super(SystemCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_2/'
'system_collection.json', 'r') as f:
with open(
"rsd_lib/tests/unit/json_samples/v2_2/" "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')
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)
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)
@mock.patch.object(system, "System", autospec=True)
def test_get_member(self, mock_system):
self.system_col.get_member(
'/redfish/v1/Systems/System1')
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)
"/redfish/v1/Systems/System1",
redfish_version=self.system_col.redfish_version,
)
@mock.patch.object(system, 'System', autospec=True)
@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.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)