Skip to content
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

bond: T7191: fix error message when member interface is used multiple times #4362

Merged
merged 1 commit into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
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
13 changes: 10 additions & 3 deletions smoketest/scripts/cli/test_interfaces_bonding.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,25 @@ def test_bonding_mii_monitoring_interval(self):

def test_bonding_multi_use_member(self):
# Define available bonding hash policies
for interface in ['bond10', 'bond20']:
bonds = ['bond10', 'bond20', 'bond30']
for interface in bonds:
for member in self._members:
self.cli_set(self._base_path + [interface, 'member', 'interface', member])

# check validate() - can not use the same member interfaces multiple times
with self.assertRaises(ConfigSessionError):
self.cli_commit()

self.cli_delete(self._base_path + ['bond20'])
# only keep the first bond interface configuration
for interface in bonds[1:]:
self.cli_delete(self._base_path + [interface])

self.cli_commit()

bond = bonds[0]
member_ifaces = read_file(f'/sys/class/net/{bond}/bonding/slaves').split()
for member in self._members:
self.assertIn(member, member_ifaces)

def test_bonding_source_interface(self):
# Re-use member interface that is already a source-interface
bond = 'bond99'
Expand Down
28 changes: 14 additions & 14 deletions src/conf_mode/interfaces_bonding.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,8 @@ def get_config(config=None):
# Restore existing config level
conf.set_level(old_level)

if dict_search('member.interface', bond):
for interface, interface_config in bond['member']['interface'].items():

if dict_search('member.interface', bond) is not None:
for interface in bond['member']['interface']:
interface_ethernet_config = conf.get_config_dict(
['interfaces', 'ethernet', interface],
key_mangling=('-', '_'),
Expand All @@ -137,44 +136,45 @@ def get_config(config=None):
with_defaults=False,
with_recursive_defaults=False)

interface_config['config_paths'] = dict_to_paths_values(interface_ethernet_config)
bond['member']['interface'][interface].update({'config_paths' :
dict_to_paths_values(interface_ethernet_config)})

# Check if member interface is a new member
if not conf.exists_effective(base + [ifname, 'member', 'interface', interface]):
bond['shutdown_required'] = {}
interface_config['new_added'] = {}
bond['member']['interface'][interface].update({'new_added' : {}})

# Check if member interface is disabled
conf.set_level(['interfaces'])

section = Section.section(interface) # this will be 'ethernet' for 'eth0'
if conf.exists([section, interface, 'disable']):
interface_config['disable'] = ''
if tmp: bond['member']['interface'][interface].update({'disable': ''})

conf.set_level(old_level)

# Check if member interface is already member of another bridge
tmp = is_member(conf, interface, 'bridge')
if tmp: interface_config['is_bridge_member'] = tmp
if tmp: bond['member']['interface'][interface].update({'is_bridge_member' : tmp})

# Check if member interface is already member of a bond
tmp = is_member(conf, interface, 'bonding')
for tmp in is_member(conf, interface, 'bonding'):
if bond['ifname'] == tmp:
continue
interface_config['is_bond_member'] = tmp
if ifname in tmp:
del tmp[ifname]
if tmp: bond['member']['interface'][interface].update({'is_bond_member' : tmp})

# Check if member interface is used as source-interface on another interface
tmp = is_source_interface(conf, interface)
if tmp: interface_config['is_source_interface'] = tmp
if tmp: bond['member']['interface'][interface].update({'is_source_interface' : tmp})

# bond members must not have an assigned address
tmp = has_address_configured(conf, interface)
if tmp: interface_config['has_address'] = {}
if tmp: bond['member']['interface'][interface].update({'has_address' : ''})

# bond members must not have a VRF attached
tmp = has_vrf_configured(conf, interface)
if tmp: interface_config['has_vrf'] = {}
if tmp: bond['member']['interface'][interface].update({'has_vrf' : ''})

return bond


Expand Down
Loading