#!/usr/bin/python3## Copyright (C) 2026 Red Hat, Inc.# SPDX-License-Identifier: LGPL-2.1-or-laterimport timefrom anacondalib import INSTALLER_VM_MEMORY_MB, VirtInstallMachineCase, run_on_vm_setupsfrom installer import Installerfrom network import COCKPIT_CHECKPOINT_ROLLBACK_TIME, SYSROOT_PATH, Networkfrom progress import Progressfrom testlib import nondestructive, test_main # pylint: disable=import-errorfrom utils import check_cockpit_module_js_errorclass TestNetworkDestructive(VirtInstallMachineCase):provision = {"machine1": {"memory_mb": INSTALLER_VM_MEMORY_MB}}def testCockpitConnectionsPreInstall(self):"""Description:Test network configuration modifies profiles correctly.A pre-installation phase variant - a shorter test assuming the connectionswill be passed to the system correctly at the end of installation.Expected results:- Expected connection profiles in installer with expected values- Network configuration modifies correct profiles"""b = self.browserm = self.machinei = Installer(b, m)n = Network(b, m)i.open()iface = n.get_the_iface()n.preinstall_connection_test(i, iface)@run_on_vm_setups("", "bootopts-net1")def testConnections(self):"""Description:Test network configuration modifies profiles correctly.Expected results:- Expected connection profiles in installer with expected values- Network configuration modifies correct profiles"""b = self.browserm = self.machinei = Installer(b, m)n = Network(b, m)i.open()iface = n.get_the_iface()if self.vm_setup == "bootopts-net1":configured = Trueelse:configured = Falsen.preinstall_connection_test(i, iface, configured=configured)i.begin_installation(needs_confirmation=False)p = Progress(b)p.wait_done()con_name = iface# Check profiles in installed systemn.check_con_profile_files(con_name, 1, root=SYSROOT_PATH, file_name=con_name)# Check there is only single persistent profilen.check_con_profile_files("", 1, root=SYSROOT_PATH)# FIXME add "" vm_setup back when# https://github.com/cockpit-project/cockpit/issues/22926 is fixed#@run_on_vm_setups("", "bootopts-net1")@run_on_vm_setups("bootopts-net1")def testWizardCockpitConfigurationPreInstall(self):"""Description:Test configuration of settings of a device from a wizard page.Expected results:- Change breaking connection raises expected confirmation dialog- The configured values are correctly applied to connection profile and device."""b = self.browserm = self.machinei = Installer(b, m)n = Network(b, m)i.open()i.reach(i.steps.NETWORK)iface = n.get_the_iface()n.disable_ipv4_on_iface_wizard(iface)i.next()i.back()# After editing, therefore persisting, the automatic default connection# is updated by Cockpit (COCKPIT-1750)con_name = ifacemtu_value = "1600"n.set_mtu_on_iface_wizard(iface, mtu_value)n.check_con_settings([[con_name, "802-3-ethernet.mtu", mtu_value, None],])i.next()i.back()dns_server = "8.8.8.8"n.add_dns_server_to_iface_wizard(iface, dns_server)n.check_con_settings([[con_name, "ipv4.dns", dns_server, None],])# Check that the checkpoint does not fail silently, ie check after# checkpoint timeout (INSTALLER-4594)time.sleep(COCKPIT_CHECKPOINT_ROLLBACK_TIME+2)n.check_con_settings([[con_name, "802-3-ethernet.mtu", mtu_value, None],])n.check_con_settings([[con_name, "ipv4.dns", dns_server, None],])@nondestructiveclass TestNetwork(VirtInstallMachineCase):def testCockpitJsErrorHandling(self):"""Description:Test that the installer can handle JS errors in the network moduleand that it does not crash the installerSetup:- Generate a JS error in the network moduleExpected results:- The installer should not crash- The installer should show a critical error dialog"""b = self.browserm = self.machinei = Installer(b, m)n = Network(b, m)i.open()i.reach(i.steps.NETWORK)n.enter_network()check_cockpit_module_js_error(b, "Network")if __name__ == '__main__':test_main()