| 1 |
#!/usr/bin/python3 -cimport os, sys; os.execv(os.path.dirname(sys.argv[1]) + "/../common/pywrap", sys.argv) |
| 2 |
|
| 3 |
# |
| 4 |
# Copyright (C) 2013 Red Hat, Inc. |
| 5 |
# SPDX-License-Identifier: LGPL-2.1-or-later |
| 6 |
|
| 7 |
|
| 8 |
import netlib |
| 9 |
import testlib |
| 10 |
from lib.constants import TEST_OS_DEFAULT |
| 11 |
|
| 12 |
|
| 13 |
class TestNetworkingSettings(netlib.NetworkCase): |
| 14 |
provision = { |
| 15 |
"machine1": {}, |
| 16 |
"machine2": {"image": TEST_OS_DEFAULT, "address": "10.111.113.2/20", "dhcp": True} |
| 17 |
} |
| 18 |
|
| 19 |
def testNoConnectionSettings(self): |
| 20 |
b = self.browser |
| 21 |
m = self.machine |
| 22 |
|
| 23 |
self.login_and_go("/network") |
| 24 |
b.wait_visible("#networking") |
| 25 |
|
| 26 |
iface = self.add_iface(activate=False) |
| 27 |
self.wait_for_iface(iface, active=False) |
| 28 |
# checkpoints are realtime sensitive, avoid long NM operations |
| 29 |
self.settle_cpu() |
| 30 |
|
| 31 |
self.select_iface(iface) |
| 32 |
b.wait_visible("#network-interface") |
| 33 |
|
| 34 |
# Check that there is no connection for the device |
| 35 |
cons = m.execute(f"nmcli -t -m tabular -f CONNECTIONS.AVAILABLE-CONNECTION-PATHS dev show {iface}") |
| 36 |
self.assertEqual(cons.strip(), "") |
| 37 |
|
| 38 |
# Edit and apply the ghost settings |
| 39 |
self.configure_iface_setting('IPv4') |
| 40 |
b.wait_visible("#network-ip-settings-dialog") |
| 41 |
b.select_from_dropdown("#network-ip-settings-select-method", "manual") |
| 42 |
b.set_input_text('#network-ip-settings-address-0', "1.2.3.4") |
| 43 |
b.set_input_text('#network-ip-settings-netmask-0', "24") |
| 44 |
b.click("#network-ip-settings-save") |
| 45 |
b.wait_not_present("#network-ip-settings-dialog") |
| 46 |
self.wait_for_iface_setting('IPv4', 'Address 1.2.3.4/24') |
| 47 |
self.toggle_onoff("label[for='interface-switch']") |
| 48 |
|
| 49 |
def assert_connection_setting(con_id, field, value): |
| 50 |
self.assertEqual(m.execute(f'nmcli -m tabular -t -f {field} con show "{con_id}"').strip(), |
| 51 |
value) |
| 52 |
|
| 53 |
# Check that we now have connection settings |
| 54 |
con_id = testlib.wait(lambda: self.iface_con_id(iface)) |
| 55 |
assert_connection_setting(con_id, "ipv4.method", "manual") |
| 56 |
|
| 57 |
# The interface will be activated. Deactivate it. |
| 58 |
self.wait_for_iface_setting('Status', '1.2.3.4/24') |
| 59 |
self.toggle_onoff("label[for='interface-switch']") |
| 60 |
self.wait_for_iface_setting('Status', 'Inactive') |
| 61 |
|
| 62 |
# Delete the connection settings again and wait for the ghost |
| 63 |
# settings to be re-created. |
| 64 |
m.execute(f'nmcli con del "{con_id}"') |
| 65 |
self.wait_for_iface_setting('IPv4', 'Automatic') |
| 66 |
|
| 67 |
# Activate with ghost settings |
| 68 |
self.toggle_onoff("label[for='interface-switch']") |
| 69 |
self.wait_for_iface_setting('Status', '10.111.') |
| 70 |
|
| 71 |
# Check again that we now have connection settings |
| 72 |
con_id = testlib.wait(lambda: self.iface_con_id(iface)) |
| 73 |
assert_connection_setting(con_id, "ipv4.method", "auto") |
| 74 |
|
| 75 |
# Change some more settings and check that the actual config |
| 76 |
# and dialog reflects the change |
| 77 |
|
| 78 |
self.configure_iface_setting('IPv4') |
| 79 |
b.wait_visible("#network-ip-settings-dialog") |
| 80 |
self.wait_onoff("[data-field=dns]", val=True) |
| 81 |
self.toggle_onoff("[data-field=dns]") |
| 82 |
self.wait_onoff("[data-field=dns_search]", val=False) |
| 83 |
b.click("#network-ip-settings-dns-add") |
| 84 |
b.set_input_text("#network-ip-settings-dns-server-0", "1.2.3.4") |
| 85 |
b.click("#network-ip-settings-dns-search-add") |
| 86 |
b.set_input_text("#network-ip-settings-search-domain-0", "foo.com") |
| 87 |
b.click("#network-ip-settings-save") |
| 88 |
b.wait_not_present("#network-ip-settings-dialog") |
| 89 |
|
| 90 |
assert_connection_setting(con_id, "ipv4.ignore-auto-dns", "yes") |
| 91 |
assert_connection_setting(con_id, "ipv4.dns", "1.2.3.4") |
| 92 |
assert_connection_setting(con_id, "ipv4.dns-search", "foo.com") |
| 93 |
|
| 94 |
self.configure_iface_setting('IPv4') |
| 95 |
self.wait_onoff("[data-field=dns]", val=False) |
| 96 |
self.wait_onoff("[data-field=dns_search]", val=False) |
| 97 |
b.wait_val("#network-ip-settings-dns-server-0", "1.2.3.4") |
| 98 |
b.wait_val("#network-ip-settings-search-domain-0", "foo.com") |
| 99 |
b.click("#network-ip-settings-cancel") |
| 100 |
b.wait_not_present("#network-ip-settings-dialog") |
| 101 |
|
| 102 |
self.configure_iface_setting('IPv6') |
| 103 |
b.wait_visible("#network-ip-settings-dialog") |
| 104 |
b.select_from_dropdown("#network-ip-settings-select-method", "disabled") |
| 105 |
b.click("#network-ip-settings-save") |
| 106 |
b.wait_not_present("#network-ip-settings-dialog") |
| 107 |
|
| 108 |
assert_connection_setting(con_id, "ipv6.method", "disabled") |
| 109 |
|
| 110 |
# Open the dialog, expand all the fields and assert pixels |
| 111 |
self.configure_iface_setting("IPv4") |
| 112 |
b.click("#network-ip-settings-address-add") |
| 113 |
b.click("#network-ip-settings-route-add") |
| 114 |
b.click("#network-ip-settings-dns-add") |
| 115 |
b.click("#network-ip-settings-dns-search-add") |
| 116 |
b.assert_pixels("#network-ip-settings-dialog", "network-ip-settings-dialog") |
| 117 |
|
| 118 |
# Check that IPv4/IPv6 settings dialogs only show the supported IP methods for wireguard |
| 119 |
# Skip images without the wireguard-tools package |
| 120 |
if not m.image.startswith("rhel-8"): |
| 121 |
b.go("/network") |
| 122 |
b.click("#networking-add-wg") |
| 123 |
b.set_input_text("#network-wireguard-settings-addresses-input", "1.2.3.4/24") |
| 124 |
wg_iface = b.val("#network-wireguard-settings-interface-name-input") |
| 125 |
b.click("#network-wireguard-settings-save") |
| 126 |
b.wait_text("#network-interface-name", wg_iface) |
| 127 |
self.configure_iface_setting("IPv4") |
| 128 |
b._wait_present("#network-ip-settings-select-method option[value='manual']") |
| 129 |
b._wait_present("#network-ip-settings-select-method option[value='disabled']") |
| 130 |
unsupported_ip4_methods = ['auto', 'dhcp', 'link-local', 'ignore', 'shared'] |
| 131 |
for method in unsupported_ip4_methods: |
| 132 |
b.wait_not_present(f"#network-ip-settings-select-method option[value='{method}']") |
| 133 |
b.click("#network-ip-settings-cancel") |
| 134 |
b.wait_not_present("#network-ip-settings-dialog") |
| 135 |
self.configure_iface_setting("IPv6") |
| 136 |
supported_ip6_methods = ['link-local', 'manual', 'disabled'] |
| 137 |
for method in supported_ip6_methods: |
| 138 |
b._wait_present(f"#network-ip-settings-select-method option[value='{method}']") |
| 139 |
unsupported_ip6_methods = ['auto', 'dhcp', 'ignore', 'shared'] |
| 140 |
for method in unsupported_ip6_methods: |
| 141 |
b.wait_not_present(f"#network-ip-settings-select-method option[value='{method}']") |
| 142 |
|
| 143 |
def testOtherSettings(self): |
| 144 |
b = self.browser |
| 145 |
m = self.machine |
| 146 |
|
| 147 |
iface = self.add_iface() |
| 148 |
con_id = self.iface_con_id(iface) |
| 149 |
m.execute(f"nmcli con mod '{con_id}' connection.gateway-ping-timeout 12") |
| 150 |
|
| 151 |
self.login_and_go("/network") |
| 152 |
self.wait_for_iface(iface) |
| 153 |
|
| 154 |
# IPv4 address sharing |
| 155 |
|
| 156 |
self.select_iface(iface) |
| 157 |
b.wait_visible("#network-interface") |
| 158 |
|
| 159 |
self.configure_iface_setting('IPv4') |
| 160 |
b.wait_visible("#network-ip-settings-dialog") |
| 161 |
b.select_from_dropdown("#network-ip-settings-select-method", "shared") |
| 162 |
b.click("#network-ip-settings-save") |
| 163 |
b.wait_not_present("#network-ip-settings-dialog") |
| 164 |
|
| 165 |
self.assertEqual(m.execute(f"nmcli -m tabular -t -f ipv4.method con show '{con_id}'").strip(), |
| 166 |
"shared") |
| 167 |
self.assertEqual(m.execute(f"nmcli -m tabular -t -f connection.gateway-ping-timeout con show '{con_id}'").strip(), |
| 168 |
"12") |
| 169 |
|
| 170 |
# IPv6 route |
| 171 |
|
| 172 |
# by default there's a route to link-local only (fe80::) |
| 173 |
show_cmd = f"ip -6 route show dev {iface}" |
| 174 |
testlib.wait(lambda: "fe80::/64" in m.execute(show_cmd)) |
| 175 |
# add a manual one |
| 176 |
self.configure_iface_setting('IPv6') |
| 177 |
b.wait_visible("#network-ip-settings-dialog") |
| 178 |
b.click('#network-ip-settings-route-add') |
| 179 |
b.set_input_text('#network-ip-settings-route-address-0', "fe80:2::") |
| 180 |
b.set_input_text('#network-ip-settings-route-netmask-0', "60") |
| 181 |
b.set_input_text('#network-ip-settings-route-gateway-0', "fe80:2::3") |
| 182 |
b.set_input_text('#network-ip-settings-route-metric-0', "42") |
| 183 |
b.click('#network-ip-settings-save') |
| 184 |
b.wait_not_present("#network-ip-settings-dialog") |
| 185 |
|
| 186 |
# setting should be applied |
| 187 |
testlib.wait(lambda: "metric 42" in m.execute(show_cmd)) |
| 188 |
out = m.execute(show_cmd) |
| 189 |
self.assertIn("fe80:2::/60 via fe80:2::3 proto static metric 42", out) |
| 190 |
self.assertIn("fe80:2::3 proto static metric 42", out) |
| 191 |
# original link-local route still exists |
| 192 |
self.assertIn("fe80::/64", out) |
| 193 |
|
| 194 |
b.wait_attr("#network-interface", "data-test-wait", "false") |
| 195 |
|
| 196 |
# dialog prefills fields with current settings |
| 197 |
self.configure_iface_setting('IPv6') |
| 198 |
b.wait_visible("#network-ip-settings-dialog") |
| 199 |
|
| 200 |
b.wait_val('#network-ip-settings-route-address-0', "fe80:2::") |
| 201 |
b.wait_val('#network-ip-settings-route-netmask-0', "60") |
| 202 |
b.wait_val('#network-ip-settings-route-gateway-0', "fe80:2::3") |
| 203 |
b.wait_val('#network-ip-settings-route-metric-0', "42") |
| 204 |
b.click('#network-ip-settings-cancel') |
| 205 |
b.wait_not_present("#network-ip-settings-dialog") |
| 206 |
|
| 207 |
# Test editing connection without a hardcoded interface |
| 208 |
iface = self.add_iface(activate=False) |
| 209 |
con_name = "cockpit-test-con" |
| 210 |
b.go("/network") |
| 211 |
b.wait_visible("#networking") |
| 212 |
|
| 213 |
m.execute(f""" |
| 214 |
nmcli con add con-name {con_name} connection.type 802-3-ethernet connection.autoconnect no \ |
| 215 |
ipv4.meth auto ipv6.meth auto ipv6.addr-gen-mode eui64 |
| 216 |
nmcli con sh | grep -q '{con_name}' |
| 217 |
nmcli con up {con_name} ifname {iface} |
| 218 |
# check that no connection.interface-name is configured |
| 219 |
[ -z "$(nmcli --get connection.interface-name con sh {con_name})" ] |
| 220 |
""") |
| 221 |
self.addCleanup(m.execute, f"nmcli con del {con_name}") |
| 222 |
|
| 223 |
self.select_iface(iface) |
| 224 |
b.wait_visible("#network-interface") |
| 225 |
self.configure_iface_setting('IPv4') |
| 226 |
b.click("#network-ip-settings-dns-add") |
| 227 |
b.set_input_text('#network-ip-settings-dns-server-0', "8.8.8.8") |
| 228 |
b.click("#network-ip-settings-save") |
| 229 |
# page should still display interface detail page after saving |
| 230 |
b.wait_visible("#network-interface") |
| 231 |
self.wait_for_iface_setting("IPv4", "AutomaticAdditional DNS 8.8.8.8") |
| 232 |
|
| 233 |
# Test multiconnect connection |
| 234 |
b.go("/network") |
| 235 |
b.wait_visible("#networking") |
| 236 |
iface1 = self.add_iface(activate=False) |
| 237 |
iface2 = self.add_iface(activate=False) |
| 238 |
# add temporary connections with multiconnect enabled |
| 239 |
m.execute(f""" |
| 240 |
nmcli con add con-name 'Wired Connection' save no connection.type 802-3-ethernet \ |
| 241 |
connection.autoconnect no connection.multi-connect multiple \ |
| 242 |
ipv4.meth auto ipv6.meth auto ipv6.addr-gen-mode eui64 |
| 243 |
nmcli con sh | grep -q 'Wired Connection' |
| 244 |
|
| 245 |
for IFACE in {iface1} {iface2}; do |
| 246 |
nmcli con up 'Wired Connection' ifname ${{IFACE}} |
| 247 |
done |
| 248 |
""") |
| 249 |
|
| 250 |
# Edit interface with nonpersistent Wired Connection active |
| 251 |
self.select_iface(iface1) |
| 252 |
b.wait_visible("#network-interface") |
| 253 |
self.configure_iface_setting('IPv4') |
| 254 |
b.select_from_dropdown("#network-ip-settings-select-method", "manual") |
| 255 |
b.set_input_text('#network-ip-settings-address-0', "10.11.12.13") |
| 256 |
b.set_input_text('#network-ip-settings-netmask-0', "24") |
| 257 |
b.click("#network-ip-settings-dns-add") |
| 258 |
b.set_input_text('#network-ip-settings-dns-server-0', "8.8.8.8") |
| 259 |
b.click("#network-ip-settings-save") |
| 260 |
b.wait_not_present("#network-ip-settings-dialog") |
| 261 |
self.wait_for_iface_setting("IPv4", "Address 10.11.12.13/24Gateway 10.11.12.1DNS 8.8.8.8") |
| 262 |
# Check that new connection exists and is applied to the interface |
| 263 |
self.assertEqual(m.execute(f"nmcli --get connection.interface-name,connection.multi-connect,ipv4.addresses,ipv4.dns con sh {iface1}"), |
| 264 |
f"{iface1}\n0\n10.11.12.13/24\n8.8.8.8\n") |
| 265 |
# Wired Connection is unmodified |
| 266 |
self.assertEqual(m.execute("nmcli --get ipv4.method con sh 'Wired Connection'"), "auto\n") |
| 267 |
|
| 268 |
# Further edits will edit the new connection |
| 269 |
self.configure_iface_setting('IPv4') |
| 270 |
b.set_input_text('#network-ip-settings-dns-server-0', "1.1.1.1") |
| 271 |
b.click("#network-ip-settings-save") |
| 272 |
b.wait_not_present("#network-ip-settings-dialog") |
| 273 |
self.wait_for_iface_setting("IPv4", "Address 10.11.12.13/24Gateway 10.11.12.1DNS 1.1.1.1") |
| 274 |
m.execute(f'[ $(nmcli --get ipv4.dns con sh {iface1}) == "1.1.1.1" ]') |
| 275 |
|
| 276 |
# Editing auto-connect also creates new connection when necessary |
| 277 |
b.go("/network") |
| 278 |
b.wait_visible("#networking") |
| 279 |
self.select_iface(iface2) |
| 280 |
b.wait_visible("#network-interface") |
| 281 |
b.wait_visible('#autoreconnect:not(:checked)') |
| 282 |
b.set_checked('#autoreconnect', val=True) |
| 283 |
b.wait_visible('#autoreconnect:checked') |
| 284 |
# Check that new connection exists and autoconnect is enabled |
| 285 |
self.assertEqual( |
| 286 |
m.execute(f"nmcli --get connection.interface-name,connection.autoconnect,connection.multi-connect con sh {iface2}"), |
| 287 |
f"{iface2}\nyes\n0\n") |
| 288 |
|
| 289 |
|
| 290 |
if __name__ == '__main__': |
| 291 |
testlib.test_main() |