Browse Source

Merge "Stop sending bad values from libosinfo to libvirt" into stable/queens

tags/17.0.13
Zuul 4 months ago
parent
commit
929945be77
3 changed files with 99 additions and 17 deletions
  1. +53
    -8
      nova/tests/unit/virt/fakelibosinfo.py
  2. +27
    -1
      nova/tests/unit/virt/test_osinfo.py
  3. +19
    -8
      nova/virt/osinfo.py

+ 53
- 8
nova/tests/unit/virt/fakelibosinfo.py View File

@@ -33,32 +33,77 @@ class Loader(object):

class Db(object):

def __init__(self):
# Generate test devices
self.devs = []
self.oslist = None
def _get_fedora19(self):
devs = []
net = Device()
net._class = 'net'
net.name = 'rtl8139'
devs.append(net)

net = Device()
net._class = 'block'
net.name = 'ide'
devs.append(net)

devlist = DeviceList()
devlist.devices = devs

fedora = Os()
fedora.name = 'Fedora 19'
fedora.id = 'http://fedoraproject.org/fedora/19'
fedora.short_id = 'fedora19'
fedora.dev_list = devlist
return fedora

def _get_fedora22(self):
devs = []
net = Device()
net._class = 'net'
net.name = 'virtio-net'
self.devs.append(net)
devs.append(net)

net = Device()
net._class = 'block'
net.name = 'virtio-block'
self.devs.append(net)
devs.append(net)

devlist = DeviceList()
devlist.devices = self.devs
devlist.devices = devs

fedora = Os()
fedora.name = 'Fedora 22'
fedora.id = 'http://fedoraproject.org/fedora/22'
fedora.short_id = 'fedora22'
fedora.dev_list = devlist
return fedora

def _get_fedora23(self):
devs = []
net = Device()
net._class = 'net'
net.name = 'virtio1.0-net'
devs.append(net)

net = Device()
net._class = 'block'
net.name = 'virtio1.0-block'
devs.append(net)

devlist = DeviceList()
devlist.devices = devs

fedora = Os()
fedora.name = 'Fedora 23'
fedora.id = 'http://fedoraproject.org/fedora/23'
fedora.short_id = 'fedora23'
fedora.dev_list = devlist
return fedora

def __init__(self):
self.oslist = OsList()
self.oslist.os_list = [fedora]
self.oslist.os_list = [
self._get_fedora19(), self._get_fedora22(), self._get_fedora23(),
]

def get_os_list(self):
return self.oslist

+ 27
- 1
nova/tests/unit/virt/test_osinfo.py View File

@@ -66,7 +66,20 @@ class LibvirtOsInfoTest(test.NoDBTestCase):
self.assertIsNone(os_info_db.get_os('fedora19'))
self.assertEqual(1, mock_log.call_count)

def test_hardware_properties_from_osinfo(self):
def test_hardware_properties_from_osinfo_fedora19(self):
"""Verifies that HardwareProperties attributes are being set
from libosinfo.
"""
img_meta = {'properties':
{'os_distro': 'fedora19'}
}

img_meta = objects.ImageMeta.from_dict(img_meta)
osinfo_obj = osinfo.HardwareProperties(img_meta)
self.assertEqual('rtl8139', osinfo_obj.network_model)
self.assertEqual('ide', osinfo_obj.disk_model)

def test_hardware_properties_from_osinfo_fedora22(self):
"""Verifies that HardwareProperties attributes are being set
from libosinfo.
"""
@@ -79,6 +92,19 @@ class LibvirtOsInfoTest(test.NoDBTestCase):
self.assertEqual('virtio', osinfo_obj.network_model)
self.assertEqual('virtio', osinfo_obj.disk_model)

def test_hardware_properties_from_osinfo_fedora23(self):
"""Verifies that HardwareProperties attributes are being set
from libosinfo.
"""
img_meta = {'properties':
{'os_distro': 'fedora23'}
}

img_meta = objects.ImageMeta.from_dict(img_meta)
osinfo_obj = osinfo.HardwareProperties(img_meta)
self.assertEqual('virtio', osinfo_obj.network_model)
self.assertEqual('virtio', osinfo_obj.disk_model)

def test_hardware_properties_from_meta(self):
"""Verifies that HardwareProperties attributes are being set
from image properties.

+ 19
- 8
nova/virt/osinfo.py View File

@@ -16,6 +16,7 @@ from oslo_log import log as logging
from oslo_utils import importutils

from nova import exception
from nova.objects import fields

libosinfo = None
LOG = logging.getLogger(__name__)
@@ -102,7 +103,13 @@ class OsInfo(object):
fltr.add_constraint("class", "net")
devs = self._os_obj.get_all_devices(fltr)
if devs.get_length():
return devs.get_nth(0).get_name()
net_model = devs.get_nth(0).get_name()
# convert to valid libvirt values
if net_model in ['virtio-net', 'virtio1.0-net']:
return 'virtio'
# ignore any invalid ones
if net_model in fields.VIFModel.ALL:
return net_model

@property
def disk_model(self):
@@ -111,7 +118,13 @@ class OsInfo(object):
fltr.add_constraint("class", "block")
devs = self._os_obj.get_all_devices(fltr)
if devs.get_length():
return devs.get_nth(0).get_name()
disk_model = devs.get_nth(0).get_name()
# convert to valid libvirt values
if disk_model in ['virtio-block', 'virtio1.0-block']:
return 'virtio'
# ignore any invalid ones
if disk_model in fields.DiskBus.ALL:
return disk_model


class HardwareProperties(object):
@@ -125,12 +138,10 @@ class HardwareProperties(object):

@property
def network_model(self):
model = self.img_props.get('hw_vif_model',
self.os_info_obj.network_model)
return 'virtio' if model == 'virtio-net' else model
return self.img_props.get('hw_vif_model',
self.os_info_obj.network_model)

@property
def disk_model(self):
model = self.img_props.get('hw_disk_bus',
self.os_info_obj.disk_model)
return 'virtio' if model == 'virtio-block' else model
return self.img_props.get('hw_disk_bus',
self.os_info_obj.disk_model)

Loading…
Cancel
Save