Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: lint error from ruff #151

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
with:
python-version: '3.x'
- run: pip install ruff
# - run: ruff check .
- run: ruff check .

docker-lint:
runs-on: ubuntu-latest
Expand Down
94 changes: 93 additions & 1 deletion redfish_utilities/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,98 @@
from .update import get_simple_update_info
from .update import simple_update
from .update import multipart_push_update
from .misc import *
from .misc import logout, print_password_change_required_and_logout

from . import config

__all__ = [
"get_users",
"print_users",
"add_user",
"delete_user",
"modify_user",
"get_assembly",
"print_assembly",
"download_assembly",
"upload_assembly",
"get_all_certificates",
"print_certificates",
"get_generate_csr_info",
"generate_csr",
"install_certificate",
"delete_certificate",
"get_event_service",
"print_event_service",
"get_event_subscriptions",
"print_event_subscriptions",
"create_event_subscription",
"delete_event_subscription",
"get_system_inventory",
"print_system_inventory",
"write_system_inventory",
"get_licenses",
"print_licenses",
"install_license",
"delete_license",
"log_container",
"diagnostic_data_types",
"get_log_entries",
"print_log_entries",
"clear_log_entries",
"collect_diagnostic_data",
"download_diagnostic_data",
"get_manager_ids",
"get_manager",
"set_manager",
"print_manager",
"get_manager_reset_info",
"manager_reset",
"get_manager_reset_to_defaults_info",
"manager_reset_to_defaults",
"get_manager_network_protocol",
"set_manager_network_protocol",
"print_manager_network_protocol",
"get_manager_ethernet_interface_ids",
"get_manager_ethernet_interface",
"set_manager_ethernet_interface",
"print_manager_ethernet_interface",
"print_error_payload",
"verify_response",
"power_equipment_types",
"power_equipment_electrical_types",
"get_power_equipment_ids",
"get_power_equipment",
"print_power_equipment",
"get_power_equipment_summary",
"print_power_equipment_summary",
"get_power_equipment_electrical",
"print_power_equipment_electrical",
"print_power_equipment_electrical_summary",
"reset_types",
"reset_to_defaults_types",
"get_sensors",
"print_sensors",
"get_system_ids",
"get_system",
"get_system_boot",
"set_system_boot",
"print_system_boot",
"get_system_reset_info",
"system_reset",
"get_virtual_media",
"print_virtual_media",
"insert_virtual_media",
"eject_virtual_media",
"get_system_bios",
"set_system_bios",
"print_system_bios",
"poll_task_monitor",
"operation_apply_times",
"get_update_service",
"get_simple_update_info",
"simple_update",
"multipart_push_update",
"logout",
"print_password_change_required_and_logout",
"config",
]
2 changes: 1 addition & 1 deletion redfish_utilities/accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def get_users( context ):
}

# Some implementations always expose "slots" for users; ignore empty slots
if account_info["UserName"] == "" and account_info["Enabled"] == False:
if account_info["UserName"] == "" and account_info["Enabled"] is False:
continue

user_list.append( account_info )
Expand Down
1 change: 0 additions & 1 deletion redfish_utilities/certificates.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
certificates on a Redfish service
"""

import os
from .messages import verify_response

class RedfishCertificateServiceNotFoundError( Exception ):
Expand Down
12 changes: 6 additions & 6 deletions redfish_utilities/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def get_system_inventory( context ):
# Get the set of chassis instances to initialize the structure
try:
chassis_ids = get_chassis_ids( context )
except:
except Exception:
# No chassis instances
return inventory_list

Expand All @@ -68,7 +68,7 @@ def get_system_inventory( context ):
chassis = context.get( chassis_uri )
try:
verify_response( chassis )
except:
except Exception:
if config.__workarounds__:
warnings.warn( "Could not access '{}'. Contact your vendor. Skipping...".format( chassis_uri ) )
continue
Expand All @@ -95,7 +95,7 @@ def catalog_array( context, resource, name, inventory, chassis_id ):
member_res = context.get( member["@odata.id"] )
try:
verify_response( member_res )
except:
except Exception:
if config.__workarounds__:
warnings.warn( "Could not access '{}'. Contact your vendor. Skipping...".format( member["@odata.id"] ) )
continue
Expand All @@ -119,7 +119,7 @@ def catalog_collection( context, resource, name, inventory, chassis_id ):
collection = context.get( resource[name]["@odata.id"] )
try:
verify_response( collection )
except:
except Exception:
if config.__workarounds__:
warnings.warn( "Could not access '{}'. Contact your vendor. Skipping...".format( resource[name]["@odata.id"] ) )
return
Expand Down Expand Up @@ -213,11 +213,11 @@ def catalog_resource( context, resource, inventory, chassis_id ):
# For nested properties, need to protect against malformed payloads to avoid exceptions
try:
catalog["Label"] = resource.get( location_prop, {} ).get( "PartLocation", {} ).get( "ServiceLabel", None )
except:
except Exception:
pass
try:
catalog["State"] = resource.get( "Status", {} ).get( "State", None )
except:
except Exception:
pass
# Ensure all fields are strings
for item in catalog:
Expand Down
6 changes: 3 additions & 3 deletions redfish_utilities/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
with Messages for a given Redfish service
"""

from redfish.messages import *
from redfish.messages import get_messages_detail, get_error_messages, search_message, RedfishPasswordChangeRequiredError, RedfishOperationFailedError

def verify_response( response ):
"""
Expand All @@ -26,7 +26,7 @@ def verify_response( response ):
messages_detail = get_messages_detail( response )
exception_string = get_error_messages( messages_detail )
message_item = search_message( messages_detail, "Base", "PasswordChangeRequired" )
if not message_item is None:
if message_item is not None:
raise RedfishPasswordChangeRequiredError( "Operation failed: HTTP {}\n{}".format( response.status, exception_string ), message_item["MessageArgs"][0] )
else:
raise RedfishOperationFailedError( "Operation failed: HTTP {}\n{}".format( response.status, exception_string ) )
Expand All @@ -43,7 +43,7 @@ def print_error_payload( response ):

try:
print( get_error_messages( response ) )
except:
except Exception:
# No response body
if response.status >= 400:
print( "Failed" )
Expand Down
3 changes: 1 addition & 2 deletions redfish_utilities/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
Brief : Miscellaneous functions with common script logic
"""

import sys

def logout( context, ignore_error = False ):
"""
Expand All @@ -25,7 +24,7 @@ def logout( context, ignore_error = False ):
if context is not None:
try:
context.logout()
except Exception as e:
except Exception:
if ignore_error:
pass
else:
Expand Down
8 changes: 4 additions & 4 deletions redfish_utilities/systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ def insert_virtual_media( context, image, system_id = None, media_id = None, med
try:
# Preference for using the InsertMedia action
response = context.post( media.dict["Actions"]["#VirtualMedia.InsertMedia"]["target"], body = payload )
except:
except Exception:
# Fallback to PATCH method
if "Inserted" not in payload:
payload["Inserted"] = True
Expand Down Expand Up @@ -514,7 +514,7 @@ def eject_virtual_media( context, media_id, system_id = None ):
try:
# Preference for using the EjectMedia action
response = context.post( media.dict["Actions"]["#VirtualMedia.EjectMedia"]["target"], body = {} )
except:
except Exception:
# Fallback to PATCH method
payload = {
"Image": None,
Expand Down Expand Up @@ -593,7 +593,7 @@ def get_system_bios( context, system_id = None ):
try:
bios_settings = get_system_bios_settings( context, bios, system.dict["Id"] )
future_settings = bios_settings.dict["Attributes"]
except:
except Exception:
if config.__workarounds__:
warnings.warn( "System '{}' BIOS resource contains the settings term, but no 'SettingsObject'. Contact your vendor. Workarounds exhausted for reading the settings data and falling back on using the active attributes.".format( system_id ) )
else:
Expand Down Expand Up @@ -662,7 +662,7 @@ def get_system_bios_settings( context, bios, system_id ):
break
try:
verify_response( bios_settings )
except:
except Exception:
raise RedfishSystemBiosInvalidSettingsError( "System '{}' BIOS resource contains the settings term, but no 'SettingsObject'. Workarounds exhausted. Contact your vendor.".format( system_id ) ) from None
else:
raise RedfishSystemBiosInvalidSettingsError( "System '{}' BIOS resource contains the settings term, but no 'SettingsObject'. Contact your vendor, or retry with the '__workarounds__' flag.".format( system_id ) )
Expand Down
2 changes: 1 addition & 1 deletion redfish_utilities/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def poll_task_monitor( context, response ):
try:
task_state = task_monitor.dict.get( "TaskState", None )
task_percent = task_monitor.dict.get( "PercentComplete", None )
except:
except Exception:
# 202 responses are allowed to not have a response body
pass
if task_state is None:
Expand Down
1 change: 0 additions & 1 deletion redfish_utilities/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import json
import os
import errno
import math
from .messages import verify_response
from enum import Enum

Expand Down
2 changes: 1 addition & 1 deletion scripts/rf_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
else:
redfish_utilities.print_password_change_required_and_logout( redfish_obj, args )
sys.exit( 1 )
except Exception as e:
except Exception:
raise

exit_code = 0
Expand Down
4 changes: 2 additions & 2 deletions scripts/rf_assembly.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@
try:
redfish_obj = redfish.redfish_client( base_url = args.rhost, username = args.user, password = args.password, timeout = 15, max_retry = 3 )
redfish_obj.login( auth = "session" )
except RedfishPasswordChangeRequiredError as e:
except RedfishPasswordChangeRequiredError:
redfish_utilities.print_password_change_required_and_logout( redfish_obj, args )
sys.exit( 1 )
except Exception as e:
except Exception:
raise

exit_code = 0
Expand Down
6 changes: 3 additions & 3 deletions scripts/rf_bios_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@
try:
redfish_obj = redfish.redfish_client( base_url = args.rhost, username = args.user, password = args.password, timeout = 15, max_retry = 3 )
redfish_obj.login( auth = "session" )
except RedfishPasswordChangeRequiredError as e:
except RedfishPasswordChangeRequiredError:
redfish_utilities.print_password_change_required_and_logout( redfish_obj, args )
sys.exit( 1 )
except Exception as e:
except Exception:
raise

exit_code = 0
Expand All @@ -72,7 +72,7 @@
# Integer or float; go by the user input to determine how to convert since the current value may be truncated
try:
new_value = int( new_value )
except:
except Exception:
new_value = float( new_value )

# Set the specified attribute to the new value
Expand Down
4 changes: 2 additions & 2 deletions scripts/rf_boot_override.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@
try:
redfish_obj = redfish.redfish_client( base_url = args.rhost, username = args.user, password = args.password, timeout = 15, max_retry = 3 )
redfish_obj.login( auth = "session" )
except RedfishPasswordChangeRequiredError as e:
except RedfishPasswordChangeRequiredError:
redfish_utilities.print_password_change_required_and_logout( redfish_obj, args )
sys.exit( 1 )
except Exception as e:
except Exception:
raise

exit_code = 0
Expand Down
4 changes: 2 additions & 2 deletions scripts/rf_certificates.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@
try:
redfish_obj = redfish.redfish_client( base_url = args.rhost, username = args.user, password = args.password, timeout = 15, max_retry = 3 )
redfish_obj.login( auth = "session" )
except RedfishPasswordChangeRequiredError as e:
except RedfishPasswordChangeRequiredError:
redfish_utilities.print_password_change_required_and_logout( redfish_obj, args )
sys.exit( 1 )
except Exception as e:
except Exception:
raise

exit_code = 0
Expand Down
10 changes: 5 additions & 5 deletions scripts/rf_diagnostic_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@
# Effectively if the user gives multiple targets, some will be ignored
container_type = redfish_utilities.log_container.MANAGER
container_id = None
if args.manager != False:
if args.manager is not False:
container_type = redfish_utilities.log_container.MANAGER
container_id = args.manager
elif args.system != False:
elif args.system is not False:
container_type = redfish_utilities.log_container.SYSTEM
container_id = args.system
elif args.chassis != False:
elif args.chassis is not False:
container_type = redfish_utilities.log_container.CHASSIS
container_id = args.chassis

Expand All @@ -61,10 +61,10 @@
try:
redfish_obj = redfish.redfish_client( base_url = args.rhost, username = args.user, password = args.password, timeout = 15, max_retry = 3 )
redfish_obj.login( auth = "session" )
except RedfishPasswordChangeRequiredError as e:
except RedfishPasswordChangeRequiredError:
redfish_utilities.print_password_change_required_and_logout( redfish_obj, args )
sys.exit( 1 )
except Exception as e:
except Exception:
raise

exit_code = 0
Expand Down
2 changes: 1 addition & 1 deletion scripts/rf_discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
url = groups.group( 1 )
redfish_obj = redfish.redfish_client( base_url = url, timeout = 15, max_retry = 3 )
print( "{}: {} ({})".format( service, services[service], redfish_obj.root["Product"] ) )
except:
except Exception:
print( "{}: {}".format( service, services[service] ) )

sys.exit( 0 )
4 changes: 2 additions & 2 deletions scripts/rf_event_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@
try:
redfish_obj = redfish.redfish_client( base_url = args.rhost, username = args.user, password = args.password, timeout = 15, max_retry = 3 )
redfish_obj.login( auth = "session" )
except RedfishPasswordChangeRequiredError as e:
except RedfishPasswordChangeRequiredError:
redfish_utilities.print_password_change_required_and_logout( redfish_obj, args )
sys.exit( 1 )
except Exception as e:
except Exception:
raise

exit_code = 0
Expand Down
Loading