Skip to content

Commit

Permalink
test: reduce line length to 130
Browse files Browse the repository at this point in the history
  • Loading branch information
jelly committed Nov 4, 2024
1 parent 02db321 commit da34dd2
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 50 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ exclude = [
"node_modules/",
]
# FIXME: we want 118, but needs fixing tests first
line-length = 135
line-length = 130
preview = true
src = []

Expand Down
3 changes: 2 additions & 1 deletion test/check-machines-consoles
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ fullscreen=0
b.wait_not_present("#pf-v5-c-console__type-selector + .pf-v5-c-select__menu")

# In case the OS already finished booting, press Enter into the console to re-trigger the login prompt
# Sometimes, pressing Enter one time doesn't take effect, so loop to press Enter to make sure the console has accepted it
# Sometimes, pressing Enter one time doesn't take effect, so loop to press Enter to make sure
# the console has accepted it.
for _ in range(0, 60):
b.focus(f"#{name}-terminal .xterm-accessibility-tree")
b.key("Enter")
Expand Down
35 changes: 23 additions & 12 deletions test/check-machines-create
Original file line number Diff line number Diff line change
Expand Up @@ -174,20 +174,22 @@ class TestMachinesCreate(machineslib.VirtualMachinesCase):
is_warning=True)

# user login
errors = {"create-vm-dialog-user-login": "User login must not be empty when user password is set"}
runner.checkDialogFormValidationTest(TestMachinesCreate.VmDialog(self, sourceType='cloud',
storage_size=10, storage_size_unit='MiB',
location=config.VALID_DISK_IMAGE_PATH,
user_password="catsaremybestfr13nds",
create_and_run=True),
{"create-vm-dialog-user-login": "User login must not be empty when user password is set"})
errors)

# user login
errors = {"create-vm-dialog-root-password-pw1": "Password quality check failed"}
runner.checkDialogFormValidationTest(TestMachinesCreate.VmDialog(self, sourceType='cloud',
storage_size=10, storage_size_unit='MiB',
location=config.VALID_DISK_IMAGE_PATH,
root_password="foo",
create_and_run=True),
{"create-vm-dialog-root-password-pw1": "Password quality check failed"},
errors,
create=False,
is_warning=True)

Expand All @@ -199,22 +201,25 @@ class TestMachinesCreate(machineslib.VirtualMachinesCase):
self.machine.execute("ssh-keygen -t rsa -N '' -f /tmp/rsakey")
rsakey = self.machine.execute("cat /tmp/rsakey.pub").strip()
self.addCleanup(self.machine.execute, "rm -f /tmp/rsakey*")

errors = {"create-vm-dialog-user-login": "User login must not be empty when SSH keys are set"}
runner.checkDialogFormValidationTest(TestMachinesCreate.VmDialog(self, sourceType='cloud',
storage_size=10, storage_size_unit='MiB',
location=config.VALID_DISK_IMAGE_PATH,
root_password="foobar",
user_login="",
ssh_keys=[rsakey],
create_and_run=True),
{"create-vm-dialog-user-login": "User login must not be empty when SSH keys are set"})
errors)

# Without the root password and "Create and edit"
errors = {"create-vm-dialog-user-login": "User login must not be empty when SSH keys are set"}
runner.checkDialogFormValidationTest(TestMachinesCreate.VmDialog(self, sourceType='cloud',
storage_size=10, storage_size_unit='MiB',
location=config.VALID_DISK_IMAGE_PATH,
user_login="",
ssh_keys=[rsakey]),
{"create-vm-dialog-user-login": "User login must not be empty when SSH keys are set"})
errors)

# Delete SSH keys
dialog = TestMachinesCreate.VmDialog(self, sourceType='cloud',
Expand Down Expand Up @@ -1050,9 +1055,11 @@ vnc_password= "{vnc_passwd}"

b.wait_visible("#create-vm-dialog")
if self.sourceType == 'disk_image':
b.wait_in_text(".pf-v5-c-modal-box .pf-v5-c-modal-box__header .pf-v5-c-modal-box__title", "Import a virtual machine")
b.wait_in_text(".pf-v5-c-modal-box .pf-v5-c-modal-box__header .pf-v5-c-modal-box__title",
"Import a virtual machine")
else:
b.wait_in_text(".pf-v5-c-modal-box .pf-v5-c-modal-box__header .pf-v5-c-modal-box__title", "Create new virtual machine")
b.wait_in_text(".pf-v5-c-modal-box .pf-v5-c-modal-box__header .pf-v5-c-modal-box__title",
"Create new virtual machine")

if self.os_name is not None:
# remove os codename from os name, e.g.: 'bullseye' in 'Debian 11 (bullseye)'
Expand Down Expand Up @@ -1459,7 +1466,8 @@ vnc_password= "{vnc_passwd}"
append=True, value_check=False)
# Check that ssh key was validated
if self.ssh_key_invalid:
self.browser.wait_attr(f"#create-vm-dialog-ssh-key-{idx} .pf-v5-c-form__group", "testdata", "key-invalid")
self.browser.wait_attr(f"#create-vm-dialog-ssh-key-{idx} .pf-v5-c-form__group",
"testdata", "key-invalid")
else:
b.wait_visible(f"#create-vm-dialog-ssh-key-{idx} #validated")

Expand Down Expand Up @@ -1632,8 +1640,8 @@ vnc_password= "{vnc_passwd}"
self.machine.execute("virsh pool-start default")

def _fakeOsDBInfoFedora(self):
# Fake the osinfo-db data in order that it will allow spawn the installation - of course we don't expect it to succeed -
# we just need to check that the VM was spawned
# Fake the osinfo-db data in order that it will allow spawn the installation
# - of course we don't expect it to succeed - we just need to check that the VM was spawned
fedora_28_xml = self.machine.execute("cat /usr/share/osinfo/os/fedoraproject.org/fedora-28.xml")
root = ET.fromstring(fedora_28_xml)
root.find('os').find('resources').find('minimum').find('ram').text = '134217728'
Expand Down Expand Up @@ -1722,7 +1730,8 @@ vnc_password= "{vnc_passwd}"
else:
b.wait_in_text(".pf-v5-c-empty-state__content", "Downloading image")
# Progress is shown at VM page empty state
self.assertRegex(b.text(".pf-v5-c-empty-state__body .pf-v5-c-progress__status"), r"^[0-9][0-9]?%$|^100%$")
self.assertRegex(b.text(".pf-v5-c-empty-state__body .pf-v5-c-progress__status"),
r"^[0-9][0-9]?%$|^100%$")

with b.wait_timeout(60):
b.wait_in_text(f"#vm-{dialog.name}-{dialog.connection}-state", final_state)
Expand Down Expand Up @@ -1785,7 +1794,8 @@ vnc_password= "{vnc_passwd}"
b.wait_in_text(f"#vm-{name}-{connection}-state", "Running")
self._assertCorrectConfiguration(dialog)

# Wait for virt-install to define the VM and then stop it - otherwise we get 'domain is ready being removed' error
# Wait for virt-install to define the VM and then stop it -
# otherwise we get 'domain is ready being removed' error
testlib.wait(lambda: dialog.name in self.machine.execute("virsh list --persistent"), delay=3)

# unfinished install script runs indefinitely, so we need to force it off
Expand Down Expand Up @@ -2062,7 +2072,8 @@ vnc_password= "{vnc_passwd}"
def createThenInstallTest(self, dialog, installFromVmDetails=False, tryWithFailInstall=False):
self._tryCreateThenInstall(dialog, installFromVmDetails, tryWithFailInstall) \
._assertScriptFinished() \
._assertDomainDefined(dialog.name, dialog.connection, install_phase="true" if tryWithFailInstall else "false") \
._assertDomainDefined(dialog.name,
dialog.connection, install_phase="true" if tryWithFailInstall else "false") \
._deleteVm(dialog) \
.checkEnvIsEmpty()

Expand Down
21 changes: 13 additions & 8 deletions test/check-machines-disks
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,8 @@ class TestMachinesDisks(machineslib.VirtualMachinesCase):
# https://piware.de/2013/09/how-to-watch-system-d-bus-method-calls/
m.write("/usr/share/dbus-1/system-local.conf", SYSTEM_LOCAL_CONF)
# Setup dbus monitor to watch for disk ejection call
m.spawn(
"dbus-monitor --system \"interface='org.libvirt.Domain',member='UpdateDevice'\" > /tmp/dbus_monitor_logs", "dbusmonitor")
m.spawn("dbus-monitor --system \"interface='org.libvirt.Domain',member='UpdateDevice'\" > /tmp/dbus_monitor_logs",
"dbusmonitor")

# Force eject the disc
b.click(".pf-v5-c-modal-box__footer button:contains(Force eject)")
Expand Down Expand Up @@ -589,9 +589,11 @@ class TestMachinesDisks(machineslib.VirtualMachinesCase):
self.verify_disk_added()
else:
if self.xfail_object:
self.test_obj.browser.wait_in_text(f"{prefix}-{self.xfail_object}-helper.pf-m-error", self.xfail_error_message)
self.test_obj.browser.wait_in_text(f"{prefix}-{self.xfail_object}-helper.pf-m-error",
self.xfail_error_message)
else:
self.test_obj.browser.wait_in_text(".pf-v5-c-modal-box__body .pf-v5-c-alert__title", self.xfail_error_title)
self.test_obj.browser.wait_in_text(".pf-v5-c-modal-box__body .pf-v5-c-alert__title",
self.xfail_error_title)
self.test_obj.browser.click(f"{prefix}-dialog-cancel")
self.test_obj.browser.wait_not_present(".pf-v5-c-modal-box")

Expand Down Expand Up @@ -712,7 +714,8 @@ class TestMachinesDisks(machineslib.VirtualMachinesCase):
m = self.test_obj.machine
with b.wait_timeout(60):
b.wait_not_present(f"#vm-{self.vm_name}-disks-adddisk-dialog-modal-window")
if self.device == "cdrom" or (self.file_path and self.file_path.endswith(".iso")) or self.expected_volume_format == "iso":
if self.device == "cdrom" or (self.file_path and self.file_path.endswith(".iso")) \
or self.expected_volume_format == "iso":
expected_bus_type = self.bus_type or "scsi"
expected_device = self.device or "cdrom"
else:
Expand Down Expand Up @@ -758,7 +761,8 @@ class TestMachinesDisks(machineslib.VirtualMachinesCase):
b.wait_in_text(f"#vm-{self.vm_name}-disks-{self.expected_target}-type", "raw")
elif self.expected_volume_format != "iso":
# If volume is ISO file, libvirt doesn't assign drive.type to a disk
b.wait_in_text(f"#vm-{self.vm_name}-disks-{self.expected_target}-type", self.volume_format or expected_format)
b.wait_in_text(f"#vm-{self.vm_name}-disks-{self.expected_target}-type",
self.volume_format or expected_format)
else:
b.wait_in_text(f'#vm-{self.vm_name}-disks-{self.expected_target}-source-file', self.file_path)
domainXML = self.test_obj.machine.execute(f"virsh dumpxml {self.vm_name}")
Expand Down Expand Up @@ -801,7 +805,8 @@ class TestMachinesDisks(machineslib.VirtualMachinesCase):
virsh pool-define-as iscsi-pool --type iscsi --target /dev/disk/by-id --source-host 127.0.0.1 --source-dev {target_iqn}
virsh pool-start iscsi-pool
""")
testlib.wait(lambda: "unit:0:0:0" in self.machine.execute("virsh pool-refresh iscsi-pool; virsh vol-list iscsi-pool"), delay=3)
cmd = "virsh pool-refresh iscsi-pool; virsh vol-list iscsi-pool"
testlib.wait(lambda: "unit:0:0:0" in self.machine.execute(cmd), delay=3)

self.addCleanup(self.machine.execute, "virsh pool-destroy iscsi-pool; virsh pool-undefine iscsi-pool")

Expand Down Expand Up @@ -1292,7 +1297,7 @@ class TestMachinesDisks(machineslib.VirtualMachinesCase):

# Ensure that the bus type autofilled value is according to the bus types of the existing disks of the guest,
# even when these are not in the predefined value (see ide)
m.execute("virt-xml subVmTest1 --edit --disk target=vda,bus=ide,path=/var/lib/libvirt/images/subVmTest1-2.img,clearxml=yes")
m.execute("virt-xml subVmTest1 --edit --disk target=vda,bus=ide,path=/var/lib/libvirt/images/subVmTest1-2.img,clearxml=yes") # noqa: E501
b.wait_text("#vm-subVmTest1-disks-vda-bus", "ide")
b.click(prefix)
b.click(f"{prefix}-custompath")
Expand Down
6 changes: 4 additions & 2 deletions test/check-machines-filesystems
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ class TestMachinesFilesystems(machineslib.VirtualMachinesCase):
domain_xml = "virsh -c qemu:///system dumpxml subVmTest1"
xmllint_element = f"{domain_xml} | xmllint --xpath 'string(//domain/{{prop}})' -"

self.assertEqual('/tmp/dir1/', self.machine.execute(xmllint_element.format(prop='devices/filesystem/source/@dir')).strip())
self.assertEqual('/tmp/dir1/',
self.machine.execute(xmllint_element.format(prop='devices/filesystem/source/@dir')).strip())
self.assertEqual('dir1', self.machine.execute(xmllint_element.format(prop='devices/filesystem/target/@dir')).strip())
self.assertEqual('on', self.machine.execute(xmllint_element.format(prop='devices/filesystem/binary/@xattr')).strip())
self.assertEqual('shared', self.machine.execute(xmllint_element.format(prop='memoryBacking/access/@mode')).strip())
Expand All @@ -110,7 +111,8 @@ class TestMachinesFilesystems(machineslib.VirtualMachinesCase):
b.wait_in_text("tr[data-row-id='vm-subVmTest1-filesystem-/tmp/dir2/-dir2'] td[data-label='Source path']", "/tmp/dir2/")
b.wait_in_text("tr[data-row-id='vm-subVmTest1-filesystem-/tmp/dir2/-dir2'] td[data-label='Mount tag']", "dir2")

self.assertEqual('/tmp/dir2/', self.machine.execute(xmllint_element.format(prop='devices/filesystem[2]/source/@dir')).strip())
self.assertEqual('/tmp/dir2/',
self.machine.execute(xmllint_element.format(prop='devices/filesystem[2]/source/@dir')).strip())
self.assertEqual('dir2', self.machine.execute(xmllint_element.format(prop='devices/filesystem[2]/target/@dir')).strip())
self.assertEqual('', self.machine.execute(xmllint_element.format(prop='devices/filesystem[2]/binary/@xattr')).strip())

Expand Down
2 changes: 1 addition & 1 deletion test/check-machines-lifecycle
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ class TestMachinesLifecycle(machineslib.VirtualMachinesCase):
self.createVm(name, running=False)

m.execute("virsh vol-create-as --pool images --name tmpdisk --capacity 1 --format qcow2")
m.execute(f"virt-xml {name} --add-device --disk source.pool=images,source.volume=tmpdisk,target.dev=sdb,driver.type=qcow2")
m.execute(f"virt-xml {name} --add-device --disk source.pool=images,source.volume=tmpdisk,target.dev=sdb,driver.type=qcow2") # noqa: E501
m.execute(f"virsh snapshot-create-as --domain {name} --name snapshotFails")
b.reload()
b.enter_page('/machines')
Expand Down
3 changes: 2 additions & 1 deletion test/check-machines-manifest
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class TestMachinesManifest(testlib.MachineCase):
b.wait_in_text("#host-apps .pf-m-current", "Overview")

# Cockpit with a C bridge
if m.image.startswith("rhel-8") or m.image.startswith("centos-8") or m.image == "debian-stable" or m.image == "ubuntu-2204":
if m.image.startswith("rhel-8") or m.image.startswith("centos-8") \
or m.image == "debian-stable" or m.image == "ubuntu-2204":
self.assertIn("Virtual machines", b.text("#host-apps"))
else:
self.assertNotIn("Virtual machines", b.text("#host-apps"))
Expand Down
3 changes: 2 additions & 1 deletion test/check-machines-networks
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ class TestMachinesNetworks(machineslib.VirtualMachinesCase):
def verify_overview(self):
# Check basic network properties
modes = {"nat": "NAT", "none": "None (isolated network)", "open": "Open", "route": "Routed",
"bridge": "Bridge", "private": "Private", "vepa": "VEPA", "passthrough": "Passthrough", "hostdev": "Hostdev"}
"bridge": "Bridge", "private": "Private", "vepa": "VEPA",
"passthrough": "Passthrough", "hostdev": "Hostdev"}
connectionName = m.execute("virsh uri | head -1 | cut -d/ -f4").strip()

b.wait_in_text(f"#network-{self.name}-{connectionName}-forwarding", modes[self.forward_mode])
Expand Down
Loading

0 comments on commit da34dd2

Please sign in to comment.