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
|
|
|
|
18
|
|
|
from integration.orchestra import base |
19
|
|
|
|
20
|
|
|
from st2common.constants import action as ac_const |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
class ErrorHandlingTest(base.TestWorkflowExecution): |
24
|
|
|
|
25
|
|
|
def test_inspection_error(self): |
26
|
|
|
expected_errors = { |
27
|
|
|
'context': [ |
28
|
|
|
{ |
29
|
|
|
'type': 'yaql', |
30
|
|
|
'expression': '<% $.foobar %>', |
31
|
|
|
'message': 'Variable "foobar" is referenced before assignment.', |
32
|
|
|
'schema_path': 'properties.tasks.patternProperties.^\w+$.properties.input', |
|
|
|
|
33
|
|
|
'spec_path': 'tasks.task1.input', |
34
|
|
|
} |
35
|
|
|
], |
36
|
|
|
'expressions': [ |
37
|
|
|
{ |
38
|
|
|
'type': 'yaql', |
39
|
|
|
'expression': '<% <% succeeded() %>', |
40
|
|
|
'message': ( |
41
|
|
|
'Parse error: unexpected \'<\' at ' |
42
|
|
|
'position 0 of expression \'<% succeeded()\'' |
43
|
|
|
), |
44
|
|
|
'schema_path': ( |
45
|
|
|
'properties.tasks.patternProperties.^\w+$.' |
|
|
|
|
46
|
|
|
'properties.next.items.properties.when' |
47
|
|
|
), |
48
|
|
|
'spec_path': 'tasks.task2.next[0].when' |
49
|
|
|
} |
50
|
|
|
], |
51
|
|
|
'syntax': [ |
52
|
|
|
{ |
53
|
|
|
'message': '[{\'cmd\': \'echo <% $.macro %>\'}] is not of type \'object\'', |
54
|
|
|
'schema_path': 'properties.tasks.patternProperties.^\w+$.properties.input.type', |
|
|
|
|
55
|
|
|
'spec_path': 'tasks.task2.input' |
56
|
|
|
} |
57
|
|
|
] |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
ex = self._execute_workflow('examples.orchestra-fail-inspection') |
61
|
|
|
ex = self._wait_for_completion(ex) |
62
|
|
|
self.assertEqual(ex.status, ac_const.LIVEACTION_STATUS_FAILED) |
63
|
|
|
self.assertDictEqual(ex.result, {'errors': expected_errors, 'output': None}) |
64
|
|
|
|
65
|
|
|
def test_input_error(self): |
66
|
|
|
expected_errors = [{'message': 'Unknown function "#property#value"'}] |
67
|
|
|
ex = self._execute_workflow('examples.orchestra-fail-input-rendering') |
68
|
|
|
ex = self._wait_for_completion(ex) |
69
|
|
|
self.assertEqual(ex.status, ac_const.LIVEACTION_STATUS_FAILED) |
70
|
|
|
self.assertDictEqual(ex.result, {'errors': expected_errors, 'output': None}) |
71
|
|
|
|
72
|
|
|
def test_vars_error(self): |
73
|
|
|
expected_errors = [{'message': 'Unknown function "#property#value"'}] |
74
|
|
|
ex = self._execute_workflow('examples.orchestra-fail-vars-rendering') |
75
|
|
|
ex = self._wait_for_completion(ex) |
76
|
|
|
self.assertEqual(ex.status, ac_const.LIVEACTION_STATUS_FAILED) |
77
|
|
|
self.assertDictEqual(ex.result, {'errors': expected_errors, 'output': None}) |
78
|
|
|
|
79
|
|
|
def test_start_task_error(self): |
80
|
|
|
expected_errors = [{'message': 'Unknown function "#property#value"', 'task_id': 'task1'}] |
81
|
|
|
ex = self._execute_workflow('examples.orchestra-fail-start-task') |
82
|
|
|
ex = self._wait_for_completion(ex) |
83
|
|
|
self.assertEqual(ex.status, ac_const.LIVEACTION_STATUS_FAILED) |
84
|
|
|
self.assertDictEqual(ex.result, {'errors': expected_errors, 'output': None}) |
85
|
|
|
|
86
|
|
|
def test_task_transition_error(self): |
87
|
|
|
expected_errors = [ |
88
|
|
|
{ |
89
|
|
|
'message': ( |
90
|
|
|
'Unable to resolve key \'value\' in expression \'' |
91
|
|
|
'<% succeeded() and result().value %>\' from context.' |
92
|
|
|
), |
93
|
|
|
'task_transition_id': 'task2__0', |
94
|
|
|
'task_id': 'task1' |
95
|
|
|
} |
96
|
|
|
] |
97
|
|
|
|
98
|
|
|
ex = self._execute_workflow('examples.orchestra-fail-task-transition') |
99
|
|
|
ex = self._wait_for_completion(ex) |
100
|
|
|
self.assertEqual(ex.status, ac_const.LIVEACTION_STATUS_FAILED) |
101
|
|
|
self.assertDictEqual(ex.result, {'errors': expected_errors, 'output': None}) |
102
|
|
|
|
103
|
|
|
def test_task_publish_error(self): |
104
|
|
|
expected_errors = [ |
105
|
|
|
{ |
106
|
|
|
'message': ( |
107
|
|
|
'Unable to resolve key \'value\' in expression \'' |
108
|
|
|
'<% result().value %>\' from context.' |
109
|
|
|
), |
110
|
|
|
'task_transition_id': 'task2__0', |
111
|
|
|
'task_id': 'task1' |
112
|
|
|
} |
113
|
|
|
] |
114
|
|
|
|
115
|
|
|
ex = self._execute_workflow('examples.orchestra-fail-task-publish') |
116
|
|
|
ex = self._wait_for_completion(ex) |
117
|
|
|
self.assertEqual(ex.status, ac_const.LIVEACTION_STATUS_FAILED) |
118
|
|
|
self.assertDictEqual(ex.result, {'errors': expected_errors, 'output': None}) |
119
|
|
|
|
120
|
|
|
def test_output_error(self): |
121
|
|
|
expected_errors = [{'message': 'Unknown function "#property#value"'}] |
122
|
|
|
ex = self._execute_workflow('examples.orchestra-fail-output-rendering') |
123
|
|
|
ex = self._wait_for_completion(ex) |
124
|
|
|
self.assertEqual(ex.status, ac_const.LIVEACTION_STATUS_FAILED) |
125
|
|
|
self.assertDictEqual(ex.result, {'errors': expected_errors, 'output': None}) |
126
|
|
|
|
Escape sequences in Python are generally interpreted according to rules similar to standard C. Only if strings are prefixed with
r
orR
are they interpreted as regular expressions.The escape sequence that was used indicates that you might have intended to write a regular expression.
Learn more about the available escape sequences. in the Python documentation.