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.
Test Failed
Push — plexxi-v2.2.1 ( 00dc5d...9862bf )
by
unknown
04:14
created

test_cancellation_cascade_subworkflow_action()   B

Complexity

Conditions 3

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
c 0
b 0
f 0
dl 0
loc 29
rs 8.8571
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 os
17
import shutil
18
import tempfile
19
20
import eventlet
21
22
from integration.mistral import base
23
24
25
class WiringTest(base.TestWorkflowExecution):
26
27
    temp_dir_path = None
28
29
    def setUp(self):
30
        super(WiringTest, self).setUp()
31
32
        # Create temporary directory used by the tests
33
        _, self.temp_dir_path = tempfile.mkstemp()
34
        os.chmod(self.temp_dir_path, 0755)   # nosec
35
36
    def tearDown(self):
37
        if self.temp_dir_path and os.path.exists(self.temp_dir_path):
38
            if os.path.isdir(self.temp_dir_path):
39
                shutil.rmtree(self.temp_dir_path)
40
            else:
41
                os.remove(self.temp_dir_path)
42
43
    def test_basic_workflow(self):
44
        execution = self._execute_workflow('examples.mistral-basic', {'cmd': 'date'})
45
        execution = self._wait_for_completion(execution)
46
        self._assert_success(execution, num_tasks=1)
47
        self.assertIn('stdout', execution.result)
48
49
    def test_basic_workbook(self):
50
        execution = self._execute_workflow('examples.mistral-workbook-basic', {'cmd': 'date'})
51
        execution = self._wait_for_completion(execution)
52
        self._assert_success(execution, num_tasks=1)
53
        self.assertIn('stdout', execution.result)
54
55
    def test_complex_workbook_with_yaql(self):
56
        execution = self._execute_workflow(
57
            'examples.mistral-workbook-complex', {'vm_name': 'demo1'})
58
        execution = self._wait_for_completion(execution)
59
        self._assert_success(execution, num_tasks=8)
60
        self.assertIn('vm_id', execution.result)
61
62
    def test_complex_workbook_with_jinja(self):
63
        execution = self._execute_workflow(
64
            'examples.mistral-jinja-workbook-complex', {'vm_name': 'demo2'})
65
        execution = self._wait_for_completion(execution)
66
        self._assert_success(execution, num_tasks=8)
67
        self.assertIn('vm_id', execution.result)
68
69
    def test_complex_workbook_subflow_actions(self):
70
        execution = self._execute_workflow(
71
            'examples.mistral-workbook-subflows', {'subject': 'st2', 'adjective': 'cool'})
72
        execution = self._wait_for_completion(execution)
73
        self._assert_success(execution, num_tasks=2)
74
        self.assertIn('tagline', execution.result)
75
        self.assertEqual(execution.result['tagline'], 'st2 is cool!')
76
77
    def test_with_items(self):
78
        params = {'cmd': 'date', 'count': 8}
79
        execution = self._execute_workflow('examples.mistral-repeat', params)
80
        execution = self._wait_for_completion(execution)
81
        self._assert_success(execution, num_tasks=1)
82
        self.assertEqual(len(execution.result['result']), params['count'])
83
84
    def test_concurrent_load(self):
85
        wf_name = 'examples.mistral-workbook-complex'
86
        wf_params = {'vm_name': 'demo1'}
87
        executions = [self._execute_workflow(wf_name, wf_params) for i in range(3)]
88
89
        eventlet.sleep(30)
90
91
        for execution in executions:
92
            e = self._wait_for_completion(execution)
93
            self._assert_success(e, num_tasks=8)
94
            self.assertIn('vm_id', e.result)
95
96
    def test_execution_failure(self):
97
        execution = self._execute_workflow('examples.mistral-basic', {'cmd': 'foo'})
98
        execution = self._wait_for_completion(execution)
99
        self._assert_failure(execution)
100
101
    def test_cancellation(self):
102
        execution = self._execute_workflow('examples.mistral-test-cancel', {'sleep': 10})
103
        execution = self._wait_for_state(execution, ['running'])
104
        self.st2client.liveactions.delete(execution)
105
106
        execution = self._wait_for_completion(
107
            execution,
108
            expect_tasks=False,
109
            expect_tasks_completed=False
110
        )
111
112
        self._assert_canceled(execution, are_tasks_completed=False)
113
114
    def test_cancellation_cascade_subworkflow_action(self):
115
        execution = self._execute_workflow(
116
            'examples.mistral-test-cancel-subworkflow-action',
117
            {'sleep': 10}
118
        )
119
120
        execution = self._wait_for_state(execution, ['running'])
121
        self.st2client.liveactions.delete(execution)
122
123
        execution = self._wait_for_completion(
124
            execution,
125
            expect_tasks=False,
126
            expect_tasks_completed=False
127
        )
128
129
        self.assertEqual(execution.status, 'canceled')
130
131
        task_executions = [e for e in self.st2client.liveactions.get_all()
132
                           if e.context.get('parent', {}).get('execution_id') == execution.id]
133
134
        subworkflow_execution = self.st2client.liveactions.get_by_id(task_executions[0].id)
135
136
        subworkflow_execution = self._wait_for_completion(
137
            subworkflow_execution,
138
            expect_tasks=False,
139
            expect_tasks_completed=False
140
        )
141
142
        self.assertEqual(execution.status, 'canceled')
143
144
    def test_task_cancellation(self):
145
        execution = self._execute_workflow('examples.mistral-test-cancel', {'sleep': 30})
146
        execution = self._wait_for_state(execution, ['running'])
147
148
        task_executions = [e for e in self.st2client.liveactions.get_all()
149
                           if e.context.get('parent', {}).get('execution_id') == execution.id]
150
151
        self.assertGreater(len(task_executions), 0)
152
153
        self.st2client.liveactions.delete(task_executions[0])
154
        execution = self._wait_for_completion(execution, expect_tasks_completed=True)
155
        self._assert_failure(execution)
156
157
        task_results = execution.result.get('tasks', [])
158
        self.assertGreater(len(task_results), 0)
159
        expected_state_info = '{error: Execution canceled by user.}'
160
        self.assertEqual(task_results[0]['state_info'], expected_state_info)
161
162
    def test_basic_rerun(self):
163
        path = self.temp_dir_path
164
165
        with open(path, 'w') as f:
166
            f.write('1')
167
168
        execution = self._execute_workflow('examples.mistral-test-rerun', {'tempfile': path})
169
        execution = self._wait_for_completion(execution)
170
        self._assert_failure(execution)
171
        orig_st2_ex_id = execution.id
172
        orig_wf_ex_id = execution.context['mistral']['execution_id']
173
174
        with open(path, 'w') as f:
175
            f.write('0')
176
177
        execution = self.st2client.liveactions.re_run(orig_st2_ex_id)
178
        self.assertNotEqual(execution.id, orig_st2_ex_id)
179
        execution = self._wait_for_completion(execution)
180
        self._assert_success(execution, num_tasks=1)
181
        self.assertNotEqual(execution.context['mistral']['execution_id'], orig_wf_ex_id)
182
183
    def test_basic_rerun_task(self):
184
        path = self.temp_dir_path
185
186
        with open(path, 'w') as f:
187
            f.write('1')
188
189
        execution = self._execute_workflow('examples.mistral-test-rerun', {'tempfile': path})
190
        execution = self._wait_for_completion(execution)
191
        self._assert_failure(execution)
192
        orig_st2_ex_id = execution.id
193
        orig_wf_ex_id = execution.context['mistral']['execution_id']
194
195
        with open(path, 'w') as f:
196
            f.write('0')
197
198
        execution = self.st2client.liveactions.re_run(orig_st2_ex_id, tasks=['task1'])
199
        self.assertNotEqual(execution.id, orig_st2_ex_id)
200
        execution = self._wait_for_completion(execution)
201
        self._assert_success(execution, num_tasks=1)
202
        self.assertEqual(execution.context['mistral']['execution_id'], orig_wf_ex_id)
203
204
    def test_rerun_subflow_task(self):
205
        path = self.temp_dir_path
206
207
        with open(path, 'w') as f:
208
            f.write('1')
209
210
        workflow_name = 'examples.mistral-test-rerun-subflow'
211
        execution = self._execute_workflow(workflow_name, {'tempfile': path})
212
        execution = self._wait_for_completion(execution)
213
        self._assert_failure(execution)
214
        orig_st2_ex_id = execution.id
215
        orig_wf_ex_id = execution.context['mistral']['execution_id']
216
217
        with open(path, 'w') as f:
218
            f.write('0')
219
220
        execution = self.st2client.liveactions.re_run(orig_st2_ex_id, tasks=['task1.task1'])
221
        self.assertNotEqual(execution.id, orig_st2_ex_id)
222
        execution = self._wait_for_completion(execution)
223
        self._assert_success(execution, num_tasks=1)
224
        self.assertEqual(execution.context['mistral']['execution_id'], orig_wf_ex_id)
225
226
    def test_basic_rerun_and_reset_with_items_task(self):
227
        path = self.temp_dir_path
228
229
        with open(path, 'w') as f:
230
            f.write('1')
231
232
        execution = self._execute_workflow(
233
            'examples.mistral-test-rerun-with-items',
234
            {'tempfile': path}
235
        )
236
237
        execution = self._wait_for_completion(execution)
238
        self._assert_failure(execution)
239
        orig_st2_ex_id = execution.id
240
        orig_wf_ex_id = execution.context['mistral']['execution_id']
241
242
        with open(path, 'w') as f:
243
            f.write('0')
244
245
        execution = self.st2client.liveactions.re_run(orig_st2_ex_id, tasks=['task1'])
246
        self.assertNotEqual(execution.id, orig_st2_ex_id)
247
248
        execution = self._wait_for_completion(execution)
249
        self._assert_success(execution, num_tasks=1)
250
        self.assertEqual(execution.context['mistral']['execution_id'], orig_wf_ex_id)
251
252
        children = self.st2client.liveactions.get_property(execution.id, 'children')
253
        self.assertEqual(len(children), 4)
254
255
    def test_basic_rerun_and_resume_with_items_task(self):
256
        path = self.temp_dir_path
257
258
        with open(path, 'w') as f:
259
            f.write('1')
260
261
        execution = self._execute_workflow(
262
            'examples.mistral-test-rerun-with-items',
263
            {'tempfile': path}
264
        )
265
266
        execution = self._wait_for_completion(execution)
267
        self._assert_failure(execution)
268
        orig_st2_ex_id = execution.id
269
        orig_wf_ex_id = execution.context['mistral']['execution_id']
270
271
        with open(path, 'w') as f:
272
            f.write('0')
273
274
        execution = self.st2client.liveactions.re_run(
275
            orig_st2_ex_id,
276
            tasks=['task1'],
277
            no_reset=['task1']
278
        )
279
280
        self.assertNotEqual(execution.id, orig_st2_ex_id)
281
282
        execution = self._wait_for_completion(execution)
283
        self._assert_success(execution, num_tasks=1)
284
        self.assertEqual(execution.context['mistral']['execution_id'], orig_wf_ex_id)
285
286
        children = self.st2client.liveactions.get_property(execution.id, 'children')
287
        self.assertEqual(len(children), 2)
288
289
    def test_rerun_subflow_and_reset_with_items_task(self):
290
        path = self.temp_dir_path
291
292
        with open(path, 'w') as f:
293
            f.write('1')
294
295
        execution = self._execute_workflow(
296
            'examples.mistral-test-rerun-subflow-with-items',
297
            {'tempfile': path}
298
        )
299
300
        execution = self._wait_for_completion(execution)
301
        self._assert_failure(execution)
302
        orig_st2_ex_id = execution.id
303
        orig_wf_ex_id = execution.context['mistral']['execution_id']
304
305
        with open(path, 'w') as f:
306
            f.write('0')
307
308
        execution = self.st2client.liveactions.re_run(orig_st2_ex_id, tasks=['task1.task1'])
309
        self.assertNotEqual(execution.id, orig_st2_ex_id)
310
311
        execution = self._wait_for_completion(execution)
312
        self._assert_success(execution, num_tasks=1)
313
        self.assertEqual(execution.context['mistral']['execution_id'], orig_wf_ex_id)
314
315
        children = self.st2client.liveactions.get_property(execution.id, 'children')
316
        self.assertEqual(len(children), 4)
317
318
    def test_rerun_subflow_and_resume_with_items_task(self):
319
        path = self.temp_dir_path
320
321
        with open(path, 'w') as f:
322
            f.write('1')
323
324
        execution = self._execute_workflow(
325
            'examples.mistral-test-rerun-subflow-with-items',
326
            {'tempfile': path}
327
        )
328
329
        execution = self._wait_for_completion(execution)
330
        self._assert_failure(execution)
331
        orig_st2_ex_id = execution.id
332
        orig_wf_ex_id = execution.context['mistral']['execution_id']
333
334
        with open(path, 'w') as f:
335
            f.write('0')
336
337
        execution = self.st2client.liveactions.re_run(
338
            orig_st2_ex_id,
339
            tasks=['task1.task1'],
340
            no_reset=['task1.task1']
341
        )
342
343
        self.assertNotEqual(execution.id, orig_st2_ex_id)
344
345
        execution = self._wait_for_completion(execution)
346
        self._assert_success(execution, num_tasks=1)
347
        self.assertEqual(execution.context['mistral']['execution_id'], orig_wf_ex_id)
348
349
        children = self.st2client.liveactions.get_property(execution.id, 'children')
350
        self.assertEqual(len(children), 2)
351