From af2453a6ee32f90db5d1a64c10a7db0c0da4efeb Mon Sep 17 00:00:00 2001 From: Boris Glimcher Date: Wed, 1 May 2024 03:53:51 +0300 Subject: [PATCH] fix: lint error from ruff Fixes #149 Signed-off-by: Boris Glimcher --- .github/workflows/linters.yml | 2 +- redfish_utilities/__init__.py | 94 ++++++++++++++++++++++++++++++- redfish_utilities/accounts.py | 2 +- redfish_utilities/certificates.py | 1 - redfish_utilities/inventory.py | 12 ++-- redfish_utilities/messages.py | 6 +- redfish_utilities/misc.py | 3 +- redfish_utilities/systems.py | 8 +-- redfish_utilities/tasks.py | 2 +- redfish_utilities/update.py | 1 - scripts/rf_accounts.py | 2 +- scripts/rf_assembly.py | 4 +- scripts/rf_bios_settings.py | 6 +- scripts/rf_boot_override.py | 4 +- scripts/rf_certificates.py | 4 +- scripts/rf_diagnostic_data.py | 10 ++-- scripts/rf_discover.py | 2 +- scripts/rf_event_service.py | 4 +- scripts/rf_licenses.py | 4 +- scripts/rf_logs.py | 10 ++-- scripts/rf_manager_config.py | 4 +- scripts/rf_power_equipment.py | 4 +- scripts/rf_power_reset.py | 4 +- scripts/rf_raw_request.py | 9 ++- scripts/rf_sensor_list.py | 4 +- scripts/rf_sys_inventory.py | 4 +- scripts/rf_update.py | 10 ++-- scripts/rf_virtual_media.py | 4 +- setup.py | 1 - 29 files changed, 156 insertions(+), 69 deletions(-) diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index fdf8daf..475d9b5 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -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 diff --git a/redfish_utilities/__init__.py b/redfish_utilities/__init__.py index 22c9526..62475f5 100644 --- a/redfish_utilities/__init__.py +++ b/redfish_utilities/__init__.py @@ -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", +] diff --git a/redfish_utilities/accounts.py b/redfish_utilities/accounts.py index 4bf6566..f697ec9 100644 --- a/redfish_utilities/accounts.py +++ b/redfish_utilities/accounts.py @@ -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 ) diff --git a/redfish_utilities/certificates.py b/redfish_utilities/certificates.py index d53eaff..b5affcb 100644 --- a/redfish_utilities/certificates.py +++ b/redfish_utilities/certificates.py @@ -12,7 +12,6 @@ certificates on a Redfish service """ -import os from .messages import verify_response class RedfishCertificateServiceNotFoundError( Exception ): diff --git a/redfish_utilities/inventory.py b/redfish_utilities/inventory.py index c012d86..2736888 100644 --- a/redfish_utilities/inventory.py +++ b/redfish_utilities/inventory.py @@ -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 @@ -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 @@ -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 @@ -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 @@ -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: diff --git a/redfish_utilities/messages.py b/redfish_utilities/messages.py index cfa5b94..cc2e9fb 100644 --- a/redfish_utilities/messages.py +++ b/redfish_utilities/messages.py @@ -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 ): """ @@ -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 ) ) @@ -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" ) diff --git a/redfish_utilities/misc.py b/redfish_utilities/misc.py index 424d8c8..c02271f 100644 --- a/redfish_utilities/misc.py +++ b/redfish_utilities/misc.py @@ -11,7 +11,6 @@ Brief : Miscellaneous functions with common script logic """ -import sys def logout( context, ignore_error = False ): """ @@ -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: diff --git a/redfish_utilities/systems.py b/redfish_utilities/systems.py index b171466..8ce110c 100644 --- a/redfish_utilities/systems.py +++ b/redfish_utilities/systems.py @@ -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 @@ -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, @@ -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: @@ -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 ) ) diff --git a/redfish_utilities/tasks.py b/redfish_utilities/tasks.py index 205e13f..078a15f 100644 --- a/redfish_utilities/tasks.py +++ b/redfish_utilities/tasks.py @@ -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: diff --git a/redfish_utilities/update.py b/redfish_utilities/update.py index 7c56a15..86b8117 100644 --- a/redfish_utilities/update.py +++ b/redfish_utilities/update.py @@ -15,7 +15,6 @@ import json import os import errno -import math from .messages import verify_response from enum import Enum diff --git a/scripts/rf_accounts.py b/scripts/rf_accounts.py index 872b9bb..f1c6466 100644 --- a/scripts/rf_accounts.py +++ b/scripts/rf_accounts.py @@ -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 diff --git a/scripts/rf_assembly.py b/scripts/rf_assembly.py index edca4b5..25591ef 100644 --- a/scripts/rf_assembly.py +++ b/scripts/rf_assembly.py @@ -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 diff --git a/scripts/rf_bios_settings.py b/scripts/rf_bios_settings.py index cda5172..13ea9c1 100644 --- a/scripts/rf_bios_settings.py +++ b/scripts/rf_bios_settings.py @@ -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 @@ -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 diff --git a/scripts/rf_boot_override.py b/scripts/rf_boot_override.py index 1a04f24..6c40f93 100644 --- a/scripts/rf_boot_override.py +++ b/scripts/rf_boot_override.py @@ -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 diff --git a/scripts/rf_certificates.py b/scripts/rf_certificates.py index c0132b9..c6c062f 100644 --- a/scripts/rf_certificates.py +++ b/scripts/rf_certificates.py @@ -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 diff --git a/scripts/rf_diagnostic_data.py b/scripts/rf_diagnostic_data.py index a30ae11..79ac103 100644 --- a/scripts/rf_diagnostic_data.py +++ b/scripts/rf_diagnostic_data.py @@ -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 @@ -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 diff --git a/scripts/rf_discover.py b/scripts/rf_discover.py index 99fb595..89833d3 100644 --- a/scripts/rf_discover.py +++ b/scripts/rf_discover.py @@ -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 ) diff --git a/scripts/rf_event_service.py b/scripts/rf_event_service.py index 924b712..2b96198 100644 --- a/scripts/rf_event_service.py +++ b/scripts/rf_event_service.py @@ -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 diff --git a/scripts/rf_licenses.py b/scripts/rf_licenses.py index 9373e68..07f71da 100644 --- a/scripts/rf_licenses.py +++ b/scripts/rf_licenses.py @@ -46,10 +46,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 diff --git a/scripts/rf_logs.py b/scripts/rf_logs.py index e1eb4f4..8e1bb3d 100644 --- a/scripts/rf_logs.py +++ b/scripts/rf_logs.py @@ -38,13 +38,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 @@ -59,10 +59,10 @@ try: redfish_obj = redfish.redfish_client( base_url = args.rhost, username = args.user, password = args.password, timeout = 30, 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 diff --git a/scripts/rf_manager_config.py b/scripts/rf_manager_config.py index d86d2a1..9dedec4 100644 --- a/scripts/rf_manager_config.py +++ b/scripts/rf_manager_config.py @@ -71,10 +71,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 diff --git a/scripts/rf_power_equipment.py b/scripts/rf_power_equipment.py index 2bfa12c..4d8b332 100644 --- a/scripts/rf_power_equipment.py +++ b/scripts/rf_power_equipment.py @@ -59,10 +59,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 diff --git a/scripts/rf_power_reset.py b/scripts/rf_power_reset.py index 11a2e34..fb767c6 100644 --- a/scripts/rf_power_reset.py +++ b/scripts/rf_power_reset.py @@ -42,10 +42,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 diff --git a/scripts/rf_raw_request.py b/scripts/rf_raw_request.py index 698f8a8..c614025 100644 --- a/scripts/rf_raw_request.py +++ b/scripts/rf_raw_request.py @@ -17,7 +17,6 @@ import redfish import redfish_utilities import sys -import re from redfish.messages import RedfishPasswordChangeRequiredError def ifmatch_header( redfish_obj, path, headers = None ): @@ -60,10 +59,10 @@ def ifmatch_header( redfish_obj, path, headers = None ): 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 # Encode the body @@ -75,7 +74,7 @@ def ifmatch_header( redfish_obj, path, headers = None ): # Not a file; either JSON or a raw string try: body = json.loads( args.body ) - except: + except Exception: body = args.body if body is None: # Default case if nothing resolves (empty JSON object) @@ -109,7 +108,7 @@ def ifmatch_header( redfish_obj, path, headers = None ): if resp.status != 204: try: print( json.dumps( resp.dict, sort_keys = True, indent = 4, separators = ( ",", ": " ) ) ) - except: + except Exception: # The response is either malformed JSON or not JSON at all print( resp.text ) else: diff --git a/scripts/rf_sensor_list.py b/scripts/rf_sensor_list.py index edf01a4..7410e19 100644 --- a/scripts/rf_sensor_list.py +++ b/scripts/rf_sensor_list.py @@ -41,10 +41,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 diff --git a/scripts/rf_sys_inventory.py b/scripts/rf_sys_inventory.py index a0101bf..795239a 100644 --- a/scripts/rf_sys_inventory.py +++ b/scripts/rf_sys_inventory.py @@ -47,10 +47,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 diff --git a/scripts/rf_update.py b/scripts/rf_update.py index bcf857e..621bb57 100644 --- a/scripts/rf_update.py +++ b/scripts/rf_update.py @@ -46,7 +46,7 @@ def local_web_server( filepath ): # Create a temporary folder and move the file to the folder try: shutil.rmtree( WEB_SERVER_FOLDER ) - except: + except Exception: pass os.mkdir( WEB_SERVER_FOLDER ) shutil.copy( filepath, WEB_SERVER_FOLDER ) @@ -73,7 +73,7 @@ def print_error_payload( response ): try: print(redfish_utilities.get_error_messages( response ) ) - except: + except Exception: # No response body if response.status >= 400: print( "Failed" ) @@ -102,10 +102,10 @@ def print_error_payload( response ): 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 start_path = os.getcwd() @@ -166,7 +166,7 @@ def print_error_payload( response ): os.chdir( start_path ) try: shutil.rmtree( WEB_SERVER_FOLDER ) - except: + except Exception: pass # Log out redfish_utilities.logout( redfish_obj ) diff --git a/scripts/rf_virtual_media.py b/scripts/rf_virtual_media.py index 4e5a411..e2a268e 100644 --- a/scripts/rf_virtual_media.py +++ b/scripts/rf_virtual_media.py @@ -50,10 +50,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 diff --git a/setup.py b/setup.py index 8088ff2..dfbc9a9 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,6 @@ from setuptools import setup from setuptools import Command as _Command from codecs import open -import sys import os class Pyinstaller(_Command):