-
Notifications
You must be signed in to change notification settings - Fork 190
Add fallback logic for interface detection when ifconfig is unavailable! #6884
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -207,6 +207,36 @@ def check_device_status(net_ip, server_ip, netmask): | |||||||||
| # ping to server from each function | ||||||||||
| for val in bus_info: | ||||||||||
| nic_name = str(utils_misc.get_interface_from_pci_id(val, session)) | ||||||||||
|
|
||||||||||
| # If get_interface_from_pci_id returns None, use uevent file | ||||||||||
| if nic_name == "None" or not nic_name: | ||||||||||
| logging.warning("get_interface_from_pci_id returned None for %s, trying uevent method", val) | ||||||||||
| try: | ||||||||||
| # Get all network interfaces using modern 'ip' command instead of deprecated 'ifconfig' | ||||||||||
| ifaces_output = session.cmd_output("ip -o link show | awk -F': ' '{print $2}'") | ||||||||||
| interfaces = [iface.strip() for iface in ifaces_output.strip().split("\n") if iface.strip()] | ||||||||||
|
|
||||||||||
| # Find interface matching PCI address using uevent file | ||||||||||
| for iface in interfaces: | ||||||||||
| if iface in ["lo", "sit0"]: # Skip loopback | ||||||||||
| continue | ||||||||||
|
Comment on lines
+221
to
+222
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clarify the comment to reflect both interface types. The comment says "Skip loopback" but the code also skips 📝 Suggested fix- if iface in ["lo", "sit0"]: # Skip loopback
+ if iface in ["lo", "sit0"]: # Skip loopback and tunnel interfaces
continue📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
| # Read PCI address from uevent file | ||||||||||
| pci_cmd = "cat /sys/class/net/{}/device/uevent 2>/dev/null | grep PCI_SLOT_NAME | cut -d= -f2".format(iface) | ||||||||||
| status, pci_addr = session.cmd_status_output(pci_cmd) | ||||||||||
| if status == 0 and pci_addr.strip(): | ||||||||||
| # Normalize for comparison (case-insensitive) | ||||||||||
| pci_normalized = pci_addr.strip().lower() | ||||||||||
| val_normalized = val.lower() | ||||||||||
| if pci_normalized == val_normalized: | ||||||||||
| nic_name = iface | ||||||||||
| logging.info("Found interface %s for PCI %s using uevent method", nic_name, val) | ||||||||||
| break | ||||||||||
| except Exception as e: | ||||||||||
| logging.error("Failed to find interface for PCI %s: %s", val, str(e)) | ||||||||||
|
|
||||||||||
| if nic_name == "None" or not nic_name: | ||||||||||
| test.error("Could not determine interface name for PCI device {}".format(val)) | ||||||||||
| continue | ||||||||||
| session.cmd("ip addr flush dev %s" % nic_name) | ||||||||||
| session.cmd("ip addr add %s/%s dev %s" | ||||||||||
| % (net_ip, netmask, nic_name)) | ||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win
Check the return value before converting to string.
Converting the result to string before checking for
Nonemakes the logic harder to follow. The check on line 212 has to compare against the string"None"instead of the PythonNoneobject.♻️ Cleaner approach
Then ensure
nic_nameis converted to string only after the fallback succeeds (it's already a string from line 231, so this works correctly).📝 Committable suggestion
🤖 Prompt for AI Agents