aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--sos/policies/__init__.py1
-rw-r--r--sos/utilities.py33
-rw-r--r--[-rwxr-xr-x]tests/archive_tests.py0
-rw-r--r--tests/importer_tests.py13
-rw-r--r--tests/policy_tests.py8
6 files changed, 38 insertions, 19 deletions
diff --git a/.gitignore b/.gitignore
index 0176f5ed..8bd9c08a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,5 @@ buildjar/
gpgkeys/rhsupport.*
rpm-build/*
sos/__init__.py
+cover/
+.coverage
diff --git a/sos/policies/__init__.py b/sos/policies/__init__.py
index a1cdab4b..f5c0e036 100644
--- a/sos/policies/__init__.py
+++ b/sos/policies/__init__.py
@@ -173,7 +173,6 @@ No changes will be made to your system.
archive_fp.close()
return digest.hexdigest()
-
def getPreferredHashAlgorithm(self):
"""Returns the string name of the hashlib-supported checksum algorithm
to use"""
diff --git a/sos/utilities.py b/sos/utilities.py
index 55fab228..5aef0cb8 100644
--- a/sos/utilities.py
+++ b/sos/utilities.py
@@ -317,15 +317,18 @@ class TarFileArchive(Archive):
else:
dest = self.prepend(src)
- fp = open(src, 'rb')
- content = fp.read()
- fp.close()
+ if os.path.isdir(src):
+ self.tarfile.add(src, dest)
+ else:
+ fp = open(src, 'rb')
+ content = fp.read()
+ fp.close()
- tar_info = tarfile.TarInfo(name=dest)
- tar_info.size = len(content)
- tar_info.mtime = os.stat(src).st_mtime
+ tar_info = tarfile.TarInfo(name=dest)
+ tar_info.size = len(content)
+ tar_info.mtime = os.stat(src).st_mtime
- self.tarfile.addfile(tar_info, StringIO(content))
+ self.tarfile.addfile(tar_info, StringIO(content))
def add_string(self, content, dest):
dest = self.prepend(dest)
@@ -423,29 +426,25 @@ def compress(archive, method):
methods = ['xz', 'bzip2', 'gzip']
- if method in ('xz', 'bzip2', 'gzip'):
+ if method in methods:
methods = [method]
- compressed = False
- last_error = None
- for cmd in ('xz', 'bzip2', 'gzip'):
- if compressed:
- break
+ last_error = Exception("compression failed for an unknown reason")
+ log = logging.getLogger('sos')
+
+ for cmd in methods:
try:
command = shlex.split("%s %s" % (cmd,archive.name()))
p = Popen(command, stdout=PIPE, stderr=PIPE, bufsize=-1)
stdout, stderr = p.communicate()
- log = logging.getLogger('sos')
if stdout:
log.info(stdout)
if stderr:
log.error(stderr)
- compressed = True
return archive.name() + "." + cmd.replace('ip','')
except Exception, e:
last_error = e
-
- if not compressed:
+ else:
raise last_error
diff --git a/tests/archive_tests.py b/tests/archive_tests.py
index 01c46395..01c46395 100755..100644
--- a/tests/archive_tests.py
+++ b/tests/archive_tests.py
diff --git a/tests/importer_tests.py b/tests/importer_tests.py
new file mode 100644
index 00000000..91f82cc0
--- /dev/null
+++ b/tests/importer_tests.py
@@ -0,0 +1,13 @@
+import unittest
+
+from sos.utilities import ImporterHelper
+
+class ImporterHelperTests(unittest.TestCase):
+
+ def test_runs(self):
+ h = ImporterHelper(unittest)
+ modules = h.get_modules()
+ self.assertTrue('main' in modules)
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/tests/policy_tests.py b/tests/policy_tests.py
index 1c192bdf..2654c82c 100644
--- a/tests/policy_tests.py
+++ b/tests/policy_tests.py
@@ -1,6 +1,6 @@
import unittest
-from sos.policies import Policy
+from sos.policies import Policy, import_policy
from sos.plugins import Plugin, IndependentPlugin, RedHatPlugin, DebianPlugin
class FauxPolicy(Policy):
@@ -41,5 +41,11 @@ class PolicyTests(unittest.TestCase):
self.assertFalse(p.validatePlugin(FauxDebianPlugin))
+ def test_can_import(self):
+ self.assertTrue(import_policy('redhat') is not None)
+
+ def test_cant_import(self):
+ self.assertTrue(import_policy('notreal') is None)
+
if __name__ == "__main__":
unittest.main()