GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Push — kale/action-datastore ( 9f47ff...fd1ef0 )
by
unknown
12:31 queued 06:24
created

integration.mistral.WiringTest   A

Complexity

Total Complexity 34

Size/Duplication

Total Lines 274
Duplicated Lines 0 %
Metric Value
wmc 34
dl 0
loc 274
rs 9.2

16 Methods

Rating   Name   Duplication   Size   Complexity  
A test_with_items() 0 6 1
A test_concurrent_load() 0 11 3
A test_complex_workbook() 0 6 1
A test_cancellation() 0 6 1
A test_basic_workbook() 0 5 1
A test_execution_failure() 0 4 1
A test_basic_workflow() 0 5 1
A test_task_cancellation() 0 17 3
A test_complex_workbook_subflow_actions() 0 7 1
A test_basic_rerun_task() 0 21 3
A test_basic_rerun() 0 21 3
B test_rerun_subflow_and_resume_with_items_task() 0 34 3
B test_rerun_subflow_and_reset_with_items_task() 0 29 3
B test_basic_rerun_and_reset_with_items_task() 0 29 3
A test_rerun_subflow_task() 0 22 3
B test_basic_rerun_and_resume_with_items_task() 0 34 3
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
import ast
17
import eventlet
18
import os
19
import tempfile
20
21
from integration.mistral import base
22
23
24
class WiringTest(base.TestWorkflowExecution):
25
26
    def test_basic_workflow(self):
27
        execution = self._execute_workflow('examples.mistral-basic', {'cmd': 'date'})
28
        execution = self._wait_for_completion(execution)
29
        self._assert_success(execution, num_tasks=1)
30
        self.assertIn('stdout', execution.result)
31
32
    def test_basic_workbook(self):
33
        execution = self._execute_workflow('examples.mistral-workbook-basic', {'cmd': 'date'})
34
        execution = self._wait_for_completion(execution)
35
        self._assert_success(execution, num_tasks=1)
36
        self.assertIn('stdout', execution.result)
37
38
    def test_complex_workbook(self):
39
        execution = self._execute_workflow(
40
            'examples.mistral-workbook-complex', {'vm_name': 'demo1'})
41
        execution = self._wait_for_completion(execution)
42
        self._assert_success(execution, num_tasks=8)
43
        self.assertIn('vm_id', execution.result)
44
45
    def test_complex_workbook_subflow_actions(self):
46
        execution = self._execute_workflow(
47
            'examples.mistral-workbook-subflows', {'subject': 'st2', 'adjective': 'cool'})
48
        execution = self._wait_for_completion(execution)
49
        self._assert_success(execution, num_tasks=2)
50
        self.assertIn('tagline', execution.result)
51
        self.assertEqual(execution.result['tagline'], 'st2 is cool!')
52
53
    def test_with_items(self):
54
        params = {'cmd': 'date', 'count': 8}
55
        execution = self._execute_workflow('examples.mistral-repeat', params)
56
        execution = self._wait_for_completion(execution)
57
        self._assert_success(execution, num_tasks=1)
58
        self.assertEqual(len(execution.result['result']), params['count'])
59
60
    def test_concurrent_load(self):
61
        wf_name = 'examples.mistral-workbook-complex'
62
        wf_params = {'vm_name': 'demo1'}
63
        executions = [self._execute_workflow(wf_name, wf_params) for i in range(3)]
64
65
        eventlet.sleep(30)
66
67
        for execution in executions:
68
            e = self._wait_for_completion(execution)
69
            self._assert_success(e, num_tasks=8)
70
            self.assertIn('vm_id', e.result)
71
72
    def test_execution_failure(self):
73
        execution = self._execute_workflow('examples.mistral-basic', {'cmd': 'foo'})
74
        execution = self._wait_for_completion(execution)
75
        self._assert_failure(execution)
76
77
    def test_cancellation(self):
78
        execution = self._execute_workflow('examples.mistral-test-cancel', {'sleep': 10})
79
        execution = self._wait_for_state(execution, ['running'])
80
        self.st2client.liveactions.delete(execution)
81
        execution = self._wait_for_completion(execution, expect_tasks_completed=False)
82
        self._assert_canceled(execution, are_tasks_completed=False)
83
84
    def test_task_cancellation(self):
85
        execution = self._execute_workflow('examples.mistral-test-cancel', {'sleep': 30})
86
        execution = self._wait_for_state(execution, ['running'])
87
88
        task_executions = [e for e in self.st2client.liveactions.get_all()
89
                           if e.context.get('parent', {}).get('execution_id') == execution.id]
90
91
        self.assertGreater(len(task_executions), 0)
92
93
        self.st2client.liveactions.delete(task_executions[0])
94
        execution = self._wait_for_completion(execution, expect_tasks_completed=True)
95
        self._assert_failure(execution)
96
97
        task_results = execution.result.get('tasks', [])
98
        self.assertGreater(len(task_results), 0)
99
        expected_state_info = {'error': 'Execution canceled by user.'}
100
        self.assertDictEqual(ast.literal_eval(task_results[0]['state_info']), expected_state_info)
101
102
    def test_basic_rerun(self):
103
        fd, path = tempfile.mkstemp()
104
        os.chmod(path, 0666)
105
106
        with open(path, 'w') as f:
107
            f.write('1')
108
109
        execution = self._execute_workflow('examples.mistral-test-rerun', {'tempfile': path})
110
        execution = self._wait_for_completion(execution)
111
        self._assert_failure(execution)
112
        orig_st2_ex_id = execution.id
113
        orig_wf_ex_id = execution.context['mistral']['execution_id']
114
115
        with open(path, 'w') as f:
116
            f.write('0')
117
118
        execution = self.st2client.liveactions.re_run(orig_st2_ex_id)
119
        self.assertNotEqual(execution.id, orig_st2_ex_id)
120
        execution = self._wait_for_completion(execution)
121
        self._assert_success(execution, num_tasks=1)
122
        self.assertNotEqual(execution.context['mistral']['execution_id'], orig_wf_ex_id)
123
124
    def test_basic_rerun_task(self):
125
        fd, path = tempfile.mkstemp()
126
        os.chmod(path, 0666)
127
128
        with open(path, 'w') as f:
129
            f.write('1')
130
131
        execution = self._execute_workflow('examples.mistral-test-rerun', {'tempfile': path})
132
        execution = self._wait_for_completion(execution)
133
        self._assert_failure(execution)
134
        orig_st2_ex_id = execution.id
135
        orig_wf_ex_id = execution.context['mistral']['execution_id']
136
137
        with open(path, 'w') as f:
138
            f.write('0')
139
140
        execution = self.st2client.liveactions.re_run(orig_st2_ex_id, tasks=['task1'])
141
        self.assertNotEqual(execution.id, orig_st2_ex_id)
142
        execution = self._wait_for_completion(execution)
143
        self._assert_success(execution, num_tasks=1)
144
        self.assertEqual(execution.context['mistral']['execution_id'], orig_wf_ex_id)
145
146
    def test_rerun_subflow_task(self):
147
        fd, path = tempfile.mkstemp()
148
        os.chmod(path, 0666)
149
150
        with open(path, 'w') as f:
151
            f.write('1')
152
153
        workflow_name = 'examples.mistral-test-rerun-subflow'
154
        execution = self._execute_workflow(workflow_name, {'tempfile': path})
155
        execution = self._wait_for_completion(execution)
156
        self._assert_failure(execution)
157
        orig_st2_ex_id = execution.id
158
        orig_wf_ex_id = execution.context['mistral']['execution_id']
159
160
        with open(path, 'w') as f:
161
            f.write('0')
162
163
        execution = self.st2client.liveactions.re_run(orig_st2_ex_id, tasks=['task1.task1'])
164
        self.assertNotEqual(execution.id, orig_st2_ex_id)
165
        execution = self._wait_for_completion(execution)
166
        self._assert_success(execution, num_tasks=1)
167
        self.assertEqual(execution.context['mistral']['execution_id'], orig_wf_ex_id)
168
169
    def test_basic_rerun_and_reset_with_items_task(self):
170
        fd, path = tempfile.mkstemp()
171
        os.chmod(path, 0666)
172
173
        with open(path, 'w') as f:
174
            f.write('1')
175
176
        execution = self._execute_workflow(
177
            'examples.mistral-test-rerun-with-items',
178
            {'tempfile': path}
179
        )
180
181
        execution = self._wait_for_completion(execution)
182
        self._assert_failure(execution)
183
        orig_st2_ex_id = execution.id
184
        orig_wf_ex_id = execution.context['mistral']['execution_id']
185
186
        with open(path, 'w') as f:
187
            f.write('0')
188
189
        execution = self.st2client.liveactions.re_run(orig_st2_ex_id, tasks=['task1'])
190
        self.assertNotEqual(execution.id, orig_st2_ex_id)
191
192
        execution = self._wait_for_completion(execution)
193
        self._assert_success(execution, num_tasks=1)
194
        self.assertEqual(execution.context['mistral']['execution_id'], orig_wf_ex_id)
195
196
        children = self.st2client.liveactions.get_property(execution.id, 'children')
197
        self.assertEqual(len(children), 4)
198
199
    def test_basic_rerun_and_resume_with_items_task(self):
200
        fd, path = tempfile.mkstemp()
201
        os.chmod(path, 0666)
202
203
        with open(path, 'w') as f:
204
            f.write('1')
205
206
        execution = self._execute_workflow(
207
            'examples.mistral-test-rerun-with-items',
208
            {'tempfile': path}
209
        )
210
211
        execution = self._wait_for_completion(execution)
212
        self._assert_failure(execution)
213
        orig_st2_ex_id = execution.id
214
        orig_wf_ex_id = execution.context['mistral']['execution_id']
215
216
        with open(path, 'w') as f:
217
            f.write('0')
218
219
        execution = self.st2client.liveactions.re_run(
220
            orig_st2_ex_id,
221
            tasks=['task1'],
222
            no_reset=['task1']
223
        )
224
225
        self.assertNotEqual(execution.id, orig_st2_ex_id)
226
227
        execution = self._wait_for_completion(execution)
228
        self._assert_success(execution, num_tasks=1)
229
        self.assertEqual(execution.context['mistral']['execution_id'], orig_wf_ex_id)
230
231
        children = self.st2client.liveactions.get_property(execution.id, 'children')
232
        self.assertEqual(len(children), 2)
233
234
    def test_rerun_subflow_and_reset_with_items_task(self):
235
        fd, path = tempfile.mkstemp()
236
        os.chmod(path, 0666)
237
238
        with open(path, 'w') as f:
239
            f.write('1')
240
241
        execution = self._execute_workflow(
242
            'examples.mistral-test-rerun-subflow-with-items',
243
            {'tempfile': path}
244
        )
245
246
        execution = self._wait_for_completion(execution)
247
        self._assert_failure(execution)
248
        orig_st2_ex_id = execution.id
249
        orig_wf_ex_id = execution.context['mistral']['execution_id']
250
251
        with open(path, 'w') as f:
252
            f.write('0')
253
254
        execution = self.st2client.liveactions.re_run(orig_st2_ex_id, tasks=['task1.task1'])
255
        self.assertNotEqual(execution.id, orig_st2_ex_id)
256
257
        execution = self._wait_for_completion(execution)
258
        self._assert_success(execution, num_tasks=1)
259
        self.assertEqual(execution.context['mistral']['execution_id'], orig_wf_ex_id)
260
261
        children = self.st2client.liveactions.get_property(execution.id, 'children')
262
        self.assertEqual(len(children), 4)
263
264
    def test_rerun_subflow_and_resume_with_items_task(self):
265
        fd, path = tempfile.mkstemp()
266
        os.chmod(path, 0666)
267
268
        with open(path, 'w') as f:
269
            f.write('1')
270
271
        execution = self._execute_workflow(
272
            'examples.mistral-test-rerun-subflow-with-items',
273
            {'tempfile': path}
274
        )
275
276
        execution = self._wait_for_completion(execution)
277
        self._assert_failure(execution)
278
        orig_st2_ex_id = execution.id
279
        orig_wf_ex_id = execution.context['mistral']['execution_id']
280
281
        with open(path, 'w') as f:
282
            f.write('0')
283
284
        execution = self.st2client.liveactions.re_run(
285
            orig_st2_ex_id,
286
            tasks=['task1.task1'],
287
            no_reset=['task1.task1']
288
        )
289
290
        self.assertNotEqual(execution.id, orig_st2_ex_id)
291
292
        execution = self._wait_for_completion(execution)
293
        self._assert_success(execution, num_tasks=1)
294
        self.assertEqual(execution.context['mistral']['execution_id'], orig_wf_ex_id)
295
296
        children = self.st2client.liveactions.get_property(execution.id, 'children')
297
        self.assertEqual(len(children), 2)
298