From 3b0676b90ff65f20eaba3062775ff72b89386ffc Mon Sep 17 00:00:00 2001 From: Jake Hunsaker Date: Tue, 22 Mar 2022 14:25:24 -0400 Subject: [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 --- .../plugin_tests/plugin_environment.py | 44 ++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 tests/report_tests/plugin_tests/plugin_environment.py (limited to 'tests/report_tests') 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') -- cgit