summaryrefslogtreecommitdiff
path: root/ironic_python_agent
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-01-26 21:47:15 +0000
committerGerrit Code Review <review@openstack.org>2018-01-26 21:47:16 +0000
commita3463dc57d1dc2dc34345ed3b476f6ebfbe5649c (patch)
tree15b1cdcbf4231c0c75c2981ce79daf72c632422d /ironic_python_agent
parenta246bf3777662eb2abd32ca6974fd130b2193c04 (diff)
parentf55b8a34c4b796632940652219091265498b60c5 (diff)
downloadironic-python-agent-a3463dc57d1dc2dc34345ed3b476f6ebfbe5649c.tar.gz
Merge "Execute error in _detect_cna_card"
Diffstat (limited to 'ironic_python_agent')
-rw-r--r--ironic_python_agent/hardware_managers/cna.py18
-rw-r--r--ironic_python_agent/tests/unit/hardware_managers/test_cna.py17
2 files changed, 21 insertions, 14 deletions
diff --git a/ironic_python_agent/hardware_managers/cna.py b/ironic_python_agent/hardware_managers/cna.py
index e2962327..6998422a 100644
--- a/ironic_python_agent/hardware_managers/cna.py
+++ b/ironic_python_agent/hardware_managers/cna.py
@@ -14,6 +14,7 @@
import os
+from oslo_concurrency import processutils
from oslo_config import cfg
from oslo_log import log
@@ -27,13 +28,18 @@ CONF = cfg.CONF
def _detect_cna_card():
addr_path = '/sys/class/net'
for net_dev in os.listdir(addr_path):
+ link_path = '{}/{}/device/driver/module'.format(addr_path, net_dev)
try:
- link_command = 'readlink {}/{}/device/driver/module'.format(
- addr_path, net_dev)
- out = utils.execute(link_command.split())
- if not out or out[1]:
- continue
- except OSError:
+ out = utils.execute('readlink', '-v', link_path)
+ except OSError as e:
+ LOG.warning('Something went wrong when readlink for '
+ 'interface %(device)s. Error: %(error)s',
+ {'device': net_dev, 'error': e})
+ continue
+ except processutils.ProcessExecutionError as e:
+ LOG.debug('Get driver for interface %(device)s failed. '
+ 'Error: %(error)s',
+ {'device': net_dev, 'error': e})
continue
driver_name = os.path.basename(out[0].strip())
if driver_name == 'i40e':
diff --git a/ironic_python_agent/tests/unit/hardware_managers/test_cna.py b/ironic_python_agent/tests/unit/hardware_managers/test_cna.py
index 3b9226f3..5948bb75 100644
--- a/ironic_python_agent/tests/unit/hardware_managers/test_cna.py
+++ b/ironic_python_agent/tests/unit/hardware_managers/test_cna.py
@@ -15,6 +15,7 @@
import os
import mock
+from oslo_concurrency import processutils
from oslo_config import cfg
from ironic_python_agent import hardware
@@ -38,9 +39,9 @@ class TestIntelCnaHardwareManager(base.IronicAgentTest):
@mock.patch.object(utils, 'execute', autospec=True)
def test_detect_cna_card(self, mock_execute, mock_listdir):
def mock_return_execute(*args, **kwargs):
- if 'eth0' in args[0][1]:
+ if 'eth0' in args[2]:
return '/foo/bar/fake', ''
- if 'eth1' in args[0][1]:
+ if 'eth1' in args[2]:
return '/foo/bar/i40e', ''
mock_listdir.return_value = ['eth0', 'eth1']
@@ -51,11 +52,11 @@ class TestIntelCnaHardwareManager(base.IronicAgentTest):
@mock.patch.object(utils, 'execute', autospec=True)
def test_detect_cna_card_execute_error(self, mock_execute, mock_listdir):
def mock_return_execute(*args, **kwargs):
- if 'eth0' in args[0][1]:
+ if 'eth0' in args[2]:
return '/foo/bar/fake', ''
- if 'eth1' in args[0][1]:
- return '', 'fake error'
- if 'eth2' in args[0][1]:
+ if 'eth1' in args[2]:
+ raise processutils.ProcessExecutionError('fake')
+ if 'eth2' in args[2]:
raise OSError('fake')
mock_listdir.return_value = ['eth0', 'eth1', 'eth2']
@@ -66,9 +67,9 @@ class TestIntelCnaHardwareManager(base.IronicAgentTest):
@mock.patch.object(utils, 'execute', autospec=True)
def test_detect_cna_card_no_i40e_driver(self, mock_execute, mock_listdir):
def mock_return_execute(*args, **kwargs):
- if 'eth0' in args[0][1]:
+ if 'eth0' in args[2]:
return '/foo/bar/fake1', ''
- if 'eth1' in args[0][1]:
+ if 'eth1' in args[2]:
return '/foo/bar/fake2', ''
mock_listdir.return_value = ['eth0', 'eth1']