Skip to content

Commit d6ff511

Browse files
committed
Remove assumption that a valid IPMI channel cannot follow an invalid one
It seems to be incorrect at least for some iLO machines. Also harden the code against invalid output from ipmitool. Change-Id: I733785e9c7d86eadca963f0776910504bf91bcfe Closes-Bug: #1714944
1 parent c90b150 commit d6ff511

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

ironic_python_agent/hardware.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
from ironic_lib import disk_utils
2323
from ironic_lib import utils as il_utils
24+
import netaddr
2425
from oslo_concurrency import processutils
2526
from oslo_config import cfg
2627
from oslo_log import log
@@ -944,14 +945,20 @@ def get_bmc_address(self):
944945
out, e = utils.execute(
945946
"ipmitool lan print {} | awk '/IP Address[[:space:]]*:/"
946947
" {{print $4}}'".format(channel), shell=True)
947-
# Invalid channel cannot be followed by a valid one, so we can
948-
# safely break here
949948
if e.startswith("Invalid channel"):
950-
break
951-
# In case we get empty IP or 0.0.0.0 on a valid channel,
952-
# we need to keep querying
953-
if out.strip() not in ('', '0.0.0.0'):
954-
return out.strip()
949+
continue
950+
out = out.strip()
951+
952+
try:
953+
netaddr.IPAddress(out)
954+
except netaddr.AddrFormatError:
955+
LOG.warning('Invalid IP address: %s', out)
956+
continue
957+
958+
# In case we get 0.0.0.0 on a valid channel, we need to keep
959+
# querying
960+
if out != '0.0.0.0':
961+
return out
955962

956963
except (processutils.ProcessExecutionError, OSError) as e:
957964
# Not error, because it's normal in virtual environment

ironic_python_agent/tests/unit/test_hardware.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,7 +1564,11 @@ def test_get_bmc_address_iterate_channels(self, mocked_execute):
15641564
# and for any other we return a correct IP address
15651565
def side_effect(*args, **kwargs):
15661566
if args[0].startswith("ipmitool lan print 1"):
1567+
return '', 'Invalid channel 1\n'
1568+
elif args[0].startswith("ipmitool lan print 2"):
15671569
return '0.0.0.0\n', ''
1570+
elif args[0].startswith("ipmitool lan print 3"):
1571+
return 'meow', ''
15681572
else:
15691573
return '192.1.2.3\n', ''
15701574
mocked_execute.side_effect = side_effect
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
fixes:
3+
- |
4+
Fixes incorrect assumption that a valid channel cannot follow an invalid
5+
one in IPMI (`bug 1714944
6+
<https://bugs.launchpad.net/ironic-python-agent/+bug/1714944>`_).

0 commit comments

Comments
 (0)