| 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 |
@testlib.nondestructive |
| 14 |
class TestBonding(netlib.NetworkCase): |
| 15 |
def testBasic(self): |
| 16 |
b = self.browser |
| 17 |
|
| 18 |
self.login_and_go("/network") |
| 19 |
|
| 20 |
b.wait_visible("#networking") |
| 21 |
iface1 = "cockpit1" |
| 22 |
self.add_veth(iface1, dhcp_cidr="10.111.113.1/24", dhcp_range=['10.111.113.2', '10.111.113.254']) |
| 23 |
self.nm_activate_eth(iface1) |
| 24 |
iface2 = "cockpit2" |
| 25 |
self.add_veth(iface2, dhcp_cidr="10.111.114.1/24", dhcp_range=['10.111.114.2', '10.111.114.254']) |
| 26 |
self.nm_activate_eth(iface2) |
| 27 |
self.wait_for_iface(iface1) |
| 28 |
self.wait_for_iface(iface2) |
| 29 |
|
| 30 |
# Bond them |
| 31 |
b.click("button:contains('Add bond')") |
| 32 |
b.wait_visible("#network-bond-settings-dialog") |
| 33 |
# wait until dialog initialized |
| 34 |
b.wait_visible("#network-bond-settings-dialog button[aria-label=Close]") |
| 35 |
b.wait_visible("#network-bond-settings-mac-input") |
| 36 |
# menu is not visible by default, but gets initialized dynamically |
| 37 |
b.assert_pixels("#network-bond-settings-dialog", "networking-bond-settings-dialog", |
| 38 |
# help icon gets rendered with unstable noise |
| 39 |
ignore=["#bond-help-popup-button"]) |
| 40 |
|
| 41 |
b.click("#network-bond-settings-dialog button[aria-label=Close]") |
| 42 |
b.wait_not_present("#network-bond-settings-dialog") |
| 43 |
b.click("button:contains('Add bond')") |
| 44 |
b.wait_visible("#network-bond-settings-dialog") |
| 45 |
b.click("#network-bond-settings-dialog #bond-help-popup-button") |
| 46 |
b.wait_in_text("#popover-bond-help-header", "Network bond") |
| 47 |
b.click("#network-bond-settings-dialog #bond-help-popup-button") |
| 48 |
b.wait_not_present("#popover-bond-help-header") |
| 49 |
|
| 50 |
b.set_input_text("#network-bond-settings-interface-name-input", "tbond") |
| 51 |
b.set_checked(f"input[data-iface='{iface1}']", val=True) |
| 52 |
b.set_checked(f"input[data-iface='{iface2}']", val=True) |
| 53 |
b.click("#network-bond-settings-dialog button:contains('Add')") |
| 54 |
b.wait_not_present("#network-bond-settings-dialog") |
| 55 |
|
| 56 |
# Check that the members are displayed and both On |
| 57 |
b.wait_text("#network-interface-name", "tbond") |
| 58 |
b.wait_visible(f"#network-interface-members tr[data-interface='{iface1}']") |
| 59 |
self.wait_onoff(f"#network-interface-members tr[data-interface='{iface1}']", val=True) |
| 60 |
b.wait_visible(f"#network-interface-members tr[data-interface='{iface2}']") |
| 61 |
self.wait_onoff(f"#network-interface-members tr[data-interface='{iface2}']", val=True) |
| 62 |
|
| 63 |
b.wait_text_not("#network-interface-mac", "") |
| 64 |
|
| 65 |
# Check that link monitoring is correctly set up |
| 66 |
b.click("#network-interface-settings [data-label='Bond'] button") |
| 67 |
b.wait_val("#network-bond-settings-link-monitoring-select", "mii") |
| 68 |
b.click("#network-bond-settings-dialog button:contains('Cancel')") |
| 69 |
b.wait_not_present("#network-bond-settings-dialog") |
| 70 |
|
| 71 |
# Navigate to the first member, check it, navigate back |
| 72 |
b.click(f"#network-interface-members tr[data-interface='{iface1}'] button.pf-m-link") |
| 73 |
b.wait_in_text("#network-interface-name", iface1) |
| 74 |
b.wait_in_text("#network-interface-settings", "MTU") |
| 75 |
b.wait_not_in_text("#network-interface-settings", "IPv4") |
| 76 |
b.wait_not_in_text("#network-interface-settings", "IPv6") |
| 77 |
b.click("#network-interface-settings button:contains('tbond')") |
| 78 |
b.wait_in_text("#network-interface-name", "tbond") |
| 79 |
|
| 80 |
# Deactivate the bond and make sure it is still there after a |
| 81 |
# reload. |
| 82 |
self.wait_onoff("label[for='interface-switch']", val=False) |
| 83 |
self.wait_for_iface_setting('Status', 'Inactive') |
| 84 |
b.wait_not_present("#interface-switch:disabled") |
| 85 |
|
| 86 |
b.reload() |
| 87 |
b.enter_page("/network") |
| 88 |
b.wait_text("#network-interface-name", "tbond") |
| 89 |
b.wait_text("#network-interface-hw", "Bond") |
| 90 |
b.wait_visible(f"#network-interface-members tr[data-interface='{iface1}']") |
| 91 |
b.wait_visible(f"#network-interface-members tr[data-interface='{iface2}']") |
| 92 |
|
| 93 |
# Delete the bond |
| 94 |
b.click("#network-interface button:contains('Delete')") |
| 95 |
b.wait_visible("#networking") |
| 96 |
b.wait_not_present("#networking-interfaces tr[data-interface='tbond']") |
| 97 |
|
| 98 |
# Check that the former members are displayed and both On |
| 99 |
self.wait_for_iface(iface1) |
| 100 |
self.wait_for_iface(iface2) |
| 101 |
|
| 102 |
def testNonDefaultSettings(self): |
| 103 |
b = self.browser |
| 104 |
m = self.machine |
| 105 |
|
| 106 |
iface1 = "cockpit1" |
| 107 |
self.add_veth(iface1, dhcp_cidr="10.111.113.1/24", dhcp_range=['10.111.113.2', '10.111.113.254']) |
| 108 |
testlib.wait(lambda: m.execute(f'nmcli device | grep {iface1} | grep -v unavailable')) |
| 109 |
|
| 110 |
iface2 = "cockpit2" |
| 111 |
self.add_veth(iface2, dhcp_cidr="10.111.114.1/24", dhcp_range=['10.111.114.2', '10.111.114.254']) |
| 112 |
testlib.wait(lambda: m.execute(f'nmcli device | grep {iface2} | grep -v unavailable')) |
| 113 |
|
| 114 |
m.execute(f"nmcli con add type ethernet ifname {iface1} con-name TEST1") |
| 115 |
m.execute(f"nmcli con add type ethernet ifname {iface2} con-name TEST2") |
| 116 |
|
| 117 |
self.login_and_go("/network") |
| 118 |
self.wait_for_iface(iface1) |
| 119 |
self.wait_for_iface(iface2) |
| 120 |
|
| 121 |
m.execute("nmcli con mod TEST1 ipv4.method link-local; nmcli con up TEST1") |
| 122 |
m.execute(f"nmcli dev dis {iface2}") |
| 123 |
|
| 124 |
b.wait_in_text(f"tr[data-interface='{iface1}'] td:nth-child(2)", "169.254.") |
| 125 |
b.wait_not_in_text(f"tr[data-interface='{iface1}'] td:nth-child(2)", "10.111.") |
| 126 |
b.wait_text(f"tr[data-interface='{iface2}'] td:nth-child(3)", "Inactive") |
| 127 |
|
| 128 |
b.click("button:contains('Add bond')") |
| 129 |
b.wait_visible("#network-bond-settings-dialog") |
| 130 |
b.set_input_text("#network-bond-settings-interface-name-input", "tbond") |
| 131 |
b.set_checked(f"input[data-iface='{iface1}']", val=True) |
| 132 |
b.set_checked(f"input[data-iface='{iface2}']", val=True) |
| 133 |
b.click("#network-bond-settings-dialog button:contains('Add')") |
| 134 |
b.wait_not_present("#network-bond-settings-dialog") |
| 135 |
|
| 136 |
b.wait_text("#network-interface-name", "tbond") |
| 137 |
self.wait_for_iface_setting('IPv4', 'Link local') |
| 138 |
|
| 139 |
def testRename(self): |
| 140 |
b = self.browser |
| 141 |
m = self.machine |
| 142 |
|
| 143 |
self.login_and_go("/network") |
| 144 |
|
| 145 |
# Wait until the page is really ready by waiting for some ethernet interface |
| 146 |
# to show up in some row. |
| 147 |
iface = m.execute("cd /sys/class/net; ls -d e* | head -n1").strip() |
| 148 |
b.wait_visible(f"tr[data-interface='{iface}']") |
| 149 |
|
| 150 |
iface1 = "cockpit1" |
| 151 |
self.add_veth(iface1, dhcp_cidr="10.111.113.1/24", dhcp_range=['10.111.113.2', '10.111.113.254']) |
| 152 |
self.nm_activate_eth(iface1) |
| 153 |
self.wait_for_iface(iface1) |
| 154 |
|
| 155 |
b.click("button:contains('Add bond')") |
| 156 |
b.wait_visible("#network-bond-settings-dialog") |
| 157 |
b.select_from_dropdown("#network-bond-settings-link-monitoring-select", "arp") |
| 158 |
b.set_input_text("#network-bond-settings-monitoring-targets-input", "1.1.1.1") |
| 159 |
b.set_input_text("#network-bond-settings-interface-name-input", "tbond") |
| 160 |
b.set_checked(f"input[data-iface='{iface1}']", val=True) |
| 161 |
b.click("#network-bond-settings-dialog button:contains('Add')") |
| 162 |
b.wait_not_present("#network-bond-settings-dialog") |
| 163 |
|
| 164 |
# Rename while it is active |
| 165 |
self.addCleanup(m.execute, "nmcli dev delete tbond3000 2>/dev/null || true") |
| 166 |
|
| 167 |
b.wait_text("#network-interface-name", "tbond") |
| 168 |
self.wait_onoff("#network-interface .pf-v6-c-card__header", val=False) |
| 169 |
self.toggle_onoff("label[for='interface-switch']") |
| 170 |
self.wait_onoff("#network-interface .pf-v6-c-card__header", val=True) |
| 171 |
|
| 172 |
self.configure_iface_setting('Bond') |
| 173 |
b.wait_visible("#network-bond-settings-dialog") |
| 174 |
|
| 175 |
# Check that link monitoring is correctly set up |
| 176 |
b.wait_val("#network-bond-settings-link-monitoring-select", "arp") |
| 177 |
b.wait_val("#network-bond-settings-monitoring-targets-input", "1.1.1.1") |
| 178 |
|
| 179 |
b.set_input_text("#network-bond-settings-interface-name-input", "tbond3000") |
| 180 |
b.click("#network-bond-settings-dialog button:contains('Save')") |
| 181 |
b.wait_not_present("#network-bond-settings-dialog") |
| 182 |
b.wait_text("#network-interface-name", "tbond3000") |
| 183 |
|
| 184 |
# Check that the member is still there and active |
| 185 |
b.wait_visible(f"#network-interface-members tr[data-interface='{iface1}']") |
| 186 |
self.wait_onoff(f"#network-interface-members tr[data-interface='{iface1}']", val=True) |
| 187 |
|
| 188 |
def testActive(self): |
| 189 |
b = self.browser |
| 190 |
|
| 191 |
self.login_and_go("/network") |
| 192 |
|
| 193 |
b.wait_visible("#networking") |
| 194 |
iface = "cockpit1" |
| 195 |
self.add_veth(iface, dhcp_cidr="10.111.112.2/20") |
| 196 |
self.nm_activate_eth(iface) |
| 197 |
self.wait_for_iface(iface) |
| 198 |
ip = b.text(f"#networking-interfaces tr[data-interface='{iface}'] td:nth-child(2)") |
| 199 |
|
| 200 |
# Put an active interface into a bond. The bond should get |
| 201 |
# the same IP as the active interface. |
| 202 |
|
| 203 |
b.click("button:contains('Add bond')") |
| 204 |
b.wait_visible("#network-bond-settings-dialog") |
| 205 |
b.set_input_text("#network-bond-settings-interface-name-input", "tbond") |
| 206 |
b.set_checked(f"input[data-iface='{iface}']", val=True) |
| 207 |
b.click("#network-bond-settings-mac-input input") |
| 208 |
b.click("li button:contains('(cockpit1)')") |
| 209 |
b.click("#network-bond-settings-dialog button:contains('Add')") |
| 210 |
b.wait_not_present("#network-bond-settings-dialog") |
| 211 |
|
| 212 |
# Check that it has the interface and the right IP address |
| 213 |
b.wait_text("#network-interface-name", "tbond") |
| 214 |
b.wait_visible(f"#network-interface-members tr[data-interface='{iface}']") |
| 215 |
self.toggle_onoff("label[for='interface-switch']") |
| 216 |
b.wait_in_text("#network-interface .pf-v6-c-card:contains('tbond')", ip) |
| 217 |
|
| 218 |
def testPrimary(self): |
| 219 |
b = self.browser |
| 220 |
|
| 221 |
self.login_and_go("/network") |
| 222 |
|
| 223 |
b.wait_visible("#networking") |
| 224 |
iface = "cockpit" |
| 225 |
self.add_veth(iface, dhcp_cidr="10.111.112.2/20") |
| 226 |
self.nm_activate_eth(iface) |
| 227 |
self.wait_for_iface(iface) |
| 228 |
|
| 229 |
# Create a bond |
| 230 |
b.click("button:contains('Add bond')") |
| 231 |
b.wait_visible("#network-bond-settings-dialog") |
| 232 |
b.set_input_text("#network-bond-settings-interface-name-input", "tbond") |
| 233 |
# add interface to bond |
| 234 |
b.set_checked(f"input[data-iface='{iface}']", val=True) |
| 235 |
# select it as primary |
| 236 |
b.select_from_dropdown("#network-bond-settings-primary-select", iface) |
| 237 |
# finish creating the bond |
| 238 |
b.click("#network-bond-settings-dialog button:contains('Add')") |
| 239 |
b.wait_not_present("#network-bond-settings-dialog") |
| 240 |
b.wait_text("#network-interface-name", "tbond") |
| 241 |
b.click("#network-interface #networking-edit-bond") |
| 242 |
|
| 243 |
# edit bond dialog |
| 244 |
b.wait_visible("#network-bond-settings-dialog") |
| 245 |
b.wait_val("#network-bond-settings-primary-select", iface) |
| 246 |
|
| 247 |
def testAmbiguousMember(self): |
| 248 |
b = self.browser |
| 249 |
m = self.machine |
| 250 |
|
| 251 |
self.login_and_go("/network") |
| 252 |
|
| 253 |
b.wait_visible("#networking") |
| 254 |
iface = "cockpit1" |
| 255 |
self.add_veth(iface, dhcp_cidr="10.111.113.2/20") |
| 256 |
self.nm_activate_eth(iface) |
| 257 |
self.wait_for_iface(iface) |
| 258 |
|
| 259 |
# Now 'iface' has a normal connection |
| 260 |
con_id = self.iface_con_id(iface) |
| 261 |
self.assertTrue(con_id) |
| 262 |
|
| 263 |
# Manually create a bond and make 'iface' its member via a |
| 264 |
# second connection. Cockpit should ignore that second |
| 265 |
# connection and still show iface as a normal interface. |
| 266 |
m.execute(f"nmcli con add type bond-slave ifname {iface} con-name bond0-member-1 master bond0") |
| 267 |
m.execute("nmcli con add type bond ifname bond0 con-name bond0") |
| 268 |
|
| 269 |
self.wait_for_iface("bond0", state="Configuring") |
| 270 |
self.wait_for_iface(iface) |
| 271 |
|
| 272 |
# Now activate 'iface' as a member. Cockpit should now ignore |
| 273 |
# the first connection and show 'iface' as a member of bond0. |
| 274 |
|
| 275 |
m.execute("nmcli con up bond0-member-1") |
| 276 |
b.wait_not_present(f"#networking-interfaces tr[data-interface='{iface}']") |
| 277 |
|
| 278 |
b.click("#networking-interfaces tr[data-interface='bond0'] button") |
| 279 |
b.wait_visible("#network-interface") |
| 280 |
b.wait_visible(f"#network-interface-members tr[data-interface='{iface}']") |
| 281 |
|
| 282 |
|
| 283 |
class TestBondingVirt(netlib.NetworkCase): |
| 284 |
provision = { |
| 285 |
"machine1": {"address": "10.111.113.1/20"}, |
| 286 |
"machine2": {"image": TEST_OS_DEFAULT, "address": "10.111.113.2/20", "dhcp": True} |
| 287 |
} |
| 288 |
|
| 289 |
@testlib.skipImage("Main interface can't be managed", "debian-*", "ubuntu-*") |
| 290 |
def testMain(self): |
| 291 |
b = self.browser |
| 292 |
m = self.machine |
| 293 |
|
| 294 |
iface = self.get_iface(m.networking["mac"]) |
| 295 |
|
| 296 |
self.login_and_go("/network") |
| 297 |
self.wait_for_iface(iface) |
| 298 |
|
| 299 |
# Put the main interface into a bond. Everything should keep working. |
| 300 |
b.click("button:contains('Add bond')") |
| 301 |
b.wait_visible("#network-bond-settings-dialog") |
| 302 |
b.set_input_text("#network-bond-settings-interface-name-input", "tbond") |
| 303 |
b.set_checked(f"input[data-iface='{iface}']", val=True) |
| 304 |
b.click("#network-bond-settings-dialog button:contains('Add')") |
| 305 |
b.wait_not_present("#network-bond-settings-dialog") |
| 306 |
|
| 307 |
# Check that it has the main connection and the right IP address |
| 308 |
b.wait_text("#network-interface-name", "tbond") |
| 309 |
b.wait_visible(f"#network-interface-members tr[data-interface='{iface}']") |
| 310 |
b.wait_in_text("#network-interface .pf-v6-c-card:contains('tbond')", "10.111.113.1") |
| 311 |
|
| 312 |
# Delete the bond |
| 313 |
b.click("#network-interface button:contains('Delete')") |
| 314 |
b.wait_visible("#networking") |
| 315 |
b.wait_not_present("#networking-interfaces tr[data-interface='tbond']") |
| 316 |
b.wait_visible(f"#networking-interfaces tr[data-interface='{iface}']") |
| 317 |
|
| 318 |
@testlib.skipImage("no dhclient on OS image", "arch", "centos-10*", "rhel-10*") |
| 319 |
@testlib.skipImage("Main interface can't be managed", "debian-*", "ubuntu-*") |
| 320 |
@testlib.skipOstree("not using dhclient") |
| 321 |
def testSlowly(self): |
| 322 |
b = self.browser |
| 323 |
m = self.machine |
| 324 |
|
| 325 |
iface = self.get_iface(m.networking["mac"]) |
| 326 |
self.ensure_nm_uses_dhclient() |
| 327 |
|
| 328 |
self.login_and_go("/network") |
| 329 |
self.wait_for_iface(iface) |
| 330 |
|
| 331 |
# Slow down DHCP enough that it would trigger a rollback. |
| 332 |
self.slow_down_dhclient(20) |
| 333 |
|
| 334 |
# Put the main interface into a bond. Everything should keep |
| 335 |
# working since checkpoints are not used and thus no rollback |
| 336 |
# is actually triggered. |
| 337 |
|
| 338 |
b.click("button:contains('Add bond')") |
| 339 |
b.wait_visible("#network-bond-settings-dialog") |
| 340 |
b.set_input_text("#network-bond-settings-interface-name-input", "tbond") |
| 341 |
b.set_checked(f"input[data-iface='{iface}']", val=True) |
| 342 |
b.click("#network-bond-settings-dialog button:contains('Add')") |
| 343 |
b.wait_not_present("#network-bond-settings-dialog") |
| 344 |
|
| 345 |
# Check that it has the main connection and the right IP address |
| 346 |
b.wait_text("#network-interface-name", "tbond") |
| 347 |
b.wait_visible(f"#network-interface-members tr[data-interface='{iface}']") |
| 348 |
b.wait_in_text("#network-interface .pf-v6-c-card:contains('tbond')", "10.111.113.1") |
| 349 |
|
| 350 |
|
| 351 |
if __name__ == '__main__': |
| 352 |
testlib.test_main() |