Merge "Set SCSI as the default cdrom bus for PowerKVM"
This commit is contained in:
@@ -547,16 +547,22 @@ class LibvirtBlockInfoTest(test.TestCase):
|
||||
block_device_info['block_device_mapping'][0])
|
||||
|
||||
def test_get_disk_bus(self):
|
||||
bus = blockinfo.get_disk_bus_for_device_type('kvm')
|
||||
self.assertEqual(bus, 'virtio')
|
||||
|
||||
bus = blockinfo.get_disk_bus_for_device_type('kvm',
|
||||
device_type='cdrom')
|
||||
self.assertEqual(bus, 'ide')
|
||||
|
||||
bus = blockinfo.get_disk_bus_for_device_type('kvm',
|
||||
device_type='floppy')
|
||||
self.assertEqual(bus, 'fdc')
|
||||
expected = (
|
||||
('x86_64', 'disk', 'virtio'),
|
||||
('x86_64', 'cdrom', 'ide'),
|
||||
('x86_64', 'floppy', 'fdc'),
|
||||
('ppc', 'disk', 'virtio'),
|
||||
('ppc', 'cdrom', 'scsi'),
|
||||
('ppc64', 'disk', 'virtio'),
|
||||
('ppc64', 'cdrom', 'scsi')
|
||||
)
|
||||
for arch, dev, res in expected:
|
||||
with mock.patch.object(blockinfo.libvirt_utils,
|
||||
'get_arch',
|
||||
return_value=arch):
|
||||
bus = blockinfo.get_disk_bus_for_device_type('kvm',
|
||||
device_type=dev)
|
||||
self.assertEqual(bus, res)
|
||||
|
||||
image_meta = {'properties': {'hw_disk_bus': 'scsi'}}
|
||||
bus = blockinfo.get_disk_bus_for_device_type('kvm',
|
||||
|
||||
@@ -81,7 +81,7 @@ from nova.openstack.common.gettextutils import _
|
||||
from nova.virt import block_device as driver_block_device
|
||||
from nova.virt import configdrive
|
||||
from nova.virt import driver
|
||||
|
||||
from nova.virt.libvirt import utils as libvirt_utils
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
@@ -217,6 +217,7 @@ def get_disk_bus_for_device_type(virt_type,
|
||||
type, return the optimal disk_bus to use for a given
|
||||
device type. For example, for a disk on KVM it will
|
||||
return 'virtio', while for a CDROM it will return 'ide'
|
||||
on x86_64 and 'scsi' on ppc64.
|
||||
|
||||
Returns the disk_bus, or returns None if the device
|
||||
type is not supported for this virtualization
|
||||
@@ -245,7 +246,11 @@ def get_disk_bus_for_device_type(virt_type,
|
||||
return "xen"
|
||||
elif virt_type in ("qemu", "kvm"):
|
||||
if device_type == "cdrom":
|
||||
return "ide"
|
||||
arch = libvirt_utils.get_arch(image_meta)
|
||||
if arch in ("ppc", "ppc64"):
|
||||
return "scsi"
|
||||
else:
|
||||
return "ide"
|
||||
elif device_type == "disk":
|
||||
return "virtio"
|
||||
elif device_type == "floppy":
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
|
||||
import errno
|
||||
import os
|
||||
import platform
|
||||
|
||||
from lxml import etree
|
||||
from oslo.config import cfg
|
||||
@@ -653,3 +654,23 @@ def get_instance_path(instance, forceold=False, relative=False):
|
||||
if relative:
|
||||
return instance['uuid']
|
||||
return os.path.join(CONF.instances_path, instance['uuid'])
|
||||
|
||||
|
||||
def get_arch(image_meta):
|
||||
"""Determine the architecture of the guest (or host).
|
||||
|
||||
This method determines the CPU architecture that must be supported by
|
||||
the hypervisor. It gets the (guest) arch info from image_meta properties,
|
||||
and it will fallback to the nova-compute (host) arch if no architecture
|
||||
info is provided in image_meta.
|
||||
|
||||
:param image_meta: the metadata associated with the instance image
|
||||
|
||||
:returns: guest (or host) architecture
|
||||
"""
|
||||
if image_meta:
|
||||
arch = image_meta.get('properties', {}).get('architecture')
|
||||
if arch is not None:
|
||||
return arch
|
||||
|
||||
return platform.processor()
|
||||
|
||||
Reference in New Issue
Block a user