mirror of
https://github.com/virt-manager/virt-manager.git
synced 2026-08-08 12:08:08 -05:00
guest: Lookup osinfo object from libosinfo metadata XML
This commit is contained in:
@@ -225,6 +225,20 @@ class TestXMLMisc(unittest.TestCase):
|
||||
xml2 = g.get_xml()
|
||||
self.assertEqual(xml1, xml2)
|
||||
|
||||
def test_guest_osinfo_metadata(self):
|
||||
g = _make_guest()
|
||||
self.assertEqual(g.osinfo.name, "generic")
|
||||
g.set_os_name("fedora17")
|
||||
self.assertEqual(g.osinfo.name, "fedora17")
|
||||
|
||||
g = _make_guest()
|
||||
g._metadata.libosinfo.os_id = "http://fedoraproject.org/fedora/20" # pylint: disable=protected-access
|
||||
self.assertEqual(g.osinfo.name, "fedora20")
|
||||
|
||||
g = _make_guest()
|
||||
g._metadata.libosinfo.os_id = "http://example.com/idontexit" # pylint: disable=protected-access
|
||||
self.assertEqual(g.osinfo.name, "generic")
|
||||
|
||||
def test_dir_searchable(self):
|
||||
# Normally the dir searchable test is skipped in the unittest,
|
||||
# but let's contrive an example that should trigger all the code
|
||||
|
||||
@@ -241,6 +241,16 @@ class Guest(XMLBuilder):
|
||||
##############################
|
||||
|
||||
def _get_osinfo(self):
|
||||
if self.__osinfo:
|
||||
return self.__osinfo
|
||||
|
||||
os_id = self._metadata.libosinfo.os_id
|
||||
if os_id:
|
||||
self.__osinfo = OSDB.lookup_os_by_full_id(os_id)
|
||||
if not self.__osinfo:
|
||||
logging.debug("XML had libosinfo os id=%s but we didn't "
|
||||
"find any libosinfo object matching that", os_id)
|
||||
|
||||
if not self.__osinfo:
|
||||
self.set_os_name("generic")
|
||||
return self.__osinfo
|
||||
|
||||
@@ -159,6 +159,11 @@ class _OSDB(object):
|
||||
# Public APIs #
|
||||
###############
|
||||
|
||||
def lookup_os_by_full_id(self, full_id):
|
||||
for osobj in self._all_variants.values():
|
||||
if osobj.full_id == full_id:
|
||||
return osobj
|
||||
|
||||
def lookup_os(self, key):
|
||||
key = self._aliases.get(key) or key
|
||||
return self._all_variants.get(key)
|
||||
@@ -211,6 +216,7 @@ class _OsVariant(object):
|
||||
self._os = o
|
||||
self._family = self._os and self._os.get_family() or None
|
||||
|
||||
self.full_id = self._os and self._os.get_id() or None
|
||||
self.name = self._os and self._os.get_short_id() or "generic"
|
||||
self.label = self._os and self._os.get_name() or "Generic"
|
||||
self.codename = self._os and self._os.get_codename() or ""
|
||||
|
||||
Reference in New Issue
Block a user