1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
|
#!/usr/bin/python3 -cimport os, sys; os.execv(os.path.dirname(sys.argv[1]) + "/../common/pywrap", sys.argv)
# This file is part of Cockpit.
#
# Copyright (C) 2013 Red Hat, Inc.
#
# Cockpit is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Cockpit is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Cockpit; If not, see <https://www.gnu.org/licenses/>.
import netlib
import testlib
@testlib.nondestructive
class TestNetworkingBasic(netlib.NetworkCase):
def testBasic(self):
b = self.browser
m = self.machine
if not m.ostree_image:
# screenshot assumes running firewalld and absent virbr0 (in particular, *3* interfaces)
m.execute("systemctl start firewalld")
# ensure PCP is on for pixel tests, so that we get the zoom/range selectors
if b.pixels_label:
m.execute("systemctl start pmlogger")
self.login_and_go("/network")
b.wait_visible("#networking")
iface = 'cockpit1'
self.add_veth(iface, dhcp_cidr="10.111.113.2/20")
self.nm_activate_eth(iface)
self.wait_for_iface(iface)
b.wait_not_present("#network-interface")
b.wait_in_text("#networking-graphs", "Transmitting")
b.wait_in_text("#networking-graphs", "Receiving")
# PCP is only enabled for pixel tests
# zoom/range selectors are hidden when PCP is disabled
if b.pixels_label:
b.click("#zoom-control button:nth-of-type(2)")
b.wait_in_text("#zoom-control button.pf-v6-c-menu-toggle", "1 hour")
b.click("#zoom-control button.pf-v6-c-menu-toggle")
b.click(".pf-v6-c-menu ul li:nth-child(3) > button")
b.wait_in_text("#zoom-control button.pf-v6-c-menu-toggle", "5 minutes")
# FIXME: rtl test was flaky, debug it and remove the skip
b.assert_pixels(
"#networking", "network-main",
ignore=[
"td[data-label=Sending]",
"td[data-label=Receiving]",
"td[data-label='IP address']",
"#networking-graphs .pf-v6-l-grid",
".cockpit-log-panel .pf-v6-c-card__body",
"#networking-firewall-summary .pf-v6-c-card__body",
],
# IPv6 addresses vary wildly, and their different rendered widths change the column widths
skip_layouts=['medium', 'mobile', 'rtl']
)
# Details of test iface
self.select_iface(iface)
b.wait_visible("#network-interface")
b.assert_pixels("#network-interface .network-interface-details",
"network-interface",
mock={
"#network-interface-mac": "11:22:33:44:55:66",
".networking-interface-status": "12.123.123.123/20, fedc:0:0:0:1234:ff:abcd:1234/64",
})
con_id = testlib.wait(lambda: self.iface_con_id(iface))
# Toggle "Connect automatically"
#
b.wait_visible('#autoreconnect:checked')
b.set_checked('#autoreconnect', val=False)
self.assertEqual(m.execute(f"nmcli -g connection.autoconnect con show {con_id}"), "no\n")
b.wait_visible('#autoreconnect:not(:checked)')
b.set_checked('#autoreconnect', val=True)
b.wait_visible('#autoreconnect:checked')
self.assertEqual(m.execute(f"nmcli -g connection.autoconnect con show {con_id}"), "yes\n")
# Configure a manual IPv4 address
self.configure_iface_setting('IPv4')
b.wait_visible("#network-ip-settings-dialog")
b.select_from_dropdown("#network-ip-settings-dialog select", "manual")
# Manual mode disables automatic switches
b.wait_visible("#network-ip-settings-dialog [data-field='dns'] input[type=checkbox]:disabled")
b.wait_visible("#network-ip-settings-dialog [data-field='dns_search'] input[type=checkbox]:disabled")
b.wait_visible("#network-ip-settings-dialog [data-field='routes'] input[type=checkbox]:disabled")
b.set_input_text('#network-ip-settings-address-0', "1.2.3.4")
b.set_input_text('#network-ip-settings-netmask-0', "255.255.0.8")
b.click("#network-ip-settings-save")
b.wait_text_not("#network-ip-settings-error h4", "")
b.set_input_text('#network-ip-settings-netmask-0', "255.255.192.0")
b.click("#network-ip-settings-save")
b.wait_not_present("#network-ip-settings-dialog")
self.wait_for_iface_setting("IPv4", "Address 1.2.3.4/18 via 1.2.3.1")
m.execute(f"until ip a show dev {iface} | grep -q 'inet 1.2.3.4/18'; do sleep 0.3; done",
timeout=10)
# Configure manual IPv6 address
b.click("#networking-edit-ipv6")
b.wait_visible("#network-ip-settings-dialog")
b.select_from_dropdown("#network-ip-settings-select-method", "manual")
b.set_input_text("#network-ip-settings-address-0", "2001::1")
b.set_input_text("#network-ip-settings-netmask-0", "64")
b.set_input_text("#network-ip-settings-gateway-0", "::")
b.click("button:contains('Save')")
b.wait_not_present("#network-ip-settings-dialog")
self.wait_for_iface_setting("IPv6", "Address 2001:0:0:0:0:0:0:1/64")
m.execute(f"until ip a show dev {iface} | grep -q 'inet6 2001::1/64 scope global'; do sleep 0.3; done",
timeout=10)
# Disconnect
self.wait_onoff(f".pf-v6-c-card__header:contains('{iface}')", val=True)
self.toggle_onoff(f".pf-v6-c-card__header:contains('{iface}')")
self.wait_for_iface_setting('Status', 'Inactive')
# Reconnect through the UI
self.toggle_onoff(f".pf-v6-c-card__header:contains('{iface}')")
b.wait_in_text(f"#network-interface .pf-v6-c-card:contains('{iface}')", "1.2.3.4/18")
# Disconnect from the CLI, UI reacts
m.execute(f"nmcli device disconnect {iface}")
self.wait_onoff(f".pf-v6-c-card__header:contains('{iface}')", val=False)
# Switch it back to "auto" from the command line and bring it
# up again
#
m.execute(f"nmcli connection modify '{con_id}' ipv4.method auto")
m.execute(f"nmcli connection modify '{con_id}' ipv4.gateway ''")
m.execute(f"nmcli connection modify '{con_id}' ipv4.addresses ''")
self.wait_for_iface_setting('IPv4', "Automatic")
m.execute(f"nmcli connection up '{con_id}'")
self.wait_for_iface_setting('Status', '10.111.')
# Switch off automatic DNS
#
self.configure_iface_setting('IPv4')
b.wait_visible("#network-ip-settings-dialog")
self.wait_onoff("#network-ip-settings-dialog [data-field='dns']", val=True)
self.toggle_onoff("#network-ip-settings-dialog [data-field='dns']")
# The "DNS search domains" setting should follow suit
self.wait_onoff("#network-ip-settings-dialog [data-field='dns_search']", val=False)
b.click("#network-ip-settings-save")
b.wait_not_present("#network-ip-settings-dialog")
testlib.wait(lambda: "yes" in m.execute(f"nmcli -f ipv4.ignore-auto-dns connection show '{con_id}'"))
def testIpHelper(self):
b = self.browser
m = self.machine
self.login_and_go("/network")
b.wait_visible("#networking")
iface = "cockpit1"
self.add_veth(iface, dhcp_cidr="10.111.113.2/20")
self.nm_activate_eth(iface)
self.wait_for_iface(iface)
b.click("button:contains('cockpit1')")
# wait until dialog initialized
b.click("#networking-edit-ipv4:contains('edit')")
b.wait_visible("#network-ip-settings-dialog")
b.select_from_dropdown("#network-ip-settings-select-method", "manual")
b.wait_visible("#network-ip-settings-address-0")
# test class A IP
b.set_input_text("#network-ip-settings-address-0", "10.0.5.1")
b.wait_val("#network-ip-settings-netmask-0", "255.0.0.0")
b.wait_val("#network-ip-settings-gateway-0", "10.0.5.254")
# test class B IP
b.set_input_text("#network-ip-settings-address-0", "172.16.44.2")
b.wait_val("#network-ip-settings-netmask-0", "255.255.0.0")
b.wait_val("#network-ip-settings-gateway-0", "172.16.44.1")
# test class C IP
b.set_input_text("#network-ip-settings-address-0", "192.168.1.1")
b.wait_val("#network-ip-settings-netmask-0", "255.255.255.0")
b.wait_val("#network-ip-settings-gateway-0", "192.168.1.254")
# others | Need to manually reset fields
b.set_input_text("#network-ip-settings-netmask-0", "")
b.set_input_text("#network-ip-settings-gateway-0", "")
b.set_input_text("#network-ip-settings-address-0", "225.4.3.2")
b.wait_val("#network-ip-settings-netmask-0", "")
b.wait_val("#network-ip-settings-gateway-0", "")
# free manual edit & save
b.set_input_text("#network-ip-settings-address-0", "192.168.1.1")
b.set_input_text("#network-ip-settings-netmask-0", "255.255.255.128")
b.set_input_text("#network-ip-settings-gateway-0", "192.168.1.126")
b.click("#network-ip-settings-save")
b.wait_not_present("#network-ip-settings-dialog")
self.assertIn("192.168.1.1/25", m.execute(f"nmcli -g ipv4.addresses connection show {iface}"))
self.assertIn("192.168.1.126", m.execute(f"nmcli -g ipv4.gateway connection show {iface}"))
def testNoService(self):
b = self.browser
m = self.machine
iface = "cockpit42"
self.add_veth(iface)
self.addCleanup(m.execute, "systemctl enable --now NetworkManager")
def assert_running():
b.wait_not_present("#networking-nm-crashed")
b.wait_not_present("#networking-nm-disabled")
b.wait_visible("#networking-graphs")
b.wait_in_text("#networking-interfaces", iface)
def assert_stopped(enabled):
# should hide graphs and actions and show the appropriate notification
b.wait_not_present("#networking-graphs")
b.wait_not_present("#networking-interfaces")
if enabled:
b.wait_visible("#networking-nm-crashed")
b.wait_not_present("#networking-nm-disabled")
else:
b.wait_not_present("#networking-nm-crashed")
b.wait_visible("#networking-nm-disabled")
def assert_not_found():
# should hide graphs and actions and show the appropriate notification
b.wait_not_present("#networking-graphs")
b.wait_not_present("#networking-interfaces")
b.wait_visible("#networking-nm-not-found")
self.login_and_go("/network")
assert_running()
# stop/start NM on CLI, page should notice
m.execute("systemctl stop NetworkManager")
assert_stopped(enabled=True)
m.execute("systemctl start NetworkManager")
assert_running()
# stop NM, test inline start button
m.execute("systemctl stop NetworkManager")
assert_stopped(enabled=True)
b.click("#networking-nm-crashed button")
assert_running()
# stop NM, test troubleshoot button
m.execute("systemctl stop NetworkManager")
assert_stopped(enabled=True)
b.click("#networking-nm-crashed a")
b.enter_page("/system/services")
b.wait_text(".service-name", "Network Manager")
b.click(".service-top-panel button.pf-v6-c-menu-toggle")
b.click("#services-page > .pf-v6-c-menu .pf-v6-c-menu__list-item:contains('Start') button")
b.wait_in_text("#statuses", "Running")
# networking page should notice start from Services page
b.go("/network")
b.enter_page("/network")
assert_running()
# stop and disable NM, enablement info notification
m.execute("systemctl stop NetworkManager; systemctl disable NetworkManager")
assert_stopped(enabled=False)
b.click("#networking-nm-disabled button")
assert_running()
testlib.wait(lambda: m.execute("systemctl is-enabled NetworkManager"))
# /usr in ostree is readonly
if not m.ostree_image:
# remove the NM service file, test 'no-found' notification
# This works for ND tests since there is a self.addCleanup(m.execute, "systemctl enable --now NetworkManager") in the start of the test
self.restore_file('/usr/lib/systemd/system/NetworkManager.service')
m.execute("rm /usr/lib/systemd/system/NetworkManager.service; systemctl daemon-reload; systemctl stop NetworkManager")
assert_not_found()
self.allow_journal_messages(".*org.freedesktop.NetworkManager.*")
# Killing NM affects realmd as well
self.allow_journal_messages(".*org.freedesktop.realmd.Service.*")
def testUnprivileged(self):
b = self.browser
m = self.machine
self.login_and_go("/network", superuser=False)
b.wait_visible("#networking")
iface = 'cockpit1'
self.add_veth(iface, dhcp_cidr="10.111.113.2/20")
self.nm_activate_eth(iface)
self.wait_for_iface(iface)
con_id = testlib.wait(lambda: self.iface_con_id(iface))
mac = m.execute(f"cat /sys/class/net/{iface}/address").strip()
self.select_iface(iface)
b.wait_visible("#network-interface")
# On/Off button is disabled, but shows the correct value
b.wait_visible(f".pf-v6-c-card__header:contains('{iface}') .pf-v6-c-switch input:disabled")
self.wait_onoff(f".pf-v6-c-card__header:contains('{iface}')", val=True)
# not editable
b.wait_visible('#autoreconnect:disabled')
b.wait_not_present("#networking-edit-ipv4")
b.wait_not_present("#networking-edit-mac")
b.wait_text("#network-interface-mac", mac.upper())
# unpriv UI reacts to system change
m.execute(f"nmcli device disconnect {iface}")
self.wait_onoff(f".pf-v6-c-card__header:contains('{iface}')", val=False)
m.execute(f"nmcli connection up '{con_id}'")
self.wait_onoff(f".pf-v6-c-card__header:contains('{iface}')", val=True)
# UI becomes editable when gaining privileges
b.become_superuser()
b.wait_visible('#autoreconnect:not(disabled)')
b.wait_visible("#networking-edit-ipv4")
b.wait_visible("#networking-edit-mac")
b.wait_visible(f".pf-v6-c-card__header:contains('{iface}') .pf-v6-c-switch input:not(disabled)")
if __name__ == '__main__':
testlib.test_main()
|