diff --git a/lib/hypervisor/hv_kvm.py b/lib/hypervisor/hv_kvm.py index 2ed07aece5d44383b49aeeae0676d939112e5bc4..a481997cb9953da1e29c3ca2bcee83251bfbf4df 100644 --- a/lib/hypervisor/hv_kvm.py +++ b/lib/hypervisor/hv_kvm.py @@ -570,6 +570,10 @@ class KVMHypervisor(hv_base.BaseHypervisor): if boot_network: kvm_cmd.extend(["-boot", "n"]) + # whether this is an older KVM version that uses the boot=on flag + # on devices + needs_boot_flag = (v_major, v_min) < (0, 14) + disk_type = hvp[constants.HV_DISK_TYPE] if disk_type == constants.HT_DISK_PARAVIRTUAL: if_val = ",if=virtio" @@ -597,7 +601,7 @@ class KVMHypervisor(hv_base.BaseHypervisor): if boot_disk: kvm_cmd.extend(["-boot", "c"]) boot_disk = False - if (v_major, v_min) < (0, 14) and disk_type != constants.HT_DISK_IDE: + if needs_boot_flag and disk_type != constants.HT_DISK_IDE: boot_val = ",boot=on" drive_val = "file=%s,format=raw%s%s%s" % (dev_path, if_val, boot_val, @@ -612,19 +616,22 @@ class KVMHypervisor(hv_base.BaseHypervisor): iso_image = hvp[constants.HV_CDROM_IMAGE_PATH] if iso_image: options = ",format=raw,media=cdrom" + # set cdrom 'if' type if boot_cdrom: - kvm_cmd.extend(["-boot", "d"]) - if cdrom_disk_type != constants.HT_DISK_IDE: - options = "%s,boot=on,if=%s" % (options, constants.HT_DISK_IDE) - else: - options = "%s,boot=on" % options + actual_cdrom_type = constants.HT_DISK_IDE + elif cdrom_disk_type == constants.HT_DISK_PARAVIRTUAL: + actual_cdrom_type = "virtio" else: - if cdrom_disk_type == constants.HT_DISK_PARAVIRTUAL: - if_val = ",if=virtio" - else: - if_val = ",if=%s" % cdrom_disk_type - options = "%s%s" % (options, if_val) - drive_val = "file=%s%s" % (iso_image, options) + actual_cdrom_type = cdrom_disk_type + if_val = ",if=%s" % actual_cdrom_type + # set boot flag, if needed + boot_val = "" + if boot_cdrom: + kvm_cmd.extend(["-boot", "d"]) + if needs_boot_flag: + boot_val = ",boot=on" + # and finally build the entire '-drive' value + drive_val = "file=%s%s%s%s" % (iso_image, options, if_val, boot_val) kvm_cmd.extend(["-drive", drive_val]) iso_image2 = hvp[constants.HV_KVM_CDROM2_IMAGE_PATH] @@ -634,8 +641,7 @@ class KVMHypervisor(hv_base.BaseHypervisor): if_val = ",if=virtio" else: if_val = ",if=%s" % cdrom_disk_type - options = "%s%s" % (options, if_val) - drive_val = "file=%s%s" % (iso_image2, options) + drive_val = "file=%s%s%s" % (iso_image2, options, if_val) kvm_cmd.extend(["-drive", drive_val]) floppy_image = hvp[constants.HV_KVM_FLOPPY_IMAGE_PATH]