summaryrefslogtreecommitdiff
path: root/ironic/drivers
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
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')
-rw-r--r--ironic/drivers/modules/agent.py8
-rw-r--r--ironic/drivers/modules/agent_base.py10
-rw-r--r--ironic/drivers/modules/drac/raid.py5
-rw-r--r--ironic/drivers/modules/ilo/management.py4
-rw-r--r--ironic/drivers/modules/ilo/power.py4
-rw-r--r--ironic/drivers/modules/ipmitool.py8
-rw-r--r--ironic/drivers/modules/network/flat.py4
-rw-r--r--ironic/drivers/modules/redfish/boot.py4
-rw-r--r--ironic/drivers/modules/redfish/inspect.py123
-rw-r--r--ironic/drivers/modules/redfish/management.py15
-rw-r--r--ironic/drivers/modules/redfish/utils.py6
-rw-r--r--ironic/drivers/modules/snmp.py16
-rw-r--r--ironic/drivers/modules/storage/external.py12
13 files changed, 114 insertions, 105 deletions
diff --git a/ironic/drivers/modules/agent.py b/ironic/drivers/modules/agent.py
index 44d4abab1..787ea21fe 100644
--- a/ironic/drivers/modules/agent.py
+++ b/ironic/drivers/modules/agent.py
@@ -152,8 +152,8 @@ def validate_http_provisioning_configuration(node):
:raises: MissingParameterValue if required option(s) is not set.
"""
image_source = node.instance_info.get('image_source')
- if (not service_utils.is_glance_image(image_source) or
- CONF.agent.image_download_source != 'http'):
+ if (not service_utils.is_glance_image(image_source)
+ or CONF.agent.image_download_source != 'http'):
return
params = {
@@ -221,8 +221,8 @@ class AgentDeployMixin(agent_base.AgentDeployMixin):
if node.instance_info.get('image_checksum'):
image_info['checksum'] = node.instance_info['image_checksum']
- if (node.instance_info.get('image_os_hash_algo') and
- node.instance_info.get('image_os_hash_value')):
+ if (node.instance_info.get('image_os_hash_algo')
+ and node.instance_info.get('image_os_hash_value')):
image_info['os_hash_algo'] = node.instance_info[
'image_os_hash_algo']
image_info['os_hash_value'] = node.instance_info[
diff --git a/ironic/drivers/modules/agent_base.py b/ironic/drivers/modules/agent_base.py
index e8426dc51..70ea04411 100644
--- a/ironic/drivers/modules/agent_base.py
+++ b/ironic/drivers/modules/agent_base.py
@@ -268,8 +268,8 @@ def log_and_raise_deployment_error(task, msg, collect_logs=True, exc=None):
CONF.agent.deploy_logs_collect config option.
:param exc: Exception that caused the failure.
"""
- log_traceback = (exc is not None and
- not isinstance(exc, exception.IronicException))
+ log_traceback = (exc is not None
+ and not isinstance(exc, exception.IronicException))
LOG.error(msg, exc_info=log_traceback)
deploy_utils.set_failed_state(task, msg, collect_logs=collect_logs)
raise exception.InstanceDeployFailure(msg)
@@ -1057,9 +1057,9 @@ class AgentDeployMixin(HeartbeatMixin):
# For whole disk images it is not necessary that the root_uuid
# be provided since the bootloaders on the disk will be used
whole_disk_image = internal_info.get('is_whole_disk_image')
- if (software_raid or (root_uuid and not whole_disk_image) or
- (whole_disk_image and
- boot_mode_utils.get_boot_mode(node) == 'uefi')):
+ if (software_raid or (root_uuid and not whole_disk_image)
+ or (whole_disk_image
+ and boot_mode_utils.get_boot_mode(node) == 'uefi')):
LOG.debug('Installing the bootloader for node %(node)s on '
'partition %(part)s, EFI system partition %(efi)s',
{'node': node.uuid, 'part': root_uuid,
diff --git a/ironic/drivers/modules/drac/raid.py b/ironic/drivers/modules/drac/raid.py
index 2a8b87349..08d1fbd31 100644
--- a/ironic/drivers/modules/drac/raid.py
+++ b/ironic/drivers/modules/drac/raid.py
@@ -769,8 +769,9 @@ def _assign_disks_to_volume(logical_disks, physical_disks_by_type,
for disks_count in range(min_disks, candidate_max_disks + 1):
if ('number_of_physical_disks' in logical_disk
- and logical_disk['number_of_physical_disks'] != disks_count):
- continue
+ and (logical_disk['number_of_physical_disks']
+ != disks_count)):
+ continue
# skip invalid disks_count
if disks_count != _usable_disks_count(logical_disk['raid_level'],
diff --git a/ironic/drivers/modules/ilo/management.py b/ironic/drivers/modules/ilo/management.py
index e92fbcd2b..07cbe7b41 100644
--- a/ironic/drivers/modules/ilo/management.py
+++ b/ironic/drivers/modules/ilo/management.py
@@ -735,10 +735,10 @@ class Ilo5Management(IloManagement):
for device_type, pattern in erase_pattern.items():
if device_type == 'hdd' and pattern in (
'overwrite', 'crypto', 'zero'):
- continue
+ continue
elif device_type == 'ssd' and pattern in (
'block', 'crypto', 'zero'):
- continue
+ continue
else:
invalid = True
break
diff --git a/ironic/drivers/modules/ilo/power.py b/ironic/drivers/modules/ilo/power.py
index 35439ff25..8461341af 100644
--- a/ironic/drivers/modules/ilo/power.py
+++ b/ironic/drivers/modules/ilo/power.py
@@ -127,8 +127,8 @@ def _wait_for_state_change(node, target_state, requested_state,
use_post_state = False
if _can_get_server_post_state(node):
use_post_state = True
- if (target_state in [states.POWER_OFF, states.SOFT_POWER_OFF] or
- target_state == states.SOFT_REBOOT and not is_final_state):
+ if (target_state in [states.POWER_OFF, states.SOFT_POWER_OFF]
+ or target_state == states.SOFT_REBOOT and not is_final_state):
state_to_check = ilo_common.POST_POWEROFF_STATE
else:
# It may not be able to finish POST if no bootable device is
diff --git a/ironic/drivers/modules/ipmitool.py b/ironic/drivers/modules/ipmitool.py
index d3682bfd3..da3db756e 100644
--- a/ironic/drivers/modules/ipmitool.py
+++ b/ironic/drivers/modules/ipmitool.py
@@ -287,8 +287,8 @@ def _parse_driver_info(node):
password = str(info.get('ipmi_password', ''))
hex_kg_key = info.get('ipmi_hex_kg_key')
dest_port = info.get('ipmi_port')
- port = (info.get('ipmi_terminal_port') or
- internal_info.get('allocated_ipmi_terminal_port'))
+ port = (info.get('ipmi_terminal_port')
+ or internal_info.get('allocated_ipmi_terminal_port'))
priv_level = info.get('ipmi_priv_level', 'ADMINISTRATOR')
bridging_type = info.get('ipmi_bridging', 'no')
local_address = info.get('ipmi_local_address')
@@ -527,8 +527,8 @@ def _exec_ipmitool(driver_info, command, check_exit_code=None,
with excutils.save_and_reraise_exception() as ctxt:
err_list = [
x for x in (
- IPMITOOL_RETRYABLE_FAILURES +
- CONF.ipmi.additional_retryable_ipmi_errors)
+ IPMITOOL_RETRYABLE_FAILURES
+ + CONF.ipmi.additional_retryable_ipmi_errors)
if x in str(e)]
if ((time.time() > end_time)
or (num_tries == 0)
diff --git a/ironic/drivers/modules/network/flat.py b/ironic/drivers/modules/network/flat.py
index da5c646f8..06f7ff8cf 100644
--- a/ironic/drivers/modules/network/flat.py
+++ b/ironic/drivers/modules/network/flat.py
@@ -87,8 +87,8 @@ class FlatNetwork(common.NeutronVIFPortIDMixin,
portgroups = task.portgroups
for port_like_obj in ports + portgroups:
vif_port_id = (
- port_like_obj.internal_info.get(common.TENANT_VIF_KEY) or
- port_like_obj.extra.get('vif_port_id'))
+ port_like_obj.internal_info.get(common.TENANT_VIF_KEY)
+ or port_like_obj.extra.get('vif_port_id'))
if not vif_port_id:
continue
neutron.unbind_neutron_port(vif_port_id, context=task.context)
diff --git a/ironic/drivers/modules/redfish/boot.py b/ironic/drivers/modules/redfish/boot.py
index 005f77d37..107dd42be 100644
--- a/ironic/drivers/modules/redfish/boot.py
+++ b/ironic/drivers/modules/redfish/boot.py
@@ -758,8 +758,8 @@ class RedfishVirtualMediaBoot(base.BootInterface):
self._eject_vmedia(task, sushy.VIRTUAL_MEDIA_CD)
self._cleanup_iso_image(task)
- if (config_via_floppy and
- self._has_vmedia_device(task, sushy.VIRTUAL_MEDIA_FLOPPY)):
+ if (config_via_floppy
+ and self._has_vmedia_device(task, sushy.VIRTUAL_MEDIA_FLOPPY)):
self._eject_vmedia(task, sushy.VIRTUAL_MEDIA_FLOPPY)
self._cleanup_floppy_image(task)
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))
diff --git a/ironic/drivers/modules/redfish/management.py b/ironic/drivers/modules/redfish/management.py
index 591f46ae0..69d5f82f0 100644
--- a/ironic/drivers/modules/redfish/management.py
+++ b/ironic/drivers/modules/redfish/management.py
@@ -485,8 +485,9 @@ class RedfishManagement(base.ManagementInterface):
'%(error)s', {'node': task.node.uuid, 'error': e})
try:
- if (component in (None, components.DISK) and
- system.simple_storage and system.simple_storage.drives):
+ if (component in (None, components.DISK)
+ and system.simple_storage
+ and system.simple_storage.drives):
indicators[components.DISK] = {
drive.uuid: properties
for drive in system.simple_storage.drives
@@ -530,8 +531,9 @@ class RedfishManagement(base.ManagementInterface):
INDICATOR_MAP_REV[state])
return
- elif (component == components.DISK and
- system.simple_storage and system.simple_storage.drives):
+ elif (component == components.DISK
+ and system.simple_storage
+ and system.simple_storage.drives):
for drive in system.simple_storage.drives:
if drive.uuid == indicator:
drive.set_indicator_led(
@@ -581,8 +583,9 @@ class RedfishManagement(base.ManagementInterface):
if chassis.uuid == indicator:
return INDICATOR_MAP[chassis.indicator_led]
- if (component == components.DISK and
- system.simple_storage and system.simple_storage.drives):
+ if (component == components.DISK
+ and system.simple_storage
+ and system.simple_storage.drives):
for drive in system.simple_storage.drives:
if drive.uuid == indicator:
return INDICATOR_MAP[drive.indicator_led]
diff --git a/ironic/drivers/modules/redfish/utils.py b/ironic/drivers/modules/redfish/utils.py
index 9decac47c..5c20667d0 100644
--- a/ironic/drivers/modules/redfish/utils.py
+++ b/ironic/drivers/modules/redfish/utils.py
@@ -173,7 +173,7 @@ def parse_driver_info(node):
'auth_type': auth_type,
'node_uuid': node.uuid}
if root_prefix:
- sushy_params['root_prefix'] = root_prefix
+ sushy_params['root_prefix'] = root_prefix
return sushy_params
@@ -223,8 +223,8 @@ class SessionCache(object):
if CONF.redfish.connection_cache_size:
self.__class__._sessions[self._session_key] = conn
- if (len(self.__class__._sessions) >
- CONF.redfish.connection_cache_size):
+ if (len(self.__class__._sessions)
+ > CONF.redfish.connection_cache_size):
self._expire_oldest_session()
return conn
diff --git a/ironic/drivers/modules/snmp.py b/ironic/drivers/modules/snmp.py
index 462053bf1..008886b90 100644
--- a/ironic/drivers/modules/snmp.py
+++ b/ironic/drivers/modules/snmp.py
@@ -808,8 +808,8 @@ class SNMPDriverAuto(SNMPDriverBase):
system_id = self.oid_enterprise + getattr(obj, 'system_id')
- if (system_id in drivers_map and
- drivers_map[system_id] is not obj):
+ if (system_id in drivers_map
+ and drivers_map[system_id] is not obj):
raise exception.InvalidParameterValue(_(
"SNMPDriverAuto: duplicate driver system ID prefix "
"%(system_id)s") % {'system_id': system_id})
@@ -954,23 +954,23 @@ def _parse_driver_info_snmpv3_crypto(node, info):
if 'priv_protocol' not in snmp_info:
snmp_info['priv_protocol'] = snmp_priv_protocols['des']
- if ('priv_protocol' in snmp_info and
- 'auth_protocol' not in snmp_info):
+ if ('priv_protocol' in snmp_info
+ and 'auth_protocol' not in snmp_info):
raise exception.MissingParameterValue(_(
"SNMPPowerDriver: SNMPv3 privacy requires authentication. "
"Please add `driver_info/auth_protocol` property to node "
"%(node)s configuration.") % {'node': node.uuid})
- if ('auth_protocol' in snmp_info and
- 'auth_key' not in snmp_info):
+ if ('auth_protocol' in snmp_info
+ and 'auth_key' not in snmp_info):
raise exception.MissingParameterValue(_(
"SNMPPowerDriver: missing SNMPv3 authentication key while "
"`driver_info/snmp_auth_protocol` is present. Please "
"add `driver_info/snmp_auth_key` to node %(node)s "
"configuration.") % {'node': node.uuid})
- if ('priv_protocol' in snmp_info and
- 'priv_key' not in snmp_info):
+ if ('priv_protocol' in snmp_info
+ and 'priv_key' not in snmp_info):
raise exception.MissingParameterValue(_(
"SNMPPowerDriver: missing SNMPv3 privacy key while "
"`driver_info/snmp_priv_protocol` is present. Please "
diff --git a/ironic/drivers/modules/storage/external.py b/ironic/drivers/modules/storage/external.py
index 94e1699a4..28456e69c 100644
--- a/ironic/drivers/modules/storage/external.py
+++ b/ironic/drivers/modules/storage/external.py
@@ -36,12 +36,12 @@ class ExternalStorage(base.StorageInterface):
raise exception(msg)
if (not self.should_write_image(task)
- and not common_pxe_utils.is_ipxe_enabled(task)):
- msg = _("The [pxe]/ipxe_enabled option must "
- "be set to True to support network "
- "booting to an iSCSI volume or the boot "
- "interface must be set to ``ipxe``.")
- _fail_validation(task, msg)
+ and not common_pxe_utils.is_ipxe_enabled(task)):
+ msg = _("The [pxe]/ipxe_enabled option must "
+ "be set to True to support network "
+ "booting to an iSCSI volume or the boot "
+ "interface must be set to ``ipxe``.")
+ _fail_validation(task, msg)
def get_properties(self):
return {}