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
This commit is contained in:
Lucas Alvares Gomes 2016-07-25 16:34:53 +01:00
parent 53f8b173ae
commit 79cee4f6fb
1 changed files with 16 additions and 32 deletions

View File

@ -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()