Skip to content

Commit

Permalink
test: add a check about disk bus if creating a VM without OS
Browse files Browse the repository at this point in the history
  • Loading branch information
yunmingyang authored and martinpitt committed Jan 18, 2024
1 parent 2dff5f0 commit 0adf7e2
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
37 changes: 26 additions & 11 deletions test/check-machines-disks
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,20 @@ class TestMachinesDisks(machineslib.VirtualMachinesCase):
b = self.browser
m = self.machine

def openDialog(target):
b.click(f"#vm-subVmTest1-disks-{target}-edit")
b.wait_visible(f"#vm-subVmTest1-disks-{target}-edit-dialog")
def openDialog(target, name="subVmTest1"):
b.click(f"#vm-{name}-disks-{target}-edit")
b.wait_visible(f"#vm-{name}-disks-{target}-edit-dialog")

def cancel(target):
b.click(f"#vm-subVmTest1-disks-{target}-edit-dialog-cancel")
b.wait_not_present(f"#vm-subVmTest1-disks-{target}-edit-dialog")
def cancel(target, name="subVmTest1"):
b.click(f"#vm-{name}-disks-{target}-edit-dialog-cancel")
b.wait_not_present(f"#vm-{name}-disks-{target}-edit-dialog")

def save(target, xfail=None):
b.click(f"#vm-subVmTest1-disks-{target}-edit-dialog-save")
def save(target, name="subVmTest1", xfail=None):
b.click(f"#vm-{name}-disks-{target}-edit-dialog-save")
if xfail:
b.wait_in_text(f"#vm-subVmTest1-disks-{target}-edit-dialog .pf-v5-c-alert", xfail)
b.wait_in_text(f"#vm-{name}-disks-{target}-edit-dialog .pf-v5-c-alert", xfail)
else:
b.wait_not_present(f"#vm-subVmTest1-disks-{target}-edit-dialog")
b.wait_not_present(f"#vm-{name}-disks-{target}-edit-dialog")

self.createVm("subVmTest1")

Expand Down Expand Up @@ -184,7 +184,7 @@ class TestMachinesDisks(machineslib.VirtualMachinesCase):
b.enter_page('/machines')
openDialog("sdb")
b.set_checked("#vm-subVmTest1-disks-sdb-edit-readonly", True)
save("sdb", "readonly sata disks are not supported")
save("sdb", xfail="readonly sata disks are not supported")
cancel("sdb")
openDialog("sdb")
b.wait_not_present("#vm-subVmTest1-disks-sdb-edit-dialog .pf-v5-c-alert")
Expand Down Expand Up @@ -219,6 +219,21 @@ class TestMachinesDisks(machineslib.VirtualMachinesCase):
m.execute("virsh undefine subVmTest1")
b.wait_not_present("#vm-subVmTest1-disks-vde-edit")

self.goToMainPage()
self.createVm("subVmTest2", running=False, os="unknown")
self.goToVmPage("subVmTest2")

b.wait_in_text("#vm-subVmTest2-disks-hda-bus", "ide")

openDialog("hda", name="subVmTest2")
b._wait_present("#vm-subVmTest2-disks-hda-edit-bus-type option[value=ide]:disabled")
b.select_from_dropdown("#vm-subVmTest2-disks-hda-edit-bus-type", "sata")
save("hda", name="subVmTest2")

b.wait_in_text("#vm-subVmTest2-disks-sda-bus", "sata")
openDialog("sda", name="subVmTest2")
b.wait_not_present("#vm-subVmTest2-disks-hda-edit-bus-type option[value=ide]")

def testDisks(self):
b = self.browser
m = self.machine
Expand Down
16 changes: 8 additions & 8 deletions test/machineslib.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def startLibvirt(self, m):
m.execute("virsh net-start default || true")
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):
def createVm(self, name, graphics='none', ptyconsole=False, running=True, memory=128, connection='system', machine=None, os="cirros0.4.0"):
m = machine or self.machine

image_file = m.pull("cirros")
Expand Down Expand Up @@ -174,15 +174,15 @@ def createVm(self, name, graphics='none', ptyconsole=False, running=True, memory
else:
console = "file,target.type=serial,source.path={} ".format(args["logfile"])

command = ["virt-install --connect qemu:///{5} --name {0} "
"--os-variant cirros0.4.0 "
command = [f"virt-install --connect qemu:///{connection} --name {name} "
f"--os-variant {os} "
"--boot hd,network "
"--vcpus 1 "
"--memory {1} "
"--import --disk {2} "
"--graphics {3} "
"--console {4}"
"--print-step 1 > /tmp/xml-{5}".format(name, memory, img, "none" if graphics == "none" else graphics + ",listen=127.0.0.1", console, connection)]
f"--memory {memory} "
f"--import --disk {img} "
f"--graphics {'none' if graphics == 'none' else graphics + ',listen=127.0.0.1'} "
f"--console {console}"
f"--print-step 1 > /tmp/xml-{connection}"]

command.append(f"virsh -c qemu:///{connection} define /tmp/xml-{connection}")
if running:
Expand Down

0 comments on commit 0adf7e2

Please sign in to comment.