Update schema check for node composition for RSD 2.2

Change-Id: I43ba1d5f3b486c4a2d207e00b0d52ef01970e364
This commit is contained in:
Lin Yang 2018-09-05 17:23:23 -07:00
parent 317902aac1
commit f8ef9f903f
7 changed files with 475 additions and 1 deletions

View File

@ -16,6 +16,7 @@
from sushy.resources import base
from rsd_lib.resources import v2_1
from rsd_lib.resources.v2_2.node import node
from rsd_lib.resources.v2_2.system import system
from rsd_lib.resources.v2_2.telemetry import telemetry
@ -57,6 +58,16 @@ class RSDLibV2_2(v2_1.RSDLibV2_1):
return system.SystemCollection(self._conn, self._systems_path,
redfish_version=self.redfish_version)
def get_node_collection(self):
"""Get the NodeCollection object
:raises: MissingAttributeError, if the collection attribute is
not found
:returns: a NodeCollection object
"""
return node.NodeCollection(self._conn, self._nodes_path,
redfish_version=self.redfish_version)
def get_telemetry_service(self):
"""Given the identity return a Telemetry Service object

View File

View File

@ -0,0 +1,130 @@
# Copyright (c) 2018 Intel, Corp.
# 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 jsonschema import validate
import logging
from rsd_lib.resources.v2_1.node import node as v2_1_node
from rsd_lib.resources.v2_2.node import schemas as node_schemas
LOG = logging.getLogger(__name__)
class NodeCollection(v2_1_node.NodeCollection):
def _create_compose_request(self, name=None, description=None,
processor_req=None, memory_req=None,
remote_drive_req=None, local_drive_req=None,
ethernet_interface_req=None,
security_req=None, total_system_core_req=None,
total_system_memory_req=None):
request = {}
if name is not None:
request['Name'] = name
if description is not None:
request['Description'] = description
if processor_req is not None:
validate(processor_req,
node_schemas.processor_req_schema)
request['Processors'] = processor_req
if memory_req is not None:
validate(memory_req,
node_schemas.memory_req_schema)
request['Memory'] = memory_req
if remote_drive_req is not None:
validate(remote_drive_req,
node_schemas.remote_drive_req_schema)
request['RemoteDrives'] = remote_drive_req
if local_drive_req is not None:
validate(local_drive_req,
node_schemas.local_drive_req_schema)
request['LocalDrives'] = local_drive_req
if ethernet_interface_req is not None:
validate(ethernet_interface_req,
node_schemas.ethernet_interface_req_schema)
request['EthernetInterfaces'] = ethernet_interface_req
if security_req is not None:
validate(security_req,
node_schemas.security_req_schema)
request['Security'] = security_req
if total_system_core_req is not None:
validate(total_system_core_req,
node_schemas.total_system_core_req_schema)
request['TotalSystemCoreCount'] = total_system_core_req
if total_system_memory_req is not None:
validate(total_system_memory_req,
node_schemas.total_system_memory_req_schema)
request['TotalSystemMemoryMiB'] = total_system_memory_req
return request
def compose_node(self, name=None, description=None,
processor_req=None, memory_req=None,
remote_drive_req=None, local_drive_req=None,
ethernet_interface_req=None, security_req=None,
total_system_core_req=None, total_system_memory_req=None):
"""Compose a node from RackScale hardware
:param name: Name of node
:param description: Description of node
:param processor_req: JSON for node processors
:param memory_req: JSON for node memory modules
:param remote_drive_req: JSON for node remote drives
:param local_drive_req: JSON for node local drives
:param ethernet_interface_req: JSON for node ethernet ports
:param security_req: JSON for node security requirements
:param total_system_core_req: Total processor cores available in
composed node
:param total_system_memory_req: Total memory available in composed node
:returns: The location of the composed node
When the 'processor_req' is not none: it need a computer system
contains processors whose each processor meet all conditions in the
value.
When the 'total_system_core_req' is not none: it need a computer
system contains processors whose cores sum up to number equal or
greater than 'total_system_core_req'.
When both values are not none: it need meet all conditions.
'memory_req' and 'total_system_memory_req' is the same.
"""
target_uri = self._get_compose_action_element().target_uri
properties = self._create_compose_request(
name=name, description=description,
processor_req=processor_req,
memory_req=memory_req,
remote_drive_req=remote_drive_req,
local_drive_req=local_drive_req,
ethernet_interface_req=ethernet_interface_req,
security_req=security_req,
total_system_core_req=total_system_core_req,
total_system_memory_req=total_system_memory_req)
resp = self._conn.post(target_uri, data=properties)
LOG.info("Node created at %s", resp.headers['Location'])
node_url = resp.headers['Location']
return node_url[node_url.find(self._path):]

View File

@ -0,0 +1,195 @@
# Copyright (c) 2018 Intel, Corp.
#
# 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.
processor_req_schema = {
'type': 'array',
'items': [{
'type': 'object',
'properties': {
'Model': {'type': 'string'},
'TotalCores': {'type': 'number'},
'AchievableSpeedMHz': {'type': 'number'},
'InstructionSet': {
'type': 'string',
'enum': ['x86', 'x86-64', 'IA-64', 'ARM-A32',
'ARM-A64', 'MIPS32', 'MIPS64', 'OEM']
},
'Resource': {
'type': 'object',
'properties': {
'@odata.id': {'type': 'string'}
}
},
'Chassis': {
'type': 'object',
'properties': {
'@odata.id': {'type': 'string'}
}
},
'ProcessorType': {
'type': 'string',
'enum': ['CPU', 'FPGA', 'GPU', 'DSP', 'Accelerator', 'OEM']
}
},
'additionalProperties': False,
}]
}
memory_req_schema = {
'type': 'array',
'items': [{
'type': 'object',
'properties': {
'CapacityMiB': {'type': 'number'},
'MemoryDeviceType': {
'type': 'string',
'enum': ['DDR', 'DDR2', 'DDR3', 'DDR4', 'DDR4_SDRAM',
'DDR4E_SDRAM', 'LPDDR4_SDRAM', 'DDR3_SDRAM',
'LPDDR3_SDRAM', 'DDR2_SDRAM', 'DDR2_SDRAM_FB_DIMM',
'DDR2_SDRAM_FB_DIMM_PROBE', 'DDR_SGRAM',
'DDR_SDRAM', 'ROM', 'SDRAM', 'EDO',
'FastPageMode', 'PipelinedNibble']
},
'SpeedMHz': {'type': 'number'},
'Manufacturer': {'type': 'string'},
'DataWidthBits': {'type': 'number'},
'Resource': {
'type': 'object',
'properties': {
'@odata.id': {'type': 'string'}
}
},
'Chassis': {
'type': 'object',
'properties': {
'@odata.id': {'type': 'string'}
}
}
},
'additionalProperties': False,
}]
}
remote_drive_req_schema = {
'type': 'array',
'items': [{
'type': 'object',
'properties': {
'CapacityGiB': {'type': 'number'},
'iSCSIAddress': {'type': 'string'},
'Master': {
'type': 'object',
'properties': {
'Type': {
'type': 'string',
'enum': ['Snapshot', 'Clone']
},
'Address': {
'type': 'object',
'properties': {
'@odata.id': {'type': 'string'}
}
}
}
}
},
'additionalProperties': False,
}]
}
local_drive_req_schema = {
'type': 'array',
'items': [{
'type': 'object',
'properties': {
'CapacityGiB': {'type': 'number'},
'Type': {
'type': 'string',
'enum': ['HDD', 'SSD']
},
'MinRPM': {'type': 'number'},
'SerialNumber': {'type': 'string'},
'Interface': {
'type': 'string',
'enum': ['SAS', 'SATA', 'NVMe']
},
'Resource': {
'type': 'object',
'properties': {
'@odata.id': {'type': 'string'}
}
},
'Chassis': {
'type': 'object',
'properties': {
'@odata.id': {'type': 'string'}
}
},
'FabricSwitch': {'type': 'boolean'}
},
'additionalProperties': False,
}]
}
ethernet_interface_req_schema = {
'type': 'array',
'items': [{
'type': 'object',
'properties': {
'SpeedMbps': {'type': 'number'},
'PrimaryVLAN': {'type': 'number'},
'VLANs': {
'type': 'array',
'additionalItems': {
'type': 'object',
'properties': {
'VLANId': {'type': 'number'},
'Tagged': {'type': 'boolean'}
}
}
},
'Resource': {
'type': 'object',
'properties': {
'@odata.id': {'type': 'string'}
}
},
'Chassis': {
'type': 'object',
'properties': {
'@odata.id': {'type': 'string'}
}
}
},
'additionalProperties': False,
}]
}
security_req_schema = {
'type': 'object',
'properties': {
'TpmPresent': {'type': 'boolean'},
'TpmInterfaceType': {'type': 'string'},
'TxtEnabled': {'type': 'boolean'},
},
'additionalProperties': False,
}
total_system_core_req_schema = {
'type': 'number'
}
total_system_memory_req_schema = {
'type': 'number'
}

View File

@ -0,0 +1,137 @@
# Copyright (c) 2018 Intel, Corp.
# 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 jsonschema
import mock
import testtools
from rsd_lib.resources.v2_2.node import node
from rsd_lib.tests.unit.fakes import request_fakes
class NodeCollectionTestCase(testtools.TestCase):
def setUp(self):
super(NodeCollectionTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_1/node_collection.json',
'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.conn.post.return_value = request_fakes.fake_request_post(
None, headers={"Location": "https://localhost:8443/"
"redfish/v1/Nodes/1"})
self.node_col = node.NodeCollection(
self.conn, '/redfish/v1/Nodes', redfish_version='1.0.2')
def test_compose_node(self):
reqs = {
'Name': 'test',
'Description': 'this is a test node',
'Processors': [{
'TotalCores': 4,
'ProcessorType': 'FPGA'
}],
'Memory': [{
'CapacityMiB': 8000
}],
'Security': {
'TpmPresent': True,
'TpmInterfaceType': 'TPM2_0',
'TxtEnabled': True
},
'TotalSystemCoreCount': 8,
'TotalSystemMemoryMiB': 16000
}
result = self.node_col.compose_node(
name='test', description='this is a test node',
processor_req=[{
'TotalCores': 4,
'ProcessorType': 'FPGA'}],
memory_req=[{'CapacityMiB': 8000}],
security_req={
'TpmPresent': True,
'TpmInterfaceType': 'TPM2_0',
'TxtEnabled': True
},
total_system_core_req=8,
total_system_memory_req=16000)
self.node_col._conn.post.assert_called_once_with(
'/redfish/v1/Nodes/Actions/Allocate', data=reqs)
self.assertEqual(result, '/redfish/v1/Nodes/1')
def test_compose_node_with_invalid_reqs(self):
# Wrong processor type
with self.assertRaisesRegex(
jsonschema.exceptions.ValidationError,
("'invalid' is not one of \['CPU', 'FPGA', 'GPU', 'DSP', "
"'Accelerator', 'OEM'\]")):
self.node_col.compose_node(
name='test', description='this is a test node',
processor_req=[{
'TotalCores': 4,
'ProcessorType': 'invalid'}])
# Wrong security parameter "TpmPresent"
with self.assertRaisesRegex(
jsonschema.exceptions.ValidationError,
"'invalid' is not of type 'boolean'"):
self.node_col.compose_node(
name='test', description='this is a test node',
security_req={
'TpmPresent': 'invalid',
'TpmInterfaceType': 'TPM2_0',
'TxtEnabled': True
})
# Wrong security parameter "TpmInterfaceType"
with self.assertRaisesRegex(
jsonschema.exceptions.ValidationError,
"True is not of type 'string'"):
self.node_col.compose_node(
name='test', description='this is a test node',
security_req={
'TpmPresent': False,
'TpmInterfaceType': True,
'TxtEnabled': True
})
# Wrong security parameter "TxtEnabled"
with self.assertRaisesRegex(
jsonschema.exceptions.ValidationError,
"'invalid' is not of type 'boolean'"):
self.node_col.compose_node(
name='test', description='this is a test node',
security_req={
'TpmPresent': True,
'TpmInterfaceType': 'TPM2_0',
'TxtEnabled': 'invalid'
})
# Wrong additional security parameter
with self.assertRaisesRegex(
jsonschema.exceptions.ValidationError,
("Additional properties are not allowed \('invalid-key' was "
"unexpected\)")):
self.node_col.compose_node(
name='test', description='this is a test node',
security_req={
'TpmPresent': True,
'TpmInterfaceType': 'TPM2_0',
'TxtEnabled': False,
'invalid-key': 'invalid-value'
})

View File

@ -26,6 +26,7 @@ from rsd_lib.resources.v2_1.node import node as v2_1_node
from rsd_lib.resources.v2_1.storage_service import storage_service \
as v2_1_storage_service
from rsd_lib.resources import v2_2
from rsd_lib.resources.v2_2.node import node as v2_2_node
from rsd_lib.resources.v2_2.system import system as v2_2_system
from rsd_lib.resources.v2_2.telemetry import telemetry as v2_2_telemetry
@ -66,7 +67,7 @@ class RSDLibV2_2TestCase(testtools.TestCase):
self.rsd._conn, 'fake-system-id',
redfish_version=self.rsd.redfish_version)
@mock.patch.object(v2_1_node, 'NodeCollection', autospec=True)
@mock.patch.object(v2_2_node, 'NodeCollection', autospec=True)
def test_get_node_collection(self, mock_node_collection):
self.rsd.get_node_collection()
mock_node_collection.assert_called_once_with(