Merge "Gather details about bond interfaces if present"
This commit is contained in:
commit
ccf4ee31cf
@ -1272,11 +1272,17 @@ class GenericHardwareManager(HardwareManager):
|
||||
|
||||
return vlan.isdigit()
|
||||
|
||||
def _is_bond(self, interface_name):
|
||||
device_path = '{}/class/net/{}/bonding'.format(self.sys_path,
|
||||
interface_name)
|
||||
return os.path.exists(device_path)
|
||||
|
||||
def list_network_interfaces(self):
|
||||
network_interfaces_list = []
|
||||
iface_names = os.listdir('{}/class/net'.format(self.sys_path))
|
||||
iface_names = [name for name in iface_names
|
||||
if self._is_vlan(name) or self._is_device(name)]
|
||||
if self._is_vlan(name) or self._is_device(name)
|
||||
or self._is_bond(name)]
|
||||
|
||||
if CONF.collect_lldp:
|
||||
self.lldp_data = dispatch_to_managers('collect_lldp_data',
|
||||
|
@ -281,7 +281,7 @@ class TestGenericHardwareManager(base.IronicAgentTest):
|
||||
mockedget_managers):
|
||||
mockedget_managers.return_value = [hardware.GenericHardwareManager()]
|
||||
mocked_listdir.return_value = ['lo', 'eth0', 'foobar']
|
||||
mocked_exists.side_effect = [False, True, True]
|
||||
mocked_exists.side_effect = [False, 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
|
||||
@ -325,7 +325,7 @@ class TestGenericHardwareManager(base.IronicAgentTest):
|
||||
mockedget_managers):
|
||||
mockedget_managers.return_value = [hardware.GenericHardwareManager()]
|
||||
mocked_listdir.return_value = ['lo', 'eth0']
|
||||
mocked_exists.side_effect = [False, True]
|
||||
mocked_exists.side_effect = [False, False, True]
|
||||
mocked_open.return_value.__enter__ = lambda s: s
|
||||
mocked_open.return_value.__exit__ = mock.Mock()
|
||||
read_mock = mocked_open.return_value.read
|
||||
@ -420,7 +420,7 @@ class TestGenericHardwareManager(base.IronicAgentTest):
|
||||
mockedget_managers.return_value = [hardware.GenericHardwareManager()]
|
||||
CONF.set_override('collect_lldp', True)
|
||||
mocked_listdir.return_value = ['lo', 'eth0']
|
||||
mocked_exists.side_effect = [False, True]
|
||||
mocked_exists.side_effect = [False, False, True]
|
||||
mocked_open.return_value.__enter__ = lambda s: s
|
||||
mocked_open.return_value.__exit__ = mock.Mock()
|
||||
read_mock = mocked_open.return_value.read
|
||||
@ -470,7 +470,7 @@ class TestGenericHardwareManager(base.IronicAgentTest):
|
||||
mockedget_managers.return_value = [hardware.GenericHardwareManager()]
|
||||
CONF.set_override('collect_lldp', True)
|
||||
mocked_listdir.return_value = ['lo', 'eth0']
|
||||
mocked_exists.side_effect = [False, True]
|
||||
mocked_exists.side_effect = [False, False, True]
|
||||
mocked_open.return_value.__enter__ = lambda s: s
|
||||
mocked_open.return_value.__exit__ = mock.Mock()
|
||||
read_mock = mocked_open.return_value.read
|
||||
@ -513,7 +513,7 @@ class TestGenericHardwareManager(base.IronicAgentTest):
|
||||
|
||||
mockedget_managers.return_value = [hardware.GenericHardwareManager()]
|
||||
mocked_listdir.return_value = ['lo', 'eth0']
|
||||
mocked_exists.side_effect = [False, True]
|
||||
mocked_exists.side_effect = [False, False, True]
|
||||
mocked_open.return_value.__enter__ = lambda s: s
|
||||
mocked_open.return_value.__exit__ = mock.Mock()
|
||||
read_mock = mocked_open.return_value.read
|
||||
@ -554,7 +554,7 @@ class TestGenericHardwareManager(base.IronicAgentTest):
|
||||
mockedget_managers):
|
||||
mockedget_managers.return_value = [hardware.GenericHardwareManager()]
|
||||
mocked_listdir.return_value = ['lo', 'eth0']
|
||||
mocked_exists.side_effect = [False, True]
|
||||
mocked_exists.side_effect = [False, False, True]
|
||||
mocked_open.return_value.__enter__ = lambda s: s
|
||||
mocked_open.return_value.__exit__ = mock.Mock()
|
||||
read_mock = mocked_open.return_value.read
|
||||
@ -578,6 +578,50 @@ class TestGenericHardwareManager(base.IronicAgentTest):
|
||||
self.assertEqual('0x1014', interfaces[0].product)
|
||||
self.assertEqual('em0', interfaces[0].biosdevname)
|
||||
|
||||
@mock.patch('ironic_python_agent.hardware.get_managers', autospec=True)
|
||||
@mock.patch('netifaces.ifaddresses', autospec=True)
|
||||
@mock.patch('os.listdir', autospec=True)
|
||||
@mock.patch('os.path.exists', autospec=True)
|
||||
@mock.patch('builtins.open', autospec=True)
|
||||
@mock.patch.object(il_utils, 'execute', autospec=True)
|
||||
@mock.patch.object(netutils, 'get_mac_addr', autospec=True)
|
||||
@mock.patch.object(netutils, 'interface_has_carrier', autospec=True)
|
||||
def test_list_network_interfaces_with_bond(self,
|
||||
mock_has_carrier,
|
||||
mock_get_mac,
|
||||
mocked_execute,
|
||||
mocked_open,
|
||||
mocked_exists,
|
||||
mocked_listdir,
|
||||
mocked_ifaddresses,
|
||||
mockedget_managers):
|
||||
mockedget_managers.return_value = [hardware.GenericHardwareManager()]
|
||||
mocked_listdir.return_value = ['lo', 'bond0']
|
||||
mocked_exists.side_effect = [False, False, True]
|
||||
mocked_open.return_value.__enter__ = lambda s: s
|
||||
mocked_open.return_value.__exit__ = mock.Mock()
|
||||
read_mock = mocked_open.return_value.read
|
||||
read_mock.side_effect = ['1']
|
||||
mocked_ifaddresses.return_value = {
|
||||
netifaces.AF_INET: [{'addr': '192.168.1.2'}],
|
||||
netifaces.AF_INET6: [{'addr': 'fd00::101'}]
|
||||
}
|
||||
mocked_execute.return_value = ('\n', '')
|
||||
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('bond0', interfaces[0].name)
|
||||
self.assertEqual('00:0c:29:8c:11:b1', interfaces[0].mac_address)
|
||||
self.assertEqual('192.168.1.2', interfaces[0].ipv4_address)
|
||||
self.assertEqual('fd00::101', interfaces[0].ipv6_address)
|
||||
self.assertIsNone(interfaces[0].lldp)
|
||||
self.assertTrue(interfaces[0].has_carrier)
|
||||
self.assertEqual('', interfaces[0].biosdevname)
|
||||
|
||||
@mock.patch('ironic_python_agent.hardware.get_managers', autospec=True)
|
||||
@mock.patch('netifaces.ifaddresses', autospec=True)
|
||||
@mock.patch('os.listdir', autospec=True)
|
||||
@ -598,7 +642,7 @@ class TestGenericHardwareManager(base.IronicAgentTest):
|
||||
mockedget_managers.return_value = [hardware.GenericHardwareManager()]
|
||||
CONF.set_override('enable_vlan_interfaces', 'eth0.100')
|
||||
mocked_listdir.return_value = ['lo', 'eth0']
|
||||
mocked_exists.side_effect = [False, True, False]
|
||||
mocked_exists.side_effect = [False, False, True]
|
||||
mocked_open.return_value.__enter__ = lambda s: s
|
||||
mocked_open.return_value.__exit__ = mock.Mock()
|
||||
read_mock = mocked_open.return_value.read
|
||||
@ -645,7 +689,7 @@ class TestGenericHardwareManager(base.IronicAgentTest):
|
||||
CONF.set_override('enable_vlan_interfaces', 'eth0')
|
||||
mocked_listdir.return_value = ['lo', 'eth0']
|
||||
mocked_execute.return_value = ('em0\n', '')
|
||||
mocked_exists.side_effect = [False, True, False]
|
||||
mocked_exists.side_effect = [False, False, True]
|
||||
mocked_open.return_value.__enter__ = lambda s: s
|
||||
mocked_open.return_value.__exit__ = mock.Mock()
|
||||
read_mock = mocked_open.return_value.read
|
||||
@ -697,7 +741,7 @@ class TestGenericHardwareManager(base.IronicAgentTest):
|
||||
CONF.set_override('collect_lldp', True)
|
||||
CONF.set_override('enable_vlan_interfaces', 'enp0s1')
|
||||
mocked_listdir.return_value = ['lo', 'eth0']
|
||||
mocked_exists.side_effect = [False, True, False]
|
||||
mocked_exists.side_effect = [False, False, True]
|
||||
mocked_open.return_value.__enter__ = lambda s: s
|
||||
mocked_open.return_value.__exit__ = mock.Mock()
|
||||
read_mock = mocked_open.return_value.read
|
||||
@ -734,7 +778,7 @@ class TestGenericHardwareManager(base.IronicAgentTest):
|
||||
CONF.set_override('enable_vlan_interfaces', 'all')
|
||||
mocked_listdir.return_value = ['lo', 'eth0', 'eth1']
|
||||
mocked_execute.return_value = ('em0\n', '')
|
||||
mocked_exists.side_effect = [False, True, True]
|
||||
mocked_exists.side_effect = [False, 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
|
||||
|
5
releasenotes/notes/findbonds-733c7c91a5665b05.yaml
Normal file
5
releasenotes/notes/findbonds-733c7c91a5665b05.yaml
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
fixes:
|
||||
- |
|
||||
Fixes GenericHardwareManager to find network information
|
||||
for bonded interfaces if they exist.
|
Loading…
Reference in New Issue
Block a user