Execute error in _detect_cna_card
A list type parameter pass to utils.execute will raise OSError. Change-Id: Ic5dd30f7e819e433d05bf9cc888902abe7a82def
This commit is contained in:
parent
cd2ab6b1fb
commit
f55b8a34c4
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
from oslo_concurrency import processutils
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
|
|
||||||
@ -27,13 +28,18 @@ CONF = cfg.CONF
|
|||||||
def _detect_cna_card():
|
def _detect_cna_card():
|
||||||
addr_path = '/sys/class/net'
|
addr_path = '/sys/class/net'
|
||||||
for net_dev in os.listdir(addr_path):
|
for net_dev in os.listdir(addr_path):
|
||||||
|
link_path = '{}/{}/device/driver/module'.format(addr_path, net_dev)
|
||||||
try:
|
try:
|
||||||
link_command = 'readlink {}/{}/device/driver/module'.format(
|
out = utils.execute('readlink', '-v', link_path)
|
||||||
addr_path, net_dev)
|
except OSError as e:
|
||||||
out = utils.execute(link_command.split())
|
LOG.warning('Something went wrong when readlink for '
|
||||||
if not out or out[1]:
|
'interface %(device)s. Error: %(error)s',
|
||||||
continue
|
{'device': net_dev, 'error': e})
|
||||||
except OSError:
|
continue
|
||||||
|
except processutils.ProcessExecutionError as e:
|
||||||
|
LOG.debug('Get driver for interface %(device)s failed. '
|
||||||
|
'Error: %(error)s',
|
||||||
|
{'device': net_dev, 'error': e})
|
||||||
continue
|
continue
|
||||||
driver_name = os.path.basename(out[0].strip())
|
driver_name = os.path.basename(out[0].strip())
|
||||||
if driver_name == 'i40e':
|
if driver_name == 'i40e':
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
from oslo_concurrency import processutils
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
|
|
||||||
from ironic_python_agent import hardware
|
from ironic_python_agent import hardware
|
||||||
@ -38,9 +39,9 @@ class TestIntelCnaHardwareManager(base.IronicAgentTest):
|
|||||||
@mock.patch.object(utils, 'execute', autospec=True)
|
@mock.patch.object(utils, 'execute', autospec=True)
|
||||||
def test_detect_cna_card(self, mock_execute, mock_listdir):
|
def test_detect_cna_card(self, mock_execute, mock_listdir):
|
||||||
def mock_return_execute(*args, **kwargs):
|
def mock_return_execute(*args, **kwargs):
|
||||||
if 'eth0' in args[0][1]:
|
if 'eth0' in args[2]:
|
||||||
return '/foo/bar/fake', ''
|
return '/foo/bar/fake', ''
|
||||||
if 'eth1' in args[0][1]:
|
if 'eth1' in args[2]:
|
||||||
return '/foo/bar/i40e', ''
|
return '/foo/bar/i40e', ''
|
||||||
|
|
||||||
mock_listdir.return_value = ['eth0', 'eth1']
|
mock_listdir.return_value = ['eth0', 'eth1']
|
||||||
@ -51,11 +52,11 @@ class TestIntelCnaHardwareManager(base.IronicAgentTest):
|
|||||||
@mock.patch.object(utils, 'execute', autospec=True)
|
@mock.patch.object(utils, 'execute', autospec=True)
|
||||||
def test_detect_cna_card_execute_error(self, mock_execute, mock_listdir):
|
def test_detect_cna_card_execute_error(self, mock_execute, mock_listdir):
|
||||||
def mock_return_execute(*args, **kwargs):
|
def mock_return_execute(*args, **kwargs):
|
||||||
if 'eth0' in args[0][1]:
|
if 'eth0' in args[2]:
|
||||||
return '/foo/bar/fake', ''
|
return '/foo/bar/fake', ''
|
||||||
if 'eth1' in args[0][1]:
|
if 'eth1' in args[2]:
|
||||||
return '', 'fake error'
|
raise processutils.ProcessExecutionError('fake')
|
||||||
if 'eth2' in args[0][1]:
|
if 'eth2' in args[2]:
|
||||||
raise OSError('fake')
|
raise OSError('fake')
|
||||||
|
|
||||||
mock_listdir.return_value = ['eth0', 'eth1', 'eth2']
|
mock_listdir.return_value = ['eth0', 'eth1', 'eth2']
|
||||||
@ -66,9 +67,9 @@ class TestIntelCnaHardwareManager(base.IronicAgentTest):
|
|||||||
@mock.patch.object(utils, 'execute', autospec=True)
|
@mock.patch.object(utils, 'execute', autospec=True)
|
||||||
def test_detect_cna_card_no_i40e_driver(self, mock_execute, mock_listdir):
|
def test_detect_cna_card_no_i40e_driver(self, mock_execute, mock_listdir):
|
||||||
def mock_return_execute(*args, **kwargs):
|
def mock_return_execute(*args, **kwargs):
|
||||||
if 'eth0' in args[0][1]:
|
if 'eth0' in args[2]:
|
||||||
return '/foo/bar/fake1', ''
|
return '/foo/bar/fake1', ''
|
||||||
if 'eth1' in args[0][1]:
|
if 'eth1' in args[2]:
|
||||||
return '/foo/bar/fake2', ''
|
return '/foo/bar/fake2', ''
|
||||||
|
|
||||||
mock_listdir.return_value = ['eth0', 'eth1']
|
mock_listdir.return_value = ['eth0', 'eth1']
|
||||||
|
Loading…
Reference in New Issue
Block a user