Browse Source

Do not fail network interface collection on unsupported interface

Currently if one interface cannot be handled (e.g. it has empty MAC),
the whole collection fails. Ignore unsupported interfaces instead.

Change-Id: Ibdaad62b39c239d4f3fb3111c2fae9e31e877b28
(cherry picked from commit 1ab405b509)
changes/98/787598/1
Dmitry Tantsur 1 month ago
parent
commit
b3f489caf3
3 changed files with 19 additions and 6 deletions
  1. +7
    -2
      ironic_python_agent/hardware.py
  2. +7
    -4
      ironic_python_agent/tests/unit/test_hardware.py
  3. +5
    -0
      releasenotes/notes/no-mac-54616606ee6b844d.yaml

+ 7
- 2
ironic_python_agent/hardware.py View File

@ -1086,8 +1086,13 @@ class GenericHardwareManager(HardwareManager):
interface_names=iface_names)
for iface_name in iface_names:
result = dispatch_to_managers(
'get_interface_info', interface_name=iface_name)
try:
result = dispatch_to_managers(
'get_interface_info', interface_name=iface_name)
except errors.HardwareManagerMethodNotFound:
LOG.warning('No hardware manager was able to handle '
'interface %s', iface_name)
continue
result.lldp = self._get_lldp_data(iface_name)
network_interfaces_list.append(result)


+ 7
- 4
ironic_python_agent/tests/unit/test_hardware.py View File

@ -1023,8 +1023,8 @@ class TestGenericHardwareManager(base.IronicAgentTest):
mocked_ifaddresses,
mockedget_managers):
mockedget_managers.return_value = [hardware.GenericHardwareManager()]
mocked_listdir.return_value = ['lo', 'eth0']
mocked_exists.side_effect = [False, True]
mocked_listdir.return_value = ['lo', 'eth0', 'foobar']
mocked_exists.side_effect = [False, True, True]
mocked_open.return_value.__enter__ = lambda s: s
mocked_open.return_value.__exit__ = mock.Mock()
read_mock = mocked_open.return_value.read
@ -1034,8 +1034,11 @@ class TestGenericHardwareManager(base.IronicAgentTest):
netifaces.AF_INET6: [{'addr': 'fd00::101'}]
}
mocked_execute.return_value = ('em0\n', '')
mock_get_mac.mock_has_carrier = True
mock_get_mac.return_value = '00:0c:29:8c:11:b1'
mock_has_carrier.return_value = True
mock_get_mac.side_effect = [
'00:0c:29:8c:11:b1',
None,
]
interfaces = self.hardware.list_network_interfaces()
self.assertEqual(1, len(interfaces))
self.assertEqual('eth0', interfaces[0].name)


+ 5
- 0
releasenotes/notes/no-mac-54616606ee6b844d.yaml View File

@ -0,0 +1,5 @@
---
fixes:
- |
No longer crashes if MAC address cannot be determined for one of the
network interfaces.

Loading…
Cancel
Save