Add export system configuration

This change adds support for exporting system configuration. The
configuration of the entire system or individual subsystems, such as
iDRAC, BIOS, NIC, and RAID, can be exported.

Change-Id: Ia7db0223d72566cf4a4d013a35ef2782f273695f
Co-Authored-By: Sonali Borkar <sonaliborkar85@gmail.com>
This commit is contained in:
Mahendra Kamble 2020-02-27 12:38:34 -05:00 committed by Aija Jauntēva
parent abe646e951
commit b9d65b5ef2
5 changed files with 194 additions and 1 deletions

View File

@ -0,0 +1,21 @@
# Copyright (c) 2020-2021 Dell Inc. or its subsidiaries.
#
# 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.resources import common
class ExportActionField(common.ActionField):
allowed_values = base.Field('ShareParameters',
adapter=dict)

View File

@ -0,0 +1,30 @@
# Copyright (c) 2020-2021 Dell Inc. or its subsidiaries.
#
# 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.
# export system config action constants
EXPORT_ALL_CONFIG = 'all'
"""Export entire system configuration"""
EXPORT_BIOS_CONFIG = 'BIOS'
"""Export BIOS related configuration"""
EXPORT_IDRAC_CONFIG = 'iDRAC'
"""Export IDRAC related configuration"""
EXPORT_NIC_CONFIG = 'NIC'
"""Export NIC related configuration"""
EXPORT_RAID_CONFIG = 'RAID'
"""Export RAID related configuration"""

View File

@ -1,3 +1,5 @@
# Copyright (c) 2020-2021 Dell Inc. or its subsidiaries.
#
# 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
@ -20,6 +22,8 @@ from sushy.resources.oem import base as oem_base
from sushy_oem_idrac import asynchronous
from sushy_oem_idrac import constants
from sushy_oem_idrac.resources import common as res_common
from sushy_oem_idrac.resources.manager import mappings as mgr_maps
from sushy_oem_idrac import utils
LOG = logging.getLogger(__name__)
@ -30,6 +34,10 @@ class DellManagerActionsField(base.CompositeField):
lambda key, **kwargs: key.endswith(
'#OemManager.ImportSystemConfiguration'))
export_system_configuration = res_common.ExportActionField(
lambda key, **kwargs: key.endswith(
'#OemManager.ExportSystemConfiguration'))
class DellManagerExtension(oem_base.OEMResourceBase):
@ -83,6 +91,10 @@ VFDD\
def import_system_configuration_uri(self):
return self._actions.import_system_configuration.target_uri
@property
def export_system_configuration_uri(self):
return self._actions.export_system_configuration.target_uri
def set_virtual_boot_device(self, device, persistent=False,
manager=None, system=None):
"""Set boot device for a node.
@ -97,7 +109,7 @@ VFDD\
:raises: InvalidParameterValue if Dell OEM extension can't
be used.
:raises: ExtensionError on failure to perform requested
operation
operation.
"""
try:
idrac_media = self.IDRAC_MEDIA_TYPES[device]
@ -170,6 +182,67 @@ VFDD\
attempts -= 1
def get_allowed_export_system_config_values(self):
"""Get the allowed values of export system configuration.
:returns: A set of allowed values.
"""
export_action = self._actions.export_system_configuration
allowed_values = export_action.allowed_values[
'Target@Redfish.AllowableValues']
return set([mgr_maps.EXPORT_CONFIG_VALUE_MAP[value] for value in
set(mgr_maps.EXPORT_CONFIG_VALUE_MAP).
intersection(allowed_values)])
def _export_system_configuration(self, target):
"""Export system configuration.
It exports system configuration for specified target
like NIC, BIOS, RAID.
:param target: Component of the system to export the
configuration from. Can be the entire system.
Valid values can be gotten from
`get_allowed_export_system_config_values`.
:returns: a response object containing configuration details for
the specified target.
:raises: InvalidParameterValueError on invalid target.
:raises: ExtensionError on failure to perform requested
operation
"""
valid_allowed_targets = self.get_allowed_export_system_config_values()
if target not in valid_allowed_targets:
raise sushy.exceptions.InvalidParameterValueError(
parameter='target', value=target,
valid_values=valid_allowed_targets)
target = mgr_maps.EXPORT_CONFIG_VALUE_MAP_REV[target]
action_data = {
'ShareParameters': {
'Target': target
},
'ExportFormat': "JSON"
}
try:
response = asynchronous.http_call(
self._conn,
'post',
self.export_system_configuration_uri,
data=action_data)
LOG.info("Successfully exported system configuration "
"for %(target)s", {'target': target})
return response
except (sushy.exceptions.ExtensionError,
sushy.exceptions.InvalidParameterValueError) as exc:
LOG.error('Dell OEM export system configuration failed : %s', exc)
raise
def get_extension(*args, **kwargs):
return DellManagerExtension

View File

@ -0,0 +1,27 @@
# Copyright (c) 2020-2021 Dell Inc. or its subsidiaries.
#
# 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 import utils
from sushy_oem_idrac.resources.manager import constants as mgr_cons
EXPORT_CONFIG_VALUE_MAP = {
'ALL': mgr_cons.EXPORT_ALL_CONFIG,
'BIOS': mgr_cons.EXPORT_BIOS_CONFIG,
'IDRAC': mgr_cons.EXPORT_IDRAC_CONFIG,
'NIC': mgr_cons.EXPORT_NIC_CONFIG,
'RAID': mgr_cons.EXPORT_RAID_CONFIG
}
EXPORT_CONFIG_VALUE_MAP_REV = utils.revert_dictionary(EXPORT_CONFIG_VALUE_MAP)

View File

@ -1,5 +1,6 @@
# Copyright 2017 Red Hat, Inc.
# All Rights Reserved.
# Copyright (c) 2020-2021 Dell Inc. or its subsidiaries.
#
# 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
@ -20,6 +21,8 @@ from oslotest.base import BaseTestCase
import sushy
from sushy.resources.manager import manager
from sushy_oem_idrac.resources.manager import constants as mgr_cons
class ManagerTestCase(BaseTestCase):
@ -58,3 +61,42 @@ class ManagerTestCase(BaseTestCase):
self.conn.post.assert_called_once_with(
'/redfish/v1/Managers/iDRAC.Embedded.1/Actions/Oem/EID_674_Manager'
'.ImportSystemConfiguration', data=mock.ANY)
@mock.patch('sushy.resources.oem.common._global_extn_mgrs_by_resource', {})
def test_get_allowed_export_system_config_values(self):
oem = self.manager.get_oem_extension('Dell')
expected_values = {mgr_cons.EXPORT_IDRAC_CONFIG,
mgr_cons.EXPORT_RAID_CONFIG,
mgr_cons.EXPORT_ALL_CONFIG,
mgr_cons.EXPORT_BIOS_CONFIG,
mgr_cons.EXPORT_NIC_CONFIG}
allowed_values = oem.get_allowed_export_system_config_values()
self.assertEqual(expected_values, allowed_values)
@mock.patch('sushy.resources.oem.common._global_extn_mgrs_by_resource', {})
def test_export_system_configuration_uri(self):
oem = self.manager.get_oem_extension('Dell')
self.assertEqual(
'/redfish/v1/Managers/iDRAC.Embedded.1/Actions/Oem/EID_674_Manager'
'.ExportSystemConfiguration',
oem.export_system_configuration_uri)
@mock.patch('sushy.resources.oem.common._global_extn_mgrs_by_resource', {})
def test__export_system_configuration(self):
oem = self.manager.get_oem_extension('Dell')
oem._export_system_configuration(
target=mgr_cons.EXPORT_ALL_CONFIG)
self.conn.post.assert_called_once_with(
'/redfish/v1/Managers/iDRAC.Embedded.1/Actions/Oem/EID_674_Manager'
'.ExportSystemConfiguration', data={'ShareParameters':
{'Target': 'ALL'},
'ExportFormat': 'JSON'})
@mock.patch('sushy.resources.oem.common._global_extn_mgrs_by_resource', {})
def test__export_system_configuration_invalid_target(self):
oem = self.manager.get_oem_extension('Dell')
target = "xyz"
self.assertRaises(sushy.exceptions.InvalidParameterValueError,
oem._export_system_configuration, target)