diff --git a/pyipmi/errors.py b/pyipmi/errors.py index 828a17d..9d10cc1 100644 --- a/pyipmi/errors.py +++ b/pyipmi/errors.py @@ -90,3 +90,12 @@ def __init__(self, msg=None): def __str__(self): return "{}".format(self.msg) + + +class IpmiLongPasswordError(Exception): + """Password longer than 20 bytes.""" + def __init__(self, msg=None): + self.msg = msg + + def __str__(self): + return "{}".format(self.msg) diff --git a/pyipmi/interfaces/ipmitool.py b/pyipmi/interfaces/ipmitool.py index f2c1b54..815041a 100644 --- a/pyipmi/interfaces/ipmitool.py +++ b/pyipmi/interfaces/ipmitool.py @@ -21,7 +21,7 @@ from array import array from ..session import Session -from ..errors import IpmiTimeoutError, IpmiConnectionError +from ..errors import IpmiTimeoutError, IpmiConnectionError, IpmiLongPasswordError from ..logger import log from ..msgs import encode_message, decode_message, create_message from ..msgs.constants import CC_OK @@ -62,7 +62,8 @@ def __init__(self, interface_type='lan', cipher=None): r".*Unable to establish.*") self.re_could_not_open = re.compile( r".*Could not open device.*") - + self.re_long_password = re.compile( + r".*password is longer than.*") self._session = None def open(self): @@ -135,6 +136,9 @@ def _parse_output(self, output): if self.re_could_not_open.match(line): raise RuntimeError('ipmitool failed: {}'.format(output)) + if self.re_long_password.match(line): + raise IpmiLongPasswordError(line) + hexstr += line.replace('\r', '').strip() + ' ' hexstr = hexstr.strip() diff --git a/tests/interfaces/test_ipmitool.py b/tests/interfaces/test_ipmitool.py index cbe1c46..0d4f860 100644 --- a/tests/interfaces/test_ipmitool.py +++ b/tests/interfaces/test_ipmitool.py @@ -5,7 +5,7 @@ import pytest -from pyipmi.errors import IpmiTimeoutError, IpmiConnectionError +from pyipmi.errors import IpmiTimeoutError, IpmiConnectionError, IpmiLongPasswordError from pyipmi.interfaces import Ipmitool from pyipmi import Session, Target from pyipmi.utils import py3_array_tobytes @@ -223,3 +223,9 @@ def test_parse_output_connection_error_rmcp(self): with pytest.raises(IpmiConnectionError): cc, rsp = self._interface._parse_output(test_str) assert rsp is None + + def test_parse_long_password_error(self): + test_str = b'lanplus: password is longer than 20 bytes.' + with pytest.raises(IpmiLongPasswordError): + cc, rsp = self._interface._parse_output(test_str) + assert rsp is None