summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2022-07-02 02:56:46 +0000
committerGerrit Code Review <review@openstack.org>2022-07-02 02:56:46 +0000
commitccf4ee31cfe0b85f81092d865baa59100887c445 (patch)
tree1fe90fd3230189b2804b55defb85f0794c763b6d
parent7d15efd7a66d2c5bd4bd57e8806471ebd50201b7 (diff)
parent7e4fe3bf6a2ae41656b7923796f9c2d056a2ed04 (diff)
downloadironic-python-agent-ccf4ee31cfe0b85f81092d865baa59100887c445.tar.gz
Merge "Gather details about bond interfaces if present"
-rw-r--r--ironic_python_agent/hardware.py8
-rw-r--r--ironic_python_agent/tests/unit/test_hardware.py64
-rw-r--r--releasenotes/notes/findbonds-733c7c91a5665b05.yaml5
3 files changed, 66 insertions, 11 deletions
diff --git a/ironic_python_agent/hardware.py b/ironic_python_agent/hardware.py
index d32b4b28..0f7e4f82 100644
--- a/ironic_python_agent/hardware.py
+++ b/ironic_python_agent/hardware.py
@@ -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',
diff --git a/ironic_python_agent/tests/unit/test_hardware.py b/ironic_python_agent/tests/unit/test_hardware.py
index c4b1b6fb..a610eb2f 100644
--- a/ironic_python_agent/tests/unit/test_hardware.py
+++ b/ironic_python_agent/tests/unit/test_hardware.py
@@ -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
@@ -586,6 +586,50 @@ class TestGenericHardwareManager(base.IronicAgentTest):
@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)
+ @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_vlan_interfaces(self,
mock_has_carrier,
mock_get_mac,
@@ -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
diff --git a/releasenotes/notes/findbonds-733c7c91a5665b05.yaml b/releasenotes/notes/findbonds-733c7c91a5665b05.yaml
new file mode 100644
index 00000000..d1161cf6
--- /dev/null
+++ b/releasenotes/notes/findbonds-733c7c91a5665b05.yaml
@@ -0,0 +1,5 @@
+---
+fixes:
+ - |
+ Fixes GenericHardwareManager to find network information
+ for bonded interfaces if they exist.