summaryrefslogtreecommitdiff
path: root/ironic/drivers/modules/redfish/inspect.py
diff options
context:
space:
mode:
authorDmitry Tantsur <dtantsur@protonmail.com>2020-03-30 11:37:02 +0200
committerDmitry Tantsur <dtantsur@protonmail.com>2020-03-31 13:40:00 +0000
commit1faa3397a6ae1c9d82d8f4ba90134148bc022e61 (patch)
tree24de6242cc44bf2b8d108cc7342932d41a4a0669 /ironic/drivers/modules/redfish/inspect.py
parenta3d7d73a69f85b396aad30610294d5ea246a0df7 (diff)
downloadironic-1faa3397a6ae1c9d82d8f4ba90134148bc022e61.tar.gz
Fix the remaining hacking issues
Fixes W504 and E117, resulting in some indentation changes. Also fixes code that exceeds the complexity requirement, that is bumped to 20 (mostly to avoid refactoring the agent heartbeat call, resulting in conflicts for the deploy steps work). Change-Id: I8e49f2c039b0ddfca9138f8e148708b7e8b5df7e
Diffstat (limited to 'ironic/drivers/modules/redfish/inspect.py')
-rw-r--r--ironic/drivers/modules/redfish/inspect.py123
1 files changed, 64 insertions, 59 deletions
diff --git a/ironic/drivers/modules/redfish/inspect.py b/ironic/drivers/modules/redfish/inspect.py
index 0d1e24b51..a0d7cf485 100644
--- a/ironic/drivers/modules/redfish/inspect.py
+++ b/ironic/drivers/modules/redfish/inspect.py
@@ -120,13 +120,74 @@ class RedfishInspect(base.InspectInterface):
"for node %(node)s", {'node': task.node.uuid,
'arch': arch})
+ # TODO(etingof): should we respect root device hints here?
+ local_gb = self._detect_local_gb(task, system)
+
+ if local_gb:
+ inspected_properties['local_gb'] = str(local_gb)
+ else:
+ LOG.warning("Could not provide a valid storage size configured "
+ "for node %(node)s. Assuming this is a disk-less node",
+ {'node': task.node.uuid})
+ inspected_properties['local_gb'] = '0'
+
+ if system.boot.mode:
+ if not drivers_utils.get_node_capability(task.node, 'boot_mode'):
+ capabilities = utils.get_updated_capabilities(
+ inspected_properties.get('capabilities', ''),
+ {'boot_mode': BOOT_MODE_MAP[system.boot.mode]})
+
+ inspected_properties['capabilities'] = capabilities
+
+ valid_keys = self.ESSENTIAL_PROPERTIES
+ missing_keys = valid_keys - set(inspected_properties)
+ if missing_keys:
+ error = (_('Failed to discover the following properties: '
+ '%(missing_keys)s on node %(node)s'),
+ {'missing_keys': ', '.join(missing_keys),
+ 'node': task.node.uuid})
+ raise exception.HardwareInspectionFailure(error=error)
+
+ task.node.properties = inspected_properties
+ task.node.save()
+
+ LOG.debug("Node properties for %(node)s are updated as "
+ "%(properties)s", {'properties': inspected_properties,
+ 'node': task.node.uuid})
+
+ self._create_ports(task, system)
+
+ 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})
+ else:
+ LOG.warning("No NIC information discovered "
+ "for node %(node)s", {'node': task.node.uuid})
+
+ def _detect_local_gb(self, task, system):
simple_storage_size = 0
try:
LOG.debug("Attempting to discover system simple storage size for "
"node %(node)s", {'node': task.node.uuid})
- if (system.simple_storage and
- system.simple_storage.disks_sizes_bytes):
+ if (system.simple_storage
+ and system.simple_storage.disks_sizes_bytes):
simple_storage_size = [
size for size in system.simple_storage.disks_sizes_bytes
if size >= 4 * units.Gi
@@ -184,60 +245,4 @@ class RedfishInspect(base.InspectInterface):
# Note(deray): Convert the received size to GiB and reduce the
# value by 1 GB as consumers like Ironic requires the ``local_gb``
# to be returned 1 less than actual size.
- local_gb = max(0, int(local_gb / units.Gi - 1))
-
- # TODO(etingof): should we respect root device hints here?
-
- if local_gb:
- inspected_properties['local_gb'] = str(local_gb)
- else:
- LOG.warning("Could not provide a valid storage size configured "
- "for node %(node)s. Assuming this is a disk-less node",
- {'node': task.node.uuid})
- inspected_properties['local_gb'] = '0'
-
- if system.boot.mode:
- if not drivers_utils.get_node_capability(task.node, 'boot_mode'):
- capabilities = utils.get_updated_capabilities(
- inspected_properties.get('capabilities', ''),
- {'boot_mode': BOOT_MODE_MAP[system.boot.mode]})
-
- inspected_properties['capabilities'] = capabilities
-
- valid_keys = self.ESSENTIAL_PROPERTIES
- missing_keys = valid_keys - set(inspected_properties)
- if missing_keys:
- error = (_('Failed to discover the following properties: '
- '%(missing_keys)s on node %(node)s'),
- {'missing_keys': ', '.join(missing_keys),
- 'node': task.node.uuid})
- raise exception.HardwareInspectionFailure(error=error)
-
- task.node.properties = inspected_properties
- task.node.save()
-
- LOG.debug("Node properties for %(node)s are updated as "
- "%(properties)s", {'properties': inspected_properties,
- 'node': task.node.uuid})
-
- 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})
- else:
- LOG.warning("No NIC information discovered "
- "for node %(node)s", {'node': task.node.uuid})
-
- return states.MANAGEABLE
+ return max(0, int(local_gb / units.Gi - 1))