diff options
author | Jake Hunsaker <jhunsake@redhat.com> | 2022-02-21 14:37:09 -0500 |
---|---|---|
committer | Jake Hunsaker <jhunsake@redhat.com> | 2022-02-22 14:10:49 -0500 |
commit | 2ae16e0245e1b01b8547e507abb69c11871a8467 (patch) | |
tree | 9717e58feb89efd793e8de98ab0e8f15bcf00d4f | |
parent | 2c1d0ff547a0ae3500f7b6d8479f801fd455be00 (diff) | |
download | sos-2ae16e0245e1b01b8547e507abb69c11871a8467.tar.gz |
[sosnode] Handle downstream versioning for runtime option check
First, adds parsing and formatting for an sos installation's release
version according to the loaded package manager for that node.
Adds a fallback version check for 4.2-13 for RHEL downstreams that
backport the `container-runtime` option into sos-4.2.
Carry this in upstream to account for use cases where a workstation used
to run `collect` from may be from a different stream than those used by
cluster nodes.
Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
-rw-r--r-- | sos/collector/sosnode.py | 60 |
1 files changed, 51 insertions, 9 deletions
diff --git a/sos/collector/sosnode.py b/sos/collector/sosnode.py index 7bbe0cd1..d9b998b0 100644 --- a/sos/collector/sosnode.py +++ b/sos/collector/sosnode.py @@ -275,21 +275,34 @@ class SosNode(): def _load_sos_info(self): """Queries the node for information about the installed version of sos """ + ver = None + rel = None if self.host.container_version_command is None: pkg = self.host.package_manager.pkg_version(self.host.sos_pkg_name) if pkg is not None: ver = '.'.join(pkg['version']) - self.sos_info['version'] = ver + if pkg['release']: + rel = pkg['release'] + else: # use the containerized policy's command pkgs = self.run_command(self.host.container_version_command, use_container=True, need_root=True) if pkgs['status'] == 0: - ver = pkgs['output'].strip().split('-')[1] - if ver: - self.sos_info['version'] = ver - else: - self.sos_info['version'] = None + _, ver, rel = pkgs['output'].strip().split('-') + + if ver: + if len(ver.split('.')) == 2: + # safeguard against maintenance releases throwing off the + # comparison by LooseVersion + ver += '.0' + try: + ver += '-%s' % rel.split('.')[0] + except Exception as err: + self.log_debug("Unable to fully parse sos release: %s" % err) + + self.sos_info['version'] = ver + if self.sos_info['version']: self.log_info('sos version is %s' % self.sos_info['version']) else: @@ -381,9 +394,37 @@ class SosNode(): """Checks to see if the sos installation on the node is AT LEAST the given ver. This means that if the installed version is greater than ver, this will still return True + + :param ver: Version number we are trying to verify is installed + :type ver: ``str`` + + :returns: True if installed version is at least ``ver``, else False + :rtype: ``bool`` """ - return self.sos_info['version'] is not None and \ - LooseVersion(self.sos_info['version']) >= ver + def _format_version(ver): + # format the version we're checking to a standard form of X.Y.Z-R + try: + _fver = ver.split('-')[0] + _rel = '' + if '-' in ver: + _rel = '-' + ver.split('-')[-1].split('.')[0] + if len(_fver.split('.')) == 2: + _fver += '.0' + + return _fver + _rel + except Exception as err: + self.log_debug("Unable to format '%s': %s" % (ver, err)) + return ver + + _ver = _format_version(ver) + + try: + _node_ver = LooseVersion(self.sos_info['version']) + _test_ver = LooseVersion(_ver) + return _node_ver >= _test_ver + except Exception as err: + self.log_error("Error checking sos version: %s" % err) + return False def is_installed(self, pkg): """Checks if a given package is installed on the node""" @@ -587,7 +628,8 @@ class SosNode(): sos_opts.append('--cmd-timeout=%s' % quote(str(self.opts.cmd_timeout))) - if self.check_sos_version('4.3'): + # handle downstream versions that backported this option + if self.check_sos_version('4.3') or self.check_sos_version('4.2-13'): if self.opts.container_runtime != 'auto': sos_opts.append( "--container-runtime=%s" % self.opts.container_runtime |