aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/__init__.py1
-rw-r--r--tests/commons.py32
-rw-r--r--tests/fixture/__init__.py0
-rw-r--r--tests/fixture/dummyPluginDisabled.py31
-rw-r--r--tests/fixture/dummyPluginEnabled.py32
-rw-r--r--tests/testbasic.py59
-rw-r--r--tests/testldap.py41
7 files changed, 196 insertions, 0 deletions
diff --git a/tests/__init__.py b/tests/__init__.py
new file mode 100644
index 00000000..8b137891
--- /dev/null
+++ b/tests/__init__.py
@@ -0,0 +1 @@
+
diff --git a/tests/commons.py b/tests/commons.py
new file mode 100644
index 00000000..de2906fd
--- /dev/null
+++ b/tests/commons.py
@@ -0,0 +1,32 @@
+# commons.py
+import sys, os
+
+commons = {}
+commons['bin'] = '/usr/sbin/sosreport'
+commons['fnameRe'] = '/tmp/sosreport-*.xz'
+commons['testName'] = 'tester'
+commons['testID'] = 1
+commons['batch'] = True
+commons['i18n'] = 'en_US.UTF-8'
+commons['pluginpath'] = None
+commons['plugins'] = []
+commons['testOptions'] = ['--build','--batch']
+if os.path.isfile('/etc/fedora-release'):
+ commons['distro'] = 'Fedora'
+else:
+ commons['distro'] = 'RHEL'
+
+paths = sys.path
+for path in paths:
+ if path.strip()[-len("site-packages"):] == "site-packages" \
+ and os.path.isdir(path + "/sos/plugins"):
+ commons['pluginpath'] = path + "/sos/plugins"
+
+for plugin in os.listdir(commons['pluginpath']):
+ plugbase = plugin[:-3]
+ if not plugin[-3:] == '.py' or plugbase == "__init__":
+ continue
+ commons['plugins'].append(plugbase)
+
+def desc(txt):
+ sys.stdout.write(txt)
diff --git a/tests/fixture/__init__.py b/tests/fixture/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/tests/fixture/__init__.py
diff --git a/tests/fixture/dummyPluginDisabled.py b/tests/fixture/dummyPluginDisabled.py
new file mode 100644
index 00000000..c86e7b44
--- /dev/null
+++ b/tests/fixture/dummyPluginDisabled.py
@@ -0,0 +1,31 @@
+### This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+import sos.plugintools
+import os
+
+class dummyPluginDisabled(sos.plugintools.PluginBase):
+ """ dummy test plugin """
+
+ def defaultenabled(self):
+ return False
+
+ def setup(self):
+ filename = "/tmp/testenabled.file"
+ f = open(filename,'w')
+ f.close()
+ self.addCopySpec(filename)
+ return
+
+
diff --git a/tests/fixture/dummyPluginEnabled.py b/tests/fixture/dummyPluginEnabled.py
new file mode 100644
index 00000000..9074ae6b
--- /dev/null
+++ b/tests/fixture/dummyPluginEnabled.py
@@ -0,0 +1,32 @@
+### This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+import sos.plugintools
+import os
+
+class dummyPluginEnabled(sos.plugintools.PluginBase):
+ """ dummy test plugin """
+
+ def defaultenabled(self):
+ return True
+
+ def setup(self):
+ filename = "/tmp/testenabled.file"
+ f = open(filename,'w')
+ f.close()
+ self.addCopySpec(filename)
+ return
+
+
+
diff --git a/tests/testbasic.py b/tests/testbasic.py
new file mode 100644
index 00000000..231481ae
--- /dev/null
+++ b/tests/testbasic.py
@@ -0,0 +1,59 @@
+import os, sys, shutil
+from commons import *
+from nose.tools import *
+from sos.sosreport import *
+from glob import glob
+
+class GlobalVars:
+ pass
+
+class TestBasicSos:
+ def __init__(self):
+ GlobalVars.dstroot = None
+ GlobalVars.commons = commons
+ # clean pre-existing dummy plugins
+ for i in glob(GlobalVars.commons['pluginpath']+'/dummyPlugin*'):
+ os.remove(os.path.join(GlobalVars.commons['pluginpath'],i))
+
+ def setup(self):
+ """ prework """
+ pass
+
+ def teardown(self):
+ """ cleanup dstroot and other miscellaneous files """
+ if os.path.isdir(GlobalVars.dstroot) and not None:
+ shutil.rmtree(GlobalVars.dstroot)
+
+ def testSosreportBin(self):
+ """ test existence of sosreport bin """
+ if not os.path.isfile(GlobalVars.commons['bin']):
+ raise AssertionError("Sosreport executable does not exist")
+
+
+ def testUnattended(self):
+ """ test unattended """
+ GlobalVars.commons['testOptions'].append("-ofilesys")
+ GlobalVars.dstroot = sosreport(GlobalVars.commons['testOptions'])
+ if not os.path.isdir(GlobalVars.dstroot):
+ raise AssertionError("No sosreport created")
+
+ def testPluginEnable(self):
+ """ test success of plugin enable """
+ if os.path.isdir(GlobalVars.commons['pluginpath']):
+ shutil.copy('fixture/dummyPluginEnabled.py',GlobalVars.commons['pluginpath'])
+ GlobalVars.commons['testOptions'].append('-odummyPluginEnabled')
+ GlobalVars.dstroot = sosreport(GlobalVars.commons['testOptions'])
+ if os.path.isdir(GlobalVars.dstroot) \
+ and os.path.isfile(os.path.join(GlobalVars.dstroot,'tmp/testenabled.file')):
+ return True
+ raise AssertionError("testenabled.file not found")
+
+ def testPluginDisable(self):
+ """ test plugin disable """
+ if os.path.isdir(GlobalVars.commons['pluginpath']):
+ shutil.copy('fixture/dummyPluginDisabled.py',GlobalVars.commons['pluginpath'])
+ GlobalVars.dstroot = sosreport(["-nrpm","-nselinux","--batch","--build"])
+ if os.path.isdir(GlobalVars.dstroot) \
+ and os.path.isfile(os.path.join(GlobalVars.dstroot,'tmp/testenabled.file')):
+ raise AssertionError("plugin not disabled")
+ return True
diff --git a/tests/testldap.py b/tests/testldap.py
new file mode 100644
index 00000000..19511f74
--- /dev/null
+++ b/tests/testldap.py
@@ -0,0 +1,41 @@
+from sos.sosreport import *
+from commons import *
+from nose.tools import *
+import os, sys, shutil
+
+class GlobalVars:
+ pass
+
+class TestLDAP:
+ def __init__(self):
+ GlobalVars.commons = commons
+ GlobalVars.dstroot = None
+
+ def setup(self):
+ """ prework """
+ pass
+
+ def teardown(self):
+ """ cleanup dstroot and other miscellaneous files """
+ if os.path.isdir(GlobalVars.dstroot) and not None:
+ shutil.rmtree(GlobalVars.dstroot)
+
+ def testPostProc(self):
+ """ check scraping of bindpw if exists """
+ GlobalVars.commons['testOptions'].append("-oldap")
+ GlobalVars.dstroot = sosreport(GlobalVars.commons['testOptions'])
+ ldapconf = os.path.join(GlobalVars.dstroot,'etc/ldap.conf')
+ if os.path.isfile(ldapconf) and os.path.isfile("/etc/ldap.conf"):
+ f = open('/etc/ldap.conf','r').readlines()
+ for line in f:
+ assert_false('bindpw ***' in line)
+
+ def testCapture(self):
+ """ check for capture of proper files """
+ GlobalVars.commons['testOptions'].append("-oldap")
+ GlobalVars.dstroot = sosreport(GlobalVars.commons['testOptions'])
+ ldapdir = os.path.join(GlobalVars.dstroot,'etc/openldap')
+ if os.path.isdir(ldapdir) and \
+ os.path.isfile(os.path.join(GlobalVars.dstroot,'etc/ldap.conf')):
+ GlobalVars.commons['testOptions'].pop()
+ assert_true