Passed
Pull Request — master (#3753)
by W
09:44
created

RerunWiringTest.setUp()   A

Complexity

Conditions 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
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
from integration.mistral import base
21
22
23
class RerunWiringTest(base.TestWorkflowExecution):
24
25
    temp_dir_path = None
26
27
    def setUp(self):
28
        super(RerunWiringTest, self).setUp()
29
30
        # Create temporary directory used by the tests
31
        _, self.temp_dir_path = tempfile.mkstemp()
32
        os.chmod(self.temp_dir_path, 0755)   # nosec
33
34
    def tearDown(self):
35
        if self.temp_dir_path and os.path.exists(self.temp_dir_path):
36
            if os.path.isdir(self.temp_dir_path):
37
                shutil.rmtree(self.temp_dir_path)
38
            else:
39
                os.remove(self.temp_dir_path)
40
41
    def test_rerun(self):
42
        path = self.temp_dir_path
43
44
        with open(path, 'w') as f:
45
            f.write('1')
46
47
        execution = self._execute_workflow('examples.mistral-test-rerun', {'tempfile': path})
48
        execution = self._wait_for_completion(execution)
49
        self._assert_failure(execution)
50
        orig_st2_ex_id = execution.id
51
        orig_wf_ex_id = execution.context['mistral']['execution_id']
52
53
        with open(path, 'w') as f:
54
            f.write('0')
55
56
        execution = self.st2client.liveactions.re_run(orig_st2_ex_id)
57
        self.assertNotEqual(execution.id, orig_st2_ex_id)
58
        execution = self._wait_for_completion(execution)
59
        self._assert_success(execution, num_tasks=1)
60
        self.assertNotEqual(execution.context['mistral']['execution_id'], orig_wf_ex_id)
61
62
    def test_rerun_task(self):
63
        path = self.temp_dir_path
64
65
        with open(path, 'w') as f:
66
            f.write('1')
67
68
        execution = self._execute_workflow('examples.mistral-test-rerun', {'tempfile': path})
69
        execution = self._wait_for_completion(execution)
70
        self._assert_failure(execution)
71
        orig_st2_ex_id = execution.id
72
        orig_wf_ex_id = execution.context['mistral']['execution_id']
73
74
        with open(path, 'w') as f:
75
            f.write('0')
76
77
        execution = self.st2client.liveactions.re_run(orig_st2_ex_id, tasks=['task1'])
78
        self.assertNotEqual(execution.id, orig_st2_ex_id)
79
        execution = self._wait_for_completion(execution)
80
        self._assert_success(execution, num_tasks=1)
81
        self.assertEqual(execution.context['mistral']['execution_id'], orig_wf_ex_id)
82
83
    def test_rerun_subflow_task(self):
84
        path = self.temp_dir_path
85
86
        with open(path, 'w') as f:
87
            f.write('1')
88
89
        workflow_name = 'examples.mistral-test-rerun-subflow'
90
        execution = self._execute_workflow(workflow_name, {'tempfile': path})
91
        execution = self._wait_for_completion(execution)
92
        self._assert_failure(execution)
93
        orig_st2_ex_id = execution.id
94
        orig_wf_ex_id = execution.context['mistral']['execution_id']
95
96
        with open(path, 'w') as f:
97
            f.write('0')
98
99
        execution = self.st2client.liveactions.re_run(orig_st2_ex_id, tasks=['task1.task1'])
100
        self.assertNotEqual(execution.id, orig_st2_ex_id)
101
        execution = self._wait_for_completion(execution)
102
        self._assert_success(execution, num_tasks=1)
103
        self.assertEqual(execution.context['mistral']['execution_id'], orig_wf_ex_id)
104
105
    def test_rerun_and_reset_with_items_task(self):
106
        path = self.temp_dir_path
107
108
        with open(path, 'w') as f:
109
            f.write('1')
110
111
        execution = self._execute_workflow(
112
            'examples.mistral-test-rerun-with-items',
113
            {'tempfile': path}
114
        )
115
116
        execution = self._wait_for_completion(execution)
117
        self._assert_failure(execution)
118
        orig_st2_ex_id = execution.id
119
        orig_wf_ex_id = execution.context['mistral']['execution_id']
120
121
        with open(path, 'w') as f:
122
            f.write('0')
123
124
        execution = self.st2client.liveactions.re_run(orig_st2_ex_id, tasks=['task1'])
125
        self.assertNotEqual(execution.id, orig_st2_ex_id)
126
127
        execution = self._wait_for_completion(execution)
128
        self._assert_success(execution, num_tasks=1)
129
        self.assertEqual(execution.context['mistral']['execution_id'], orig_wf_ex_id)
130
131
        children = self.st2client.liveactions.get_property(execution.id, 'children')
132
        self.assertEqual(len(children), 4)
133
134
    def test_rerun_and_resume_with_items_task(self):
135
        path = self.temp_dir_path
136
137
        with open(path, 'w') as f:
138
            f.write('1')
139
140
        execution = self._execute_workflow(
141
            'examples.mistral-test-rerun-with-items',
142
            {'tempfile': path}
143
        )
144
145
        execution = self._wait_for_completion(execution)
146
        self._assert_failure(execution)
147
        orig_st2_ex_id = execution.id
148
        orig_wf_ex_id = execution.context['mistral']['execution_id']
149
150
        with open(path, 'w') as f:
151
            f.write('0')
152
153
        execution = self.st2client.liveactions.re_run(
154
            orig_st2_ex_id,
155
            tasks=['task1'],
156
            no_reset=['task1']
157
        )
158
159
        self.assertNotEqual(execution.id, orig_st2_ex_id)
160
161
        execution = self._wait_for_completion(execution)
162
        self._assert_success(execution, num_tasks=1)
163
        self.assertEqual(execution.context['mistral']['execution_id'], orig_wf_ex_id)
164
165
        children = self.st2client.liveactions.get_property(execution.id, 'children')
166
        self.assertEqual(len(children), 2)
167
168
    def test_rerun_subflow_and_reset_with_items_task(self):
169
        path = self.temp_dir_path
170
171
        with open(path, 'w') as f:
172
            f.write('1')
173
174
        execution = self._execute_workflow(
175
            'examples.mistral-test-rerun-subflow-with-items',
176
            {'tempfile': path}
177
        )
178
179
        execution = self._wait_for_completion(execution)
180
        self._assert_failure(execution)
181
        orig_st2_ex_id = execution.id
182
        orig_wf_ex_id = execution.context['mistral']['execution_id']
183
184
        with open(path, 'w') as f:
185
            f.write('0')
186
187
        execution = self.st2client.liveactions.re_run(orig_st2_ex_id, tasks=['task1.task1'])
188
        self.assertNotEqual(execution.id, orig_st2_ex_id)
189
190
        execution = self._wait_for_completion(execution)
191
        self._assert_success(execution, num_tasks=1)
192
        self.assertEqual(execution.context['mistral']['execution_id'], orig_wf_ex_id)
193
194
        children = self.st2client.liveactions.get_property(execution.id, 'children')
195
        self.assertEqual(len(children), 4)
196
197
    def test_rerun_subflow_and_resume_with_items_task(self):
198
        path = self.temp_dir_path
199
200
        with open(path, 'w') as f:
201
            f.write('1')
202
203
        execution = self._execute_workflow(
204
            'examples.mistral-test-rerun-subflow-with-items',
205
            {'tempfile': path}
206
        )
207
208
        execution = self._wait_for_completion(execution)
209
        self._assert_failure(execution)
210
        orig_st2_ex_id = execution.id
211
        orig_wf_ex_id = execution.context['mistral']['execution_id']
212
213
        with open(path, 'w') as f:
214
            f.write('0')
215
216
        execution = self.st2client.liveactions.re_run(
217
            orig_st2_ex_id,
218
            tasks=['task1.task1'],
219
            no_reset=['task1.task1']
220
        )
221
222
        self.assertNotEqual(execution.id, orig_st2_ex_id)
223
224
        execution = self._wait_for_completion(execution)
225
        self._assert_success(execution, num_tasks=1)
226
        self.assertEqual(execution.context['mistral']['execution_id'], orig_wf_ex_id)
227
228
        children = self.st2client.liveactions.get_property(execution.id, 'children')
229
        self.assertEqual(len(children), 2)
230