diff --git a/tests/cli-test-xml/compare/virt-install-cdrom-double.xml b/tests/cli-test-xml/compare/virt-install-cdrom-double.xml
new file mode 100644
index 00000000..551bc6c6
--- /dev/null
+++ b/tests/cli-test-xml/compare/virt-install-cdrom-double.xml
@@ -0,0 +1,103 @@
+
+ foobar
+ 00000000-1111-2222-3333-444444444444
+ 65536
+ 65536
+ 1
+
+ hvm
+
+
+
+
+
+
+
+ destroy
+
+
+
+
+
+ /usr/bin/test-hv
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ foobar
+ 00000000-1111-2222-3333-444444444444
+ 65536
+ 65536
+ 1
+
+ hvm
+
+
+
+
+
+
+
+
+
+
+
+ /usr/bin/test-hv
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/clitest.py b/tests/clitest.py
index 73646563..4473c74f 100644
--- a/tests/clitest.py
+++ b/tests/clitest.py
@@ -682,6 +682,7 @@ c.add_valid("--panic help --disk=?") # Make sure introspection doesn't blow up
c.add_valid("--test-stub-command") # --test-stub-command
c.add_invalid("--hvm --nodisks --pxe foobar") # Positional arguments error
c.add_invalid("--nodisks --pxe --name test") # Colliding name
+c.add_compare("--cdrom %(EXISTIMG1)s --disk size=1 --disk %(EXISTIMG2)s,device=cdrom", "cdrom-double") # ensure --disk device=cdrom is ordered after --cdrom, this is important for virtio-win installs with a driver ISO
diff --git a/virtinst/installer.py b/virtinst/installer.py
index b6d760ec..906d8ca7 100644
--- a/virtinst/installer.py
+++ b/virtinst/installer.py
@@ -89,7 +89,14 @@ class Installer(object):
dev.sync_path_props()
dev.validate()
self._install_cdrom_device = dev
- guest.add_device(dev)
+
+ # Insert the CDROM before any other CDROM, so boot=cdrom picks
+ # it as the priority
+ for idx, disk in enumerate(guest.devices.disk):
+ if disk.is_cdrom():
+ guest.devices.add_child(self._install_cdrom_device, idx=idx)
+ return
+ guest.add_device(self._install_cdrom_device)
def _remove_install_cdrom_media(self, guest):
if not self._install_cdrom_device:
diff --git a/virtinst/xmlbuilder.py b/virtinst/xmlbuilder.py
index 6cde1153..90c5090f 100644
--- a/virtinst/xmlbuilder.py
+++ b/virtinst/xmlbuilder.py
@@ -152,6 +152,8 @@ class XMLChildProperty(_XMLPropertyBase):
for obj in self._get(xmlbuilder)[:]:
xmlbuilder.remove_child(obj)
+ def insert(self, xmlbuilder, newobj, idx):
+ self._get(xmlbuilder).insert(idx, newobj)
def append(self, xmlbuilder, newobj):
self._get(xmlbuilder).append(newobj)
def remove(self, xmlbuilder, obj):
@@ -646,14 +648,17 @@ class XMLBuilder(object):
for p in util.listify(getattr(self, propname, [])):
p._parse_with_children(None, self._xmlstate)
- def add_child(self, obj):
+ def add_child(self, obj, idx=None):
"""
Insert the passed XMLBuilder object into our XML document. The
object needs to have an associated mapping via XMLChildProperty
"""
xmlprop = self._find_child_prop(obj.__class__)
xml = obj.get_xml()
- xmlprop.append(self, obj)
+ if idx is None:
+ xmlprop.append(self, obj)
+ else:
+ xmlprop.insert(self, obj, idx)
self._set_child_xpaths()
# Only insert the XML directly into the parent XML for !is_build