Completed
Pull Request — master (#2263)
by James
07:55 queued 01:16
created

st2actions.runners.NoopRunner   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 25
Duplicated Lines 0 %
Metric Value
wmc 2
dl 0
loc 25
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 16 1
A __init__() 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 run(self, action_parameters):
34
35
        LOG.info('Executing action via NoopRunner: %s', self.runner_id)
36
        LOG.info('[Action info] name: %s, Id: %s' %
37
                 (self.action_name, str(self.liveaction_id)))
38
39
        result = {
40
            'failed': False,
41
            'succeeded': True,
42
            'return_code': 0,
43
            'stdout': "",
44
            'stderr': ""
45
        }
46
47
        status = LIVEACTION_STATUS_SUCCEEDED
48
        return (status, jsonify.json_loads(result, NoopRunner.KEYS_TO_TRANSFORM), None)
49