Skip to content

Commit

Permalink
test: reduce line length to 135
Browse files Browse the repository at this point in the history
  • Loading branch information
jelly committed Oct 16, 2024
1 parent 8db8a5d commit 5f8a4be
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 39 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 = 140
line-length = 135
preview = true
src = []

Expand Down
14 changes: 9 additions & 5 deletions test/check-machines-create
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,8 @@ class TestMachinesCreate(machineslib.VirtualMachinesCase):
self.machine.execute("virsh start pxe-guest")

# The file is full of ANSI control characters in between every letter, filter them out
testlib.wait(lambda: self.machine.execute(r"sed 's,\x1B\[[0-9;]*[a-zA-Z],,g' /tmp/serial.txt | grep 'Rebooting in 60'"), delay=3)
cmd = r"sed 's,\x1B\[[0-9;]*[a-zA-Z],,g' /tmp/serial.txt | grep 'Rebooting in 60'"
testlib.wait(lambda: self.machine.execute(cmd), delay=3)
self.goToMainPage()

self.machine.execute("virsh destroy pxe-guest")
Expand Down Expand Up @@ -683,7 +684,8 @@ vnc_password= "{vnc_passwd}"
"virsh pool-start iscsi-pool"
]
print(self.machine.execute("; ".join(cmd).format(target_iqn)))
testlib.wait(lambda: "unit:0:0:0" in self.machine.execute("virsh pool-refresh iscsi-pool; virsh vol-list iscsi-pool"), delay=3)
pool_refresh_dump_cmd = "virsh pool-refresh iscsi-pool; virsh vol-list iscsi-pool"
testlib.wait(lambda: "unit:0:0:0" in self.machine.execute(pool_refresh_dump_cmd), delay=3)

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

Expand Down Expand Up @@ -1039,6 +1041,7 @@ vnc_password= "{vnc_passwd}"

def open(self):
b = self.browser
m = self.machine

if self.sourceType == 'disk_image':
b.click("#import-existing-vm")
Expand All @@ -1057,8 +1060,8 @@ vnc_password= "{vnc_passwd}"
query_result = f'{query_result}'
# check if there is os present in osinfo-query because it can be filtered out in the UI
# throws exception if grep fails
self.machine.execute(
fr"osinfo-query os --fields=name | tail -n +3 | sed -e 's/\s*|\s*/|/g; s/^\s*//g; s/\s*$//g' | grep '{query_result}'")
sanitize_cmd = r"sed -e 's/\s*|\s*/|/g; s/^\s*//g; s/\s*$//g'"
m.execute(fr"osinfo-query os --fields=name | tail -n +3 | {sanitize_cmd} | grep '{query_result}'")

return self

Expand All @@ -1084,7 +1087,8 @@ vnc_password= "{vnc_passwd}"
# Check minimum requirement warnings are present
b.set_input_text("#memory-size", "127")
# memory limit must be a warning, not an error
b.wait_in_text("#memory-size-helper.pf-m-warning", "The selected operating system has minimum memory requirement of 128 MiB")
b.wait_in_text("#memory-size-helper.pf-m-warning",
"The selected operating system has minimum memory requirement of 128 MiB")

b.set_input_text("#storage-limit", "127")
# storage limit must be a warning, not an error
Expand Down
27 changes: 16 additions & 11 deletions test/check-machines-disks
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ class TestMachinesDisks(machineslib.VirtualMachinesCase):
m.execute("virsh vol-create-as myPoolOne mydisk2 --capacity 100M --format raw")
m.execute("virsh vol-create-as myPoolOne mydisk3 --capacity 100M --format qcow2")
m.execute("virsh vol-create-as myPoolOne mydisk4 --capacity 100M --format qcow2")
testlib.wait(lambda: all(disk in m.execute("virsh vol-list myPoolOne") for disk in ["mydisk", "mydisk2", "mydisk3", "mydisk4"]))
disks = ["mydisk", "mydisk2", "mydisk3", "mydisk4"]
testlib.wait(lambda: all(disk in m.execute("virsh vol-list myPoolOne") for disk in disks))

m.execute(f"""
virsh attach-disk --domain subVmTest1 --source {p1}/mydisk --target vde --targetbus virtio --persistent
Expand Down Expand Up @@ -393,7 +394,8 @@ class TestMachinesDisks(machineslib.VirtualMachinesCase):
elif self.mode == "use-existing":
b.wait_visible(f"#vm-{self.vm_name}-disks-{self.target}-insert-dialog-adddisk-existing-select-pool:enabled")
# Choose storage pool
b.select_from_dropdown(f"#vm-{self.vm_name}-disks-{self.target}-insert-dialog-adddisk-existing-select-pool", self.pool_name)
b.select_from_dropdown(f"#vm-{self.vm_name}-disks-{self.target}-insert-dialog-adddisk-existing-select-pool",
self.pool_name)
# Select from the available volumes
b.select_from_dropdown(f"#vm-{self.vm_name}-disks-{self.target}-insert-dialog-adddisk-existing-select-volume",
self.volume_name)
Expand Down Expand Up @@ -837,12 +839,13 @@ class TestMachinesDisks(machineslib.VirtualMachinesCase):
mode='use-existing',
).execute()

# Detach the iscsi disk before reaching teardown because shutting of the domains would sometimes hang when iscsi disks are attached
# Detach the iscsi disk before reaching teardown because shutting of the domains would sometimes hang when
# iscsi disks are attached.
m.execute("virsh detach-disk subVmTest1 --target vdb")

# AppArmor doesn't like the non-standard path for our storage pools
if m.image in ["debian-testing"]:
self.allow_journal_messages(f'.* type=1400 .* apparmor="DENIED" operation="open" profile="libvirt.* name="{self.vm_tmpdir}.*')
self.allow_journal_messages(f'.* type=1400 .* apparmor="DENIED" operation="open" profile="libvirt.* name="{self.vm_tmpdir}.*') # noqa: E501

def testAddDiskNFS(self):
b = self.browser
Expand All @@ -858,9 +861,11 @@ class TestMachinesDisks(machineslib.VirtualMachinesCase):
mnt_exports = os.path.join(self.vm_tmpdir, "mnt_exports")
m.execute(f"mkdir {nfs_pool} {mnt_exports}")
m.write("/etc/exports", f"{mnt_exports} 127.0.0.1/24(rw,sync,no_root_squash,no_subtree_check,fsid=0)")
m.execute("systemctl restart nfs-server")
m.execute(f"virsh pool-define-as nfs-pool --type netfs --target {nfs_pool} --source-host 127.0.0.1 --source-path {mnt_exports}")
m.execute("virsh pool-start nfs-pool")
m.execute(f"""
systemctl restart nfs-server")
virsh pool-define-as nfs-pool --type netfs --target {nfs_pool} --source-host 127.0.0.1 --source-path {mnt_exports}"
virsh pool-start nfs-pool
""")
# And create a volume on it in order to test use existing volume dialog
m.execute("virsh vol-create-as --pool nfs-pool --name nfs-volume-0 --capacity 1M --format qcow2")

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

# AppArmor doesn't like the non-standard path for our storage pools
if m.image in ["debian-testing"]:
self.allow_journal_messages(f'.* type=1400 .* apparmor="DENIED" operation="open" profile="libvirt.* name="{self.vm_tmpdir}.*')
self.allow_journal_messages(f'.* type=1400 .* apparmor="DENIED" operation="open" profile="libvirt.* name="{self.vm_tmpdir}.*') # noqa: E501

def testAddDiskPool(self):
b = self.browser
Expand Down Expand Up @@ -991,7 +996,7 @@ class TestMachinesDisks(machineslib.VirtualMachinesCase):

# AppArmor doesn't like the non-standard path for our storage pools
if m.image in ["debian-testing"]:
self.allow_journal_messages(f'.* type=1400 .* apparmor="DENIED" operation="open" profile="libvirt.* name="{self.vm_tmpdir}.*')
self.allow_journal_messages(f'.* type=1400 .* apparmor="DENIED" operation="open" profile="libvirt.* name="{self.vm_tmpdir}.*') # noqa: E501

@testlib.timeout(900)
def testAddDiskDirPool(self):
Expand Down Expand Up @@ -1159,7 +1164,7 @@ class TestMachinesDisks(machineslib.VirtualMachinesCase):

# AppArmor doesn't like the non-standard path for our storage pools
if m.image in ["debian-testing"]:
self.allow_journal_messages(f'.* type=1400 .* apparmor="DENIED" operation="open" profile="libvirt.* name="{self.vm_tmpdir}.*')
self.allow_journal_messages(f'.* type=1400 .* apparmor="DENIED" operation="open" profile="libvirt.* name="{self.vm_tmpdir}.*') # noqa: E501

def testAddDiskCustomPath(self):
b = self.browser
Expand Down Expand Up @@ -1725,7 +1730,7 @@ class TestMachinesDisks(machineslib.VirtualMachinesCase):
b.wait_text('#vm-subVmTest1-disks-vdb-source-dev', loop_dev)

if "debian" in m.image or "ubuntu" in m.image:
self.allow_journal_messages(f'.* type=1400 .* apparmor="DENIED" operation="open".*profile="virt-aa-helper" name="{loop_dev}".*')
self.allow_journal_messages(f'.* type=1400 .* apparmor="DENIED" operation="open".*profile="virt-aa-helper" name="{loop_dev}".*') # noqa: E501


if __name__ == '__main__':
Expand Down
6 changes: 4 additions & 2 deletions test/check-machines-filesystems
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,11 @@ 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.
# 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.
# 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
Expand Down
6 changes: 4 additions & 2 deletions test/check-machines-networks
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ class TestMachinesNetworks(machineslib.VirtualMachinesCase):
# HACK: Firefox 112 on RHEL 8 does not have `:has` yet, so for now use JavaScript to obtain the elements parent sibling.
b.eval_js("""
ph_input_form_helper_text = function(id) {
return document.getElementById(id).parentElement.parentElement.querySelector(".pf-v5-c-helper-text__item.pf-m-error").textContent
const selector = ".pf-v5-c-helper-text__item.pf-m-error";
return document.getElementById(id).parentElement.parentElement.querySelector(selector).textContent;
}""")

class NetworkCreateDialog(object):
Expand Down Expand Up @@ -219,7 +220,8 @@ class TestMachinesNetworks(machineslib.VirtualMachinesCase):
b.click(".pf-v5-c-modal-box__footer button:contains(Create)")

def get_helper_text(xfo):
return f"#create-network-dialog .create-network-{xfo} .pf-v5-c-form__helper-text .pf-v5-c-helper-text__item.pf-m-error"
pf_error_sel = ".pf-v5-c-form__helper-text .pf-v5-c-helper-text__item.pf-m-error"
return f"#create-network-dialog .create-network-{xfo} {pf_error_sel}"

if (self.xfail):
# Check incomplete dialog
Expand Down
26 changes: 17 additions & 9 deletions test/check-machines-nics
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TestMachinesNICs(machineslib.VirtualMachinesCase):
def setUp(self):
super().setUp()
# querying object manager often runs into that on network changes; irrelevant
self.allow_journal_messages("org.freedesktop.NetworkManager: couldn't get managed objects at /org/freedesktop: Timeout was reached")
self.allow_journal_messages("org.freedesktop.NetworkManager: couldn't get managed objects at /org/freedesktop: Timeout was reached") # noqa: E501

@testlib.no_retry_when_changed
def testVmNICs(self):
Expand All @@ -47,9 +47,11 @@ class TestMachinesNICs(machineslib.VirtualMachinesCase):
# Wait for the dynamic IP address to be assigned before logging in
# If the IP will change or get assigned after fetching the domain data the user will not see any
# changes until they refresh the page, since there is not any signal associated with this change
testlib.wait(lambda: "1" in self.machine.execute("virsh domifaddr subVmTest1 | grep 192.168.122. | wc -l"), delay=3)
cmd = "virsh domifaddr subVmTest1 | grep 192.168.122. | wc -l"
testlib.wait(lambda: "1" in self.machine.execute(cmd), delay=3)
if "rhel-8" not in m.image:
testlib.wait(lambda: "1" in self.machine.execute("virsh domifaddr --source agent subVmTest1 | grep fe80:: | wc -l"), delay=3)
cmd = "virsh domifaddr --source agent subVmTest1 | grep fe80:: | wc -l"
testlib.wait(lambda: "1" in self.machine.execute(cmd), delay=3)

self.goToVmPage("subVmTest1")

Expand Down Expand Up @@ -135,9 +137,15 @@ class TestMachinesNICs(machineslib.VirtualMachinesCase):
# https://bugzilla.redhat.com/show_bug.cgi?id=2215597
b.assert_pixels("#vm-subVmTest1-networks",
"vm-details-nics-card-edit-disabled",
ignore=["#vm-subVmTest1-network-1-mac", "#vm-subVmTest1-network-1-ipv4-address", "#vm-subVmTest1-network-1-source",
"#vm-subVmTest1-network-2-mac", "#vm-subVmTest1-network-2-ipv4-address", "#vm-subVmTest1-network-2-source",
"#vm-subVmTest1-network-3-mac", "#vm-subVmTest1-network-3-ipv4-address", "#vm-subVmTest1-network-3-source"],
ignore=["#vm-subVmTest1-network-1-mac",
"#vm-subVmTest1-network-1-ipv4-address",
"#vm-subVmTest1-network-1-source",
"#vm-subVmTest1-network-2-mac",
"#vm-subVmTest1-network-2-ipv4-address",
"#vm-subVmTest1-network-2-source",
"#vm-subVmTest1-network-3-mac",
"#vm-subVmTest1-network-3-ipv4-address",
"#vm-subVmTest1-network-3-source"],
# MAC and IP address values are not static, and their values affect the width of
# their columns and neighbouring columns
# With medium layout this variable width of the columns makes pixel tests references of
Expand Down Expand Up @@ -223,10 +231,10 @@ class TestMachinesNICs(machineslib.VirtualMachinesCase):
virsh attach-interface --domain subVmTest1 --type network --source default --model virtio --mac 52:54:00:4b:73:5f --config
virsh attach-interface --domain subVmTest1 --type bridge --source virbr0 --model virtio --mac 52:54:00:4b:73:6f --config
virsh attach-interface --domain subVmTest1 --type network --source default --model virtio --mac 52:54:00:4b:73:4f --config
""")
# Add network with the same MAC address
m.execute(
"virsh attach-interface --domain subVmTest1 --type network --source default --model e1000e --mac 52:54:00:4b:73:5f --config")
virsh attach-interface --domain subVmTest1 --type network --source default --model e1000e --mac 52:54:00:4b:73:5f --config
""")

# Refresh for getting new added NIC
b.reload()
b.enter_page('/machines')
Expand Down
12 changes: 6 additions & 6 deletions test/check-machines-settings
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ class TestMachinesSettings(machineslib.VirtualMachinesCase):

def testCPUModel(self):
b = self.browser
m = self.machine

self.createVm("subVmTest1")

Expand Down Expand Up @@ -371,8 +370,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"])
file_desc_sel = ".pf-v5-c-description-list__description .pf-v5-c-description-list__text"
b.wait_text(f"#vm-subVmTest1-order-modal-device-row-0 {file_desc_sel}", args["image"])

b.click("#vm-subVmTest1-order-modal-cancel")
b.wait_not_present("#vm-subVmTest1-order-modal-window")
Expand Down Expand Up @@ -454,7 +453,6 @@ class TestMachinesSettings(machineslib.VirtualMachinesCase):

def testMultipleSettings(self):
b = self.browser
m = self.machine

# We want a machine without watchdog
args = self.createVm("subVmTest1", os="linux2016")
Expand Down Expand Up @@ -818,8 +816,10 @@ class TestMachinesSettings(machineslib.VirtualMachinesCase):
# 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
# - 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
vmName = 'subVmTest1'
virsh_output_auto = self.getDomainXpathValue(vmName, '/domain/devices/vsock/cid/@auto')
Expand Down
8 changes: 5 additions & 3 deletions test/check-machines-storage-pools
Original file line number Diff line number Diff line change
Expand Up @@ -518,9 +518,11 @@ class TestMachinesStoragePools(machineslib.VirtualMachinesCase):
self.restore_file("/etc/exports")
m.execute(f"mkdir {nfs_pool} {mnt_exports}")
m.write("/etc/exports", f"{mnt_exports} 127.0.0.1/24(rw,sync,no_root_squash,no_subtree_check,fsid=0)")
m.execute("systemctl restart nfs-server")
m.execute(f"virsh pool-define-as nfs-pool --type netfs --target {nfs_pool} --source-host 127.0.0.1 --source-path {mnt_exports}")
m.execute("virsh pool-start nfs-pool")
m.execute(f"""
systemctl restart nfs-server
virsh pool-define-as nfs-pool --type netfs --target {nfs_pool} --source-host 127.0.0.1 --source-path {mnt_exports}"
virsh pool-start nfs-pool
""")

# Prepare disk/block pool
dev = self.add_ram_disk(10)
Expand Down

0 comments on commit 5f8a4be

Please sign in to comment.