aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJake Hunsaker <jhunsake@redhat.com>2021-09-15 14:37:20 -0400
committerJake Hunsaker <jhunsake@redhat.com>2021-09-17 15:36:47 -0400
commit05be120ef94fecac2aacb44f44bb0d2f29998cf6 (patch)
treeecc2e557032db9ff5dc9b832a092e004feb2284f /tests
parent5b76c1b3157e9f34b73d25cd84efb3809485f410 (diff)
downloadsos-05be120ef94fecac2aacb44f44bb0d2f29998cf6.tar.gz
[Plugin] Improve add_string_as_file collection and manifest recording
This commit allows plugins that call `add_string_as_file` to specify if the string should be written to `sos_strings/$name/` (current behavior) or if it should be written to `sos_commands/$name/` which may be desireable for organizational purposes for plugin collections. `add_string_as_file()` has also been updated to write to a plugin's manifest section for any files written this way. Accordingly, the method will now accept a `tags` parameter to add specified tags to the manifest entry. Certain plugins directly calling this method have been updated, but the existing logic to write truncated data to `sos_strings/` remains untouched, and will not generate manifest entries (as those should already be handled by the method that trigged the truncated collection). Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/report_tests/plugin_tests/logs.py6
-rw-r--r--tests/report_tests/plugin_tests/string_collection_tests.py37
-rw-r--r--tests/unittests/plugin_tests.py5
3 files changed, 45 insertions, 3 deletions
diff --git a/tests/report_tests/plugin_tests/logs.py b/tests/report_tests/plugin_tests/logs.py
index 9512b0d1..14f6bd5d 100644
--- a/tests/report_tests/plugin_tests/logs.py
+++ b/tests/report_tests/plugin_tests/logs.py
@@ -74,3 +74,9 @@ class LogsSizeLimitTest(StageTwoReportTest):
self.assertFileExists(tailed)
journ = self.get_name_in_archive('sos_commands/logs/journalctl_--no-pager')
assert os.path.islink(journ), "Journal in sos_commands/logs is not a symlink"
+
+ def test_string_not_in_manifest(self):
+ # we don't want truncated collections appearing in the strings section
+ # of the manifest for the plugin
+ manifest = self.get_plugin_manifest('logs')
+ self.assertFalse(manifest['strings'])
diff --git a/tests/report_tests/plugin_tests/string_collection_tests.py b/tests/report_tests/plugin_tests/string_collection_tests.py
new file mode 100644
index 00000000..d98401b3
--- /dev/null
+++ b/tests/report_tests/plugin_tests/string_collection_tests.py
@@ -0,0 +1,37 @@
+# This file is part of the sos project: https://github.com/sosreport/sos
+#
+# This copyrighted material is made available to anyone wishing to use,
+# modify, copy, or redistribute it subject to the terms and conditions of
+# version 2 of the GNU General Public License.
+#
+# See the LICENSE file in the source distribution for further information.
+
+
+from sos_tests import StageOneReportTest
+
+
+class CollectStringTest(StageOneReportTest):
+ """Test to ensure that add_string_as_file() is working for plugins that
+ directly call it as part of their collections
+
+ :avocado: tags=stageone
+ """
+
+ sos_cmd = '-v -o unpackaged,python -k python.hashes'
+ # unpackaged is only a RedHatPlugin
+ redhat_only = True
+
+ def test_unpackaged_list_collected(self):
+ self.assertFileCollected('sos_commands/unpackaged/unpackaged')
+
+ def test_python_hashes_collected(self):
+ self.assertFileCollected('sos_commands/python/digests.json')
+
+ def test_no_strings_dir(self):
+ self.assertFileNotCollected('sos_strings/')
+
+ def test_manifest_strings_correct(self):
+ pkgman = self.get_plugin_manifest('unpackaged')
+ self.assertTrue(pkgman['strings']['unpackaged'])
+ pyman = self.get_plugin_manifest('python')
+ self.assertTrue(pyman['strings']['digests_json'])
diff --git a/tests/unittests/plugin_tests.py b/tests/unittests/plugin_tests.py
index fcd24143..0105e3b8 100644
--- a/tests/unittests/plugin_tests.py
+++ b/tests/unittests/plugin_tests.py
@@ -339,10 +339,9 @@ class AddCopySpecTests(unittest.TestCase):
self.mp.sysroot = '/'
fn = create_file(2) # create 2MB file, consider a context manager
self.mp.add_copy_spec(fn, 1)
- content, fname = self.mp.copy_strings[0]
+ content, fname, _tags = self.mp.copy_strings[0]
self.assertTrue("tailed" in fname)
self.assertTrue("tmp" in fname)
- self.assertTrue("/" not in fname)
self.assertEquals(1024 * 1024, len(content))
os.unlink(fn)
@@ -371,7 +370,7 @@ class AddCopySpecTests(unittest.TestCase):
create_file(2, dir=tmpdir)
self.mp.add_copy_spec(tmpdir + "/*", 1)
self.assertEquals(len(self.mp.copy_strings), 1)
- content, fname = self.mp.copy_strings[0]
+ content, fname, _tags = self.mp.copy_strings[0]
self.assertTrue("tailed" in fname)
self.assertEquals(1024 * 1024, len(content))
shutil.rmtree(tmpdir)