Skip to content

Commit 1f11933

Browse files
committed
get the bonding master from slave interface
The patch identifies and returns the bonding master for a slave interface. The function now correctly returns the bond master interface name (e.g., "bond0") when called on a slave interface Signed-off-by: Vaishnavi Bhat <vaishnavi@linux.vnet.ibm.com>
1 parent cbea52d commit 1f11933

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

avocado/utils/network/interfaces.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,27 @@ def _get_bondinterface_details(self):
217217
f"Slave interface not found for " f"the bond {self.name}"
218218
) from exc
219219

220+
def _get_bondingmaster(self):
221+
"""Get the bonding master interface name from a slave interface.
222+
223+
This method returns the bond interface name for the current slave interface.
224+
225+
:return: Bond master interface name as string
226+
:raises NWException: If bonding master not found or interface is not a slave
227+
"""
228+
master_path = f"/sys/class/net/{self.name}/master"
229+
cmd = f"readlink -f {master_path}"
230+
try:
231+
output = run_command(cmd, self.host)
232+
# Extract the bond interface name from the path
233+
# Output will be like: /sys/devices/virtual/net/bond0
234+
bond_name = os.path.basename(output.strip())
235+
return bond_name
236+
except Exception as exc:
237+
raise NWException(
238+
f"Bonding master not found for interface {self.name}"
239+
) from exc
240+
220241
def _move_file_to_backup(self, filename, ignore_missing=True):
221242
"""Moves a file to a backup location.
222243

0 commit comments

Comments
 (0)