aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryn M. Reeves <bmr@redhat.com>2015-01-27 13:07:52 +0000
committerBryn M. Reeves <bmr@redhat.com>2015-01-27 13:07:52 +0000
commit3a2ad99c71dae022cfb7fb02e11473001c50ae23 (patch)
treee8a97ef7f4eed08e0fe1516777a7dc70bab48ba4
parentad464fcc0882f8764e8bbb091a91eeeb4a804ff3 (diff)
downloadsos-3a2ad99c71dae022cfb7fb02e11473001c50ae23.tar.gz
[policies] run PackageManager query_command under timeout
PackageManager query commands may block due to file system locks or problems with the package database. Run the query command with a timeout of 30s and exit if the timeout expires. Signed-off-by: Aruna Balakrishnaiah <aruna@linux.vnet.ibm.com> Signed-off-by: Bryn M. Reeves <bmr@redhat.com> --- Changes from v3: Add default timeout instead of making it configurable Add print function instead of error() Changes from v2: Introduce timeout in shell_out wrapper Changes from v1: Addressed issues of the maintainer Introduce timeout instead of relying on yum.
-rw-r--r--sos/policies/__init__.py3
-rw-r--r--sos/policies/redhat.py10
-rw-r--r--sos/utilities.py4
3 files changed, 13 insertions, 4 deletions
diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py
index 9fcbd552..34a2f6a2 100644
--- a/sos/policies/__init__.py
+++ b/sos/policies/__init__.py
@@ -56,6 +56,7 @@ class PackageManager(object):
"""
query_command = None
+ timeout = 30
def __init__(self, query_command=None):
self.packages = {}
@@ -92,7 +93,7 @@ class PackageManager(object):
version': 'major.minor.version'}}
"""
if self.query_command:
- pkg_list = shell_out(self.query_command).splitlines()
+ pkg_list = shell_out(self.query_command, self.timeout).splitlines()
for pkg in pkg_list:
if '|' not in pkg:
continue
diff --git a/sos/policies/redhat.py b/sos/policies/redhat.py
index 22192463..38510d93 100644
--- a/sos/policies/redhat.py
+++ b/sos/policies/redhat.py
@@ -15,6 +15,7 @@
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
# This enables the use of with syntax in python 2.5 (e.g. jython)
+from __future__ import print_function
import os
import sys
@@ -46,8 +47,15 @@ class RedHatPolicy(LinuxPolicy):
'rpm -qa --queryformat "%{NAME}|%{VERSION}\\n"')
self.valid_subclasses = [RedHatPlugin]
+ pkgs = self.package_manager.all_pkgs()
+
+ # If rpm query timed out after timeout duration exit
+ if not pkgs:
+ print("Could not obtain installed package list", file=sys.stderr)
+ sys.exit(1)
+
# handle PATH for UsrMove
- if self.package_manager.all_pkgs()['filesystem']['version'][0] == '3':
+ if pkgs['filesystem']['version'][0] == '3':
self.PATH = "/usr/sbin:/usr/bin:/root/bin"
else:
self.PATH = "/sbin:/bin:/usr/sbin:/usr/bin:/root/bin"
diff --git a/sos/utilities.py b/sos/utilities.py
index 51909c64..2638ce4a 100644
--- a/sos/utilities.py
+++ b/sos/utilities.py
@@ -180,11 +180,11 @@ def import_module(module_fqname, superclasses=None):
return modules
-def shell_out(cmd, runat=None):
+def shell_out(cmd, timeout=30, runat=None):
"""Shell out to an external command and return the output or the empty
string in case of error.
"""
- return sos_get_command_output(cmd, runat=runat)['output']
+ return sos_get_command_output(cmd, timeout=timeout, runat=runat)['output']
class ImporterHelper(object):