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

networkmanager: fix primary bond option #21533

Merged
merged 3 commits into from
Feb 12, 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
19 changes: 14 additions & 5 deletions pkg/networkmanager/bond.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ const bond_monitoring_choices =
{ choice: 'arp', title: _("ARP") }
];

const modes_with_primary = [
'active-backup',
'balance-tlb',
'balance-alb'
];

export const BondDialog = ({ connection, dev, settings }) => {
const Dialogs = useDialogs();
const idPrefix = "network-bond-settings";
Expand All @@ -77,9 +83,12 @@ export const BondDialog = ({ connection, dev, settings }) => {
const [memberChoices, setMemberChoices] = useState(memberChoicesInit);
const [mode, setMode] = useState(options.mode);
const [monitoringTargets, setMonitoringTargets] = useState(options.arp_ip_target);
const [primary, setPrimary] = useState(undefined);
const [primary, setPrimary] = useState(options.primary);

const onSubmit = (ev) => {
const options = settings.bond.options;
delete options.primary;

const createSettingsObj = () => ({
...settings,
connection: {
Expand All @@ -94,7 +103,7 @@ export const BondDialog = ({ connection, dev, settings }) => {
...settings.bond,
interface_name: iface,
options: {
...settings.bond.options,
...options,
mode,
...(linkMonitoring == 'mii' && {
miimon: linkMonitoringInterval,
Expand All @@ -105,7 +114,7 @@ export const BondDialog = ({ connection, dev, settings }) => {
arp_interval: linkMonitoringInterval,
arp_ip_target: monitoringTargets,
}),
...(mode == "active-backup" && { primary })
...(modes_with_primary.includes(mode) && primary && { primary })
}
}
});
Expand Down Expand Up @@ -174,11 +183,11 @@ export const BondDialog = ({ connection, dev, settings }) => {
{bond_mode_choices.map(choice => <FormSelectOption value={choice.choice} label={choice.title} key={choice.choice} />)}
</FormSelect>
</FormGroup>
{mode == "active-backup" && <FormGroup fieldId={idPrefix + "-primary-select"} label={_("Primary")}>
{modes_with_primary.includes(mode) && <FormGroup fieldId={idPrefix + "-primary-select"} label={_("Primary")}>
<FormSelect id={idPrefix + "-primary-select"} onChange={(_, val) => setPrimary(val)}
value={primary}>
<>
<FormSelectOption key='-' value={null} label='-' />
<FormSelectOption key='-' value='' label='-' />
{Object.keys(memberChoices)
.filter(iface => memberChoices[iface])
.map(iface => <FormSelectOption key={iface} label={iface} value={iface} />)}
Expand Down
32 changes: 32 additions & 0 deletions test/verify/check-networkmanager-bond
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,38 @@ class TestBonding(netlib.NetworkCase):
b.wait_visible(f"#network-interface-members tr[data-interface='{iface}']")
b.wait_in_text("#network-interface .pf-v5-c-card:contains('tbond')", ip)

def testPrimary(self):
b = self.browser

self.login_and_go("/network")

b.wait_visible("#networking")
iface = "cockpit"
self.add_veth(iface, dhcp_cidr="10.111.112.2/20")
self.nm_activate_eth(iface)
self.wait_for_iface(iface)

# Create a bond
b.click("button:contains('Add bond')")
b.wait_visible("#network-bond-settings-dialog")
b.set_input_text("#network-bond-settings-interface-name-input", "tbond")
# add interface to bond
b.set_checked(f"input[data-iface='{iface}']", val=True)
# select it as primary
b.select_from_dropdown("#network-bond-settings-primary-select", iface)
# finish creating the bond
b.click("#network-bond-settings-dialog button:contains('Add')")
b.wait_not_present("#network-bond-settings-dialog")

# Navigate to bond and edit it
b.click("#networking-interfaces tr[data-interface='tbond'] button")
b.wait_visible("#network-interface")
b.click("#network-interface #networking-edit-bond")

# edit bond dialog
b.wait_visible("#network-bond-settings-dialog")
b.wait_val("#network-bond-settings-primary-select", iface)

def testAmbiguousMember(self):
b = self.browser
m = self.machine
Expand Down