diff options
| author | Dmitry Tantsur <dtantsur@protonmail.com> | 2023-04-25 12:04:37 +0200 |
|---|---|---|
| committer | Julia Kreger <juliaashleykreger@gmail.com> | 2023-04-26 19:33:51 +0000 |
| commit | 3e05a03f7c04d59cc5b6aa6bb5633431a1beb2a0 (patch) | |
| tree | 2f6d9f4915236100bddd67b74f071352b7301de4 /ironic_python_agent | |
| parent | 0304c73c0e95699650a147c1bb5ea0a5ef6861f1 (diff) | |
| download | ironic-python-agent-3e05a03f7c04d59cc5b6aa6bb5633431a1beb2a0.tar.gz | |
Deprecate LLDP in inventory in favour of a new collector
Binary LLDP data is bloating inventory causing us to disable its collection
by default. For other similar low-level information, such as PCI devices
or DMI data, we already use inspection collectors instead. Now that the
inventory format is shared with out-of-band inspection, having LLDP
there makes even less sense.
This change adds a new collector ``lldp`` to replace the now-deprecated
inventory field.
Change-Id: I56be06a7d1db28407e1128c198c12bea0809d3a3
Diffstat (limited to 'ironic_python_agent')
| -rw-r--r-- | ironic_python_agent/config.py | 4 | ||||
| -rw-r--r-- | ironic_python_agent/hardware.py | 36 | ||||
| -rw-r--r-- | ironic_python_agent/inspector.py | 9 | ||||
| -rw-r--r-- | ironic_python_agent/netutils.py | 24 |
4 files changed, 45 insertions, 28 deletions
diff --git a/ironic_python_agent/config.py b/ironic_python_agent/config.py index 9251a3e3..056cab85 100644 --- a/ironic_python_agent/config.py +++ b/ironic_python_agent/config.py @@ -149,7 +149,9 @@ cli_opts = [ help='Whether IPA should attempt to receive LLDP packets for ' 'each network interface it discovers in the inventory. ' 'Can be supplied as "ipa-collect-lldp" ' - 'kernel parameter.'), + 'kernel parameter.', + deprecated_for_removal=True, + deprecated_reason="Use the lldp collector instead"), cfg.StrOpt('inspection_callback_url', default=APARAMS.get('ipa-inspection-callback-url'), diff --git a/ironic_python_agent/hardware.py b/ironic_python_agent/hardware.py index 8dd3a961..badb07db 100644 --- a/ironic_python_agent/hardware.py +++ b/ironic_python_agent/hardware.py @@ -865,6 +865,9 @@ class HardwareManager(object, metaclass=abc.ABCMeta): def list_network_interfaces(self): raise errors.IncompatibleHardwareMethodError + def collect_lldp_data(self, interface_names=None): + raise errors.IncompatibleHardwareMethodError + def get_cpus(self): raise errors.IncompatibleHardwareMethodError @@ -1198,7 +1201,6 @@ class GenericHardwareManager(HardwareManager): HARDWARE_MANAGER_VERSION = '1.1' def __init__(self): - self.sys_path = '/sys' self.lldp_data = {} def evaluate_hardware_support(self): @@ -1213,7 +1215,7 @@ class GenericHardwareManager(HardwareManager): self.wait_for_disks() return HardwareSupport.GENERIC - def collect_lldp_data(self, interface_names): + def collect_lldp_data(self, interface_names=None): """Collect and convert LLDP info from the node. In order to process the LLDP information later, the raw data needs to @@ -1222,7 +1224,8 @@ class GenericHardwareManager(HardwareManager): :param interface_names: list of names of node's interfaces. :return: a dict, containing the lldp data from every interface. """ - + if interface_names is None: + interface_names = netutils.list_interfaces() interface_names = [name for name in interface_names if name != 'lo'] lldp_data = {} try: @@ -1292,7 +1295,7 @@ class GenericHardwareManager(HardwareManager): """ global WARN_BIOSDEVNAME_NOT_FOUND - if self._is_vlan(interface_name): + if netutils.is_vlan(interface_name): LOG.debug('Interface %s is a VLAN, biosdevname not called', interface_name) return @@ -1313,35 +1316,14 @@ class GenericHardwareManager(HardwareManager): else: LOG.warning('Biosdevname returned exit code %s', e.exit_code) - def _is_device(self, interface_name): - device_path = '{}/class/net/{}/device'.format(self.sys_path, - interface_name) - return os.path.exists(device_path) - - def _is_vlan(self, interface_name): - # A VLAN interface does not have /device, check naming convention - # used when adding VLAN interface - - interface, sep, vlan = interface_name.partition('.') - - 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) - or self._is_bond(name)] + iface_names = netutils.list_interfaces() if CONF.collect_lldp: self.lldp_data = dispatch_to_managers('collect_lldp_data', interface_names=iface_names) + network_interfaces_list = [] for iface_name in iface_names: try: result = dispatch_to_managers( diff --git a/ironic_python_agent/inspector.py b/ironic_python_agent/inspector.py index 8e570c3b..c2d98d5d 100644 --- a/ironic_python_agent/inspector.py +++ b/ironic_python_agent/inspector.py @@ -364,3 +364,12 @@ def collect_pci_devices_info(data, failures): 'revision': pci_revision, 'bus': subdir}) data['pci_devices'] = pci_devices_info + + +def collect_lldp(data, failures): + """Collect LLDP information for network interfaces. + + :param data: mutable data that we'll send to inspector + :param failures: AccumulatedFailures object + """ + data['lldp_raw'] = hardware.dispatch_to_managers('collect_lldp_data') diff --git a/ironic_python_agent/netutils.py b/ironic_python_agent/netutils.py index 0b595d96..2e289808 100644 --- a/ironic_python_agent/netutils.py +++ b/ironic_python_agent/netutils.py @@ -14,6 +14,7 @@ import ctypes import fcntl +import os import select import socket import struct @@ -247,6 +248,29 @@ def get_hostname(): return socket.gethostname() +def is_network_device(interface_name): + device_path = f'/sys/class/net/{interface_name}/device' + return os.path.exists(device_path) + + +def is_vlan(interface_name): + # A VLAN interface does not have /device, check naming convention + # used when adding VLAN interface + interface, sep, vlan = interface_name.partition('.') + return vlan.isdigit() + + +def is_bond(interface_name): + device_path = f'/sys/class/net/{interface_name}/bonding' + return os.path.exists(device_path) + + +def list_interfaces(): + iface_names = os.listdir('/sys/class/net') + return [name for name in iface_names + if is_vlan(name) or is_network_device(name) or is_bond(name)] + + def interface_has_carrier(interface_name): path = '/sys/class/net/{}/carrier'.format(interface_name) try: |
