virt: osinfo will report once if libosinfo is not loaded
Currently osinfo module emits multiple error messages when libosinfo module cannot be loaded. Since loading the libosinfo module is optional, it should only report this once as an INFO log message. Change-Id: If4b582d1ec39ba79b4f993543da11ec8c6bd023b Closes-bug: #1543288
This commit is contained in:
@@ -35,6 +35,9 @@ class LibvirtOsInfoTest(test.NoDBTestCase):
|
||||
self.useFixture(fixtures.MonkeyPatch(
|
||||
'nova.virt.osinfo.libosinfo',
|
||||
fakelibosinfo))
|
||||
self.useFixture(fixtures.MonkeyPatch(
|
||||
'nova.virt.osinfo._OsInfoDatabase._instance',
|
||||
None))
|
||||
|
||||
def test_get_os(self):
|
||||
os_info_db = osinfo._OsInfoDatabase.get_instance()
|
||||
@@ -47,6 +50,22 @@ class LibvirtOsInfoTest(test.NoDBTestCase):
|
||||
os_info_db.get_os,
|
||||
'test33')
|
||||
|
||||
def test_module_load_failed(self):
|
||||
self.useFixture(fixtures.MonkeyPatch(
|
||||
'nova.virt.osinfo.libosinfo',
|
||||
None))
|
||||
with test.nested(
|
||||
mock.patch.object(osinfo.importutils, 'import_module',
|
||||
side_effect=ImportError('gi.repository.Libosinfo')),
|
||||
mock.patch.object(osinfo.LOG, 'info')) as (mock_import, mock_log):
|
||||
|
||||
os_info_db = osinfo._OsInfoDatabase.get_instance()
|
||||
self.assertIsNone(os_info_db.get_os('fedora22'))
|
||||
|
||||
os_info_db = osinfo._OsInfoDatabase.get_instance()
|
||||
self.assertIsNone(os_info_db.get_os('fedora19'))
|
||||
self.assertEqual(1, mock_log.call_count)
|
||||
|
||||
def test_hardware_properties_from_osinfo(self):
|
||||
"""Verifies that HardwareProperties attributes are being set
|
||||
from libosinfo.
|
||||
|
||||
@@ -16,7 +16,7 @@ from oslo_log import log as logging
|
||||
from oslo_utils import importutils
|
||||
|
||||
from nova import exception
|
||||
from nova.i18n import _, _LE
|
||||
from nova.i18n import _LW, _LI
|
||||
|
||||
libosinfo = None
|
||||
LOG = logging.getLogger(__name__)
|
||||
@@ -35,14 +35,13 @@ class _OsInfoDatabase(object):
|
||||
def __init__(self):
|
||||
|
||||
global libosinfo
|
||||
if libosinfo is None:
|
||||
try:
|
||||
if libosinfo is None:
|
||||
libosinfo = importutils.import_module(
|
||||
'gi.repository.Libosinfo')
|
||||
except ImportError as exp:
|
||||
raise exception.NovaException(
|
||||
_("Cannot load Libosinfo: (%s)") % exp)
|
||||
|
||||
LOG.info(_LI("Cannot load Libosinfo: (%s)"), exp)
|
||||
else:
|
||||
self.loader = libosinfo.Loader()
|
||||
self.loader.process_default_path()
|
||||
|
||||
@@ -69,6 +68,8 @@ class _OsInfoDatabase(object):
|
||||
:returns: The operation system object Libosinfo.Os
|
||||
:raise exception.OsInfoNotFound: If os hasn't been found
|
||||
"""
|
||||
if libosinfo is None:
|
||||
return
|
||||
if not os_name:
|
||||
raise exception.OsInfoNotFound(os_name='Empty')
|
||||
fltr = libosinfo.Filter.new()
|
||||
@@ -92,7 +93,7 @@ class OsInfo(object):
|
||||
try:
|
||||
return _OsInfoDatabase.get_instance().get_os(os_name)
|
||||
except exception.NovaException as e:
|
||||
LOG.error(_LE("Cannot find OS information - Reason: (%s)"), e)
|
||||
LOG.warning(_LW("Cannot find OS information - Reason: (%s)"), e)
|
||||
|
||||
@property
|
||||
def network_model(self):
|
||||
|
||||
Reference in New Issue
Block a user