From 5f5590f7f4c90fcd1869dadc6ec7e5ea5ab6979e Mon Sep 17 00:00:00 2001 From: Vladik Romanovsky Date: Fri, 23 Jan 2015 07:30:41 -0500 Subject: [PATCH] libvirt: use osinfo when configuring the disk bus Start using libosinfo in the blockinfo module, when configuring the disk bus. Partially implements blueprint libvirt-hardware-policy-from-libosinfo Change-Id: I7a9669070a0eca04b97104aec92609fbf631ffc8 --- nova/tests/unit/virt/libvirt/test_blockinfo.py | 13 +++++++++++++ nova/virt/libvirt/blockinfo.py | 8 ++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/nova/tests/unit/virt/libvirt/test_blockinfo.py b/nova/tests/unit/virt/libvirt/test_blockinfo.py index a1450b325ef6..146caabb16fe 100644 --- a/nova/tests/unit/virt/libvirt/test_blockinfo.py +++ b/nova/tests/unit/virt/libvirt/test_blockinfo.py @@ -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")), diff --git a/nova/virt/libvirt/blockinfo.py b/nova/virt/libvirt/blockinfo.py index 5cc411cd0046..f770bbc784a3 100644 --- a/nova/virt/libvirt/blockinfo.py +++ b/nova/virt/libvirt/blockinfo.py @@ -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,