aboutsummaryrefslogtreecommitdiffstats
path: root/tests/report_tests/plugin_tests/plugin_environment.py
diff options
context:
space:
mode:
authorJake Hunsaker <jhunsake@redhat.com>2022-03-22 14:25:24 -0400
committerJake Hunsaker <jhunsake@redhat.com>2022-03-25 10:30:31 -0400
commit3b0676b90ff65f20eaba3062775ff72b89386ffc (patch)
tree5f1615ada6823c303f470715140bfefb7070b121 /tests/report_tests/plugin_tests/plugin_environment.py
parent2666cb75fd8a463a8366dfb1d969b17ab5a95152 (diff)
downloadsos-3b0676b90ff65f20eaba3062775ff72b89386ffc.tar.gz
[Plugin] Allow plugins to define default command environment vars
Adds the ability for plugins to define a default set of environment vars to pass to all commands executed by the plugin. This may be done either via the new `set_default_cmd_environment()` or `add_default_cmd_environment()` methods. The former will override any previously set values, whereas the latter will add/update/modify any existing values. Signed-off-by: Jake Hunsaker <jhunsake@redhat.com>
Diffstat (limited to 'tests/report_tests/plugin_tests/plugin_environment.py')
-rw-r--r--tests/report_tests/plugin_tests/plugin_environment.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/report_tests/plugin_tests/plugin_environment.py b/tests/report_tests/plugin_tests/plugin_environment.py
new file mode 100644
index 00000000..3158437a
--- /dev/null
+++ b/tests/report_tests/plugin_tests/plugin_environment.py
@@ -0,0 +1,44 @@
+# 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 os
+
+from sos_tests import StageTwoReportTest
+
+
+class PluginDefaultEnvironmentTest(StageTwoReportTest):
+ """
+ Ensure that being able to set a default set of environment variables is
+ working correctly and does not leave a lingering env var on the system
+
+ :avocado: tags=stageone
+ """
+
+ install_plugins = ['default_env_test']
+ sos_cmd = '-o default_env_test'
+
+ def test_environment_used_in_cmd(self):
+ self.assertFileHasContent(
+ 'sos_commands/default_env_test/env_var_test',
+ 'Does Linus play hockey?'
+ )
+
+ def test_environment_setting_logged(self):
+ self.assertSosLogContains(
+ 'Default environment for all commands now set to'
+ )
+
+ def test_environment_not_set_on_host(self):
+ self.assertTrue('TORVALDS' not in os.environ)
+ self.assertTrue('GREATESTSPORT' not in os.environ)
+
+ def test_environment_not_captured(self):
+ # we should still have an empty environment file
+ self.assertFileCollected('environment')
+ self.assertFileNotHasContent('environment', 'TORVALDS')
+ self.assertFileNotHasContent('environment', 'GREATESTSPORT')