[virt-tools-list] [PATCH virt-manager 08/14] tests: Add test case for reorder_boot_order method

Marc Hartmayer mhartmay at linux.ibm.com
Tue Feb 26 09:56:38 UTC 2019


Add a test case for `reorder_boot_order`. It verifies that the OS boot
order is removed and that all other boot order indices are adjusted
accordingly.

Signed-off-by: Marc Hartmayer <mhartmay at linux.ibm.com>
Reviewed-by: Boris Fiuczynski <fiuczy at linux.ibm.com>
---
 .../change-devices-bootorder-fixed-out.xml    | 71 +++++++++++++++++++
 .../change-devices-bootorder-in.xml           | 71 +++++++++++++++++++
 .../change-devices-bootorder-out.xml          | 71 +++++++++++++++++++
 tests/xmlparse.py                             | 49 +++++++++++++
 4 files changed, 262 insertions(+)
 create mode 100644 tests/xmlparse-xml/change-devices-bootorder-fixed-out.xml
 create mode 100644 tests/xmlparse-xml/change-devices-bootorder-in.xml
 create mode 100644 tests/xmlparse-xml/change-devices-bootorder-out.xml

diff --git a/tests/xmlparse-xml/change-devices-bootorder-fixed-out.xml b/tests/xmlparse-xml/change-devices-bootorder-fixed-out.xml
new file mode 100644
index 000000000000..e8fa69752f26
--- /dev/null
+++ b/tests/xmlparse-xml/change-devices-bootorder-fixed-out.xml
@@ -0,0 +1,71 @@
+<domain type="kvm">
+  <name>TestGuest</name>
+  <metadata>
+    <libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
+      <libosinfo:os id="http://fedoraproject.org/fedora/17"/>
+    </libosinfo:libosinfo>
+  </metadata>
+  <currentMemory>204800</currentMemory>
+  <memory>409600</memory>
+  <uuid>12345678-1234-1234-1234-123456789012</uuid>
+  <os>
+    <type arch="i686" machine="foobar">hvm</type>
+  </os>
+  <features>
+    <acpi/>
+    <apic/>
+    <hyperv>
+      <vapic state="off"/>
+      <spinlocks state="on" retries="12287"/>
+    </hyperv>
+    <vmport state="off"/>
+  </features>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <on_lockfailure>poweroff</on_lockfailure>
+  <devices>
+    <emulator>/usr/lib/xen/bin/qemu-dm</emulator>
+    <disk type="file" device="floppy">
+      <driver name="qemu" type="qcow2"/>
+      <source file="/dev/default-pool/testvol1.img"/>
+      <target dev="fda" bus="fdc"/>
+      <boot order="1"/>
+    </disk>
+    <disk type="file" device="disk">
+      <driver name="qemu" type="raw"/>
+      <source file="/tmp/test.img"/>
+      <target dev="vda" bus="virtio"/>
+      <boot order="10"/>
+    </disk>
+    <disk type="block" device="disk">
+      <driver name="qemu"/>
+      <source dev="/dev/null"/>
+      <target dev="vdb" bus="virtio"/>
+      <boot order="11"/>
+    </disk>
+    <disk type="block" device="cdrom">
+      <target dev="hdc" bus="ide"/>
+      <readonly/>
+      <boot order="2"/>
+    </disk>
+    <interface type="network">
+      <source network="default"/>
+      <mac address="22:22:33:44:55:66"/>
+      <model type="virtio"/>
+      <boot order="3"/>
+    </interface>
+    <interface type="network">
+      <source network="default"/>
+      <model type="virtio"/>
+    </interface>
+    <controller type="usb" index="0"/>
+    <redirdev bus="usb" type="tcp">
+      <source mode="connect" host="localhost" service="4000"/>
+      <boot order="4"/>
+    </redirdev>
+    <graphics type="vnc" display=":3.4" xauth="/tmp/.Xauthority"/>
+    <console type="pty"/>
+    <memballoon model="virtio"/>
+  </devices>
+</domain>
diff --git a/tests/xmlparse-xml/change-devices-bootorder-in.xml b/tests/xmlparse-xml/change-devices-bootorder-in.xml
new file mode 100644
index 000000000000..66dd57a8b3ad
--- /dev/null
+++ b/tests/xmlparse-xml/change-devices-bootorder-in.xml
@@ -0,0 +1,71 @@
+<domain type="kvm">
+  <name>TestGuest</name>
+  <metadata>
+    <libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
+      <libosinfo:os id="http://fedoraproject.org/fedora/17"/>
+    </libosinfo:libosinfo>
+  </metadata>
+  <currentMemory>204800</currentMemory>
+  <memory>409600</memory>
+  <uuid>12345678-1234-1234-1234-123456789012</uuid>
+  <os>
+    <type arch="i686" machine="foobar">hvm</type>
+    <boot dev="hd"/>
+  </os>
+  <features>
+    <acpi/>
+    <apic/>
+    <hyperv>
+      <vapic state="off"/>
+      <spinlocks state="on" retries="12287"/>
+    </hyperv>
+    <vmport state="off"/>
+  </features>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <on_lockfailure>poweroff</on_lockfailure>
+  <devices>
+    <emulator>/usr/lib/xen/bin/qemu-dm</emulator>
+    <disk type="file" device="floppy">
+      <driver name="qemu" type="qcow2"/>
+      <source file="/dev/default-pool/testvol1.img"/>
+      <target dev="fda" bus="fdc"/>
+    </disk>
+    <disk type="file" device="disk">
+      <driver name="qemu" type="raw"/>
+      <source file="/tmp/test.img"/>
+      <target dev="vda" bus="virtio"/>
+      <boot order="10"/>
+    </disk>
+    <disk type="block" device="disk">
+      <driver name="qemu"/>
+      <source dev="/dev/null"/>
+      <target dev="vdb" bus="virtio"/>
+      <boot order="10"/>
+    </disk>
+    <disk type="block" device="cdrom">
+      <target dev="hdc" bus="ide"/>
+      <readonly/>
+      <boot order="1"/>
+    </disk>
+    <interface type="network">
+      <source network="default"/>
+      <mac address="22:22:33:44:55:66"/>
+      <model type="virtio"/>
+      <boot order="2"/>
+    </interface>
+    <interface type="network">
+      <source network="default"/>
+      <model type="virtio"/>
+    </interface>
+    <controller type="usb" index="0"/>
+    <redirdev bus="usb" type="tcp">
+      <source mode="connect" host="localhost" service="4000"/>
+      <boot order="3"/>
+    </redirdev>
+    <graphics type="vnc" display=":3.4" xauth="/tmp/.Xauthority"/>
+    <console type="pty"/>
+    <memballoon model="virtio"/>
+  </devices>
+</domain>
diff --git a/tests/xmlparse-xml/change-devices-bootorder-out.xml b/tests/xmlparse-xml/change-devices-bootorder-out.xml
new file mode 100644
index 000000000000..f03bc591816b
--- /dev/null
+++ b/tests/xmlparse-xml/change-devices-bootorder-out.xml
@@ -0,0 +1,71 @@
+<domain type="kvm">
+  <name>TestGuest</name>
+  <metadata>
+    <libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
+      <libosinfo:os id="http://fedoraproject.org/fedora/17"/>
+    </libosinfo:libosinfo>
+  </metadata>
+  <currentMemory>204800</currentMemory>
+  <memory>409600</memory>
+  <uuid>12345678-1234-1234-1234-123456789012</uuid>
+  <os>
+    <type arch="i686" machine="foobar">hvm</type>
+  </os>
+  <features>
+    <acpi/>
+    <apic/>
+    <hyperv>
+      <vapic state="off"/>
+      <spinlocks state="on" retries="12287"/>
+    </hyperv>
+    <vmport state="off"/>
+  </features>
+  <on_poweroff>destroy</on_poweroff>
+  <on_reboot>restart</on_reboot>
+  <on_crash>destroy</on_crash>
+  <on_lockfailure>poweroff</on_lockfailure>
+  <devices>
+    <emulator>/usr/lib/xen/bin/qemu-dm</emulator>
+    <disk type="file" device="floppy">
+      <driver name="qemu" type="qcow2"/>
+      <source file="/dev/default-pool/testvol1.img"/>
+      <target dev="fda" bus="fdc"/>
+      <boot order="1"/>
+    </disk>
+    <disk type="file" device="disk">
+      <driver name="qemu" type="raw"/>
+      <source file="/tmp/test.img"/>
+      <target dev="vda" bus="virtio"/>
+      <boot order="10"/>
+    </disk>
+    <disk type="block" device="disk">
+      <driver name="qemu"/>
+      <source dev="/dev/null"/>
+      <target dev="vdb" bus="virtio"/>
+      <boot order="10"/>
+    </disk>
+    <disk type="block" device="cdrom">
+      <target dev="hdc" bus="ide"/>
+      <readonly/>
+      <boot order="2"/>
+    </disk>
+    <interface type="network">
+      <source network="default"/>
+      <mac address="22:22:33:44:55:66"/>
+      <model type="virtio"/>
+      <boot order="3"/>
+    </interface>
+    <interface type="network">
+      <source network="default"/>
+      <model type="virtio"/>
+    </interface>
+    <controller type="usb" index="0"/>
+    <redirdev bus="usb" type="tcp">
+      <source mode="connect" host="localhost" service="4000"/>
+      <boot order="4"/>
+    </redirdev>
+    <graphics type="vnc" display=":3.4" xauth="/tmp/.Xauthority"/>
+    <console type="pty"/>
+    <memballoon model="virtio"/>
+  </devices>
+</domain>
diff --git a/tests/xmlparse.py b/tests/xmlparse.py
index 2dbaf24ce434..d12522ab9794 100644
--- a/tests/xmlparse.py
+++ b/tests/xmlparse.py
@@ -436,6 +436,55 @@ class XMLParseTest(unittest.TestCase):
 
         self._alter_compare(guest.get_xml(), outfile)
 
+    def testAlterDevicesBootorder(self):
+        basename = "change-devices-bootorder"
+        guest, outfile = self._get_test_content(basename)
+        disk_1 = guest.devices.disk[0]
+        disk_2 = guest.devices.disk[1]
+        disk_3 = guest.devices.disk[2]
+        disk_4 = guest.devices.disk[3]
+        iface_1 = guest.devices.interface[0]
+        iface_2 = guest.devices.interface[1]
+        redirdev_1 = guest.devices.redirdev[0]
+
+        self.assertEqual(guest.os.bootorder, ['hd'])
+        self.assertEqual(disk_1.boot.order, None)
+        self.assertEqual(disk_2.boot.order, 10)
+        self.assertEqual(disk_3.boot.order, 10)
+        self.assertEqual(disk_4.boot.order, 1)
+        self.assertEqual(iface_1.boot.order, 2)
+        self.assertEqual(iface_2.boot.order, None)
+        self.assertEqual(redirdev_1.boot.order, 3)
+
+        guest.reorder_boot_order(disk_1, 1)
+
+        self.assertEqual(guest.os.bootorder, [])
+        self.assertEqual(disk_1.boot.order, 1)
+        self.assertEqual(disk_2.boot.order, 10)
+        self.assertEqual(disk_3.boot.order, 10)
+        # verify that the used algorithm preserves the order of
+        # records with equal boot indices
+        self.assertIs(disk_2, guest.devices.disk[1])
+        self.assertIs(disk_3, guest.devices.disk[2])
+        self.assertEqual(disk_4.boot.order, 2)
+        self.assertEqual(iface_1.boot.order, 3)
+        self.assertEqual(iface_2.boot.order, None)
+        self.assertEqual(redirdev_1.boot.order, 4)
+
+        try:
+            self._alter_compare(guest.get_xml(), outfile)
+        except RuntimeError as error:
+            self.assertIn("unsupported configuration", str(error))
+
+        guest.reorder_boot_order(disk_2, 10)
+        self.assertEqual(disk_2.boot.order, 10)
+        self.assertEqual(disk_3.boot.order, 11)
+        self.assertIs(disk_2, guest.devices.disk[1])
+        self.assertIs(disk_3, guest.devices.disk[2])
+
+        outfile = self._gen_outfile_path("change-devices-bootorder-fixed")
+        self._alter_compare(guest.get_xml(), outfile)
+
     def testSingleDisk(self):
         xml = ("""<disk type="file" device="disk"><source file="/a.img"/>\n"""
                """<target dev="hda" bus="ide"/></disk>\n""")
-- 
2.17.0




More information about the virt-tools-list mailing list