Add new class for attach action info of composed node

Change-Id: I091fad0b0796fb3ab7f625e952e64b3de15da8e6
This commit is contained in:
Lin Yang 2018-05-09 15:42:42 -07:00
parent 9f097bb1a2
commit b165a98e96
3 changed files with 217 additions and 0 deletions

View File

@ -0,0 +1,80 @@
# 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 logging
from sushy.resources import base
from sushy import utils
LOG = logging.getLogger(__name__)
NAME_MAPPING = {
"Name": "name",
"Required": "required",
"DataType": "data_type",
"ObjectDataType": "object_data_type",
"AllowableValues": "allowable_values"
}
class AttachResourceActionInfo(base.ResourceBase):
identity = base.Field('Id', required=True)
"""The storage pool identity string"""
description = base.Field('Description')
"""The storage pool description string"""
name = base.Field('Name')
"""The storage pool name string"""
_parameters = None # ref to allocated volumes collection
def __init__(self, connector, identity, redfish_version=None):
"""A class representing a LogicalDrive
:param connector: A Connector instance
:param identity: The identity of the AttachResourceActionInfo resource
:param redfish_version: The version of RedFish. Used to construct
the object according to schema of the given version.
"""
super(AttachResourceActionInfo, self).__init__(
connector, identity, redfish_version)
@property
def parameters(self):
"""Property to provide reference to `Parameters` instance
It is calculated once when it is queried for the first time. On
refresh, this property is reset.
"""
if self._parameters is None:
self._parameters = []
for i in self.json.get('Parameters'):
item = {}
for key in NAME_MAPPING:
item[NAME_MAPPING[key]] = i[key]
if item['name'] == 'Resource':
item['allowable_values'] = utils.get_members_identities(
item['allowable_values'])
self._parameters.append(item)
return self._parameters
def refresh(self):
super(AttachResourceActionInfo, self).refresh()
self._parameters = None

View File

@ -0,0 +1,29 @@
{
"@odata.context" : "/redfish/v1/$metadata#ActionInfo.ActionInfo",
"@odata.id" : "/redfish/v1/Nodes/2/Actions/AttachResourceActionInfo",
"@odata.type" : "#ActionInfo.v1_0_2.ActionInfo",
"Id" : "AttachResourceActionInfo",
"Name" : "Attach Resource ActionInfo",
"Description" : null,
"Parameters" : [
{
"Name" : "Resource",
"Required" : true,
"DataType" : "Object",
"ObjectDataType" : "#Resource.Resource",
"AllowableValues" : [
{
"@odata.id" : "/redfish/v1/StorageServices/1-sv-1/Volumes/1-sv-1-vl-1"
}
]
},
{
"Name" : "Protocol",
"Required" : false,
"DataType" : "String",
"ObjectDataType" : null,
"AllowableValues" : [ "NVMeOverFabrics" ]
}
],
"Oem" : {}
}

View File

@ -0,0 +1,108 @@
# 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_3.node import attach_action_info
class AttachResourceActionInfoTestCase(testtools.TestCase):
def setUp(self):
super(AttachResourceActionInfoTestCase, self).setUp()
self.conn = mock.Mock()
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'attach_action_info.json', 'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
self.attach_action_info = attach_action_info.AttachResourceActionInfo(
self.conn, '/redfish/v1/Nodes/2/Actions/AttachResourceActionInfo',
redfish_version='1.0.2')
def test__parse_attributes(self):
self.attach_action_info._parse_attributes()
self.assertEqual('1.0.2', self.attach_action_info.redfish_version)
self.assertEqual(None, self.attach_action_info.description)
self.assertEqual('AttachResourceActionInfo',
self.attach_action_info.identity)
self.assertEqual('Attach Resource ActionInfo',
self.attach_action_info.name)
self.assertIsNone(self.attach_action_info._parameters)
def test_parameters(self):
# check for the underneath variable value
self.assertIsNone(self.attach_action_info._parameters)
# | WHEN |
actual_parameters = self.attach_action_info.parameters
# | THEN |
expected = [
{
"name": "Resource",
"required": True,
"data_type": "Object",
"object_data_type": "#Resource.Resource",
"allowable_values": (
"/redfish/v1/StorageServices/1-sv-1/Volumes/1-sv-1-vl-1",
)
},
{
"name": "Protocol",
"required": False,
"data_type": "String",
"object_data_type": None,
"allowable_values": ["NVMeOverFabrics"]
}
]
self.assertEqual(expected, actual_parameters)
# tests for same object on invoking subsequently
self.assertIs(actual_parameters,
self.attach_action_info.parameters)
def test_parameters_on_refresh(self):
expected = [
{
"name": "Resource",
"required": True,
"data_type": "Object",
"object_data_type": "#Resource.Resource",
"allowable_values": (
"/redfish/v1/StorageServices/1-sv-1/Volumes/1-sv-1-vl-1",
)
},
{
"name": "Protocol",
"required": False,
"data_type": "String",
"object_data_type": None,
"allowable_values": ["NVMeOverFabrics"]
}
]
self.assertEqual(expected, self.attach_action_info.parameters)
# On refreshing the storage service instance...
self.attach_action_info.refresh()
# | WHEN & THEN |
self.assertIsNone(self.attach_action_info._parameters)
# | GIVEN |
with open('rsd_lib/tests/unit/json_samples/v2_3/'
'storage_pool_collection.json', 'r') as f:
self.conn.get.return_value.json.return_value = json.loads(f.read())
# | WHEN & THEN |
self.assertEqual(expected, self.attach_action_info.parameters)