[virt-tools-list] [PATCH] virtinst: Update SUSE media detection

Cole Robinson crobinso at redhat.com
Tue Apr 24 16:12:50 UTC 2018


On 04/10/2018 05:48 PM, Charles Arnold wrote:
> Add the ability to detect a .treeinfo file found on newer
> SUSE distro media. Specifically, SLE15, openSUSE Leap 15
> (newer than pre-release build 191), and Tumbleweed
> beginning with build 20180407 which all contain a
> .treeinfo file on the media.
> 
> Other fixes included deal with the special handling of
> Tumbleweed which doesn't have a version because it is 
> a rolling release. Fix a parsing issue with the addition of
> the name 'Leap' to newer openSUSE versions.
> 

Sorry for the long delay. This patch made it clear that the treeinfo
handling needed to be changed a bit to accomodate this case. The patch
as is throws exceptions with the ./setup.py test_urls. I pushed some
cleanups here, and wired up the tumbleweed .treeinfo detection. This is
in git now.

Please separate the other changes in this patch into individual patches
and repost, and also explain the case they are fixing.

> Signed-off-by: Charles Arnold <carnold at suse.com>
> 
> diff --git a/virtinst/urldetect.py b/virtinst/urldetect.py
> index 96c2b9a..8f2e291 100644
> --- a/virtinst/urldetect.py
> +++ b/virtinst/urldetect.py
> @@ -169,17 +169,19 @@ class _SUSEContent(object):
>          # REPOID obsproduct://build.suse.de/SUSE:SLE-12-SP3:GA/SLES/12.3/DVD/aarch64
>          #
>          # As of 2018 all latest distros match only DISTRO and REPOID.
> -        if not self.product_name:
> +        if not self.product_name or 'Tumbleweed' in self.product_name:
>              return None
>  

Where is this required? Since tumbleweed doesn't have a 'content' file
anymore, I can't tell where this code is triggered...

>          distro_version = self.content_dict.get("VERSION", "")
>          if "-" in distro_version:
>              distro_version = distro_version.split('-', 1)[0]
>  
> -        # Special case, parse version out of a line like this
> +        # Special case, parse version out of a lines like these
>          # cpe:/o:opensuse:opensuse:13.2,openSUSE
> +        # cpe:/o:opensuse:opensuse:42.3,openSUSE Leap 42.3'
>          if (not distro_version and
> -            re.match("^.*:.*,openSUSE$", self.content_dict["DISTRO"])):
> +            (re.match("^.*:.*,openSUSE$", self.content_dict["DISTRO"]) or
> +             re.match("^.*:.*,openSUSE Leap .*", self.content_dict["DISTRO"]))):
>              distro_version = self.content_dict["DISTRO"].rsplit(
>                      ",", 1)[0].strip().rsplit(":")[4]
>  

I guess this is needed for the case where we fail to detect the distro
name via the install URL? I should probably drop that code so we are
always testing this code path

> @@ -190,6 +192,8 @@ class _SUSEContent(object):
>                          self.product_name.strip().rsplit(' ')[5][2])
>              distro_version = sle_version
>  
> +        if distro_version:
> +            distro_version = distro_version.strip()
>          return distro_version
>  
>  
> @@ -500,11 +504,13 @@ class CentOSDistro(RHELDistro):
>  
>  
>  class SuseDistro(Distro):
> -    PRETTY_NAME = "SUSE"
> -    _suse_regex = []
>  
>      @classmethod
>      def is_valid(cls, cache):
> +        famregex = ".*SUSE.*"
> +        has_treeinfo = cache.treeinfo_family_regex(famregex)
> +        if has_treeinfo:
> +            return has_treeinfo
>          if not cache.suse_content:
>              cache.suse_content = -1
>              content_str = cache.acquire_file_content("content")
> @@ -525,6 +531,10 @@ class SuseDistro(Distro):
>          return False
>  
>      def __init__(self, *args, **kwargs):
> +        cache = args[3] if len(args) > 3 and isinstance(args[3], _DistroCache) else None
> +        if cache and cache._treeinfo:
> +            GenericTreeinfoDistro.__init__(self, *args, **kwargs)
> +            return
>          Distro.__init__(self, *args, **kwargs)
>          self.arch = self.cache.suse_content.tree_arch
>  
> @@ -569,6 +579,8 @@ class SuseDistro(Distro):
>      def _variantFromVersion(self):
>          distro_version = self.cache.suse_content.product_version
>          if not distro_version:
> +            if 'Tumbleweed' in self.cache.suse_content.product_name:
> +                self.os_variant = "opensusetumbleweed"
>              return
>  

Again I'm not sure where this is triggered, old tumbleweed? Is that
important to continue supporting?

>          version = distro_version.split('.', 1)[0].strip()
> @@ -582,11 +594,7 @@ class SuseDistro(Distro):
>                  if sp_version:
>                      self.os_variant += sp_version
>              else:
> -                # Tumbleweed 8 digit date
> -                if len(version) == 8:
> -                    self.os_variant += "tumbleweed"
> -                else:
> -                    self.os_variant += distro_version
> +                self.os_variant += distro_version
>          else:
>              self.os_variant += "9"
>  
> @@ -603,19 +611,67 @@ class SuseDistro(Distro):
>      def _get_kernel_url_arg(self):
>          return "install"
>  
> +    def _split_suse_version(self):
> +        verstr = self.cache.treeinfo_version
> +        def _safeint(c):
> +            try:
> +                return int(c)
> +            except Exception:
> +                return 0
> +
> +        # Parse a string like 15.0 into its two parts
> +        update = 0
> +        version = _safeint(verstr)
> +        if verstr.count(".") == 1:
> +            version = _safeint(verstr.split(".")[0])
> +            update = _safeint(verstr.split(".")[1])
> +
> +        logging.debug("converted verstr=%s to version=%s update=%s",
> +                verstr, version, update)
> +        return version, update
> +
> +    def _detect_version(self):
> +        if not self.cache.treeinfo_version:
> +            if 'Tumbleweed' in self.cache.treeinfo_family:
> +                self.os_variant = 'opensusetumbleweed'
> +            return
> +
> +        version, update = self._split_suse_version()
> +        self._version_number = version
> +
> +        # Start with example base=sles15, then walk backwards
> +        # through the OS list to find the latest os name that matches
> +        # this way we handle sles15.1 from treeinfo when osdict only
> +        # knows about sles15.0
> +        base = self._variant_prefix + str(version)
> +        while update >= 0:
> +            tryvar = base
> +            if update > 0 or not base.startswith('sles'):
> +                tryvar += ".%s" % update
> +            if self._check_osvariant_valid(tryvar):
> +                self.os_variant = tryvar
> +                break
> +            update -= 1
> +
> 

Since this code is nearly identical to _split_rhel_version + friends, we
should try to share code here. ./setup.py test_urls will ensure other
cases continue to work

Thanks,
Cole




More information about the virt-tools-list mailing list