diff --git a/test/common/testlib.py b/test/common/testlib.py index f6bb4e892058..861f02e88245 100644 --- a/test/common/testlib.py +++ b/test/common/testlib.py @@ -1625,6 +1625,33 @@ def login_and_go(self, path: Optional[str] = None, user: Optional[str] = None, h with self.browser.wait_timeout(30): self.browser.login_and_go(path, user=user, host=host, superuser=superuser, urlroot=urlroot, tls=tls) + def start_machine_troubleshoot(self, new=False, known_host=False, password=None, expect_closed_dialog=True, browser=None): + b = browser or self.browser + + b.wait_visible("#machine-troubleshoot") + b.click('#machine-troubleshoot') + + b.wait_visible('#hosts_setup_server_dialog') + if new: + b.click('#hosts_setup_server_dialog button:contains(Add)') + if not known_host: + b.wait_in_text('#hosts_setup_server_dialog', "You are connecting to") + b.wait_in_text('#hosts_setup_server_dialog', "for the first time.") + b.click("#hosts_setup_server_dialog button:contains('Trust and add host')") + if password: + b.wait_in_text('#hosts_setup_server_dialog', "Unable to log in") + b.set_input_text('#login-custom-password', password) + b.click('#hosts_setup_server_dialog button:contains(Log in)') + if expect_closed_dialog: + b.wait_not_present('#hosts_setup_server_dialog') + + def add_machine(self, address, known_host=False, password="foobar", browser=None): + b = browser or self.browser + b.switch_to_top() + b.go(f"/@{address}") + self.start_machine_troubleshoot(new=True, known_host=known_host, password=password, browser=browser) + b.enter_page("/system", host=address) + # List of allowed journal messages during tests; these need to match the *entire* message default_allowed_messages = [ # This is a failed login, which happens every time diff --git a/test/verify/check-shell-host-switching b/test/verify/check-shell-host-switching index 03e34080c37e..3b251a6784c9 100755 --- a/test/verify/check-shell-host-switching +++ b/test/verify/check-shell-host-switching @@ -61,7 +61,7 @@ class HostSwitcherHelpers: return true; })""", address) - def add_machine(self, b, address, known_host=False, pixel_label=None): + def add_new_machine(self, b, address, known_host=False, pixel_label=None): b.click("button:contains('Add new host')") b.wait_visible('#hosts_setup_server_dialog') b.set_input_text('#add-machine-address', address) @@ -139,7 +139,7 @@ class TestHostSwitching(testlib.MachineCase, HostSwitcherHelpers): b.wait_in_text("#nav-hosts .nav-item a", "mydhcpname") m1.execute("hostnamectl set-hostname 'localhost'") - self.add_machine(b, "10.111.113.2", pixel_label="host-add-dialog") + self.add_new_machine(b, "10.111.113.2", pixel_label="host-add-dialog") self.wait_host_addresses(b, ["localhost", "10.111.113.2"]) self.connect_and_wait(b, "10.111.113.2") @@ -156,7 +156,7 @@ class TestHostSwitching(testlib.MachineCase, HostSwitcherHelpers): b.wait_not_present(".nav-item a[href='/@10.111.113.2'] .nav-status") - self.add_machine(b, "10.111.113.3") + self.add_new_machine(b, "10.111.113.3") self.wait_host_addresses(b, ["localhost", "10.111.113.3", "10.111.113.2"]) self.connect_and_wait(b, "10.111.113.3") @@ -173,7 +173,7 @@ class TestHostSwitching(testlib.MachineCase, HostSwitcherHelpers): self.check_discovered_addresses(b, ["10.111.113.2", "10.111.113.3"]) # Add one back, check addresses on both browsers - self.add_machine(b, "10.111.113.2", known_host=True) + self.add_new_machine(b, "10.111.113.2", known_host=True) self.wait_host_addresses(b, ["localhost", "10.111.113.2"]) self.connect_and_wait(b, "10.111.113.2") self.check_discovered_addresses(b, ["10.111.113.3"]) @@ -181,7 +181,7 @@ class TestHostSwitching(testlib.MachineCase, HostSwitcherHelpers): b.wait_not_present(".nav-item a[href='/@10.111.113.2'] .nav-status") # And the second one, check addresses - self.add_machine(b, "10.111.113.3", known_host=True) + self.add_new_machine(b, "10.111.113.3", known_host=True) self.wait_host_addresses(b, ["localhost", "10.111.113.2", "10.111.113.3"]) self.connect_and_wait(b, "10.111.113.3") self.check_discovered_addresses(b, []) @@ -260,7 +260,7 @@ class TestHostSwitching(testlib.MachineCase, HostSwitcherHelpers): b2.click("#hosts-sel button") self.wait_host_addresses(b2, ["localhost"]) - self.add_machine(b, "10.111.113.2") + self.add_new_machine(b, "10.111.113.2") self.wait_host_addresses(b, ["localhost", "10.111.113.2"]) self.wait_host_addresses(b2, ["localhost", "10.111.113.2"]) self.connect_and_wait(b, "10.111.113.2") @@ -278,7 +278,7 @@ class TestHostSwitching(testlib.MachineCase, HostSwitcherHelpers): b.wait_not_present(".nav-item a[href='/@10.111.113.2'] .nav-status") - self.add_machine(b, "10.111.113.3") + self.add_new_machine(b, "10.111.113.3") self.wait_host_addresses(b, ["localhost", "10.111.113.3", "10.111.113.2"]) self.wait_host_addresses(b2, ["localhost", "10.111.113.3", "10.111.113.2"]) self.connect_and_wait(b, "10.111.113.3") @@ -299,7 +299,7 @@ class TestHostSwitching(testlib.MachineCase, HostSwitcherHelpers): self.check_discovered_addresses(b2, ["10.111.113.2", "10.111.113.3"]) # Add one back, check addresses on both browsers - self.add_machine(b, "10.111.113.2", known_host=True) + self.add_new_machine(b, "10.111.113.2", known_host=True) self.wait_host_addresses(b, ["localhost", "10.111.113.2"]) self.wait_host_addresses(b2, ["localhost", "10.111.113.2"]) self.connect_and_wait(b, "10.111.113.2") @@ -309,7 +309,7 @@ class TestHostSwitching(testlib.MachineCase, HostSwitcherHelpers): b.wait_not_present(".nav-item a[href='/@10.111.113.2'] .nav-status") # And the second one, check addresses on both browsers - self.add_machine(b, "10.111.113.3", known_host=True) + self.add_new_machine(b, "10.111.113.3", known_host=True) self.wait_host_addresses(b, ["localhost", "10.111.113.2", "10.111.113.3"]) self.wait_host_addresses(b2, ["localhost", "10.111.113.2", "10.111.113.3"]) self.connect_and_wait(b, "10.111.113.3") @@ -338,7 +338,7 @@ class TestHostSwitching(testlib.MachineCase, HostSwitcherHelpers): self.login_and_go(superuser=False) b.click("#hosts-sel button") - self.add_machine(b, "10.111.113.3") + self.add_new_machine(b, "10.111.113.3") self.wait_host_addresses(b, ["localhost", "10.111.113.3"]) self.connect_and_wait(b, "10.111.113.3") @@ -433,7 +433,7 @@ class TestHostSwitching(testlib.MachineCase, HostSwitcherHelpers): # And and connect to a second machine b.click("#hosts-sel button") - self.add_machine(b, "10.111.113.2") + self.add_new_machine(b, "10.111.113.2") b.click("a[href='/@10.111.113.2']") b.wait_visible("iframe.container-frame[name='cockpit1:10.111.113.2/system']") self.assertIn("admin", m2.execute("loginctl")) diff --git a/test/verify/check-shell-multi-machine b/test/verify/check-shell-multi-machine index bf0a9e1537cb..c79be854310e 100755 --- a/test/verify/check-shell-multi-machine +++ b/test/verify/check-shell-multi-machine @@ -62,36 +62,12 @@ def check_failed_state(b, expected_title): b.wait_not_present('#hosts_setup_server_dialog') -def start_machine_troubleshoot(b, new=False, known_host=False, password=None): - b.wait_visible("#machine-troubleshoot") - b.click('#machine-troubleshoot') - b.wait_visible('#hosts_setup_server_dialog') - if new: - b.click('#hosts_setup_server_dialog button:contains(Add)') - if not known_host: - b.wait_in_text('#hosts_setup_server_dialog', "You are connecting to") - b.wait_in_text('#hosts_setup_server_dialog', "for the first time.") - b.click("#hosts_setup_server_dialog button:contains('Trust and add host')") - if password: - b.wait_in_text('#hosts_setup_server_dialog', "Unable to log in") - b.set_input_text('#login-custom-password', password) - b.click('#hosts_setup_server_dialog button:contains(Log in)') - - def fail_login(b): b.click('#hosts_setup_server_dialog button:contains(Log in)') b.wait_visible('#hosts_setup_server_dialog button:contains(Log in):not([disabled])') b.wait_in_text("#hosts_setup_server_dialog .pf-v5-c-alert", "Login failed") -def add_machine(b, address, known_host=False, password="foobar"): - b.switch_to_top() - b.go(f"/@{address}") - start_machine_troubleshoot(b, new=True, known_host=known_host, password=password) - b.wait_not_present('#hosts_setup_server_dialog') - b.enter_page("/system", host=address) - - def kill_user_admin(machine): machine.execute("loginctl terminate-user admin") @@ -167,8 +143,8 @@ class TestMultiMachineAdd(testlib.MachineCase): hostname_selector = "#system_information_hostname_text" self.login_and_go(None) - add_machine(b, "10.111.113.2", password=None) - add_machine(b, m3_host, password=None) + self.add_machine("10.111.113.2", password=None) + self.add_machine(m3_host, password=None) b.switch_to_top() b.click("#hosts-sel button") @@ -224,8 +200,8 @@ class TestMultiMachineAdd(testlib.MachineCase): m.write("/etc/ssh/ssh_config", "Host m3\n\tHostName 10.111.113.3\n\tPort 2222\n", append=True) self.login_and_go(None) - add_machine(b, "m2", password=None) - add_machine(b, "m3", password=None) + self.add_machine("m2", password=None) + self.add_machine("m3", password=None) b.switch_to_top() b.click("#hosts-sel button") @@ -385,7 +361,7 @@ class TestMultiMachine(testlib.MachineCase): b.wait_js_cond('window.location.pathname == "/cockpit-new/system"') # Test 2nd machine - add_machine(b, "10.111.113.2") + self.add_machine("10.111.113.2") b.enter_page("/system", host="10.111.113.2") b.wait_text(hostname_selector, "machine2") b.switch_to_top() @@ -438,7 +414,7 @@ class TestMultiMachine(testlib.MachineCase): mount -o bind /tmp/"$(basename $FILENAME)" $FILENAME""") self.login_and_go("/system") - add_machine(b, "10.111.113.2") + self.add_machine("10.111.113.2") b.leave_page() b.go("/@10.111.113.2/system/terminal") @@ -461,7 +437,7 @@ class TestMultiMachine(testlib.MachineCase): # Add a machine self.login_and_go(None) - add_machine(b, "10.111.113.2") + self.add_machine("10.111.113.2") # Go to the path, remove the image b.go(m2_path) @@ -505,12 +481,7 @@ class TestMultiMachine(testlib.MachineCase): b.go(m2_path) with b.wait_timeout(30): b.wait_text(".curtains-ct h1", "Not connected to host") - b.click("#machine-troubleshoot") - b.wait_visible('#hosts_setup_server_dialog') - b.wait_in_text('#hosts_setup_server_dialog', "Unable to log in") - b.set_input_text('#login-custom-password', "foobar") - b.click('#hosts_setup_server_dialog button:contains(Log in)') - b.wait_not_present('#hosts_setup_server_dialog') + self.start_machine_troubleshoot(password="foobar") b.enter_page("/playground/test", "10.111.113.2", reconnect=True) # image is back because it page was reloaded after disconnection @@ -547,7 +518,7 @@ class TestMultiMachine(testlib.MachineCase): # Add a machine self.login_and_go(None) - add_machine(b, "10.111.113.2") + self.add_machine("10.111.113.2") b.switch_to_top() b.go(m2_path) @@ -599,7 +570,7 @@ class TestMultiMachine(testlib.MachineCase): # Bad hostkey break_hostkey(m1, "10.111.113.2") - start_machine_troubleshoot(b, new=True, known_host=True) + self.start_machine_troubleshoot(new=True, known_host=True, expect_closed_dialog=False) b.wait_in_text('#hosts_setup_server_dialog', "10.111.113.2 key changed") b.click("#hosts_setup_server_dialog button:contains(Cancel)") b.wait_not_present('#hosts_setup_server_dialog') @@ -609,21 +580,21 @@ class TestMultiMachine(testlib.MachineCase): m1.execute("mkdir -p /home/admin/.ssh/") break_hostkey(m1, "10.111.113.2") - start_machine_troubleshoot(b, new=True, known_host=True) + self.start_machine_troubleshoot(new=True, known_host=True, expect_closed_dialog=False) b.wait_in_text('#hosts_setup_server_dialog', "10.111.113.2 key changed") b.click("#hosts_setup_server_dialog button:contains(Cancel)") fix_hostkey(m1) # Bad cockpit break_bridge(m2) - start_machine_troubleshoot(b, new=True, password="foobar") + self.start_machine_troubleshoot(new=True, password="foobar", expect_closed_dialog=False) check_failed_state(b, "Cockpit is not installed") fix_bridge(m2) # Troubleshoot existing # Properly add machine fix_hostkey(m1) - add_machine(b, "10.111.113.2") + self.add_machine("10.111.113.2") b.logout() b.wait_visible("#login") @@ -632,7 +603,7 @@ class TestMultiMachine(testlib.MachineCase): self.login_and_go(None) b.go(machine_path) with b.wait_timeout(240): - start_machine_troubleshoot(b, password="foobar") + self.start_machine_troubleshoot(password="foobar", expect_closed_dialog=False) check_failed_state(b, "Cockpit is not installed") b.wait_visible("#machine-troubleshoot") @@ -640,7 +611,7 @@ class TestMultiMachine(testlib.MachineCase): # Clear host key fix_hostkey(m1) - start_machine_troubleshoot(b) + self.start_machine_troubleshoot(expect_closed_dialog=False) b.wait_in_text('#hosts_setup_server_dialog', "You are connecting to 10.111.113.2 for the first time.") # show fingerprint validation @@ -676,7 +647,7 @@ class TestMultiMachine(testlib.MachineCase): with b.wait_timeout(120): b.wait_visible("#machine-troubleshoot") - start_machine_troubleshoot(b) + self.start_machine_troubleshoot(expect_closed_dialog=False) b.wait_in_text('#hosts_setup_server_dialog', "Unable to log in") b.set_input_text('#login-custom-password', "") fail_login(b) @@ -701,7 +672,7 @@ class TestMultiMachine(testlib.MachineCase): b.go(machine_path) with b.wait_timeout(120): b.wait_visible("#machine-troubleshoot") - start_machine_troubleshoot(b) + self.start_machine_troubleshoot(expect_closed_dialog=False) b.wait_in_text('#hosts_setup_server_dialog h1', "Could not contact") b.set_input_text("#edit-machine-port", "2222") b.click(f'#hosts_setup_server_dialog {self.primary_btn_class}') @@ -747,6 +718,7 @@ class TestMultiMachine(testlib.MachineCase): self.login_and_go(None) b.go("/@10.111.113.2") + self.start_machine_troubleshoot(expect_closed_dialog=False) b.wait_visible("#machine-troubleshoot") b.click('#machine-troubleshoot') b.wait_visible('#hosts_setup_server_dialog') diff --git a/test/verify/check-system-shutdown-restart b/test/verify/check-system-shutdown-restart index ba68228dad61..eb4a2b500c45 100755 --- a/test/verify/check-system-shutdown-restart +++ b/test/verify/check-system-shutdown-restart @@ -69,21 +69,7 @@ class TestShutdownRestart(testlib.MachineCase): b2.login_and_go("/system") # Add machine with static IP to m2 - b2.switch_to_top() - b2.go("/@10.111.113.1") - with b2.wait_timeout(30): - b2.wait_visible("#machine-troubleshoot") - b2.click('#machine-troubleshoot') - b2.wait_visible('#hosts_setup_server_dialog') - b2.wait_text(f'#hosts_setup_server_dialog {self.primary_btn_class}', "Add") - b2.click(f'#hosts_setup_server_dialog {self.primary_btn_class}') - b2.wait_in_text('#hosts_setup_server_dialog', "You are connecting to 10.111.113.1 for the first time.") - b2.click(f'#hosts_setup_server_dialog {self.primary_btn_class}') - b2.wait_in_text('#hosts_setup_server_dialog', "Unable to log in") - b2.set_input_text("#login-custom-password", "foobar") - b2.click(f'#hosts_setup_server_dialog {self.primary_btn_class}') - b2.wait_not_present('#hosts_setup_server_dialog') - b2.enter_page("/system", host="10.111.113.1") + self.add_machine("10.111.113.1", browser=b2) b2.wait_text("#system_information_hostname_text", "machine1") # Check auto reconnect on reboot @@ -105,12 +91,7 @@ class TestShutdownRestart(testlib.MachineCase): with b2.wait_timeout(30): b2.wait_visible("#machine-troubleshoot") - b2.click('#machine-troubleshoot') - b2.wait_visible('#hosts_setup_server_dialog') - b2.wait_in_text('#hosts_setup_server_dialog', "Unable to log in") - b2.set_input_text("#login-custom-password", "foobar") - b2.click(f'#hosts_setup_server_dialog {self.primary_btn_class}') - b2.wait_not_present('#hosts_setup_server_dialog') + self.start_machine_troubleshoot(password="foobar", browser=b2) b2.enter_page("/system", host="10.111.113.1", reconnect=False)