Browse Source

Add get PXE port MACs for BIOS mode

This change adds the ability to retrieve the list of PXE-enabled device
MAC addresses for legacy BIOS boot mode.

Change-Id: I4bf42bde631c5b41710ff1faead0477063e89971
changes/04/770904/9
sonali bhausaheb borkar 3 months ago
committed by Richard G. Pioso
parent
commit
bec107ce58
3 changed files with 1532 additions and 0 deletions
  1. +45
    -0
      sushy_oem_idrac/resources/manager/manager.py
  2. +1435
    -0
      sushy_oem_idrac/tests/unit/json_samples/export_configuration_nic_bios.json
  3. +52
    -0
      sushy_oem_idrac/tests/unit/test_manager.py

+ 45
- 0
sushy_oem_idrac/resources/manager/manager.py View File

@ -23,11 +23,18 @@ 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 constants as mgr_cons
from sushy_oem_idrac.resources.manager import mappings as mgr_maps
from sushy_oem_idrac import utils
LOG = logging.getLogger(__name__)
# System Configuration Tag Constant
_SYSTEM_CONFIG_TAG = "SystemConfiguration"
# Response Code Constant
_RESPONSE_OK_CODE = 200
class DellManagerActionsField(base.CompositeField):
import_system_configuration = common.ActionField(
@ -243,6 +250,44 @@ VFDD\
LOG.error('Dell OEM export system configuration failed : %s', exc)
raise
def get_pxe_port_macs_bios(self, ethernet_interfaces_mac):
"""Get a list of pxe port MAC addresses for BIOS.
:param ethernet_interfaces_mac: Dictionary of ethernet interfaces.
:returns: List of pxe port MAC addresses.
:raises: ExtensionError on failure to perform requested operation.
"""
pxe_port_macs = []
# Get NIC configuration
nic_settings = self._export_system_configuration(
target=mgr_cons.EXPORT_NIC_CONFIG)
if nic_settings.status_code != _RESPONSE_OK_CODE:
error = (('An error occurred when attempting to export '
'the system configuration. Status code: %(code), '
'Error details: %(err)'),
{'code': nic_settings.status_code,
'err': nic_settings.__dict__})
LOG.error(error)
raise sushy.exceptions.ExtensionError(error=error)
# Parse the exported system configuration for the NIC
# ports that are set to PXE boot
json_data = nic_settings.json()
if _SYSTEM_CONFIG_TAG in json_data.keys():
for root in json_data[_SYSTEM_CONFIG_TAG]['Components']:
nic_id = root['FQDD']
for child in root['Attributes']:
if child.get('Name') == "LegacyBootProto":
if child['Value'] == "PXE":
mac_address = ethernet_interfaces_mac[nic_id]
pxe_port_macs.append(mac_address)
return pxe_port_macs
else:
error = (('Failed to get system configuration from response'))
LOG.error(error)
raise sushy.exceptions.ExtensionError(error=error)
def get_extension(*args, **kwargs):
return DellManagerExtension

+ 1435
- 0
sushy_oem_idrac/tests/unit/json_samples/export_configuration_nic_bios.json
File diff suppressed because it is too large
View File


+ 52
- 0
sushy_oem_idrac/tests/unit/test_manager.py View File

@ -100,3 +100,55 @@ class ManagerTestCase(BaseTestCase):
target = "xyz"
self.assertRaises(sushy.exceptions.InvalidParameterValueError,
oem._export_system_configuration, target)
@mock.patch('sushy.resources.oem.common._global_extn_mgrs_by_resource', {})
def test_get_pxe_port_macs_bios(self):
oem = self.manager.get_oem_extension('Dell')
oem._export_system_configuration = mock.Mock()
with open('sushy_oem_idrac/tests/unit/json_samples/'
'export_configuration_nic_bios.json') as f:
mock_response = oem._export_system_configuration.return_value
mock_response.json.return_value = json.load(f)
mock_response.status_code = 200
ethernet_interfaces_mac = {'NIC.Integrated.1-4-1': '68:05:CA:AF:AA:C9',
'NIC.Slot.7-2-1': '3C:FD:FE:CD:67:31',
'NIC.Slot.7-1-1': '3C:FD:FE:CD:67:30',
'NIC.Integrated.1-2-1': '68:05:CA:AF:AA:C7',
'NIC.Integrated.1-3-1': '68:05:CA:AF:AA:C8',
'NIC.Integrated.1-1-1': '68:05:CA:AF:AA:C6'}
self.assertEqual(["68:05:CA:AF:AA:C8"],
oem.get_pxe_port_macs_bios(ethernet_interfaces_mac))
@mock.patch('sushy.resources.oem.common._global_extn_mgrs_by_resource', {})
def test_get_pxe_port_macs_bios_invalid_system_config_tag(self):
oem = self.manager.get_oem_extension('Dell')
oem._export_system_configuration = mock.Mock()
mock_response = oem._export_system_configuration.return_value
mock_response.json.return_value = {'Model': 'PowerEdge R7525'}
mock_response.status_code = 200
ethernet_interfaces_mac = {'NIC.Integrated.1-4-1': '68:05:CA:AF:AA:C9',
'NIC.Slot.7-2-1': '3C:FD:FE:CD:67:31',
'NIC.Slot.7-1-1': '3C:FD:FE:CD:67:30',
'NIC.Integrated.1-2-1': '68:05:CA:AF:AA:C7',
'NIC.Integrated.1-3-1': '68:05:CA:AF:AA:C8',
'NIC.Integrated.1-1-1': '68:05:CA:AF:AA:C6'}
self.assertRaises(sushy.exceptions.ExtensionError,
oem.get_pxe_port_macs_bios, ethernet_interfaces_mac)
@mock.patch('sushy.resources.oem.common._global_extn_mgrs_by_resource', {})
def test_get_pxe_port_macs_bios_invalid_response(self):
oem = self.manager.get_oem_extension('Dell')
oem._export_system_configuration = mock.Mock()
mock_response = oem._export_system_configuration.return_value
mock_response.status_code = 204
ethernet_interfaces_mac = {'NIC.Integrated.1-4-1': '68:05:CA:AF:AA:C9',
'NIC.Slot.7-2-1': '3C:FD:FE:CD:67:31',
'NIC.Slot.7-1-1': '3C:FD:FE:CD:67:30',
'NIC.Integrated.1-2-1': '68:05:CA:AF:AA:C7',
'NIC.Integrated.1-3-1': '68:05:CA:AF:AA:C8',
'NIC.Integrated.1-1-1': '68:05:CA:AF:AA:C6'}
self.assertRaises(sushy.exceptions.ExtensionError,
oem.get_pxe_port_macs_bios, ethernet_interfaces_mac)

Loading…
Cancel
Save