diff --git a/yandextank/plugins/ShellExec/plugin.py b/yandextank/plugins/ShellExec/plugin.py index e3f18f2fe..c4bf4beea 100644 --- a/yandextank/plugins/ShellExec/plugin.py +++ b/yandextank/plugins/ShellExec/plugin.py @@ -1,15 +1,15 @@ ''' Contains shellexec plugin ''' -from ...common import util +from netort.process import execute from ...common.interfaces import AbstractPlugin class Plugin(AbstractPlugin): - ''' + """ ShellExec plugin allows executing shell scripts before/after test - ''' + """ SECTION = 'shellexec' def __init__(self, core, cfg, cfg_updater): @@ -47,7 +47,7 @@ def start_test(self): def is_test_finished(self): if self.poll: self.log.info("Executing: %s", self.poll) - retcode = util.execute( + retcode = execute( self.poll, shell=True, poll_period=0.1, @@ -69,11 +69,12 @@ def post_process(self, retcode): return retcode def execute(self, cmd): - ''' + """ Execute and check exit code - ''' + """ self.log.info("Executing: %s", cmd) - retcode = util.execute( + retcode = execute( cmd, shell=True, poll_period=0.1, catch_out=self.catch_out)[0] if retcode: raise RuntimeError("Subprocess returned %s" % retcode) + return retcode diff --git a/yandextank/plugins/ShellExec/tests/test_shellexec_plugin.py b/yandextank/plugins/ShellExec/tests/test_shellexec_plugin.py new file mode 100644 index 000000000..ae51adcf5 --- /dev/null +++ b/yandextank/plugins/ShellExec/tests/test_shellexec_plugin.py @@ -0,0 +1,14 @@ +import pytest +from yandextank.plugins.ShellExec import Plugin + + +def test_plugin_execute(): + plugin = Plugin(None, {}, None) + assert plugin.execute('echo foo') == 0 + + +def test_plugin_execute_raises(): + plugin = Plugin(None, {}, None) + with pytest.raises(RuntimeError) as error: + plugin.execute('echo "foo') + assert 'Subprocess returned 2' in error.message