Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions io/driver/driver_parameter.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def setUp(self):
self.module = self.params.get('module', default=None)
if not self.module:
self.cancel("Please provide the Module name")

# Validate that the interface belongs to the specified driver
self.validate_interface_driver()
self.ipaddr = self.params.get("host_ip", default="")
self.netmask = self.params.get("netmask", default="")
self.peer = self.params.get("peer_ip")
Expand Down Expand Up @@ -85,6 +88,50 @@ def setUp(self):
self.cancel("Param %s is not Valid for Module %s" %
(self.param_name, self.module))

def get_interface_driver(self):
"""
Get the driver module name for the specified interface using ethtool.
Returns the driver name or None if unable to determine.
Assisted with AI tool
"""
try:
cmd = "ethtool -i %s" % self.ifaces
output = process.system_output(cmd, ignore_status=False).decode('utf-8')
for line in output.split('\n'):
if line.startswith('driver:'):
driver = line.split(':', 1)[1].strip()
self.log.info("Interface %s is using driver: %s" %
(self.ifaces, driver))
return driver
except Exception as e:
self.log.warning("Failed to get driver info for %s: %s" %
(self.ifaces, str(e)))
return None
return None

def validate_interface_driver(self):
"""
Validate that the interface belongs to the driver module specified in YAML.
Raises an error if there's a mismatch between the YAML-specified module
and the interface's actual driver.
Assisted with AI tool
"""
actual_driver = self.get_interface_driver()

if actual_driver is None:
self.cancel("Unable to determine driver for interface %s. "
"Please verify the interface exists and ethtool is available."
% self.ifaces)

if actual_driver != self.module:
self.cancel("Driver mismatch detected: Interface %s is using driver '%s' "
"but YAML configuration specifies module '%s'. "
"Please ensure the interface belongs to the correct driver."
% (self.ifaces, actual_driver, self.module))

self.log.info("Driver validation passed: Interface %s belongs to module %s"
% (self.ifaces, self.module))

def built_in_module(self, module):
"""
checking whether the given module is built_in module or not
Expand Down
Loading