Merge "libvirt: use osinfo when configuring the disk bus"

This commit is contained in:
Jenkins 2016-02-07 04:08:54 +00:00 committed by Gerrit Code Review
commit 197bd6dd12
2 changed files with 19 additions and 2 deletions

View File

@ -15,6 +15,7 @@
import copy
import fixtures
import mock
from nova import block_device
@ -25,6 +26,7 @@ from nova import objects
from nova import test
from nova.tests.unit import fake_block_device
import nova.tests.unit.image.fake
from nova.tests.unit.virt import fakelibosinfo
from nova.virt import block_device as driver_block_device
from nova.virt import driver
from nova.virt.libvirt import blockinfo
@ -744,6 +746,17 @@ class LibvirtBlockInfoTest(test.NoDBTestCase):
blockinfo.get_disk_bus_for_device_type,
instance, 'kvm', image_meta)
def test_get_disk_bus_with_osinfo(self):
self.useFixture(fixtures.MonkeyPatch(
'nova.virt.osinfo.libosinfo',
fakelibosinfo))
instance = objects.Instance(**self.test_instance)
image_meta = {'properties': {'os_name': 'fedora22'}}
image_meta = objects.ImageMeta.from_dict(image_meta)
bus = blockinfo.get_disk_bus_for_device_type(instance,
'kvm', image_meta)
self.assertEqual('virtio', bus)
def test_success_get_disk_bus_for_disk_dev(self):
expected = (
('ide', ("kvm", "hda")),

View File

@ -84,6 +84,7 @@ from nova.objects import base as obj_base
from nova.virt import configdrive
from nova.virt import driver
from nova.virt.libvirt import utils as libvirt_utils
from nova.virt import osinfo
CONF = cfg.CONF
@ -234,8 +235,11 @@ def get_disk_bus_for_device_type(instance,
"""
# Prefer a disk bus set against the image first of all
key = "hw_" + device_type + "_bus"
disk_bus = image_meta.properties.get(key)
if device_type == "disk":
disk_bus = osinfo.HardwareProperties(image_meta).disk_model
else:
key = "hw_" + device_type + "_bus"
disk_bus = image_meta.properties.get(key)
if disk_bus is not None:
if not is_disk_bus_valid_for_virt(virt_type, disk_bus):
raise exception.UnsupportedHardware(model=disk_bus,