From d4e3bcc3ed247d8d9a1228c3661b6456f534daf4 Mon Sep 17 00:00:00 2001
From: "Bryn M. Reeves" <bmr@redhat.com>
Date: Mon, 12 Aug 2013 18:42:48 +0100
Subject: [PATCH] Fix traceback when sar module is force-enabled
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The sar plug-in assumes that when it runs the /var/lib/sa
directory and binaries exist (they are part of checkenabled() for
this module).

This leads to a traceback when the plug-in lists a non-existent
directory on hosts where sar is not installed but '-o sar' is
specified on the command line.

Catch the exception and exit gracefully.

(Edited by bmr to improve error message logged).

Signed-off-by: David Kutálek <dkutalek@redhat.com>
Signed-off-by: Bryn M. Reeves <bmr@redhat.com>
---
 sos/plugins/sar.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/sos/plugins/sar.py b/sos/plugins/sar.py
index 042989f..d10fb2f 100644
--- a/sos/plugins/sar.py
+++ b/sos/plugins/sar.py
@@ -20,7 +20,11 @@ class sar(sos.plugintools.PluginBase):
     """
     def setup(self):
         path="/var/log/sa"
-        dirList=os.listdir(path)
+        try:
+            dirList=os.listdir(path)
+        except:
+            self.soslog.error("sar: could not list /var/log/sa")
+            return
         # find all the sa file that don't have an existing sar file
         for fname in dirList:
             if fname[0:2] == 'sa' and fname[2] != 'r':
-- 
1.7.11.7

