Test Failed
Push — master ( e380d0...f5671d )
by W
02:58
created

st2tests/integration/mistral/test_wiring.py (1 issue)

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 __future__ import absolute_import
17
import os
18
import shutil
19
import tempfile
20
21
import eventlet
22
23
from integration.mistral import base
24
from six.moves import range
0 ignored issues
show
Bug Best Practice introduced by
This seems to re-define the built-in range.

It is generally discouraged to redefine built-ins as this makes code very hard to read.

Loading history...
25
26
from st2common.constants import action as action_constants
27
28
29
class WiringTest(base.TestWorkflowExecution):
30
31
    temp_dir_path = None
32
33
    def setUp(self):
34
        super(WiringTest, self).setUp()
35
36
        # Create temporary directory used by the tests
37
        _, self.temp_dir_path = tempfile.mkstemp()
38
        os.chmod(self.temp_dir_path, 0o755)   # nosec
39
40
    def tearDown(self):
41
        if self.temp_dir_path and os.path.exists(self.temp_dir_path):
42
            if os.path.isdir(self.temp_dir_path):
43
                shutil.rmtree(self.temp_dir_path)
44
            else:
45
                os.remove(self.temp_dir_path)
46
47
    def test_basic_workflow(self):
48
        ex = self._execute_workflow('examples.mistral-basic', {'cmd': 'date'})
49
        ex = self._wait_for_completion(ex)
50
        self.assertEqual(ex.status, action_constants.LIVEACTION_STATUS_SUCCEEDED)
51
        self.assertIn('stdout', ex.result)
52
        self.assertEqual(len(ex.result.get('tasks', [])), 1)
53
54
    def test_basic_workbook(self):
55
        ex = self._execute_workflow('examples.mistral-workbook-basic', {'cmd': 'date'})
56
        ex = self._wait_for_completion(ex)
57
        self.assertEqual(ex.status, action_constants.LIVEACTION_STATUS_SUCCEEDED)
58
        self.assertIn('stdout', ex.result)
59
        self.assertEqual(len(ex.result.get('tasks', [])), 1)
60
61
    def test_complex_workbook_with_yaql(self):
62
        params = {'vm_name': 'demo1'}
63
        ex = self._execute_workflow('examples.mistral-workbook-complex', params)
64
        ex = self._wait_for_completion(ex)
65
        self.assertEqual(ex.status, action_constants.LIVEACTION_STATUS_SUCCEEDED)
66
        self.assertIn('vm_id', ex.result)
67
        self.assertEqual(len(ex.result.get('tasks', [])), 8)
68
69
    def test_complex_workbook_with_jinja(self):
70
        params = {'vm_name': 'demo2'}
71
        ex = self._execute_workflow('examples.mistral-jinja-workbook-complex', params)
72
        ex = self._wait_for_completion(ex)
73
        self.assertEqual(ex.status, action_constants.LIVEACTION_STATUS_SUCCEEDED)
74
        self.assertIn('vm_id', ex.result)
75
        self.assertEqual(len(ex.result.get('tasks', [])), 8)
76
77
    def test_complex_workbook_subflow_actions(self):
78
        params = {'subject': 'st2', 'adjective': 'cool'}
79
        ex = self._execute_workflow('examples.mistral-workbook-subflows', params)
80
        ex = self._wait_for_completion(ex)
81
        self.assertEqual(ex.status, action_constants.LIVEACTION_STATUS_SUCCEEDED)
82
        self.assertIn('tagline', ex.result)
83
        self.assertEqual(ex.result['tagline'], 'st2 is cool!')
84
        self.assertEqual(len(ex.result.get('tasks', [])), 2)
85
86
    def test_with_items(self):
87
        params = {'cmd': 'date', 'count': 8}
88
        ex = self._execute_workflow('examples.mistral-repeat', params)
89
        ex = self._wait_for_completion(ex)
90
        self.assertEqual(ex.status, action_constants.LIVEACTION_STATUS_SUCCEEDED)
91
        self.assertEqual(len(ex.result['result']), params['count'])
92
        self.assertEqual(len(ex.result.get('tasks', [])), 1)
93
94
    def test_concurrent_load(self):
95
        wf_name = 'examples.mistral-workbook-complex'
96
        wf_params = {'vm_name': 'demo1'}
97
        exs = [self._execute_workflow(wf_name, wf_params) for i in range(3)]
98
99
        eventlet.sleep(20)
100
101
        for ex in exs:
102
            e = self._wait_for_completion(ex)
103
            self.assertEqual(e.status, action_constants.LIVEACTION_STATUS_SUCCEEDED)
104
            self.assertIn('vm_id', e.result)
105
            self.assertEqual(len(e.result.get('tasks', [])), 8)
106
107
    def test_execution_failure(self):
108
        ex = self._execute_workflow('examples.mistral-basic', {'cmd': 'foo'})
109
        ex = self._wait_for_completion(ex)
110
        self.assertEqual(ex.status, action_constants.LIVEACTION_STATUS_FAILED)
111
112
    def test_invoke_from_action_chain(self):
113
        ex = self._execute_workflow('examples.invoke-mistral-with-jinja', {'cmd': 'date'})
114
        ex = self._wait_for_completion(ex)
115
        self.assertEqual(ex.status, action_constants.LIVEACTION_STATUS_SUCCEEDED)
116