aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/report_tests/plugin_tests/logs.py69
-rw-r--r--tests/report_tests/plugin_tests/sos_extras.py32
-rw-r--r--tests/report_tests/plugin_tests/sudo.py36
-rw-r--r--tests/test_data/etc/sos/extras.d/sos_testing.conf4
-rw-r--r--tests/test_data/etc/sudo-ldap.conf6
5 files changed, 147 insertions, 0 deletions
diff --git a/tests/report_tests/plugin_tests/logs.py b/tests/report_tests/plugin_tests/logs.py
new file mode 100644
index 00000000..9148bbff
--- /dev/null
+++ b/tests/report_tests/plugin_tests/logs.py
@@ -0,0 +1,69 @@
+# 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.
+
+import random
+import os
+
+
+from sos_tests import StageOneReportTest, StageTwoReportTest
+from string import ascii_uppercase, digits
+from systemd import journal
+
+
+class LogsPluginTest(StageOneReportTest):
+ """Ensure common collections from the `logs` plugin are properly collected
+
+ :avocado: tags=stageone
+ """
+
+ sos_cmd = '-o logs --all-logs'
+
+ def test_journalctl_collections(self):
+ self.assertFileCollected('sos_commands/logs/journalctl_--disk-usage')
+ self.assertFileCollected('sos_commands/logs/journalctl_--no-pager_--catalog_--boot')
+
+ def test_journal_runtime_collected(self):
+ self.assertFileGlobInArchive('/var/log/journal/*')
+
+
+class LogsSizeLimitTest(StageTwoReportTest):
+ """Test that journal size limiting is working and is independent of
+ --log-size
+
+ Note: this test will insert over 100MB of garbage into the test system's
+ journal
+
+ :avocado: tags=stagetwo
+ """
+
+ sos_cmd = '-o logs'
+ packages = {
+ 'rhel': 'python3-systemd',
+ 'ubuntu': 'python3-systemd'
+ }
+
+ # override the stage2 mocking here to inject a string into the journal
+ def setup_mocking(self):
+ # write 20MB at a time to side-step rate/size limiting on some distros
+ # write over 100MB to ensure we will actually size limit inside sos,
+ # allowing for any compression or de-dupe systemd does
+ rsize = 20 * 1048576
+ for i in range(3):
+ # generate 20MB, write it, then write it in reverse.
+ # Spend less time generating new strings
+ rand = ''.join(random.choice(ascii_uppercase + digits) for _ in range(rsize))
+ journal.send(rand)
+ journal.send(rand[::-1])
+
+ def test_journal_size_limit(self):
+ journ = 'sos_commands/logs/journalctl_--no-pager_--catalog_--boot'
+ self.assertFileCollected(journ)
+ jsize = os.stat(self.get_name_in_archive(journ)).st_size
+ assert jsize <= 105906176, "Collected journal is larger than 100MB"
+ assert jsize > 27262976, "Collected journal limited by --log-size"
+
diff --git a/tests/report_tests/plugin_tests/sos_extras.py b/tests/report_tests/plugin_tests/sos_extras.py
new file mode 100644
index 00000000..fa618ffb
--- /dev/null
+++ b/tests/report_tests/plugin_tests/sos_extras.py
@@ -0,0 +1,32 @@
+# 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 StageTwoReportTest
+
+
+class SosExtrasPluginTest(StageTwoReportTest):
+ """Ensure that the sos_extras plugin is properly executing command and
+ file collections as defined in the sos_extras config file
+
+ :avocado: tags=stagetwo
+ """
+
+ files = ['/etc/sos/extras.d/sos_testing.conf']
+ # rather than only enabling this plugin, make sure the enablement trigger
+ # is working
+ sos_cmd = '-n logs,networking,devicemapper,filesys,systemd'
+
+ def test_extras_enabled(self):
+ self.assertPluginIncluded('sos_extras')
+
+ def test_setup_message_displayed(self):
+ self.assertOutputContains('Collecting data from extras file /etc/sos/extras.d/sos_testing.conf')
+
+ def test_extras_config_parsed(self):
+ self.assertFileCollected('/etc/fstab')
+ self.assertFileCollected('sos_commands/sos_extras/sos_testing.conf/echo_sos_test')
diff --git a/tests/report_tests/plugin_tests/sudo.py b/tests/report_tests/plugin_tests/sudo.py
new file mode 100644
index 00000000..ad766b4f
--- /dev/null
+++ b/tests/report_tests/plugin_tests/sudo.py
@@ -0,0 +1,36 @@
+# 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, StageTwoReportTest
+
+
+class SudoPluginTest(StageOneReportTest):
+ """Basic sanity check to make sure ocmmon config files are collected
+
+ :avocado: tags=stageone
+ """
+
+ sos_cmd = '-o sudo'
+
+ def test_sudo_conf_collected(self):
+ self.assertFileCollected('/etc/sudo.conf')
+ self.assertFileCollected('/etc/sudoers')
+
+
+class SudoLdapScrubbedTest(StageTwoReportTest):
+ """Ensure that sudo conf is picked up and properly scrubbed
+
+ :avocado: tags=stagetwo
+ """
+
+ sos_cmd = '-o sudo'
+ files = ['/etc/sudo-ldap.conf']
+
+ def test_bindpw_scrubbed(self):
+ self.assertFileNotHasContent('/etc/sudo-ldap.conf', 'sostestpassword')
+
diff --git a/tests/test_data/etc/sos/extras.d/sos_testing.conf b/tests/test_data/etc/sos/extras.d/sos_testing.conf
new file mode 100644
index 00000000..40651f4d
--- /dev/null
+++ b/tests/test_data/etc/sos/extras.d/sos_testing.conf
@@ -0,0 +1,4 @@
+# this is a fake sos_extras config file
+#
+echo sos test
+:/etc/fstab
diff --git a/tests/test_data/etc/sudo-ldap.conf b/tests/test_data/etc/sudo-ldap.conf
new file mode 100644
index 00000000..76300658
--- /dev/null
+++ b/tests/test_data/etc/sudo-ldap.conf
@@ -0,0 +1,6 @@
+# This is a fake sudo-ldap.conf
+#
+# Nothing important is here
+uri ldaps://ldap.example.com
+binddn cn=sudo,dc=example,dc=com
+bindpw sostestpassword