summaryrefslogtreecommitdiff
path: root/ironic_python_agent/hardware.py
diff options
context:
space:
mode:
authorDmitry Tantsur <divius.inside@gmail.com>2017-09-11 16:08:33 +0200
committerDmitry Tantsur <divius.inside@gmail.com>2017-09-12 15:31:56 +0000
commit81ac0b4115633437a53da99cd73ac6663e0b98e4 (patch)
tree4d0934550413fb6d6a28db279b0dc38e9a308483 /ironic_python_agent/hardware.py
parentb6144beef08f989d7d8b70a0cbc2030ce22b9c55 (diff)
downloadironic-python-agent-2.2.1.tar.gz
Remove assumption that a valid IPMI channel cannot follow an invalid one2.2.1
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 (cherry picked from commit d6ff5116f4a5586238d44a196ec89d844b151f9d)
Diffstat (limited to 'ironic_python_agent/hardware.py')
-rw-r--r--ironic_python_agent/hardware.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/ironic_python_agent/hardware.py b/ironic_python_agent/hardware.py
index 568d5bf4..30549dbc 100644
--- a/ironic_python_agent/hardware.py
+++ b/ironic_python_agent/hardware.py
@@ -21,6 +21,7 @@ import time
from ironic_lib import disk_utils
from ironic_lib import utils as il_utils
+import netaddr
from oslo_concurrency import processutils
from oslo_config import cfg
from oslo_log import log
@@ -944,14 +945,20 @@ class GenericHardwareManager(HardwareManager):
out, e = utils.execute(
"ipmitool lan print {} | awk '/IP Address[[:space:]]*:/"
" {{print $4}}'".format(channel), shell=True)
- # Invalid channel cannot be followed by a valid one, so we can
- # safely break here
if e.startswith("Invalid channel"):
- break
- # In case we get empty IP or 0.0.0.0 on a valid channel,
- # we need to keep querying
- if out.strip() not in ('', '0.0.0.0'):
- return out.strip()
+ continue
+ out = out.strip()
+
+ try:
+ netaddr.IPAddress(out)
+ except netaddr.AddrFormatError:
+ LOG.warning('Invalid IP address: %s', out)
+ continue
+
+ # In case we get 0.0.0.0 on a valid channel, we need to keep
+ # querying
+ if out != '0.0.0.0':
+ return out
except (processutils.ProcessExecutionError, OSError) as e:
# Not error, because it's normal in virtual environment