Completed
Pull Request — master (#2263)
by James
05:48
created

st2actions.runners.NoopRunner   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %
Metric Value
wmc 3
dl 0
loc 26
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __init__() 0 2 1
A run() 0 14 1
A pre_run() 0 2 1
1
# Licensed to the StackStorm, Inc ('StackStorm') under one or more
2
# contributor license agreements.  See the NOTICE file distributed with
3
# this work for additional information regarding copyright ownership.
4
# The ASF licenses this file to You under the Apache License, Version 2.0
5
# (the "License"); you may not use this file except in compliance with
6
# the License.  You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15
16
from st2common import log as logging
17
from st2actions.runners import ActionRunner
18
from st2common.constants.action import LIVEACTION_STATUS_SUCCEEDED
19
import st2common.util.jsonify as jsonify
20
21
LOG = logging.getLogger(__name__)
22
23
24
class NoopRunner(ActionRunner):
25
    """
26
    Runner which does absolutely nothing. No-op action.
27
    """
28
    KEYS_TO_TRANSFORM = ['stdout', 'stderr']
29
30
    def __init__(self, runner_id):
31
        super(NoopRunner, self).__init__(runner_id=runner_id)
32
33
    def pre_run(self):
34
        pass
35
36
    def run(self, action_parameters):
37
38
        LOG.info('Executing action via NoopRunner: %s', self.runner_id)
39
        LOG.info('[Action info] name: %s, Id: %s',
40
                 self.action_name, str(self.execution_id))
41
42
        result = {
43
            'failed': False,
44
            'succeeded': True,
45
            'return_code': 0,
46
        }
47
48
        status = LIVEACTION_STATUS_SUCCEEDED
49
        return (status, jsonify.json_loads(result, NoopRunner.KEYS_TO_TRANSFORM), None)
50