summaryrefslogtreecommitdiff
path: root/ironic/drivers
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2021-03-22 13:16:06 +0000
committerGerrit Code Review <review@openstack.org>2021-03-22 13:16:06 +0000
commitacd4b451dc866f4aee48b46f958cc46fd2220d09 (patch)
tree129e16ddbb3305ff31da17901a8336df0358ed86 /ironic/drivers
parent8251885db551b4ff539e9ebd99f3e436a65308b6 (diff)
parent05df3d7aa4aa7a1fd25a2f2d55726197e1b5f9df (diff)
downloadironic-acd4b451dc866f4aee48b46f958cc46fd2220d09.tar.gz
Merge "Use OOB inspection to fetch MACs for IB inspection"
Diffstat (limited to 'ironic/drivers')
-rw-r--r--ironic/drivers/base.py11
-rw-r--r--ironic/drivers/modules/inspector.py18
-rw-r--r--ironic/drivers/modules/redfish/inspect.py26
-rw-r--r--ironic/drivers/modules/redfish/management.py19
-rw-r--r--ironic/drivers/modules/redfish/utils.py23
5 files changed, 78 insertions, 19 deletions
diff --git a/ironic/drivers/base.py b/ironic/drivers/base.py
index db655a474..ebeff2de5 100644
--- a/ironic/drivers/base.py
+++ b/ironic/drivers/base.py
@@ -1161,6 +1161,17 @@ class ManagementInterface(BaseInterface):
raise exception.UnsupportedDriverExtension(
driver=task.node.driver, extension='detect_vendor')
+ def get_mac_addresses(self, task):
+ """Get MAC address information for the node.
+
+ :param task: A TaskManager instance containing the node to act on.
+ :raises: UnsupportedDriverExtension
+ :returns: A list of MAC addresses for the node
+
+ """
+ raise exception.UnsupportedDriverExtension(
+ driver=task.node.driver, extension='get_mac_addresses')
+
class InspectInterface(BaseInterface):
"""Interface for inspection-related actions."""
diff --git a/ironic/drivers/modules/inspector.py b/ironic/drivers/modules/inspector.py
index 0da29c63c..fa60412e2 100644
--- a/ironic/drivers/modules/inspector.py
+++ b/ironic/drivers/modules/inspector.py
@@ -34,7 +34,7 @@ from ironic.conductor import utils as cond_utils
from ironic.conf import CONF
from ironic.drivers import base
from ironic.drivers.modules import deploy_utils
-
+from ironic.drivers.modules import inspect_utils
LOG = logging.getLogger(__name__)
@@ -243,6 +243,22 @@ class Inspector(base.InspectInterface):
:returns: states.INSPECTWAIT
:raises: HardwareInspectionFailure on failure
"""
+ try:
+ enabled_macs = task.driver.management.get_mac_addresses(task)
+ if enabled_macs:
+ inspect_utils.create_ports_if_not_exist(
+ task, enabled_macs, get_mac_address=lambda x: x[0])
+ else:
+ LOG.warning("Not attempting to create any port as no NICs "
+ "were discovered in 'enabled' state for node "
+ "%(node)s: %(mac_data)s",
+ {'mac_data': enabled_macs,
+ 'node': task.node.uuid})
+
+ except exception.UnsupportedDriverExtension:
+ LOG.info('Pre-creating ports prior to inspection not supported'
+ ' on node %s.', task.node.uuid)
+
ironic_manages_boot = _ironic_manages_boot(
task, raise_exc=CONF.inspector.require_managed_boot)
diff --git a/ironic/drivers/modules/redfish/inspect.py b/ironic/drivers/modules/redfish/inspect.py
index a0d7cf485..10344c95d 100644
--- a/ironic/drivers/modules/redfish/inspect.py
+++ b/ironic/drivers/modules/redfish/inspect.py
@@ -160,25 +160,15 @@ class RedfishInspect(base.InspectInterface):
return states.MANAGEABLE
def _create_ports(self, task, system):
- if (system.ethernet_interfaces
- and system.ethernet_interfaces.summary):
- macs = system.ethernet_interfaces.summary
-
- # Create ports for the discovered NICs being in 'enabled' state
- enabled_macs = {nic_mac: nic_state
- for nic_mac, nic_state in macs.items()
- if nic_state == sushy.STATE_ENABLED}
- if enabled_macs:
- inspect_utils.create_ports_if_not_exist(
- task, enabled_macs, get_mac_address=lambda x: x[0])
- else:
- LOG.warning("Not attempting to create any port as no NICs "
- "were discovered in 'enabled' state for node "
- "%(node)s: %(mac_data)s",
- {'mac_data': macs, 'node': task.node.uuid})
+ enabled_macs = redfish_utils.get_enabled_macs(task, system)
+ if enabled_macs:
+ inspect_utils.create_ports_if_not_exist(
+ task, enabled_macs, get_mac_address=lambda x: x[0])
else:
- LOG.warning("No NIC information discovered "
- "for node %(node)s", {'node': task.node.uuid})
+ LOG.warning("Not attempting to create any port as no NICs "
+ "were discovered in 'enabled' state for node "
+ "%(node)s: %(mac_data)s",
+ {'mac_data': enabled_macs, 'node': task.node.uuid})
def _detect_local_gb(self, task, system):
simple_storage_size = 0
diff --git a/ironic/drivers/modules/redfish/management.py b/ironic/drivers/modules/redfish/management.py
index 32233903c..3dd11ff3d 100644
--- a/ironic/drivers/modules/redfish/management.py
+++ b/ironic/drivers/modules/redfish/management.py
@@ -1161,3 +1161,22 @@ class RedfishManagement(base.ManagementInterface):
self._reset_keys(task, sushy.SECURE_BOOT_RESET_KEYS_DELETE_ALL)
LOG.info('Secure boot keys have been removed from node %s',
task.node.uuid)
+
+ def get_mac_addresses(self, task):
+ """Get MAC address information for the node.
+
+ :param task: A TaskManager instance containing the node to act on.
+ :raises: RedfishConnectionError when it fails to connect to Redfish
+ :raises: RedfishError on an error from the Sushy library
+ :returns: a dictionary containing MAC addresses of enabled interfaces
+ in a {'mac': 'state'} format
+ """
+ try:
+ system = redfish_utils.get_system(task.node)
+ return redfish_utils.get_enabled_macs(task, system)
+ except sushy.exceptions.SushyError as exc:
+ msg = (_('Failed to get network interface information on node '
+ '%(node)s: %(exc)s')
+ % {'node': task.node.uuid, 'exc': exc})
+ LOG.error(msg)
+ raise exception.RedfishError(error=msg)
diff --git a/ironic/drivers/modules/redfish/utils.py b/ironic/drivers/modules/redfish/utils.py
index 58c88ccce..0cb6de1fb 100644
--- a/ironic/drivers/modules/redfish/utils.py
+++ b/ironic/drivers/modules/redfish/utils.py
@@ -349,3 +349,26 @@ def _get_connection(node, lambda_fun, *args):
'node %(node)s. Error: %(error)s',
{'address': driver_info['address'],
'node': node.uuid, 'error': e})
+
+
+def get_enabled_macs(task, system):
+ """Get information on MAC addresses of enabled ports using Redfish.
+
+ :param task: a TaskManager instance containing the node to act on.
+ :param system: a Redfish System object
+ :returns: a dictionary containing MAC addresses of enabled interfaces
+ in a {'mac': 'state'} format
+ """
+
+ if (system.ethernet_interfaces
+ and system.ethernet_interfaces.summary):
+ macs = system.ethernet_interfaces.summary
+
+ # Identify ports for the NICs being in 'enabled' state
+ enabled_macs = {nic_mac: nic_state
+ for nic_mac, nic_state in macs.items()
+ if nic_state == sushy.STATE_ENABLED}
+ return enabled_macs
+ else:
+ LOG.warning("No NIC information discovered "
+ "for node %(node)s", {'node': task.node.uuid})