Skip to content

Commit 76c8464

Browse files
committed
networkmanager: use connection.type as a fallback
fixes: RHEL-131244 When a connection is in the state `down` the `dev` variable can be `null` as no device exists and will be created once the connection is `up`. Use `connection.type` as a fallback to determine what kind of device the IP settings modal is working with.
1 parent fdba746 commit 76c8464

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

pkg/networkmanager/ip-settings.jsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,10 @@ export const IpSettingsDialog = ({ topic, connection, dev, settings }) => {
155155
} else return { ...config, gateway: '' };
156156
};
157157

158+
// Prefer device type if the device exists, otherwise fallback to a connection type
159+
// of an existing connection that is down in which case the device may not exist.
160+
const deviceType = dev?.DeviceType ?? connection?.Settings.connection.type;
161+
158162
return (
159163
<NetworkModal dialogError={dialogError}
160164
idPrefix={idPrefix}
@@ -174,7 +178,7 @@ export const IpSettingsDialog = ({ topic, connection, dev, settings }) => {
174178
aria-label={_("Select method")}
175179
onChange={(_, val) => setMethod(val)}
176180
value={method}>
177-
{get_ip_method_choices(topic, dev.DeviceType).map(choice => <FormSelectOption value={choice.choice} label={choice.title} key={choice.choice} />)}
181+
{get_ip_method_choices(topic, deviceType).map(choice => <FormSelectOption value={choice.choice} label={choice.title} key={choice.choice} />)}
178182
</FormSelect>
179183
<Tooltip content={_("Add address")}>
180184
<Button variant="secondary"

test/verify/check-networkmanager-basic

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,49 @@ class TestNetworkingBasic(netlib.NetworkCase):
156156

157157
testlib.wait(lambda: "yes" in m.execute(f"nmcli -f ipv4.ignore-auto-dns connection show '{con_id}'"))
158158

159+
b.go("/network")
160+
# Create a bridge interface and disable it to test if disabled connections can be modified.
161+
# Connection exists, is down and the device itself does not exist as long as the connection is down
162+
m.execute("nmcli con add con-name cockpitbr type bridge ifname cockpitbr ipv4.meth disab ipv6.meth disab")
163+
self.addCleanup(m.execute, "nmcli con del cockpitbr")
164+
self.wait_for_iface("cockpitbr", prefix="No carrier")
165+
m.execute("nmcli con down cockpitbr")
166+
self.wait_for_iface("cockpitbr", active=False)
167+
# check that connection exists but interface does not
168+
m.execute("nmcli con sh | grep -q 'cockpitbr'")
169+
m.execute("ip link sh | grep -q --invert-match 'cockpitbr'")
170+
171+
self.select_iface("cockpitbr")
172+
b.wait_visible("#network-interface")
173+
self.wait_for_iface_setting("Status", "Inactive")
174+
175+
# Configure IPv4 address
176+
self.configure_iface_setting("IPv4")
177+
b.wait_visible("#network-ip-settings-dialog")
178+
b.select_from_dropdown("#network-ip-settings-select-method", "manual")
179+
b.wait_visible("#network-ip-settings-address-0")
180+
b.set_input_text("#network-ip-settings-address-0", "10.0.5.10")
181+
b.set_input_text("#network-ip-settings-netmask-0", "24")
182+
b.set_input_text("#network-ip-settings-gateway-0", "10.0.5.1")
183+
b.click("#network-ip-settings-save")
184+
self.wait_for_iface_setting("IPv4", "Address 10.0.5.10/24 via 10.0.5.1")
185+
# Configure IPv6 address
186+
self.configure_iface_setting("IPv6")
187+
b.wait_visible("#network-ip-settings-dialog")
188+
b.select_from_dropdown("#network-ip-settings-select-method", "manual")
189+
b.wait_visible("#network-ip-settings-address-0")
190+
b.set_input_text("#network-ip-settings-address-0", "2001:db8::10")
191+
b.set_input_text("#network-ip-settings-netmask-0", "64")
192+
b.set_input_text("#network-ip-settings-gateway-0", "2001:db8::1")
193+
b.click("#network-ip-settings-save")
194+
self.wait_for_iface_setting("IPv6", "Address 2001:db8::10/64 via 2001:db8::1")
195+
196+
# Start the interface and verify new address is set
197+
b.click("#interface-switch")
198+
self.wait_for_iface_setting("Status", "10.0.5.10/24,")
199+
m.execute("ip addr sh cockpitbr | grep -q 'inet 10.0.5.10/24'")
200+
m.execute("ip addr sh cockpitbr | grep -q 'inet6 2001:db8::10/64'")
201+
159202
def testIpHelper(self):
160203
b = self.browser
161204
m = self.machine

0 commit comments

Comments
 (0)