Blame SOURCES/virt-manager-osdict-Always-return-the-most-generic-tree.patch

36f1ba
From b41f086d40bd0703f1776589dd4ea5579d0fd520 Mon Sep 17 00:00:00 2001
36f1ba
Message-Id: <b41f086d40bd0703f1776589dd4ea5579d0fd520@dist-git>
36f1ba
From: Pavel Hrdina <phrdina@redhat.com>
36f1ba
Date: Fri, 6 Sep 2019 18:06:08 +0200
36f1ba
Subject: [PATCH] osdict: Always return the most generic tree
36f1ba
MIME-Version: 1.0
36f1ba
Content-Type: text/plain; charset=UTF-8
36f1ba
Content-Transfer-Encoding: 8bit
36f1ba
36f1ba
From: Fabiano FidĂȘncio <fidencio@redhat.com>
36f1ba
36f1ba
Some OSes, as Fedora, have variants (which we rely to be standardised on
36f1ba
osinfo-db side), which we can use to return the most generic tree
36f1ba
possible, in case no profile is specified, in order to avoid failing to
36f1ba
install a "Workstation" system because a "Server" variant tree was used.
36f1ba
36f1ba
https://bugzilla.redhat.com/show_bug.cgi?id=1749865
36f1ba
36f1ba
Signed-off-by: Fabiano FidĂȘncio <fidencio@redhat.com>
36f1ba
(cherry picked from commit 0f1acc9f8f392eaf5edd30ce239728afd1f924cf)
36f1ba
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
36f1ba
---
36f1ba
 tests/osdict.py    |  4 ++++
36f1ba
 virtinst/osdict.py | 39 ++++++++++++++++++++++++++++++++++-----
36f1ba
 2 files changed, 38 insertions(+), 5 deletions(-)
36f1ba
36f1ba
diff --git a/tests/osdict.py b/tests/osdict.py
36f1ba
index eb0d4f86..9fb477bd 100644
36f1ba
--- a/tests/osdict.py
36f1ba
+++ b/tests/osdict.py
36f1ba
@@ -52,11 +52,15 @@ class TestOSDB(unittest.TestCase):
36f1ba
 
36f1ba
     def test_tree_url(self):
36f1ba
         f26 = OSDB.lookup_os("fedora26")
36f1ba
+        f29 = OSDB.lookup_os("fedora29")
36f1ba
         winxp = OSDB.lookup_os("winxp")
36f1ba
 
36f1ba
         # Valid tree URL
36f1ba
         assert "fedoraproject.org" in f26.get_location("x86_64")
36f1ba
 
36f1ba
+        # Most generic tree URL
36f1ba
+        assert "Everything" in f29.get_location("x86_64")
36f1ba
+
36f1ba
         # Has tree URLs, but none for arch
36f1ba
         try:
36f1ba
             f26.get_location("ia64")
36f1ba
diff --git a/virtinst/osdict.py b/virtinst/osdict.py
36f1ba
index 64d8bdb8..a53e4249 100644
36f1ba
--- a/virtinst/osdict.py
36f1ba
+++ b/virtinst/osdict.py
36f1ba
@@ -592,8 +592,36 @@ class _OsVariant(object):
36f1ba
 
36f1ba
         return "inst.repo"
36f1ba
 
36f1ba
+    def _get_generic_location(self, treelist, arch, profile):
36f1ba
+        if not hasattr(Libosinfo.Tree, "get_os_variants"):
36f1ba
+            for tree in treelist:
36f1ba
+                if tree.get_architecture() == arch:
36f1ba
+                    return tree.get_url()
36f1ba
+            return None
36f1ba
+
36f1ba
+        fallback_tree = None
36f1ba
+        if not profile:
36f1ba
+            profile = "Everything"
36f1ba
+
36f1ba
+        for tree in treelist:
36f1ba
+            if tree.get_architecture() != arch:
36f1ba
+                continue
36f1ba
+
36f1ba
+            variant_list = tree.get_os_variants()
36f1ba
+            if variant_list.get_length() == 0:
36f1ba
+                return tree.get_url()
36f1ba
+
36f1ba
+            fallback_tree = tree
36f1ba
+            for i in range(variant_list.get_length()):
36f1ba
+                variant = variant_list.get_nth(i)
36f1ba
+                if profile in variant.get_name():
36f1ba
+                    return tree.get_url()
36f1ba
+
36f1ba
+        if fallback_tree:
36f1ba
+            return fallback_tree.get_url()
36f1ba
+        return None
36f1ba
 
36f1ba
-    def get_location(self, arch):
36f1ba
+    def get_location(self, arch, profile=None):
36f1ba
         treelist = []
36f1ba
         if self._os:
36f1ba
             treelist = list(_OsinfoIter(self._os.get_tree_list()))
36f1ba
@@ -605,10 +633,11 @@ class _OsVariant(object):
36f1ba
         # Some distros have more than one URL for a specific architecture,
36f1ba
         # which is the case for Fedora and different variants (Server,
36f1ba
         # Workstation). Later on, we'll have to differentiate that and return
36f1ba
-        # the right one.
36f1ba
-        for tree in treelist:
36f1ba
-            if tree.get_architecture() == arch:
36f1ba
-                return tree.get_url()
36f1ba
+        # the right one. However, for now, let's just rely on returning the
36f1ba
+        # most generic tree possible.
36f1ba
+        location = self._get_generic_location(treelist, arch, profile)
36f1ba
+        if location:
36f1ba
+            return location
36f1ba
 
36f1ba
         raise RuntimeError(
36f1ba
             _("OS '%s' does not have a URL location for the %s architecture") %
36f1ba
-- 
36f1ba
2.23.0
36f1ba