Skip to content

Commit

Permalink
Merge pull request #557 from fomars/master
Browse files Browse the repository at this point in the history
hotfix ShellExec
  • Loading branch information
fomars committed Apr 6, 2018
2 parents 1a82bb3 + 932470b commit be9095c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
15 changes: 8 additions & 7 deletions yandextank/plugins/ShellExec/plugin.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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,
Expand All @@ -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
14 changes: 14 additions & 0 deletions yandextank/plugins/ShellExec/tests/test_shellexec_plugin.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit be9095c

Please sign in to comment.