Skip to content

Commit

Permalink
Merge pull request #2824 from StackStorm/pluggable-runners
Browse files Browse the repository at this point in the history
Adds pluggable runner support for ST2.
  • Loading branch information
bigmstone committed Oct 12, 2016
2 parents b8d4caf + 5f8a4ed commit 4213692
Show file tree
Hide file tree
Showing 173 changed files with 1,489 additions and 1,292 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ BINARIES := bin

# All components are prefixed by st2
COMPONENTS := $(wildcard st2*)
COMPONENTS += $(wildcard contrib/runners/*)

# Components that implement a component-controlled test-runner. These components provide an
# in-component Makefile. (Temporary fix until I can generalize the pecan unittest setup. -mar)
Expand Down Expand Up @@ -150,7 +151,7 @@ compile:
.st2common-circular-dependencies-check:
@echo "Checking st2common for circular dependencies"
find ${ROOT_DIR}/st2common/st2common/ -name \*.py -type f -print0 | xargs -0 cat | grep st2reactor ; test $$? -eq 1
find ${ROOT_DIR}/st2common/st2common/ \( -name \*.py ! -name runnersregistrar\.py \) -type f -print0 | xargs -0 cat | grep st2actions ; test $$? -eq 1
find ${ROOT_DIR}/st2common/st2common/ \( -name \*.py ! -name runnersregistrar\.py ! -wholename "*runners/__init__.py" ! -name python_action_wrapper.py ! -wholename "*/query/base.py" \) -type f -print0 | xargs -0 cat | grep st2actions ; test $$? -eq 1
find ${ROOT_DIR}/st2common/st2common/ -name \*.py -type f -print0 | xargs -0 cat | grep st2api ; test $$? -eq 1
find ${ROOT_DIR}/st2common/st2common/ -name \*.py -type f -print0 | xargs -0 cat | grep st2auth ; test $$? -eq 1
find ${ROOT_DIR}/st2common/st2common/ -name \*.py -type f -print0 | xargs -0 cat | grep st2debug; test $$? -eq 1
Expand Down
2 changes: 1 addition & 1 deletion contrib/chatops/actions/format_execution_result.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import six
import os

from st2actions.runners.pythonrunner import Action
from st2common.runners.base_action import Action
from st2client.client import Client
from st2common.util import jinja as jinja_utils

Expand Down
2 changes: 1 addition & 1 deletion contrib/chatops/tests/fixtures/http_execution.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"enabled": true,
"id": "54c6bb640640fd5211edef0b",
"name": "http-request",
"runner_module": "st2actions.runners.httprunner",
"runner_module": "httprunner",
"runner_parameters": {
"url": {
"type": "string"
Expand Down
2 changes: 1 addition & 1 deletion contrib/chatops/tests/fixtures/local_cmd_execution.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"enabled": true,
"id": "54c6bb640640fd5211edef0b",
"name": "local-shell-cmd",
"runner_module": "st2actions.runners.localrunner",
"runner_module": "local_runner",
"runner_parameters": {
"cmd": {
"type": "string"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"enabled": true,
"id": "54c6bb640640fd5211edef0b",
"name": "python-script",
"runner_module": "st2actions.runners.pythonrunner",
"runner_module": "pythonrunner",
"runner_parameters": {

}
Expand Down
2 changes: 1 addition & 1 deletion contrib/chatops/tests/fixtures/remote_cmd_execution.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"enabled": true,
"id": "54c6bb640640fd5211edef0b",
"name": "remote-shell-cmd",
"runner_module": "st2actions.runners.remote_command_runner",
"runner_module": "remote_command_runner",
"runner_parameters": {
"cmd": {
"type": "string"
Expand Down
2 changes: 1 addition & 1 deletion contrib/examples/actions/print_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pprint import pprint

from st2actions.runners.pythonrunner import Action
from st2common.runners.base_action import Action


class PrintConfigAction(Action):
Expand Down
2 changes: 1 addition & 1 deletion contrib/examples/actions/pythonactions/isprime.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import math

from st2actions.runners.pythonrunner import Action
from st2common.runners.base_action import Action


class PrimeCheckerAction(Action):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import json

from st2actions.runners.pythonrunner import Action
from st2common.runners.base_action import Action


class JsonStringToObject(Action):
Expand Down
2 changes: 1 addition & 1 deletion contrib/examples/actions/pythonactions/object_return.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from st2actions.runners.pythonrunner import Action
from st2common.runners.base_action import Action


class ObjectReturnAction(Action):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import yaml

from st2actions.runners.pythonrunner import Action
from st2common.runners.base_action import Action


class YamlStringToObject(Action):
Expand Down
2 changes: 1 addition & 1 deletion contrib/linux/actions/dig.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import subprocess
import random
import re
from st2actions.runners.pythonrunner import Action
from st2common.runners.base_action import Action


class DigAction(Action):
Expand Down
4 changes: 2 additions & 2 deletions contrib/linux/actions/wait_for_ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

from oslo_config import cfg

from st2actions.runners.pythonrunner import Action
from st2actions.runners.ssh.paramiko_ssh import ParamikoSSHClient
from st2common.runners.base_action import Action
from st2common.runners.paramiko_ssh import ParamikoSSHClient


class BaseAction(Action):
Expand Down
2 changes: 1 addition & 1 deletion contrib/packs/actions/check_auto_deploy_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from st2actions.runners.pythonrunner import Action
from st2common.runners.base_action import Action


class CheckAutoDeployRepo(Action):
Expand Down
2 changes: 1 addition & 1 deletion contrib/packs/actions/expand_repo_name.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from st2actions.runners.pythonrunner import Action
from st2common.runners.base_action import Action


class ExpandRepoName(Action):
Expand Down
2 changes: 1 addition & 1 deletion contrib/packs/actions/pack_mgmt/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

from oslo_config import cfg

from st2actions.runners.pythonrunner import Action
from st2common.runners.base_action import Action
from st2common.constants.pack import SYSTEM_PACK_NAMES
from st2common.util.shell import quote_unix

Expand Down
2 changes: 1 addition & 1 deletion contrib/packs/actions/pack_mgmt/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from git.repo import Repo
from lockfile import LockFile

from st2actions.runners.pythonrunner import Action
from st2common.runners.base_action import Action
from st2common.util.green import shell

ALL_PACKS = '*'
Expand Down
2 changes: 1 addition & 1 deletion contrib/packs/actions/pack_mgmt/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import os
import json

from st2actions.runners.pythonrunner import Action
from st2common.runners.base_action import Action
from st2common.content.utils import get_packs_base_paths

GITINFO_FILE = '.gitinfo'
Expand Down
2 changes: 1 addition & 1 deletion contrib/packs/actions/pack_mgmt/setup_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from st2actions.runners.pythonrunner import Action
from st2common.runners.base_action import Action
from st2common.util.virtualenvs import setup_pack_virtualenv

__all__ = [
Expand Down
2 changes: 1 addition & 1 deletion contrib/packs/actions/pack_mgmt/unload.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from oslo_config import cfg

from st2common.models.db import db_setup
from st2actions.runners.pythonrunner import Action as BaseAction
from st2common.runners.base_action import Action as BaseAction
from st2common.persistence.pack import Pack
from st2common.persistence.pack import ConfigSchema
from st2common.persistence.reactor import SensorType
Expand Down
2 changes: 1 addition & 1 deletion contrib/packs/actions/pack_mgmt/virtualenv_setup_prerun.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import six

from st2actions.runners.pythonrunner import Action
from st2common.runners.base_action import Action


class PacksTransformationAction(Action):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from jsonschema import exceptions as json_schema_exceptions

from st2actions.runners import ActionRunner
from st2common.runners import ActionRunner
from st2common import log as logging
from st2common.constants.action import ACTION_CONTEXT_KV_PREFIX
from st2common.constants.action import LIVEACTION_STATUS_SUCCEEDED
Expand Down
14 changes: 14 additions & 0 deletions contrib/runners/action_chain_runner/runner.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
- aliases: []
description: A runner for launching linear action chains.
enabled: true
name: action-chain
runner_module: action_chain_runner
runner_parameters:
display_published:
default: false
description: Intermediate published variables will be stored and displayed.
type: boolean
skip_notify:
default: []
description: List of tasks to skip notifications for.
type: array
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
# limitations under the License.

import mock

from st2actions.runners import actionchainrunner as acr
import action_chain_runner as acr
from st2actions.container.service import RunnerContainerService
from st2common.constants.action import LIVEACTION_STATUS_RUNNING
from st2common.constants.action import LIVEACTION_STATUS_SUCCEEDED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@

import mock

from st2actions.runners import actionchainrunner as acr
from st2actions.container.service import RunnerContainerService
from st2common.constants.action import LIVEACTION_STATUS_SUCCEEDED
from st2common.services import action as action_service
from st2common.util import action_db as action_db_util
from st2tests import DbTestCase
from st2tests.fixturesloader import FixturesLoader
import action_chain_runner as acr


class DummyActionExecution(object):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import unittest2

from st2actions.runners import actionchainrunner as acr
import action_chain_runner as acr
from st2common.exceptions.action import ParameterRenderingFailedException
from st2common.models.system.actionchain import Node

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import uuid

from st2actions.runners import ActionRunner
from st2common.runners import ActionRunner
from st2common import log as logging
from st2common.constants.action import LIVEACTION_STATUS_SUCCEEDED
from st2common.exceptions import actionrunner as runnerexceptions
Expand Down
18 changes: 18 additions & 0 deletions contrib/runners/announcement_runner/runner.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
- aliases: []
description: A runner for emitting an announcement event on the stream.
enabled: true
name: announcement
runner_module: announcement_runner
runner_parameters:
experimental:
default: false
description: Flag to indicate acknowledment of using experimental runner
required: true
type: boolean
route:
default: general
description: The routing_key used to route the message to consumers. Might be
a list of words, delimited by dots.
maxLength: 255
minLength: 1
type: string
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@

import mock

from st2actions.runners import announcementrunner
from st2common.constants.action import LIVEACTION_STATUS_SUCCEEDED
from st2common.models.api.trace import TraceContext
from base import RunnerTestCase
import st2tests.config as tests_config
import announcementrunner


mock_dispatcher = mock.Mock()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from st2common.util.shell import kill_process
from st2common.util.shell import quote_unix
from st2common import log as logging
from st2actions.runners import ActionRunner
from st2common.runners import ActionRunner
from st2common.constants.action import LIVEACTION_STATUS_SUCCEEDED
from st2common.constants.action import LIVEACTION_STATUS_FAILED
from st2common.constants.runners import LOCAL_RUNNER_DEFAULT_ACTION_TIMEOUT
Expand Down
16 changes: 16 additions & 0 deletions contrib/runners/cloudslang_runner/runner.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
- aliases: []
description: A runner to execute cloudslang flows.
enabled: true
name: cloudslang
runner_module: cloudslang_runner
runner_parameters:
inputs:
default: {}
description: Inputs which will be available to CLoudSlang flow execution(e.g.
input1=val1,input2=val2)
type: object
timeout:
default: 60
description: Action timeout in seconds. Action will get killed if it doesn't
finish in timeout seconds.
type: integer
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

from unittest2 import TestCase

import st2actions.runners.cloudslang.cloudslang_runner as csr
from st2common.constants.action import LIVEACTION_STATUS_SUCCEEDED
from st2common.constants.action import LIVEACTION_STATUS_FAILED
from cloudslang import cloudslang_runner as csr

import st2tests.config as tests_config
tests_config.parse_args()
Expand Down Expand Up @@ -49,8 +49,8 @@ def test_pre_run_sets_attributes(self):
self.assertEqual(runner._inputs, inputs)
self.assertEqual(runner._timeout, timeout)

@mock.patch('st2actions.runners.cloudslang.cloudslang_runner.quote_unix')
@mock.patch('st2actions.runners.cloudslang.cloudslang_runner.run_command')
@mock.patch('cloudslang.cloudslang_runner.quote_unix')
@mock.patch('cloudslang.cloudslang_runner.run_command')
def test_run_calls_a_new_process_success(self, mock_run_command, mock_quote_unix):
entry_point = 'path'
timeout = 1
Expand All @@ -69,8 +69,8 @@ def test_run_calls_a_new_process_success(self, mock_run_command, mock_quote_unix
self.assertTrue(mock_run_command.called)
self.assertEqual(LIVEACTION_STATUS_SUCCEEDED, result[0])

@mock.patch('st2actions.runners.cloudslang.cloudslang_runner.quote_unix')
@mock.patch('st2actions.runners.cloudslang.cloudslang_runner.run_command')
@mock.patch('cloudslang.cloudslang_runner.quote_unix')
@mock.patch('cloudslang.cloudslang_runner.run_command')
def test_run_calls_a_new_process_failure(self, mock_run_command, mock_quote_unix):
timeout = 1
runner = csr.get_runner()
Expand All @@ -86,7 +86,7 @@ def test_run_calls_a_new_process_failure(self, mock_run_command, mock_quote_unix
self.assertTrue(mock_run_command.called)
self.assertEqual(LIVEACTION_STATUS_FAILED, result[0])

@mock.patch('st2actions.runners.cloudslang.cloudslang_runner.run_command')
@mock.patch('cloudslang.cloudslang_runner.run_command')
def test_run_calls_a_new_process_timeout(self, mock_run_command):
entry_point = 'path'
timeout = 1
Expand All @@ -102,8 +102,8 @@ def test_run_calls_a_new_process_timeout(self, mock_run_command):
self.assertTrue(mock_run_command.called)
self.assertEqual(LIVEACTION_STATUS_FAILED, result[0])

@mock.patch('st2actions.runners.cloudslang.cloudslang_runner.run_command')
@mock.patch('st2actions.runners.cloudslang.cloudslang_runner.yaml.safe_dump')
@mock.patch('cloudslang.cloudslang_runner.run_command')
@mock.patch('cloudslang.cloudslang_runner.yaml.safe_dump')
def test_inputs_are_save_to_file_properly(self, mock_yaml_dump, mock_run_command):
entry_point = 'path'
inputs = {'a': 1}
Expand All @@ -122,8 +122,8 @@ def test_inputs_are_save_to_file_properly(self, mock_yaml_dump, mock_run_command
mock_yaml_dump.assert_called_with(inputs, default_flow_style=False)
self.assertEqual(LIVEACTION_STATUS_FAILED, result[0])

@mock.patch('st2actions.runners.cloudslang.cloudslang_runner.run_command')
@mock.patch('st2actions.runners.cloudslang.cloudslang_runner.os.remove')
@mock.patch('cloudslang.cloudslang_runner.run_command')
@mock.patch('cloudslang.cloudslang_runner.os.remove')
def test_temp_file_deletes_when_exception_occurs(self, mock_os_remove, mock_run_command):
entry_point = 'path'
inputs = {'a': 1}
Expand All @@ -144,7 +144,7 @@ def test_temp_file_deletes_when_exception_occurs(self, mock_os_remove, mock_run_
# lets really remove it now
os.remove(mock_os_remove.call_args[0][0])

@mock.patch('st2actions.runners.cloudslang.cloudslang_runner.run_command')
@mock.patch('cloudslang.cloudslang_runner.run_command')
def test_inputs_provided_via_inputs_runner_parameter(self, mock_run_command):
entry_point = 'path'
inputs = {'a': 1}
Expand All @@ -164,7 +164,7 @@ def test_inputs_provided_via_inputs_runner_parameter(self, mock_run_command):
runner.run({})
runner._write_inputs_to_a_temp_file.assert_called_with(inputs=inputs)

@mock.patch('st2actions.runners.cloudslang.cloudslang_runner.run_command')
@mock.patch('cloudslang.cloudslang_runner.run_command')
def test_inputs_provided_via_action_parameters(self, mock_run_command):
entry_point = 'path'
inputs = None
Expand Down
Empty file.
Loading

0 comments on commit 4213692

Please sign in to comment.