diff options
author | Pavel Moravec <pmoravec@redhat.com> | 2017-11-25 12:47:35 +0100 |
---|---|---|
committer | Bryn M. Reeves <bmr@redhat.com> | 2017-12-08 14:09:43 +0000 |
commit | 0b93d1f69ccfcc76e1896ea0e5ff7854be69be13 (patch) | |
tree | deb86d91b07522300957995e0e5b639e1d792461 | |
parent | 119593cff13b1d1d8d34b11fbb92893d70e634d6 (diff) | |
download | sos-0b93d1f69ccfcc76e1896ea0e5ff7854be69be13.tar.gz |
[plugins] set proper PATH for SCL commands
As SCL packages are deployed under /opt/${provider}/${scl}/,
calling a SCL command needs that prefix in any path in PATH.
Consequently, distro-specific SCL default path prefix of the provider must be
defined in sos policies.
Relevant to: #1154
Signed-off-by: Pavel Moravec <pmoravec@redhat.com>
-rw-r--r-- | sos/plugins/__init__.py | 37 | ||||
-rw-r--r-- | sos/policies/__init__.py | 4 | ||||
-rw-r--r-- | sos/policies/redhat.py | 1 |
3 files changed, 35 insertions, 7 deletions
diff --git a/sos/plugins/__init__.py b/sos/plugins/__init__.py index aa69b19d..2a8bc516 100644 --- a/sos/plugins/__init__.py +++ b/sos/plugins/__init__.py @@ -1066,25 +1066,48 @@ class SCLPlugin(RedHatPlugin): output = sos_get_command_output("scl -l")["output"] return [scl.strip() for scl in output.splitlines()] + def convert_cmd_scl(self, scl, cmd): + """wrapping command in "scl enable" call and adds proper PATH + """ + # load default SCL prefix to PATH + prefix = self.policy().get_default_scl_prefix() + # read prefix from /etc/scl/prefixes/${scl} and strip trailing '\n' + try: + prefix = open('/etc/scl/prefixes/%s' % scl, 'r').read()\ + .rstrip('\n') + except Exception as e: + self._log_error("Failed to find prefix for SCL %s, using %s" + % (scl, prefix)) + + # expand PATH by equivalent prefixes under the SCL tree + path = os.environ["PATH"] + for p in path.split(':'): + path = '%s/%s%s:%s' % (prefix, scl, p, path) + + scl_cmd = "scl enable %s \"PATH=%s %s\"" % (scl, path, cmd) + return scl_cmd + def add_cmd_output_scl(self, scl, cmds, **kwargs): """Same as add_cmd_output, except that it wraps command in - "scl enable" call. + "scl enable" call and sets proper PATH. """ if isinstance(cmds, six.string_types): cmds = [cmds] scl_cmds = [] - scl_cmd_tpl = "scl enable %s \"%s\"" for cmd in cmds: - scl_cmds.append(scl_cmd_tpl % (scl, cmd)) + scl_cmds.append(convert_cmd_scl(scl, cmd)) self.add_cmd_output(scl_cmds, **kwargs) - # config files for Software Collections are under /etc/opt/rh/${scl} and - # var files are under /var/opt/rh/${scl}. So we need to insert the paths - # after the appropriate root dir. + # config files for Software Collections are under /etc/${prefix}/${scl} and + # var files are under /var/${prefix}/${scl} where the ${prefix} is distro + # specific path. So we need to insert the paths after the appropriate root + # dir. def convert_copyspec_scl(self, scl, copyspec): + scl_prefix = self.policy().get_default_scl_prefix() for rootdir in ['etc', 'var']: p = re.compile('^/%s/' % rootdir) - copyspec = p.sub('/%s/opt/rh/%s/' % (rootdir, scl), copyspec) + copyspec = p.sub('/%s/%s/%s/' % (rootdir, scl_prefix, scl), + copyspec) return copyspec def add_copy_spec_scl(self, scl, copyspecs): diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py index dffd801c..dc043105 100644 --- a/sos/policies/__init__.py +++ b/sos/policies/__init__.py @@ -194,6 +194,7 @@ No changes will be made to system configuration. vendor_url = "http://www.example.com/" vendor_text = "" PATH = "" + default_scl_prefix = "" _in_container = False _host_sysroot = '/' @@ -271,6 +272,9 @@ No changes will be made to system configuration. return tempfile.gettempdir() return opt_tmp_dir + def get_default_scl_prefix(self): + return self.default_scl_prefix + def match_plugin(self, plugin_classes): if len(plugin_classes) > 1: for p in plugin_classes: diff --git a/sos/policies/redhat.py b/sos/policies/redhat.py index c7449439..2dfe0589 100644 --- a/sos/policies/redhat.py +++ b/sos/policies/redhat.py @@ -44,6 +44,7 @@ class RedHatPolicy(LinuxPolicy): _rpmv_filter = ["debuginfo", "-devel"] _in_container = False _host_sysroot = '/' + default_scl_prefix = '/opt/rh' def __init__(self, sysroot=None): super(RedHatPolicy, self).__init__(sysroot=sysroot) |