Skip to content

Commit f591bc0

Browse files
committed
fix soem issue and change all error to customerror
1 parent 2febfca commit f591bc0

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

providers/base/bin/check_secure_boot_state.py

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ class SecureBootNotSupportedError(SecureBootError):
148148
pass
149149

150150

151+
class SecureBootConfigurationError(SecureBootError):
152+
"""Exception raised when there's a configuration error."""
153+
154+
pass
155+
156+
151157
class UbuntuVariant(Enum):
152158
"""Enumeration of Ubuntu variants."""
153159

@@ -810,8 +816,10 @@ def create_checker(method: CheckerType) -> Tuple[SecureBootChecker, str]:
810816
Tuple of (checker_instance, checker_name)
811817
812818
Raises:
813-
ValueError: If method is not one of the valid options
814-
RuntimeError: If no supported secure boot method is found
819+
SecureBootConfigurationError: If method is not one of the valid
820+
options
821+
SecureBootNotSupportedError: If no supported secure boot method is
822+
found
815823
"""
816824
# Define available checkers with their support checks and names
817825
checkers = [
@@ -827,7 +835,7 @@ def create_checker(method: CheckerType) -> Tuple[SecureBootChecker, str]:
827835
return checker, checker_name
828836

829837
# No supported method found
830-
raise RuntimeError(
838+
raise SecureBootNotSupportedError(
831839
"No supported secure boot method found. "
832840
"Neither UEFI (mokutil) nor FIT (dumpimage) are available."
833841
)
@@ -846,16 +854,18 @@ def create_checker(method: CheckerType) -> Tuple[SecureBootChecker, str]:
846854
"system (dumpimage command not found)"
847855
),
848856
}
849-
raise RuntimeError(error_messages[method])
857+
raise SecureBootNotSupportedError(error_messages[method])
850858
checker = checker_class()
851859
return checker, checker_name
852860

853861
# This should never happen due to argument validation
854-
raise ValueError("Unknown method: {}".format(method.value))
862+
raise SecureBootConfigurationError(
863+
"Unknown method: {}".format(method.value)
864+
)
855865

856866

857-
def main() -> None:
858-
"""Main entry point for the secure boot state checker."""
867+
def create_parser() -> argparse.ArgumentParser:
868+
"""Create and configure the argument parser."""
859869
parser = argparse.ArgumentParser(
860870
description="Check and validate secure boot state",
861871
formatter_class=argparse.RawDescriptionHelpFormatter,
@@ -891,6 +901,12 @@ def main() -> None:
891901
),
892902
)
893903

904+
return parser
905+
906+
907+
def main() -> None:
908+
"""Main entry point for the secure boot state checker."""
909+
parser = create_parser()
894910
args = parser.parse_args()
895911

896912
# Setup logging
@@ -918,11 +934,11 @@ def main() -> None:
918934
exit_code = check_secure_boot_result(state, error_msg, check_mode)
919935
sys.exit(exit_code)
920936

921-
except ValueError as e:
937+
except SecureBootConfigurationError as e:
922938
logger.error("Configuration error: {}".format(str(e)))
923939
sys.exit(1)
924-
except RuntimeError as e:
925-
logger.error("Runtime error: {}".format(str(e)))
940+
except SecureBootNotSupportedError as e:
941+
logger.error("Not supported error: {}".format(str(e)))
926942
sys.exit(1)
927943
except KeyboardInterrupt:
928944
logger.info("Operation cancelled by user")

0 commit comments

Comments
 (0)