From 7ecff4b38eb066b9eca9f5228ef09452cd9cbdc4 Mon Sep 17 00:00:00 2001 From: Jelle van der Waa Date: Wed, 2 Oct 2024 16:14:36 +0200 Subject: [PATCH] test: reduce line length to 150 This is a middle step of moving the tons of long lines to a more reasonable default. --- pyproject.toml | 2 +- test/check-machines-consoles | 5 +- test/check-machines-create | 25 +++++++--- test/check-machines-disks | 6 ++- test/check-machines-filesystems | 4 +- test/check-machines-migrate | 3 +- test/check-machines-networks | 78 ++++++++++++++++++++---------- test/check-machines-settings | 37 +++++++++----- test/check-machines-snapshots | 9 ++-- test/check-machines-storage-pools | 12 +++-- test/check-machines-virtualization | 6 ++- test/files/mock-rhsm-rest | 3 +- test/machineslib.py | 41 ++++++++++------ 13 files changed, 152 insertions(+), 79 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index a5d7ee2f5..aec246cd7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,7 @@ exclude = [ "node_modules/", ] # FIXME: we want 118, but needs fixing tests first -line-length = 183 +line-length = 150 preview = true src = [] diff --git a/test/check-machines-consoles b/test/check-machines-consoles index cc728473f..24c5488b2 100755 --- a/test/check-machines-consoles +++ b/test/check-machines-consoles @@ -158,7 +158,10 @@ fullscreen=0 ignore=[".pf-v5-c-console__vnc"], skip_layouts=["rtl"]) # Add a second serial console - m.execute("virsh destroy vmWithSerialConsole; virt-xml --add-device vmWithSerialConsole --console pty,target_type=virtio; virsh start vmWithSerialConsole") + m.execute(""" + virsh destroy vmWithSerialConsole; + virt-xml --add-device vmWithSerialConsole --console pty,target_type=virtio; + virsh start vmWithSerialConsole""") b.click("#pf-v5-c-console__type-selector") b.wait_visible("#pf-v5-c-console__type-selector + .pf-v5-c-select__menu") b.click("li:contains('Serial console (serial0)') button") diff --git a/test/check-machines-create b/test/check-machines-create index 875895e0c..639d7a006 100755 --- a/test/check-machines-create +++ b/test/check-machines-create @@ -109,7 +109,8 @@ class TestMachinesCreate(machineslib.VirtualMachinesCase): # try to CREATE WITH DIALOG ERROR # name - runner.checkDialogFormValidationTest(TestMachinesCreate.VmDialog(self, "", storage_size=1, os_name=None), {"vm-name": "Name must not be empty"}) + runner.checkDialogFormValidationTest(TestMachinesCreate.VmDialog(self, "", storage_size=1, os_name=None), + {"vm-name": "Name must not be empty"}) # location runner.checkDialogFormValidationTest(TestMachinesCreate.VmDialog(self, sourceType='url', @@ -481,7 +482,8 @@ class TestMachinesCreate(machineslib.VirtualMachinesCase): create_and_run=True, delete=False)) runner.checkDialogFormValidationTest(TestMachinesCreate.VmDialog(self, "existing-name", storage_size=1, - check_script_finished=False, env_is_empty=False), {"vm-name": "already exists"}) + check_script_finished=False, env_is_empty=False), + {"vm-name": "already exists"}) @testlib.skipImage("TODO: fails in 50% of runs", "opensuse-tumbleweed") def testCreatePXE(self): @@ -1384,7 +1386,8 @@ vnc_password= "{vnc_passwd}" if self.expected_os_name: b.wait_attr("#os-select-group input", "value", self.expected_os_name) - if self.sourceType == "os" and self.os_name in [TestMachinesCreate.TestCreateConfig.RHEL_8_1, TestMachinesCreate.TestCreateConfig.RHEL_8_2]: + if self.sourceType == "os" and self.os_name in [TestMachinesCreate.TestCreateConfig.RHEL_8_1, + TestMachinesCreate.TestCreateConfig.RHEL_8_2]: if not self.offline_token_autofilled: b.set_input_text("#offline-token", self.offline_token) b.wait_in_text("#offline-token", self.offline_token) @@ -1848,7 +1851,9 @@ vnc_password= "{vnc_passwd}" else: raise AssertionError("Unknown disk device") # New volume was created or existing volume was already chosen as destination - elif (dialog.storage_size is not None and dialog.storage_size > 0) or dialog.storage_pool not in [NO_STORAGE, NEW_VOLUME_QCOW2, NEW_VOLUME_RAW]: + elif (dialog.storage_size is not None and dialog.storage_size > 0) or dialog.storage_pool not in [NO_STORAGE, + NEW_VOLUME_QCOW2, + NEW_VOLUME_RAW]: b.wait_visible(".disks-card table tbody:first-of-type") if b.is_present(f"#vm-{name}-disks-vda-device"): b.wait_in_text(f"#vm-{name}-disks-vda-device", "disk") @@ -1863,7 +1868,8 @@ vnc_password= "{vnc_passwd}" b.wait_in_text(f"#vm-{name}-disks-vda-type", "qcow2") elif dialog.storage_pool == NEW_VOLUME_RAW: b.wait_in_text(f"#vm-{name}-disks-vda-type", "raw") - elif (vm_state == "Running" and (((dialog.storage_pool == NO_STORAGE or dialog.storage_size == 0) and dialog.sourceType == 'file') or dialog.sourceType == 'url')): + elif (vm_state == "Running" and (((dialog.storage_pool == NO_STORAGE or dialog.storage_size == 0) + and dialog.sourceType == 'file') or dialog.sourceType == 'url')): b.wait_visible(".disks-card table tbody:first-of-type") if b.is_present(f"#vm-{name}-disks-sda-device"): b.wait_in_text(f"#vm-{name}-disks-sda-device", "cdrom") @@ -2075,7 +2081,8 @@ vnc_password= "{vnc_passwd}" if dialog.sourceType != 'cloud': self.browser.mouse(".pf-v5-c-tabs__list button[aria-disabled=true]:contains(Automation)", "mouseenter") - self.browser.wait_in_text("div.pf-v5-c-tooltip__content", "Automated installs are only available when downloading an image or using cloud-init.") + self.browser.wait_in_text("div.pf-v5-c-tooltip__content", + "Automated installs are only available when downloading an image or using cloud-init.") self.browser.mouse(".pf-v5-c-tabs__list button[aria-disabled=true]:contains(Automation)", "mouseleave") else: self.browser.wait_visible(".pf-v5-c-tabs__list button[aria-disabled=false]:contains(Automation)") @@ -2104,7 +2111,8 @@ vnc_password= "{vnc_passwd}" b.click(".pf-v5-c-modal-box__footer button:contains(Create and edit)") b.wait_not_present("#create-vm-dialog") - testlib.wait(lambda: "fedora28" in m.execute("virsh dumpxml VmNotInstalled"), delay=3) + testlib.wait(lambda: "fedora28" in m.execute("virsh dumpxml VmNotInstalled"), + delay=3) self.waitVmPage("VmNotInstalled") @@ -2196,7 +2204,8 @@ vnc_password= "{vnc_passwd}" m.execute(f"> {logfile}") # clear logfile self.performAction("VmNotInstalled", "forceOff", checkExpectedState=False) b.wait_in_text("#vm-VmNotInstalled-system-state", "Shut off") - testlib.wait(lambda: "133120" in m.execute("virsh dominfo VmNotInstalled | grep 'Used memory'"), delay=1) # Wait until memory parameters get adjusted after shutting the VM + # Wait until memory parameters get adjusted after shutting the VM + testlib.wait(lambda: "133120" in m.execute("virsh dominfo VmNotInstalled | grep 'Used memory'"), delay=1) # Check configuration changes survived installation # Check memory settings have persisted diff --git a/test/check-machines-disks b/test/check-machines-disks index b3320458f..dfd82e78c 100755 --- a/test/check-machines-disks +++ b/test/check-machines-disks @@ -195,7 +195,8 @@ class TestMachinesDisks(machineslib.VirtualMachinesCase): # Virtio bus type should not be shown for CDROM devices m.execute("touch /var/lib/libvirt/novell.iso") - m.execute("virsh attach-disk --domain subVmTest1 --source /var/lib/libvirt/novell.iso --target hda --type cdrom --targetbus sata --mode readonly --persistent") + m.execute( +"virsh attach-disk --domain subVmTest1 --source /var/lib/libvirt/novell.iso --target hda --type cdrom --targetbus sata --mode readonly --persistent") # virsh attach-disk want send an event for offline VM changes b.reload() b.enter_page('/machines') @@ -722,7 +723,8 @@ class TestMachinesDisks(machineslib.VirtualMachinesCase): self.test_obj.waitPoolRow(self.pool_name) self.test_obj.togglePoolRow(self.pool_name) - b.click(f"tr[data-row-id=pool-{self.pool_name}-system] + tr li:contains('Storage volumes') button") # open the "Storage volumes" subtab + # open the "Storage volumes" subtab + b.click(f"tr[data-row-id=pool-{self.pool_name}-system] + tr li:contains('Storage volumes') button") b.wait_visible(f"#pool-{self.pool_name}-system-volume-{self.volume_name}-name") b.click(".machines-listing-breadcrumb li a:contains(Virtual machines)") diff --git a/test/check-machines-filesystems b/test/check-machines-filesystems index f62251752..e4a8c6875 100755 --- a/test/check-machines-filesystems +++ b/test/check-machines-filesystems @@ -61,8 +61,8 @@ class TestMachinesFilesystems(machineslib.VirtualMachinesCase): b.set_input_text("#vm-subVmTest1-filesystems-modal-mountTag", "") b.set_input_text("#vm-subVmTest1-filesystems-modal-source-group input", "/tmp") # In some hosts with the high latency, the path of the expand list needs some time to load, the check will fail if it is too quick. - # Thus, add a check that the folder input appears in the expand list(#vm-{name}-filesystems-modal-source) to ensure that the loading is finished - # #vm-{name}-filesystems-modal-source only contains the expand list, without the input line + # Thus, add a check that the folder input appears in the expand list(#vm-{name}-filesystems-modal-source) + # to ensure that the loading is finished #vm-{name}-filesystems-modal-source only contains the expand list, without the input line. b.wait_in_text("#vm-subVmTest1-filesystems-modal-source", "/tmp") b.click("#vm-subVmTest1-filesystems-modal-source button:nth-child(1)") # Check the expand list disappears diff --git a/test/check-machines-migrate b/test/check-machines-migrate index 79b1a31b2..ae7bc462c 100755 --- a/test/check-machines-migrate +++ b/test/check-machines-migrate @@ -58,7 +58,8 @@ class TestMachinesMigration(machineslib.VirtualMachinesCase): if fail != "port_closed": # Plain migration: The source host VM opens a direct unencrypted TCP connection to the destination host for sending the migration data. - # Unless a port is manually specified, libvirt will choose a migration port in the range 49152-49215, which will need to be open in the firewall on the remote host. + # Unless a port is manually specified, libvirt will choose a migration port in the range 49152-49215, + # which will need to be open in the firewall on the remote host. # https://wiki.libvirt.org/page/FAQ machine2.execute("systemctl start firewalld") machine2.execute("firewall-cmd --permanent --add-port 49152-49215/tcp") diff --git a/test/check-machines-networks b/test/check-machines-networks index 3bca12da4..9cfc5f866 100755 --- a/test/check-machines-networks +++ b/test/check-machines-networks @@ -84,7 +84,8 @@ class TestMachinesNetworks(machineslib.VirtualMachinesCase): b.wait_in_text(f"#network-test_network2-{connectionName}-ipv6-prefix", "64") b.wait_in_text(f"#network-test_network2-{connectionName}-ipv6-dhcp-range", "fd00:e81d:a6d7:55::100 - fd00:e81d:a6d7:55::1ff") b.wait_in_text(f"#network-test_network2-{connectionName}-ipv6-dhcp-host-0", "Name: simon, IP: 2001:db8:ca2:2:3::1") - b.wait_in_text(f"#network-test_network2-{connectionName}-ipv6-dhcp-host-1", "ID: 0:1:0:1:18:aa:62:fe:0:16:3e:44:55:66, IP: 2001:db8:ca2:2:3::2") + b.wait_in_text(f"#network-test_network2-{connectionName}-ipv6-dhcp-host-1", + "ID: 0:1:0:1:18:aa:62:fe:0:16:3e:44:55:66, IP: 2001:db8:ca2:2:3::2") # Close expanded row for this pool self.toggleNetworkRow("test_network2", connectionName) @@ -97,15 +98,18 @@ class TestMachinesNetworks(machineslib.VirtualMachinesCase): b.wait_visible(f"#network-test_network3-{connectionName}-autostart:not(:checked)") # Check overview network properties are not present - for el in ["ipv4-address", "ipv4-netmask", "ipv4-dhcp-range", "ipv4-dhcp-host-0", "ipv6-address", "ipv6-prefix", "ipv6-dhcp-range", "ipv6-dhcp-host-0"]: + for el in ["ipv4-address", "ipv4-netmask", "ipv4-dhcp-range", "ipv4-dhcp-host-0", + "ipv6-address", "ipv6-prefix", "ipv6-dhcp-range", "ipv6-dhcp-host-0"]: b.wait_not_present(f"#network-test_network3-{connectionName}-{el}") # Transient network self.toggleNetworkRow("test_network4", connectionName) b.wait_in_text(f"#network-test_network4-{connectionName}-persistent", "no") - b.wait_not_present(f"#network-test_network4-{connectionName}-autostart") # Transient network shouldn't have autostart option + # Transient network shouldn't have autostart option + b.wait_not_present(f"#network-test_network4-{connectionName}-autostart") b.click(f"#network-test_network4-{connectionName}-action-kebab") - b.wait_visible(f'li.pf-m-aria-disabled > #delete-network-test_network4-{connectionName}') # Transient network cannot be deleted + # Transient network cannot be deleted + b.wait_visible(f'li.pf-m-aria-disabled > #delete-network-test_network4-{connectionName}') b.click(f'#deactivate-network-test_network4-{connectionName}') # Deactivate transient network self.waitNetworkRow("test_network4", connectionName, False) # Check it's not present after deactivation @@ -129,8 +133,9 @@ class TestMachinesNetworks(machineslib.VirtualMachinesCase): class NetworkCreateDialog(object): def __init__( - self, test_obj, name, forward_mode=None, ip_conf=None, ipv4_address=None, ipv4_netmask=None, ipv6_address=None, ipv6_prefix=None, device=None, - ipv4_dhcp_start=None, ipv4_dhcp_end=None, ipv6_dhcp_start=None, ipv6_dhcp_end=None, xfail=False, xfail_error=None, xfail_objects=None, + self, test_obj, name, forward_mode=None, ip_conf=None, ipv4_address=None, ipv4_netmask=None, + ipv6_address=None, ipv6_prefix=None, device=None, ipv4_dhcp_start=None, ipv4_dhcp_end=None, + ipv6_dhcp_start=None, ipv6_dhcp_end=None, xfail=False, xfail_error=None, xfail_objects=None, remove=True, activate=False ): self.test_obj = test_obj @@ -165,7 +170,8 @@ class TestMachinesNetworks(machineslib.VirtualMachinesCase): def open(self): b.click("#create-network") b.wait_visible("#create-network-dialog") - b.wait_in_text(".pf-v5-c-modal-box .pf-v5-c-modal-box__header .pf-v5-c-modal-box__title", "Create virtual network") + b.wait_in_text(".pf-v5-c-modal-box .pf-v5-c-modal-box__header .pf-v5-c-modal-box__title", + "Create virtual network") def fill(self): b.set_input_text("#create-network-name", self.name) @@ -212,9 +218,12 @@ class TestMachinesNetworks(machineslib.VirtualMachinesCase): else: for xfo in self.xfail_objects: if "range" in xfo: - b.wait_in_text(f"#create-network-dialog .create-network-{xfo} .pf-v5-c-form__helper-text .pf-v5-c-helper-text__item.pf-m-error", self.xfail_error) + b.wait_in_text( + f"#create-network-dialog .create-network-{xfo} .pf-v5-c-form__helper-text .pf-v5-c-helper-text__item.pf-m-error", + self.xfail_error) else: - self.test_obj.assertIn(self.xfail_error, b.eval_js(f"ph_input_form_helper_text(\"create-network-{xfo}\")")) + self.test_obj.assertIn(self.xfail_error, + b.eval_js(f"ph_input_form_helper_text(\"create-network-{xfo}\")")) self.cancel() else: @@ -240,21 +249,30 @@ class TestMachinesNetworks(machineslib.VirtualMachinesCase): self.test_obj.assertEqual(self.forward_mode, m.execute(xmllint_element.format(prop='forward/@mode')).strip()) if self.device: - self.test_obj.assertEqual(self.device, m.execute(xmllint_element.format(prop='forward/interface/@dev')).strip()) + self.test_obj.assertEqual(self.device, + m.execute(xmllint_element.format(prop='forward/interface/@dev')).strip()) if (self.ip_conf != "None"): if "4" in self.ip_conf: - self.test_obj.assertEqual(self.ipv4_address, m.execute(xmllint_element.format(prop='ip/@address')).strip()) - self.test_obj.assertEqual(self.ipv4_netmask, m.execute(xmllint_element.format(prop='ip/@netmask')).strip()) + self.test_obj.assertEqual(self.ipv4_address, + m.execute(xmllint_element.format(prop='ip/@address')).strip()) + self.test_obj.assertEqual(self.ipv4_netmask, + m.execute(xmllint_element.format(prop='ip/@netmask')).strip()) if self.ipv4_dhcp_start and self.ipv4_dhcp_start: - self.test_obj.assertEqual(self.ipv4_dhcp_start, m.execute(xmllint_element.format(prop='ip/dhcp/range/@start')).strip()) - self.test_obj.assertEqual(self.ipv4_dhcp_end, m.execute(xmllint_element.format(prop='ip/dhcp/range/@end')).strip()) + self.test_obj.assertEqual(self.ipv4_dhcp_start, + m.execute(xmllint_element.format(prop='ip/dhcp/range/@start')).strip()) + self.test_obj.assertEqual(self.ipv4_dhcp_end, + m.execute(xmllint_element.format(prop='ip/dhcp/range/@end')).strip()) if "6" in self.ip_conf: - self.test_obj.assertEqual(self.ipv6_address, m.execute(xmllint_element.format(prop='ip[starts-with(@family,"ipv6")]/@address')).strip()) - self.test_obj.assertEqual(self.ipv6_prefix, m.execute(xmllint_element.format(prop='ip[starts-with(@family,"ipv6")]/@prefix')).strip()) + self.test_obj.assertEqual(self.ipv6_address, + m.execute(xmllint_element.format(prop='ip[starts-with(@family,"ipv6")]/@address')).strip()) + self.test_obj.assertEqual(self.ipv6_prefix, + m.execute(xmllint_element.format(prop='ip[starts-with(@family,"ipv6")]/@prefix')).strip()) if self.ipv6_dhcp_start and self.ipv6_dhcp_start: - self.test_obj.assertEqual(self.ipv6_dhcp_start, m.execute(xmllint_element.format(prop='ip[starts-with(@family,"ipv6")]/dhcp/range/@start')).strip()) - self.test_obj.assertEqual(self.ipv6_dhcp_end, m.execute(xmllint_element.format(prop='ip[starts-with(@family,"ipv6")]/dhcp/range/@end')).strip()) + self.test_obj.assertEqual(self.ipv6_dhcp_start, + m.execute(xmllint_element.format(prop='ip[starts-with(@family,"ipv6")]/dhcp/range/@start')).strip()) + self.test_obj.assertEqual(self.ipv6_dhcp_end, + m.execute(xmllint_element.format(prop='ip[starts-with(@family,"ipv6")]/dhcp/range/@end')).strip()) else: self.test_obj.assertEqual("", m.execute(xmllint_element.format(prop='ip')).strip()) @@ -278,12 +296,14 @@ class TestMachinesNetworks(machineslib.VirtualMachinesCase): b.wait_in_text(f"#network-{self.name}-{connectionName}-ipv4-address", self.ipv4_address) b.wait_in_text(f"#network-{self.name}-{connectionName}-ipv4-netmask", self.ipv4_netmask) if self.ipv4_dhcp_start and self.ipv4_dhcp_start: - b.wait_in_text(f"#network-{self.name}-{connectionName}-ipv4-dhcp-range", self.ipv4_dhcp_start + " - " + self.ipv4_dhcp_end) + b.wait_in_text(f"#network-{self.name}-{connectionName}-ipv4-dhcp-range", + self.ipv4_dhcp_start + " - " + self.ipv4_dhcp_end) if "6" in self.ip_conf: b.wait_in_text(f"#network-{self.name}-{connectionName}-ipv6-address", self.ipv6_address) b.wait_in_text(f"#network-{self.name}-{connectionName}-ipv6-prefix", self.ipv6_prefix) if self.ipv6_dhcp_start and self.ipv6_dhcp_start: - b.wait_in_text(f"#network-{self.name}-{connectionName}-ipv6-dhcp-range", self.ipv6_dhcp_start + " - " + self.ipv6_dhcp_end) + b.wait_in_text(f"#network-{self.name}-{connectionName}-ipv6-dhcp-range", + self.ipv6_dhcp_start + " - " + self.ipv6_dhcp_end) if "4" not in self.ip_conf: b.wait_not_present(f"#network-{self.name}-{connectionName}-ipv4-address") @@ -693,7 +713,8 @@ class TestMachinesNetworks(machineslib.VirtualMachinesCase): virsh net-destroy default; virsh net-undefine default virsh net-define /tmp/net-test-network.xml; virsh net-start test_network""") - # First shut of the VM otherwise the interface will not be the same in the live and config XML https://www.redhat.com/archives/libvir-list/2019-August/msg01034.html + # First shut of the VM otherwise the interface will not be the same in the live and config XML + # https://www.redhat.com/archives/libvir-list/2019-August/msg01034.html self.performAction("subVmTest1", "forceOff") # Try to edit the interface changing the source to a non deleted network @@ -734,7 +755,8 @@ class TestMachinesNetworks(machineslib.VirtualMachinesCase): b.wait_visible(f"#network-test_network2-{connectionName}-autostart") # set checkbox state and check state of checkbox - b.set_checked(f"#network-test_network2-{connectionName}-autostart", True) # don't know the initial state of checkbox, so set it to checked + # don't know the initial state of checkbox, so set it to checked + b.set_checked(f"#network-test_network2-{connectionName}-autostart", True) b.wait_visible(f"#network-test_network2-{connectionName}-autostart:checked") # check virsh state autostartState = m.execute("virsh net-info test_network2 | grep 'Autostart:' | awk '{print $2}'").strip() @@ -786,14 +808,16 @@ class TestMachinesNetworks(machineslib.VirtualMachinesCase): b.click(f"#activate-network-test_network2-{connectionName}") b.wait_in_text(f"#network-test_network2-{connectionName}-state", "active") # check virsh state - testlib.wait(lambda: "yes" == m.execute("virsh net-info test_network2 | grep 'Active:' | awk '{print $2}'").strip(), tries=5) + testlib.wait(lambda: "yes" == m.execute("virsh net-info test_network2 | grep 'Active:' | awk '{print $2}'").strip(), + tries=5) # deactivate network b.wait_visible(f"#deactivate-network-test_network2-{connectionName}") b.click(f"#deactivate-network-test_network2-{connectionName}") b.wait_in_text(f"#network-test_network2-{connectionName}-state", "inactive") b.wait_visible(f"#activate-network-test_network2-{connectionName}") # check virsh state - testlib.wait(lambda: "no" == m.execute("virsh net-info test_network2 | grep 'Active:' | awk '{print $2}'").strip(), tries=5) + testlib.wait(lambda: "no" == m.execute("virsh net-info test_network2 | grep 'Active:' | awk '{print $2}'").strip(), + tries=5) # trigger error on clashing network m.write("/tmp/xml", TEST_NETWORK2_CLASH_XML) @@ -865,7 +889,8 @@ class TestMachinesNetworks(machineslib.VirtualMachinesCase): def open(self): b.click(f"#network-{self.network_name}-{self.connection_name}-static-host-entries-add") b.wait_visible("#add-new-static-entry-mac-address") - b.wait_in_text(".pf-v5-c-modal-box .pf-v5-c-modal-box__header .pf-v5-c-modal-box__title", "Add a DHCP static host entry") + b.wait_in_text(".pf-v5-c-modal-box .pf-v5-c-modal-box__header .pf-v5-c-modal-box__title", + "Add a DHCP static host entry") b.wait_in_text("div.pf-v5-c-modal-box__body label[for=add-new-static-entry-mac-address]", "MAC address") b.wait_in_text("div.pf-v5-c-modal-box__body label[for=add-new-static-entry-ip-address]", "IP address") @@ -909,7 +934,8 @@ class TestMachinesNetworks(machineslib.VirtualMachinesCase): raise Exception(f'No DHCP host with IP address {self.ip} found in network XML:\n{net_xml}') def verify_overview(self): - b.wait_in_text(f"#network-{self.network_name}-{self.connection_name}-ipv4-dhcp-host-{self.entry_id}", f"MAC: {self.mac}, IP: {self.ip}") + b.wait_in_text(f"#network-{self.network_name}-{self.connection_name}-ipv4-dhcp-host-{self.entry_id}", + f"MAC: {self.mac}, IP: {self.ip}") def cleanup(self): b.click(f"#delete-network-{self.network_name}-{self.connection_name}-ipv4-dhcp-host-{self.entry_id}-button") diff --git a/test/check-machines-settings b/test/check-machines-settings index 774d98fa1..cb4d40493 100755 --- a/test/check-machines-settings +++ b/test/check-machines-settings @@ -141,7 +141,7 @@ class TestMachinesSettings(machineslib.VirtualMachinesCase): b.wait_not_present("#machines-cpu-modal-dialog") testlib.wait(lambda: m.execute( - "virsh dumpxml subVmTest1 | tee /tmp/subVmTest1.xml | xmllint --xpath '/domain/cpu/topology[@sockets=\"2\"][@threads=\"1\"][@cores=\"2\"]' -")) + "virsh dumpxml subVmTest1 | tee /tmp/subVmTest1.xml | xmllint --xpath '/domain/cpu/topology[@sockets=\"2\"][@threads=\"1\"][@cores=\"2\"]' -")) # Run VM - this ensures that the internal state is updated before we move on. # We need this here because we can't wait for UI updates after we open the modal dialog. @@ -276,7 +276,10 @@ class TestMachinesSettings(machineslib.VirtualMachinesCase): m = self.machine args = self.createVm("subVmTest1") - m.execute("touch /var/lib/libvirt/images/phonycdrom; virsh attach-disk subVmTest1 /var/lib/libvirt/images/phonycdrom sdb --type cdrom --config") + m.execute(""" + touch /var/lib/libvirt/images/phonycdrom; + virsh attach-disk subVmTest1 /var/lib/libvirt/images/phonycdrom sdb --type cdrom --config + """) self.login_and_go("/machines") self.waitPageInit() @@ -369,7 +372,8 @@ class TestMachinesSettings(machineslib.VirtualMachinesCase): # re-open and check the boot option is the disk b.click("#vm-subVmTest1-boot-order button") b.wait_visible("#vm-subVmTest1-order-modal-window") - b.wait_text("#vm-subVmTest1-order-modal-device-row-0 .pf-v5-c-description-list__description .pf-v5-c-description-list__text", args["image"]) + b.wait_text("#vm-subVmTest1-order-modal-device-row-0 .pf-v5-c-description-list__description .pf-v5-c-description-list__text", + args["image"]) b.click("#vm-subVmTest1-order-modal-cancel") b.wait_not_present("#vm-subVmTest1-order-modal-window") @@ -522,7 +526,8 @@ class TestMachinesSettings(machineslib.VirtualMachinesCase): b.wait_not_present("#vm-subVmTest1-watchdog-modal") def setWatchdogAction(action, machine_has_no_watchdog=False, pixel_test_tag=None, reboot_machine=False): - # If no watchdog action is set, we are attaching a new watchdog device. If watchdog already is set, we are editing an exiting watchdog device + # If no watchdog action is set, we are attaching a new watchdog device. + # If watchdog already is set, we are editing an exiting watchdog device. if machine_has_no_watchdog: b.wait_in_text("#vm-subVmTest1-watchdog-button", "add") else: @@ -579,7 +584,8 @@ class TestMachinesSettings(machineslib.VirtualMachinesCase): b.wait_not_present("#watchdog-tooltip") b.wait_not_present("#vm-subVmTest1-needs-shutdown") - # Libvirt doesn't support editing watchdog device on RUNNING vm, so a live VM config will persist the previously configured watchdog action until reboot + # Libvirt doesn't support editing watchdog device on RUNNING vm, so a live VM config will persist the previously + # configured watchdog action until reboot. # On the other hand, libvirt does support attaching a watchdog to a RUNNING VM # So in summary: # - if no previous watchdog action is configured on a VM (meaning VM has no watchdog device), we are attaching a new watchdog device @@ -591,7 +597,8 @@ class TestMachinesSettings(machineslib.VirtualMachinesCase): virsh_output_offline = m.execute("virsh dumpxml subVmTest1 | xmllint --xpath '/domain/devices/watchdog/@action' -").strip() self.assertEqual(virsh_output_offline, f'action="{expected_action}"') - # Offline VM config will always have newly configured watchdog action, no matter if we are attaching a new watchdog device or editing an existing one + # Offline VM config will always have newly configured watchdog action, no matter + # if we are attaching a new watchdog device or editing an existing one virsh_output_offline = m.execute("virsh dumpxml subVmTest1 --inactive | xmllint --xpath '/domain/devices/watchdog/@action' -").strip() self.assertEqual(virsh_output_offline, f'action="{action}"') @@ -747,10 +754,12 @@ class TestMachinesSettings(machineslib.VirtualMachinesCase): b = self.browser m = self.machine - default_libvirt_vsock_address = "3" # When we don't specify address, libvit will choose lowest available (3 in case of clean VM) + # When we don't specify address, libvit will choose lowest available (3 in case of clean VM) + default_libvirt_vsock_address = "3" def setVsock(auto, address=None, machine_has_no_vsock=False, pixel_test_tag=None, reboot_machine=False): - # If no vsock configured, we are attaching a new vsock device. If vsock already is set, we are editing an exiting vsock device + # If no vsock configured, we are attaching a new vsock device. If vsock already is set, + # we are editing an exiting vsock device if machine_has_no_vsock: b.wait_in_text("#vm-subVmTest1-vsock-button", "add") else: @@ -807,11 +816,13 @@ class TestMachinesSettings(machineslib.VirtualMachinesCase): # When attaching adding a new vsock, no tooltip should be present b.wait_not_present("#vsock-tooltip") - # Libvirt doesn't support editing vsock device on RUNNING vm, so a live VM config will persist the previously configured vsock action until reboot + # Libvirt doesn't support editing vsock device on RUNNING vm, so a live VM config will + # persist the previously configured vsock action until reboot. # On the other hand, libvirt does support attaching a vsock to a RUNNING VM # So in summary: # - if no previous vsock is configured on a VM, we are attaching a new vsock device and live VM config will get updated - # - if vsock action is configured on a VM, and we are editing an editing vsock device, the live VM config will persist the old setting until VM is rebooted + # - if vsock action is configured on a VM, and we are editing an editing vsock device, the live VM config will persist + # the old setting until VM is rebooted virsh_output_auto = m.execute("virsh dumpxml subVmTest1 | xmllint --xpath '/domain/devices/vsock/cid/@auto' -").strip() if previous_auto is not None: # Editing exiting vsock expected_auto = "yes" if previous_auto else "no" @@ -836,7 +847,8 @@ class TestMachinesSettings(machineslib.VirtualMachinesCase): self.assertEqual(virsh_output_offline_auto, f'auto="{expected_auto_offline}"') expected_address_offline = new_address - virsh_output_offline_address = m.execute("virsh dumpxml subVmTest1 --inactive | xmllint --xpath '/domain/devices/vsock/cid/@address' -").strip() + address_cmd = "virsh dumpxml subVmTest1 --inactive | xmllint --xpath '/domain/devices/vsock/cid/@address' -" + virsh_output_offline_address = m.execute(address_cmd).strip() if expected_address_offline: self.assertEqual(virsh_output_offline_address, f'address="{expected_address_offline}"') @@ -882,7 +894,8 @@ class TestMachinesSettings(machineslib.VirtualMachinesCase): # Have a canary here which will let us know once this is no longer true m.execute("virt-xml subVmTest1 --add-device --vsock cid.auto=yes") # Attaching second vsock is expected to fail - self.assertRaises(subprocess.CalledProcessError, m.execute, "virt-xml subVmTest1 --add-device --vsock cid.auto=no,cid.address=8") + self.assertRaises(subprocess.CalledProcessError, m.execute, + "virt-xml subVmTest1 --add-device --vsock cid.auto=no,cid.address=8") m.execute("virt-xml subVmTest1 --remove-device --vsock 1") # Test configuring vsock for shutoff VM diff --git a/test/check-machines-snapshots b/test/check-machines-snapshots index 57a7fe007..05533c936 100755 --- a/test/check-machines-snapshots +++ b/test/check-machines-snapshots @@ -61,7 +61,8 @@ class TestMachinesSnapshots(machineslib.VirtualMachinesCase): b.wait_in_text("#vm-subVmTest1-snapshots .pf-v5-c-empty-state", "No snapshots") # Check snapshot for running VM - m.execute("virsh detach-disk --domain subVmTest1 --target vda --persistent") # vda is raw disk, which are not supported by internal snapshots + # vda is raw disk, which are not supported by internal snapshots + m.execute("virsh detach-disk --domain subVmTest1 --target vda --persistent") m.execute("qemu-img create -f qcow2 /var/lib/libvirt/images/foobar.qcow2 1M") m.execute("virsh attach-disk --domain subVmTest1 --source /var/lib/libvirt/images/foobar.qcow2 --target vdb --persistent") m.execute("virsh snapshot-create-as --domain subVmTest1 --name snapshotB --description 'Description of snapshotB' --disk-only") @@ -160,7 +161,8 @@ class TestMachinesSnapshots(machineslib.VirtualMachinesCase): def assert_pixels(self): if self.name == 'test_snap_1': - b.assert_pixels("#vm-subVmTest1-create-snapshot-modal", "create-snapshot-dialog" + ("" if not self.xfail else "-error"), skip_layouts=["rtl"]) + b.assert_pixels("#vm-subVmTest1-create-snapshot-modal", + "create-snapshot-dialog" + ("" if not self.xfail else "-error"), skip_layouts=["rtl"]) def cancel(self): b.click(".pf-v5-c-modal-box__footer button:contains(Cancel)") @@ -244,7 +246,8 @@ class TestMachinesSnapshots(machineslib.VirtualMachinesCase): def cleanup(self): b.click(f"#delete-vm-subVmTest1-snapshot-{self.snap_num}") b.wait_in_text(".pf-v5-c-modal-box .pf-v5-c-modal-box__header .pf-v5-c-modal-box__title", "Delete snapshot?") - b.wait_in_text(".pf-v5-c-modal-box__body .pf-v5-c-description-list", f"{self.name} will be deleted from {self.vm_name}") + b.wait_in_text(".pf-v5-c-modal-box__body .pf-v5-c-description-list", + f"{self.name} will be deleted from {self.vm_name}") b.click('.pf-v5-c-modal-box__footer button:contains("Delete")') b.wait_not_present(f"#vm-subVmTest1-snapshot-{self.snap_num}-name:contains({self.name})") diff --git a/test/check-machines-storage-pools b/test/check-machines-storage-pools index a00b827be..9cd7a8a12 100755 --- a/test/check-machines-storage-pools +++ b/test/check-machines-storage-pools @@ -64,7 +64,8 @@ class TestMachinesStoragePools(machineslib.VirtualMachinesCase): m.execute("virsh vol-create-as myPoolTwo VolumeTwo --capacity 1G --format qcow2") m.execute("virsh vol-create-as myPoolTwo VolumeThree --capacity 1G --format qcow2") m.execute("virsh vol-create-as myPoolTwo VolumeFour --capacity 1G --format qcow2") - testlib.wait(lambda: all(volume in m.execute("virsh vol-list myPoolTwo") for volume in ["VolumeOne", "VolumeTwo", "VolumeThree", "VolumeFour"])) + testlib.wait(lambda: all(volume in m.execute("virsh vol-list myPoolTwo") + for volume in ["VolumeOne", "VolumeTwo", "VolumeThree", "VolumeFour"])) m.execute('virsh pool-refresh myPoolOne; virsh pool-refresh myPoolTwo') connectionName = m.execute("virsh uri | head -1 | cut -d/ -f4").strip() @@ -163,7 +164,8 @@ class TestMachinesStoragePools(machineslib.VirtualMachinesCase): # Try deactivating and activating a pool b.click(f"#deactivate-pool-myPoolOne-{connectionName}") b.wait_in_text(f"#pool-myPoolOne-{connectionName}-state", "inactive") - b.wait_in_text(f"tr[data-row-id='pool-myPoolOne-{connectionName}'] + tr .pf-v5-c-empty-state", "Activate the storage pool to administer volumes") + b.wait_in_text(f"tr[data-row-id='pool-myPoolOne-{connectionName}'] + tr .pf-v5-c-empty-state", + "Activate the storage pool to administer volumes") b.wait_visible(f'#myPoolOne-{connectionName}-create-volume-button:disabled') b.click(f"#activate-pool-myPoolOne-{connectionName}") b.wait_in_text(f"#pool-myPoolOne-{connectionName}-state", "active") @@ -598,7 +600,8 @@ class TestMachinesStoragePools(machineslib.VirtualMachinesCase): b.wait_not_present("#create-volume-dialog-modal") else: for xfo in self.xfail_objects: - b.wait_in_text(f"#create-volume-dialog-{xfo}-group .pf-v5-c-form__helper-text .pf-m-error", self.xfail_error) + b.wait_in_text(f"#create-volume-dialog-{xfo}-group .pf-v5-c-form__helper-text .pf-m-error", + self.xfail_error) def verify(self): # Check that the defined volume is now visible @@ -1024,6 +1027,7 @@ class TestMachinesStoragePools(machineslib.VirtualMachinesCase): # iscsi pool deletion # TODO: Arch image has no iscsi yet if "debian" not in m.image and "arch" not in m.image: + xfail_error = "this function is not supported by the connection driver: storage pool does not support vol deletion" StoragePoolsCreationAndDeletion(self, name="iscsi-pool-1", pool_type="iscsi", @@ -1032,7 +1036,7 @@ class TestMachinesStoragePools(machineslib.VirtualMachinesCase): activate=True, remove_volume=True, xfail=True, - xfail_error="this function is not supported by the connection driver: storage pool does not support vol deletion").execute() + xfail_error=xfail_error).execute() StoragePoolsCreationAndDeletion(self, name="iscsi-pool-2", diff --git a/test/check-machines-virtualization b/test/check-machines-virtualization index a4f323f1f..902f5ed62 100755 --- a/test/check-machines-virtualization +++ b/test/check-machines-virtualization @@ -59,8 +59,10 @@ class TestMachinesVirtualization(machineslib.VirtualMachinesCase): self.addCleanup(m.execute, f"echo '{core_pattern}' > /proc/sys/kernel/core_pattern") def stopLibvirtSocket(): - m.execute(f"systemctl stop {self.getLibvirtServiceName()}-ro.socket {self.getLibvirtServiceName()}.socket {self.getLibvirtServiceName()}-admin.socket") - self.addCleanup(m.execute, f"systemctl start {self.getLibvirtServiceName()}-ro.socket {self.getLibvirtServiceName()}.socket {self.getLibvirtServiceName()}-admin.socket") + m.execute( + f"systemctl stop {self.getLibvirtServiceName()}-ro.socket {self.getLibvirtServiceName()}.socket {self.getLibvirtServiceName()}-admin.socket") + self.addCleanup(m.execute, + f"systemctl start {self.getLibvirtServiceName()}-ro.socket {self.getLibvirtServiceName()}.socket {self.getLibvirtServiceName()}-admin.socket") def stopLibvirtService(): m.execute(f"systemctl stop {libvirtServiceName}") diff --git a/test/files/mock-rhsm-rest b/test/files/mock-rhsm-rest index b3e25409b..3157b7039 100755 --- a/test/files/mock-rhsm-rest +++ b/test/files/mock-rhsm-rest @@ -54,7 +54,8 @@ class handler(BaseHTTPRequestHandler): fs = os.fstat(f.fileno()) self.send_header("Content-Length", str(fs.st_size)) self.end_headers() - shutil.copyfileobj(f, self.wfile, 10240) # Specify 1KiB buffer size, otherwise the download might be too fast on some platforms + # Specify 1KiB buffer size, otherwise the download might be too fast on some platforms + shutil.copyfileobj(f, self.wfile, 10240) return self.send_response(404) diff --git a/test/machineslib.py b/test/machineslib.py index 425a930b9..4b4d10889 100644 --- a/test/machineslib.py +++ b/test/machineslib.py @@ -34,8 +34,11 @@ def hasMonolithicDaemon(image): class VirtualMachinesCaseHelpers: def waitPageInit(self): - virtualization_disabled_ignored = self.browser.call_js_func("localStorage.getItem", "virtualization-disabled-ignored") == "true" - virtualization_enabled = "PASS" in self.machine.execute("virt-host-validate qemu | grep 'Checking for hardware virtualization' || true") + m = self.machine + virtualization_disabled_ignored = \ + self.browser.call_js_func("localStorage.getItem", "virtualization-disabled-ignored") == "true" + virtualization_enabled = \ + "PASS" in m.execute("virt-host-validate qemu | grep 'Checking for hardware virtualization' || true") if not virtualization_enabled and not virtualization_disabled_ignored: self.browser.click("#ignore-hw-virtualization-disabled-btn") with self.browser.wait_timeout(30): @@ -102,12 +105,13 @@ def waitVmRow(self, vmName, connectionName='system', present=True): b.wait_not_present(vm_row) def togglePoolRow(self, poolName, connectionName="system"): - isExpanded = 'pf-m-expanded' in self.browser.attr(f"tbody tr[data-row-id=\"pool-{poolName}-{connectionName}\"] + tr", "class") # click on the row header - self.browser.click(f"tbody tr[data-row-id=\"pool-{poolName}-{connectionName}\"] .pf-v5-c-table__toggle button") # click on the row header + b = self.browser + isExpanded = 'pf-m-expanded' in b.attr(f"tbody tr[data-row-id=\"pool-{poolName}-{connectionName}\"] + tr", "class") + b.click(f"tbody tr[data-row-id=\"pool-{poolName}-{connectionName}\"] .pf-v5-c-table__toggle button") if isExpanded: - self.browser.wait_not_present(f"tbody tr[data-row-id=\"pool-{poolName}-{connectionName}\"] + tr.pf-m-expanded") # click on the row header + b.wait_not_present(f"tbody tr[data-row-id=\"pool-{poolName}-{connectionName}\"] + tr.pf-m-expanded") else: - self.browser.wait_visible(f"tbody tr[data-row-id=\"pool-{poolName}-{connectionName}\"] + tr.pf-m-expanded") # click on the row header + b.wait_visible(f"tbody tr[data-row-id=\"pool-{poolName}-{connectionName}\"] + tr.pf-m-expanded") def waitPoolRow(self, poolName, connectionName="system", present=True): b = self.browser @@ -118,12 +122,14 @@ def waitPoolRow(self, poolName, connectionName="system", present=True): b.wait_not_present(pool_row) def toggleNetworkRow(self, networkName, connectionName="system"): - isExpanded = 'pf-m-expanded' in self.browser.attr(f"tbody tr[data-row-id=\"network-{networkName}-{connectionName}\"] + tr", "class") # click on the row header - self.browser.click(f"tbody tr[data-row-id=\"network-{networkName}-{connectionName}\"] .pf-v5-c-table__toggle button") # click on the row header + b = self.browser + isExpanded = 'pf-m-expanded' in b.attr(f"tbody tr[data-row-id=\"network-{networkName}-{connectionName}\"] + tr", + "class") + b.click(f"tbody tr[data-row-id=\"network-{networkName}-{connectionName}\"] .pf-v5-c-table__toggle button") if isExpanded: - self.browser.wait_not_present(f"tbody tr[data-row-id=\"network-{networkName}-{connectionName}\"] + tr.pf-m-expanded") # click on the row header + b.wait_not_present(f"tbody tr[data-row-id=\"network-{networkName}-{connectionName}\"] + tr.pf-m-expanded") else: - self.browser.wait_visible(f"tbody tr[data-row-id=\"network-{networkName}-{connectionName}\"] + tr.pf-m-expanded") # click on the row header + b.wait_visible(f"tbody tr[data-row-id=\"network-{networkName}-{connectionName}\"] + tr.pf-m-expanded") def waitNetworkRow(self, networkName, connectionName="system", present=True): b = self.browser @@ -156,7 +162,8 @@ def startLibvirt(self, m): if ! echo "$out" | grep -q 'Active.*yes'; then virsh net-start default; fi""") m.execute(r"until virsh net-info default | grep 'Active:\s*yes'; do sleep 1; done") - def createVm(self, name, graphics='none', ptyconsole=False, running=True, memory=128, connection='system', machine=None, os=None): + def createVm(self, name, graphics='none', ptyconsole=False, running=True, memory=128, + connection='system', machine=None, os=None): m = machine or self.machine if os is None: @@ -298,7 +305,7 @@ def setup_mock_server(self, mock_server_filename, subj_names): cmds = [ # Generate certificate for https server f"cd {self.vm_tmpdir}", - f"openssl req -x509 -newkey rsa:4096 -nodes -keyout server.key -new -out server.crt -config {self.vm_tmpdir}/min-openssl-config.cnf -sha256 -days 365 -extensions dn" + f"openssl req -x509 -newkey rsa:4096 -nodes -keyout server.key -new -out server.crt -config {self.vm_tmpdir}/min-openssl-config.cnf -sha256 -days 365 -extensions dn" # noqa: E501 ] if self.machine.image.startswith("ubuntu") or self.machine.image.startswith("debian"): @@ -330,7 +337,8 @@ def setup_mock_server(self, mock_server_filename, subj_names): # # and on certain distribution supports only https (not http) # see: block-drv-ro-whitelist option in qemu-kvm.spec for certain distribution - return self.machine.spawn(f"cd /var/lib/libvirt; exec python3 {self.vm_tmpdir}/{mock_server_filename} {self.vm_tmpdir}/server.crt {self.vm_tmpdir}/server.key", "httpsserver") + return self.machine.spawn(f"cd /var/lib/libvirt; exec python3 {self.vm_tmpdir}/{mock_server_filename} {self.vm_tmpdir}/server.crt {self.vm_tmpdir}/server.key", # noqa: E501 + "httpsserver") def waitLogFile(self, logfile, expected_text): try: @@ -438,16 +446,17 @@ def stop_all(): # user libvirtd instance tends to SIGABRT with "Failed to find user record for uid .." on shutdown during cleanup # so make sure that there are no leftover user processes that bleed into the next test - self.addCleanup(self.machine.execute, '''pkill -u admin || true; while [ -n "$(pgrep -au admin | grep -v 'systemd --user')" ]; do sleep 0.5; done''') + clean_cmd = '''pkill -u admin || true; while [ -n "$(pgrep -au admin | grep -v 'systemd --user')" ]; do sleep 0.5; done''' + self.addCleanup(m.execute, clean_cmd) # FIXME: report downstream; AppArmor noisily denies some operations, but they are not required for us self.allow_journal_messages(r'.* type=1400 .* apparmor="DENIED" operation="capable" profile="\S*libvirtd.* capname="sys_rawio".*') # AppArmor doesn't like the non-standard path for our storage pools - self.allow_journal_messages('.* type=1400 .* apparmor="DENIED" operation="open".* profile="virt-aa-helper" name="%s.*' % self.vm_tmpdir) + self.allow_journal_messages(f'.* type=1400 .* apparmor="DENIED" operation="open".* profile="virt-aa-helper" name="{self.vm_tmpdir}.*') # FIXME: Testing on Arch Linux fails randomly with networkmanager time outs while the test passes. if m.image == 'arch': - self.allow_journal_messages(r".* couldn't get all properties of org.freedesktop.NetworkManager.Device at /org/freedesktop/NetworkManager/Devices/\d+: Timeout was reached") + self.allow_journal_messages(r".* couldn't get all properties of org.freedesktop.NetworkManager.Device at /org/freedesktop/NetworkManager/Devices/\d+: Timeout was reached") # noqa: E501 # avoid error noise about resources getting cleaned up self.addCleanup(lambda: not self.browser.valid or self.browser.logout())