summaryrefslogtreecommitdiff
path: root/ironic/drivers
diff options
context:
space:
mode:
authorLucas Alvares Gomes <lucasagomes@gmail.com>2016-07-25 16:34:53 +0100
committerLucas Alvares Gomes <lucasagomes@gmail.com>2016-09-19 11:39:52 +0000
commit79cee4f6fbd3a691b50ab5daa756e25c7e4adb1b (patch)
tree68dfc76c802137b6e8fd3a7ba93bed80654eeda8 /ironic/drivers
parent53f8b173ae91b141bae1b5dbe872baedc45f7866 (diff)
downloadironic-79cee4f6fbd3a691b50ab5daa756e25c7e4adb1b.tar.gz
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
Diffstat (limited to 'ironic/drivers')
-rw-r--r--ironic/drivers/modules/ipmitool.py48
1 files changed, 16 insertions, 32 deletions
diff --git a/ironic/drivers/modules/ipmitool.py b/ironic/drivers/modules/ipmitool.py
index 5ab0d7cff..9cf145e30 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()