From 79cee4f6fbd3a691b50ab5daa756e25c7e4adb1b Mon Sep 17 00:00:00 2001 From: Lucas Alvares Gomes Date: Mon, 25 Jul 2016 16:34:53 +0100 Subject: [PATCH] Refactor common checks when instantiating the ipmitool classes The constructor for the ipmitool classes are the same but they are duplicated all over this patch is refactoring that code into a common function that can be called from the classes constructors. The VendorPassthru class wasn't checking for the 'timing' option support of the ipmitool command, it should, this patch is fixing that too. Change-Id: I456dbb9ef11230d722ff1b1fe5aa142237e0d187 --- ironic/drivers/modules/ipmitool.py | 48 ++++++++++-------------------- 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/ironic/drivers/modules/ipmitool.py b/ironic/drivers/modules/ipmitool.py index 5ab0d7cff6..9cf145e304 100644 --- a/ironic/drivers/modules/ipmitool.py +++ b/ironic/drivers/modules/ipmitool.py @@ -739,17 +739,22 @@ def _check_temp_dir(): TMP_DIR_CHECKED = True +def _constructor_checks(driver): + """Common checks to be performed when instantiating an ipmitool class.""" + try: + _check_option_support(['timing', 'single_bridge', 'dual_bridge']) + except OSError: + raise exception.DriverLoadError( + driver=driver, + reason=_("Unable to locate usable ipmitool command in " + "the system path when checking ipmitool version")) + _check_temp_dir() + + class IPMIPower(base.PowerInterface): def __init__(self): - try: - _check_option_support(['timing', 'single_bridge', 'dual_bridge']) - except OSError: - raise exception.DriverLoadError( - driver=self.__class__.__name__, - reason=_("Unable to locate usable ipmitool command in " - "the system path when checking ipmitool version")) - _check_temp_dir() + _constructor_checks(driver=self.__class__.__name__) def get_properties(self): return COMMON_PROPERTIES @@ -841,14 +846,7 @@ class IPMIManagement(base.ManagementInterface): return COMMON_PROPERTIES def __init__(self): - try: - _check_option_support(['timing', 'single_bridge', 'dual_bridge']) - except OSError: - raise exception.DriverLoadError( - driver=self.__class__.__name__, - reason=_("Unable to locate usable ipmitool command in " - "the system path when checking ipmitool version")) - _check_temp_dir() + _constructor_checks(driver=self.__class__.__name__) @METRICS.timer('IPMIManagement.validate') def validate(self, task): @@ -1041,14 +1039,7 @@ class IPMIManagement(base.ManagementInterface): class VendorPassthru(base.VendorInterface): def __init__(self): - try: - _check_option_support(['single_bridge', 'dual_bridge']) - except OSError: - raise exception.DriverLoadError( - driver=self.__class__.__name__, - reason=_("Unable to locate usable ipmitool command in " - "the system path when checking ipmitool version")) - _check_temp_dir() + _constructor_checks(driver=self.__class__.__name__) @METRICS.timer('VendorPassthru.send_raw') @base.passthru(['POST']) @@ -1138,14 +1129,7 @@ class IPMIConsole(base.ConsoleInterface): """A base ConsoleInterface that uses ipmitool.""" def __init__(self): - try: - _check_option_support(['timing', 'single_bridge', 'dual_bridge']) - except OSError: - raise exception.DriverLoadError( - driver=self.__class__.__name__, - reason=_("Unable to locate usable ipmitool command in " - "the system path when checking ipmitool version")) - _check_temp_dir() + _constructor_checks(driver=self.__class__.__name__) def get_properties(self): d = COMMON_PROPERTIES.copy()