File virtinst-add-sle15-detection-support.patch of Package virt-manager.12547

References: bsc#1054986
With SLE15 and openSUSE 15 the content file has been removed from the media.
This file was used for SUSE distro version and arch detection. Now detection
must be done by parsing the .treeinfo file.
We must continue to keep the content parsing code for the older distros.
As a fallback, detection is also setup to look at the media.1/products and
media.1/build files.

Index: virt-manager-1.2.1/virtinst/urlfetcher.py
===================================================================
--- virt-manager-1.2.1.orig/virtinst/urlfetcher.py
+++ virt-manager-1.2.1/virtinst/urlfetcher.py
@@ -308,6 +308,15 @@ def _distroFromTreeinfo(fetcher, arch, v
         dclass = RHELDistro
     elif re.match(".*Scientific Linux.*", fam):
         dclass = SLDistro
+    elif re.match(".*SUSE Linux Enterprise.*", fam):
+        if re.match(".*Server.*", fam):
+            dclass = SLESDistro
+        elif re.match(".*Desktop.*", fam):
+            dclass = SLEDDistro
+        else:
+            dclass = SLEDistro
+    elif re.match(".*openSUSE.*", fam):
+        dclass = OpensuseDistro
     else:
         dclass = GenericDistro
 
@@ -392,7 +401,7 @@ def _distroFromSUSEContent(fetcher, arch
     dclass = GenericDistro
     if distribution:
         if re.match(".*SUSE Linux Enterprise Server*", distribution[1]) or \
-            re.match(".*SUSE SLES*", distribution[1]):
+            re.match(".*SUSE SLES*", distribution[1]) or re.match("SLES*", distribution[1]):
             dclass = SLESDistro
             if distro_version is None:
                 distro_version = parse_sle_distribution(distribution)
@@ -407,7 +416,10 @@ def _distroFromSUSEContent(fetcher, arch
         elif re.match(".*openSUSE.*", distribution[1]):
             dclass = OpensuseDistro
             if distro_version is None:
-                distro_version = ['VERSION', distribution[0].strip().rsplit(':')[4]]
+                if ':' in distribution[0]:
+                    distro_version = ['VERSION', distribution[0].strip().rsplit(':')[4]]
+                else:
+                    distro_version = ['VERSION', distribution[1].strip().rsplit(' ')[2]]
                 # For tumbleweed we only have an 8 character date string so default to 13.2
                 if distro_version[1] and len(distro_version[1]) == 8:
                     distro_version = ['VERSION', '13.2']
@@ -943,6 +955,7 @@ class SLDistro(RHELDistro):
 
 class SuseDistro(Distro):
     name = "SUSE"
+    uses_treeinfo = True
 
     _boot_iso_paths   = ["boot/boot.iso"]
 
@@ -977,27 +990,53 @@ class SuseDistro(Distro):
                 self._xen_kernel_paths = [("boot/%s/vmlinuz-xenpae" % self.arch,
                                             "boot/%s/initrd-xenpae" % self.arch)]
             else:
-                self._xen_kernel_paths = [("boot/%s/vmlinuz-xen" % self.arch,
-                                            "boot/%s/initrd-xen" % self.arch)]
+                self._xen_kernel_paths = [("boot/%s/loader/linux" % self.arch,
+                                                  "boot/%s/loader/initrd" % self.arch)]
+                # By appending this gets searched for first
+                self._xen_kernel_paths.append(("boot/%s/vmlinuz-xen" % self.arch,
+                                            "boot/%s/initrd-xen" % self.arch))
 
     def _variantFromVersion(self):
         distro_version = self.version_from_content[1].strip()
         version = distro_version.split('.', 1)[0].strip()
         self.os_variant = self.urldistro
-        if int(version) >= 10:
-            if self.os_variant.startswith(("sles", "sled")):
-                sp_version = None
-                if len(distro_version.split('.', 1)) == 2:
-                    sp_version = 'sp' + distro_version.split('.', 1)[1].strip()
-                self.os_variant += version
-                if sp_version:
-                    self.os_variant += sp_version
+
+        sp_version = None
+        if self.os_variant.startswith(("sle")):
+            if len(distro_version.split('.', 1)) == 2:
+                sp_version = 'sp' + distro_version.split('.', 1)[1].strip()
+            self.os_variant += version.replace(" ", "").lower()
+            if sp_version and sp_version != 'sp0':
+                self.os_variant += sp_version
+        elif self.os_variant.startswith("opensuse"):
+            if len(version) == 8:
+                self.os_variant += "tumbleweed"
             else:
                 self.os_variant += distro_version
         else:
             self.os_variant += "9"
 
     def isValidStore(self):
+        if self.treeinfo:
+            ret = False
+            if self.urldistro:
+                family = self.treeinfo.get("general", "family")
+                if "SUSE Linux Enterprise Server" in family and 'sles' in self.urldistro or \
+                   "SUSE Linux Enterprise Desktop" in family and 'sled' in self.urldistro or \
+                   "SUSE Linux Enterprise" in family and 'sle' in self.urldistro or \
+                   "openSUSE" in family and 'opensuse' in self.urldistro or \
+                   "Open Enterprise" in family and 'oes' in self.urldistro:
+                    if 'Tumbleweed' in family:
+                        self.os_variant = "opensusetumbleweed"
+                        return True
+                    ret = True
+            if ret:
+                version = self.treeinfo.get("general", "version")
+                distro_version = ['VERSION', version]
+                self.version_from_content = distro_version
+                self._variantFromVersion()
+            return ret
+
         # self.version_from_content is the VERSION line from the contents file
         if self.version_from_content is None or \
             self.version_from_content[1] is None:
@@ -1033,6 +1072,10 @@ class SuseDistro(Distro):
         return self.os_variant
 
 
+class SLEDistro(SuseDistro):
+    urldistro = "sle"
+
+
 class SLESDistro(SuseDistro):
     urldistro = "sles"
 
@@ -1041,8 +1084,6 @@ class SLEDDistro(SuseDistro):
     urldistro = "sled"
 
 
-# Suse  image store is harder - we fetch the kernel RPM and a helper
-# RPM and then munge bits together to generate a initrd
 class OpensuseDistro(SuseDistro):
     urldistro = "opensuse"
 
openSUSE Build Service is sponsored by