Skip to content

Commit 5344f4e

Browse files
committed
fix: add long password ipmi error
The given IPMI password can be longer than IPMI expect. In that case the _parse_output method in Ipmitool's will output the following error "invalid literal for int() with base 16: 'lanplus:'". While if we look at the line that was taken from IPMI we will see that its "lanplus: password is longer than 20 bytes.". So the issue is that there is no check for this error and the function skips it and tries to convert that string from a hex into an integer. I have added an execption, regex check and the match check. Signed-off-by: FrenkenFlores <saifualdin.evloev@gmail.com>
1 parent f0df31e commit 5344f4e

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

pyipmi/errors.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,11 @@ def __init__(self, msg=None):
9090

9191
def __str__(self):
9292
return "{}".format(self.msg)
93+
94+
class IpmiLongPasswordError(Exception):
95+
"""Password longer than 20 bytes."""
96+
def __init__(self, msg=None):
97+
self.msg = msg
98+
99+
def __str__(self):
100+
return "{}".format(self.msg)

pyipmi/interfaces/ipmitool.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from array import array
2222

2323
from ..session import Session
24-
from ..errors import IpmiTimeoutError, IpmiConnectionError
24+
from ..errors import IpmiTimeoutError, IpmiConnectionError, IpmiLongPasswordError
2525
from ..logger import log
2626
from ..msgs import encode_message, decode_message, create_message
2727
from ..msgs.constants import CC_OK
@@ -62,7 +62,8 @@ def __init__(self, interface_type='lan', cipher=None):
6262
r".*Unable to establish.*")
6363
self.re_could_not_open = re.compile(
6464
r".*Could not open device.*")
65-
65+
self.re_long_password = re.compile(
66+
r".*password is longer than.*")
6667
self._session = None
6768

6869
def open(self):
@@ -135,6 +136,9 @@ def _parse_output(self, output):
135136
if self.re_could_not_open.match(line):
136137
raise RuntimeError('ipmitool failed: {}'.format(output))
137138

139+
if self.re_long_password.match(line):
140+
raise IpmiLongPasswordError(line)
141+
138142
hexstr += line.replace('\r', '').strip() + ' '
139143

140144
hexstr = hexstr.strip()

0 commit comments

Comments
 (0)