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 eventlet |
17
|
|
|
|
18
|
|
|
from st2client import models |
19
|
|
|
|
20
|
|
|
from integration.mistral import base |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
class WiringTest(base.TestWorkflowExecution): |
24
|
|
|
|
25
|
|
|
def test_basic_workflow(self): |
26
|
|
|
execution = self._execute_workflow('examples.mistral-basic', {'cmd': 'date'}) |
27
|
|
|
execution = self._wait_for_completion(execution) |
28
|
|
|
self._assert_success(execution, num_tasks=1) |
29
|
|
|
self.assertIn('stdout', execution.result) |
30
|
|
|
|
31
|
|
|
def test_basic_workbook(self): |
32
|
|
|
execution = self._execute_workflow('examples.mistral-workbook-basic', {'cmd': 'date'}) |
33
|
|
|
execution = self._wait_for_completion(execution) |
34
|
|
|
self._assert_success(execution, num_tasks=1) |
35
|
|
|
self.assertIn('stdout', execution.result) |
36
|
|
|
|
37
|
|
|
def test_complex_workbook(self): |
38
|
|
|
execution = self._execute_workflow( |
39
|
|
|
'examples.mistral-workbook-complex', {'vm_name': 'demo1'}) |
40
|
|
|
execution = self._wait_for_completion(execution) |
41
|
|
|
self._assert_success(execution, num_tasks=8) |
42
|
|
|
self.assertIn('vm_id', execution.result) |
43
|
|
|
|
44
|
|
|
def test_complex_workbook_subflow_actions(self): |
45
|
|
|
execution = self._execute_workflow( |
46
|
|
|
'examples.mistral-workbook-subflows', {'subject': 'st2', 'adjective': 'cool'}) |
47
|
|
|
execution = self._wait_for_completion(execution) |
48
|
|
|
self._assert_success(execution, num_tasks=2) |
49
|
|
|
self.assertIn('tagline', execution.result) |
50
|
|
|
self.assertEqual(execution.result['tagline'], 'st2 is cool!') |
51
|
|
|
|
52
|
|
|
def test_with_items(self): |
53
|
|
|
params = {'cmd': 'date', 'count': 8} |
54
|
|
|
execution = self._execute_workflow('examples.mistral-repeat', params) |
55
|
|
|
execution = self._wait_for_completion(execution) |
56
|
|
|
self._assert_success(execution, num_tasks=1) |
57
|
|
|
self.assertEqual(len(execution.result['result']), params['count']) |
58
|
|
|
|
59
|
|
|
def test_concurrent_load(self): |
60
|
|
|
wf_name = 'examples.mistral-workbook-complex' |
61
|
|
|
wf_params = {'vm_name': 'demo1'} |
62
|
|
|
executions = [self._execute_workflow(wf_name, wf_params) for i in range(3)] |
63
|
|
|
|
64
|
|
|
eventlet.sleep(30) |
65
|
|
|
|
66
|
|
|
for execution in executions: |
67
|
|
|
e = self._wait_for_completion(execution) |
68
|
|
|
self._assert_success(e, num_tasks=8) |
69
|
|
|
self.assertIn('vm_id', e.result) |
70
|
|
|
|
71
|
|
|
def test_execution_failure(self): |
72
|
|
|
execution = self._execute_workflow('examples.mistral-basic', {'cmd': 'foo'}) |
73
|
|
|
execution = self._wait_for_completion(execution) |
74
|
|
|
self._assert_failure(execution) |
75
|
|
|
|
76
|
|
|
def test_cancellation(self): |
77
|
|
|
execution = self._execute_workflow('examples.mistral-test-cancel', {'sleep': 10}) |
78
|
|
|
execution = self._wait_for_state(execution, ['running']) |
79
|
|
|
self.st2client.liveactions.delete(execution) |
80
|
|
|
execution = self._wait_for_completion(execution, expect_tasks_completed=False) |
81
|
|
|
self._assert_canceled(execution, are_tasks_completed=False) |
82
|
|
|
|
83
|
|
|
def test_basic_rerun(self): |
84
|
|
|
switch = 'mistral-test-rerun-switch' |
85
|
|
|
|
86
|
|
|
self.st2client.keys.update(models.KeyValuePair(name=switch, value='1')) |
87
|
|
|
execution = self._execute_workflow('examples.mistral-test-rerun') |
88
|
|
|
execution = self._wait_for_completion(execution) |
89
|
|
|
self._assert_failure(execution) |
90
|
|
|
orig_st2_ex_id = execution.id |
91
|
|
|
orig_wf_ex_id = execution.context['mistral']['execution_id'] |
92
|
|
|
|
93
|
|
|
self.st2client.keys.update(models.KeyValuePair(name=switch, value='0')) |
94
|
|
|
execution = self.st2client.liveactions.re_run(orig_st2_ex_id) |
95
|
|
|
self.assertNotEqual(execution.id, orig_st2_ex_id) |
96
|
|
|
execution = self._wait_for_completion(execution) |
97
|
|
|
self._assert_success(execution, num_tasks=1) |
98
|
|
|
self.assertNotEqual(execution.context['mistral']['execution_id'], orig_wf_ex_id) |
99
|
|
|
|
100
|
|
|
def test_basic_rerun_task(self): |
101
|
|
|
switch = 'mistral-test-rerun-switch' |
102
|
|
|
|
103
|
|
|
self.st2client.keys.update(models.KeyValuePair(name=switch, value='1')) |
104
|
|
|
execution = self._execute_workflow('examples.mistral-test-rerun') |
105
|
|
|
execution = self._wait_for_completion(execution) |
106
|
|
|
self._assert_failure(execution) |
107
|
|
|
orig_st2_ex_id = execution.id |
108
|
|
|
orig_wf_ex_id = execution.context['mistral']['execution_id'] |
109
|
|
|
|
110
|
|
|
self.st2client.keys.update(models.KeyValuePair(name=switch, value='0')) |
111
|
|
|
execution = self.st2client.liveactions.re_run(orig_st2_ex_id, tasks=['task1']) |
112
|
|
|
self.assertNotEqual(execution.id, orig_st2_ex_id) |
113
|
|
|
execution = self._wait_for_completion(execution) |
114
|
|
|
self._assert_success(execution, num_tasks=1) |
115
|
|
|
self.assertEqual(execution.context['mistral']['execution_id'], orig_wf_ex_id) |
116
|
|
|
|