Completed
Pull Request — master (#2263)
by James
06:15
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 eventlet.green import subprocess
0 ignored issues
show
Unused Code introduced by
Unused subprocess imported from eventlet.green
Loading history...
17
18
from st2common import log as logging
19
from st2actions.runners import ActionRunner
20
from st2common.constants.action import LIVEACTION_STATUS_SUCCEEDED
21
import st2common.util.jsonify as jsonify
22
23
LOG = logging.getLogger(__name__)
24
25
class NoopRunner(ActionRunner):
26
    """
27
    Runner which does absolutely nothing. No-op action.
28
    """
29
    KEYS_TO_TRANSFORM = ['stdout', 'stderr']
30
31
    def __init__(self, runner_id):
32
        super(NoopRunner, self).__init__(runner_id=runner_id)
33
34
    def run(self, action_parameters):
35
36
        LOG.info('Executing action via NoopRunner: %s', self.runner_id)
37
        LOG.info('[Action info] name: %s, Id: %s' %
38
                 (self.action_name, str(self.liveaction_id)))
39
40
        result = {
41
            'failed': False,
42
            'succeeded': True,
43
            'return_code': 0,
44
            'stdout': "",
45
            'stderr': ""
46
        }
47
48
        status = LIVEACTION_STATUS_SUCCEEDED
49
        return (status, jsonify.json_loads(result, NoopRunner.KEYS_TO_TRANSFORM), None)
50