Browse Source

Remove execution from workflow message send

Serializing all the execution in a message can make the message too big.
This change was done in tripleo-common. this supports that change
This change still supports the old format and is backwards compatible.

Partial-Bug: #1812172
Change-Id: I40ee028366222f38f5ba1db58d171f98be75d009
(cherry picked from commit cad7916ce8)
tags/9.3.1
apetrich 8 months ago
parent
commit
092449a9c6

+ 1
- 1
tripleoclient/tests/fakes.py View File

@@ -47,7 +47,7 @@ class FakeWebSocket(object):
47 47
 
48 48
     def wait_for_messages(self, timeout=None):
49 49
         yield {
50
-            'execution': {'id': 'IDID'},
50
+            'execution_id': 'IDID',
51 51
             'status': 'SUCCESS',
52 52
         }
53 53
 

+ 2
- 2
tripleoclient/tests/test_plugin.py View File

@@ -66,7 +66,7 @@ class TestPlugin(base.TestCase):
66 66
                 "payload": {
67 67
                     "status": 200,
68 68
                     "message": "Result for IDID",
69
-                    "execution": {"id": "IDID"},
69
+                    "execution_id": "IDID",
70 70
                 }
71 71
             }
72 72
         }, send_ack]
@@ -84,7 +84,7 @@ class TestPlugin(base.TestCase):
84 84
                 self.assertEqual(payload, {
85 85
                     "status": 200,
86 86
                     "message": "Result for IDID",
87
-                    "execution": {"id": "IDID"},
87
+                    "execution_id": "IDID",
88 88
                 })
89 89
                 # We only want to test the first message, as there is only one.
90 90
                 # The last one, the send_ack will be used by the context

+ 11
- 11
tripleoclient/tests/v1/overcloud_node/test_overcloud_node.py View File

@@ -63,7 +63,7 @@ class TestDeleteNode(fakes.TestDeleteNode):
63 63
         parsed_args = self.check_parser(self.cmd, argslist, verifylist)
64 64
 
65 65
         self.websocket.wait_for_messages.return_value = iter([{
66
-            "execution": {"id": "IDID"},
66
+            "execution_id": "IDID",
67 67
             "status": "SUCCESS"
68 68
         }])
69 69
 
@@ -109,7 +109,7 @@ class TestDeleteNode(fakes.TestDeleteNode):
109 109
         parsed_args = self.check_parser(self.cmd, arglist, verifylist)
110 110
 
111 111
         self.websocket.wait_for_messages.return_value = iter([{
112
-            "execution": {"id": "IDID"},
112
+            "execution_id": "IDID",
113 113
             "status": "SUCCESS"
114 114
         }])
115 115
 
@@ -136,7 +136,7 @@ class TestDeleteNode(fakes.TestDeleteNode):
136 136
 
137 137
         self.websocket.wait_for_messages.return_value = iter([{
138 138
             "status": "FAILED",
139
-            "execution": {"id": "IDID"},
139
+            "execution_id": "IDID",
140 140
             "message": """Failed to run action ERROR: Couldn't find \
141 141
                 following instances in stack overcloud: wrong_instance"""
142 142
         }])
@@ -172,7 +172,7 @@ class TestProvideNode(fakes.TestOvercloudNode):
172 172
         self.websocket.wait_for_messages.return_value = iter([{
173 173
             "status": "SUCCESS",
174 174
             "message": "Success",
175
-            "execution": {"id": "IDID"}
175
+            "execution_id": "IDID"
176 176
         }])
177 177
 
178 178
     def test_provide_all_manageable_nodes(self):
@@ -250,7 +250,7 @@ class TestIntrospectNode(fakes.TestOvercloudNode):
250 250
             "status": "SUCCESS",
251 251
             "message": "Success",
252 252
             "introspected_nodes": {},
253
-            "execution": {"id": "IDID"}
253
+            "execution_id": "IDID"
254 254
         }] * 2)
255 255
 
256 256
         self.cmd.take_action(parsed_args)
@@ -274,7 +274,7 @@ class TestIntrospectNode(fakes.TestOvercloudNode):
274 274
         self.websocket.wait_for_messages.return_value = [{
275 275
             "status": "SUCCESS",
276 276
             "message": "Success",
277
-            "execution": {"id": "IDID"},
277
+            "execution_id": "IDID",
278 278
         }]
279 279
 
280 280
         self.cmd.take_action(parsed_args)
@@ -393,7 +393,7 @@ class TestImportNode(fakes.TestOvercloudNode):
393 393
             "registered_nodes": [{
394 394
                 "uuid": "MOCK_NODE_UUID"
395 395
             }],
396
-            "execution": {"id": "IDID"}
396
+            "execution_id": "IDID"
397 397
         }]
398 398
 
399 399
         self.cmd.take_action(parsed_args)
@@ -492,7 +492,7 @@ class TestConfigureNode(fakes.TestOvercloudNode):
492 492
         self.websocket.wait_for_messages.return_value = iter([{
493 493
             "status": "SUCCESS",
494 494
             "message": "",
495
-            "execution": {"id": "IDID"}
495
+            "execution_id": "IDID"
496 496
         }])
497 497
 
498 498
         # Get the command object to test
@@ -520,7 +520,7 @@ class TestConfigureNode(fakes.TestOvercloudNode):
520 520
         self.websocket.wait_for_messages.return_value = iter([{
521 521
             "status": "FAILED",
522 522
             "message": "Test failure.",
523
-            "execution": {"id": "IDID"}
523
+            "execution_id": "IDID"
524 524
         }])
525 525
 
526 526
         parsed_args = self.check_parser(self.cmd, ['--all-manageable'], [])
@@ -549,7 +549,7 @@ class TestConfigureNode(fakes.TestOvercloudNode):
549 549
         self.websocket.wait_for_messages.return_value = iter([{
550 550
             "status": "FAILED",
551 551
             "message": "Test failure.",
552
-            "execution": {"id": "IDID"}
552
+            "execution_id": "IDID"
553 553
         }])
554 554
 
555 555
         parsed_args = self.check_parser(self.cmd, ['node_uuid1'], [])
@@ -676,7 +676,7 @@ class TestDiscoverNode(fakes.TestOvercloudNode):
676 676
             "registered_nodes": [{
677 677
                 "uuid": "MOCK_NODE_UUID"
678 678
             }],
679
-            "execution": {"id": "IDID"}
679
+            "execution_id": "IDID"
680 680
         }]
681 681
 
682 682
     def test_with_ip_range(self):

+ 24
- 7
tripleoclient/tests/v1/test_overcloud_plan.py View File

@@ -72,6 +72,13 @@ class TestOvercloudDeletePlan(utils.TestCommand):
72 72
         self.app.client_manager.workflow_engine = mock.Mock()
73 73
         self.workflow = self.app.client_manager.workflow_engine
74 74
 
75
+        self.websocket = mock.Mock()
76
+        self.websocket.__enter__ = lambda s: self.websocket
77
+        self.websocket.__exit__ = lambda s, *exc: None
78
+        self.tripleoclient = mock.Mock()
79
+        self.tripleoclient.messaging_websocket.return_value = self.websocket
80
+        self.app.client_manager.tripleoclient = self.tripleoclient
81
+
75 82
     @mock.patch(
76 83
         'tripleoclient.workflows.plan_management.delete_deployment_plan',
77 84
         autospec=True)
@@ -79,6 +86,11 @@ class TestOvercloudDeletePlan(utils.TestCommand):
79 86
         parsed_args = self.check_parser(self.cmd, ['test-plan'],
80 87
                                         [('plans', ['test-plan'])])
81 88
 
89
+        self.websocket.wait_for_messages.return_value = iter([{
90
+            "execution_id": "IDID",
91
+            "status": "SUCCESS"
92
+        }])
93
+
82 94
         self.cmd.take_action(parsed_args)
83 95
 
84 96
         delete_deployment_plan_mock.assert_called_once_with(
@@ -93,6 +105,11 @@ class TestOvercloudDeletePlan(utils.TestCommand):
93 105
         verifylist = [('plans', ['test-plan1', 'test-plan2'])]
94 106
         parsed_args = self.check_parser(self.cmd, argslist, verifylist)
95 107
 
108
+        self.websocket.wait_for_messages.return_value = iter([{
109
+            "execution_id": "IDID",
110
+            "status": "SUCCESS"
111
+        }])
112
+
96 113
         self.cmd.take_action(parsed_args)
97 114
 
98 115
         expected = [
@@ -136,7 +153,7 @@ class TestOvercloudCreatePlan(utils.TestCommand):
136 153
         parsed_args = self.check_parser(self.cmd, arglist, verifylist)
137 154
 
138 155
         self.websocket.wait_for_messages.return_value = iter([{
139
-            "execution": {"id": "IDID"},
156
+            "execution_id": "IDID",
140 157
             "status": "SUCCESS"
141 158
         }])
142 159
 
@@ -164,7 +181,7 @@ class TestOvercloudCreatePlan(utils.TestCommand):
164 181
         parsed_args = self.check_parser(self.cmd, arglist, verifylist)
165 182
 
166 183
         self.websocket.wait_for_messages.return_value = iter([{
167
-            "execution": {"id": "IDID"},
184
+            "execution_id": "IDID",
168 185
             "status": "ERROR", "message": "failed"
169 186
         }])
170 187
 
@@ -194,7 +211,7 @@ class TestOvercloudCreatePlan(utils.TestCommand):
194 211
         parsed_args = self.check_parser(self.cmd, arglist, verifylist)
195 212
 
196 213
         self.websocket.wait_for_messages.return_value = iter([{
197
-            "execution": {"id": "IDID"},
214
+            "execution_id": "IDID",
198 215
             "status": "SUCCESS"
199 216
         }])
200 217
         mock_result = mock.Mock(output='{"result": null}')
@@ -229,7 +246,7 @@ class TestOvercloudCreatePlan(utils.TestCommand):
229 246
         parsed_args = self.check_parser(self.cmd, arglist, verifylist)
230 247
 
231 248
         self.websocket.wait_for_messages.return_value = iter([{
232
-            "execution": {"id": "IDID"},
249
+            "execution_id": "IDID",
233 250
             "status": "ERROR", "message": "failed"
234 251
         }])
235 252
         mock_result = mock.Mock(output='{"result": null}')
@@ -297,7 +314,7 @@ class TestOvercloudCreatePlan(utils.TestCommand):
297 314
         parsed_args = self.check_parser(self.cmd, arglist, verifylist)
298 315
 
299 316
         self.websocket.wait_for_messages.return_value = iter([{
300
-            "execution": {"id": "IDID"},
317
+            "execution_id": "IDID",
301 318
             "status": "SUCCESS"
302 319
         }])
303 320
         mock_result = mock.Mock(output='{"result": null}')
@@ -339,7 +356,7 @@ class TestOvercloudCreatePlan(utils.TestCommand):
339 356
         parsed_args = self.check_parser(self.cmd, arglist, verifylist)
340 357
 
341 358
         self.websocket.wait_for_messages.return_value = iter([{
342
-            "execution": {"id": "IDID"},
359
+            "execution_id": "IDID",
343 360
             "status": "SUCCESS"
344 361
         }])
345 362
 
@@ -398,7 +415,7 @@ class TestOvercloudDeployPlan(utils.TestCommand):
398 415
         self.orch.stacks.get.return_value = None
399 416
 
400 417
         self.websocket.wait_for_messages.return_value = iter([{
401
-            'execution': {'id': 'IDID'},
418
+            'execution_id': 'IDID',
402 419
             'status': 'SUCCESS'
403 420
         }])
404 421
 

+ 1
- 1
tripleoclient/tests/v1/test_overcloud_raid.py View File

@@ -38,7 +38,7 @@ class TestCreateRAID(fakes.TestBaremetal):
38 38
         websocket = tripleoclient.messaging_websocket()
39 39
         websocket.wait_for_messages.return_value = iter([
40 40
             {'status': "SUCCESS",
41
-             'execution': {'id': 'IDID'}}
41
+             'execution_id': 'IDID'}
42 42
         ])
43 43
         self.websocket = websocket
44 44
 

+ 5
- 5
tripleoclient/tests/workflows/test_baremetal.py View File

@@ -37,13 +37,13 @@ class TestBaremetalWorkflows(utils.TestCommand):
37 37
         self.workflow.executions.create.return_value = execution
38 38
 
39 39
         self.message_success = iter([{
40
-            "execution": {"id": "IDID"},
40
+            "execution_id": "IDID",
41 41
             "status": "SUCCESS",
42 42
             "message": "Success.",
43 43
             "registered_nodes": [],
44 44
         }])
45 45
         self.message_failed = iter([{
46
-            "execution": {"id": "IDID"},
46
+            "execution_id": "IDID",
47 47
             "status": "FAIL",
48 48
             "message": "Fail.",
49 49
         }])
@@ -127,7 +127,7 @@ class TestBaremetalWorkflows(utils.TestCommand):
127 127
     def test_provide_error_with_format_message(self):
128 128
 
129 129
         self.websocket.wait_for_messages.return_value = iter([{
130
-            "execution": {"id": "IDID"},
130
+            "execution_id": "IDID",
131 131
             "status": "FAIL",
132 132
             "message": ['Error1', 'Error2']
133 133
         }])
@@ -175,7 +175,7 @@ class TestBaremetalWorkflows(utils.TestCommand):
175 175
     def test_introspect_manageable_nodes_success(self):
176 176
 
177 177
         self.websocket.wait_for_messages.return_value = iter([{
178
-            "execution": {"id": "IDID"},
178
+            "execution_id": "IDID",
179 179
             "status": "SUCCESS",
180 180
             "introspected_nodes": {},
181 181
         }])
@@ -209,7 +209,7 @@ class TestBaremetalWorkflows(utils.TestCommand):
209 209
     def test_introspect_manageable_nodes_mixed_status(self):
210 210
 
211 211
         self.websocket.wait_for_messages.return_value = iter([{
212
-            "execution": {"id": "IDID"},
212
+            "execution_id": "IDID",
213 213
             "status": "SUCCESS",
214 214
             "introspected_nodes": {'node1': {'error': None},
215 215
                                    'node2': {'error': 'Error'}}

+ 54
- 4
tripleoclient/tests/workflows/test_base.py View File

@@ -25,13 +25,13 @@ class TestBaseWorkflows(utils.TestCommand):
25 25
     def test_wait_for_messages_success(self):
26 26
         payload_a = {
27 27
             'status': 'ERROR',
28
-            'execution': {'id': 2,
29
-                          'root_execution_id': 1}
28
+            'execution_id': 2,
29
+            'root_execution_id': 1
30 30
         }
31 31
         payload_b = {
32 32
             'status': 'ERROR',
33
-            'execution': {'id': 1,
34
-                          'root_execution_id': 1}
33
+            'execution_id': 1,
34
+            'root_execution_id': 1
35 35
         }
36 36
 
37 37
         mistral = mock.Mock()
@@ -77,6 +77,56 @@ class TestBaseWorkflows(utils.TestCommand):
77 77
         websocket.wait_for_messages.assert_called_with(timeout=None)
78 78
 
79 79
     def test_wait_for_messages_different_execution(self):
80
+        payload_a = {
81
+            'status': 'RUNNING',
82
+            'execution_id': 'aaaa',
83
+            'root_execution_id': 'aaaa'
84
+        }
85
+        payload_b = {
86
+            'status': 'RUNNING',
87
+            'execution_id': 'bbbb',
88
+            'root_execution_id': 'bbbb'
89
+        }
90
+
91
+        mistral = mock.Mock()
92
+        websocket = mock.Mock()
93
+        websocket.wait_for_messages.return_value = iter([payload_a, payload_b])
94
+        execution = mock.Mock()
95
+        execution.id = 'aaaa'
96
+
97
+        messages = list(base.wait_for_messages(mistral, websocket, execution))
98
+
99
+        # Assert only payload_a was returned
100
+        self.assertEqual([payload_a], messages)
101
+
102
+        websocket.wait_for_messages.assert_called_with(timeout=None)
103
+
104
+    def test_backwards_compat_wait_for_messages_success(self):
105
+        payload_a = {
106
+            'status': 'ERROR',
107
+            'execution': {'id': 2,
108
+                          'root_execution_id': 1}
109
+        }
110
+        payload_b = {
111
+            'status': 'ERROR',
112
+            'execution': {'id': 1,
113
+                          'root_execution_id': 1}
114
+        }
115
+
116
+        mistral = mock.Mock()
117
+        websocket = mock.Mock()
118
+        websocket.wait_for_messages.return_value = iter([payload_a, payload_b])
119
+        execution = mock.Mock()
120
+        execution.id = 1
121
+
122
+        messages = list(base.wait_for_messages(mistral, websocket, execution))
123
+
124
+        self.assertEqual([payload_a, payload_b], messages)
125
+
126
+        self.assertFalse(mistral.executions.get.called)
127
+        websocket.wait_for_messages.assert_called_with(timeout=None)
128
+
129
+    def test_backwards_compatible_call_with_different_execution(self):
80 130
         payload_a = {
81 131
             'status': 'RUNNING',
82 132
             'execution': {'id': 'aaaa',

+ 6
- 6
tripleoclient/tests/workflows/test_parameters.py View File

@@ -48,7 +48,7 @@ class TestParameterWorkflows(utils.TestCommand):
48 48
 
49 49
     def test_get_overcloud_passwords(self):
50 50
         self.websocket.wait_for_messages.return_value = iter([{
51
-            "execution": {"id": "IDID"},
51
+            "execution_id": "IDID",
52 52
             "status": "SUCCESS",
53 53
             "message": "passwords",
54 54
         }])
@@ -77,7 +77,7 @@ class TestParameterWorkflows(utils.TestCommand):
77 77
         mock_safe_load.return_value = plan_env_data
78 78
 
79 79
         self.websocket.wait_for_messages.return_value = iter([{
80
-            "execution": {"id": "IDID"},
80
+            "execution_id": "IDID",
81 81
             "status": "SUCCESS",
82 82
             "message": "",
83 83
             "result": {}
@@ -110,7 +110,7 @@ class TestParameterWorkflows(utils.TestCommand):
110 110
         mock_safe_load.return_value = plan_env_data
111 111
 
112 112
         self.websocket.wait_for_messages.return_value = iter([{
113
-            "execution": {"id": "IDID"},
113
+            "execution_id": "IDID",
114 114
             "status": "FAILED",
115 115
             "message": "workflow failure",
116 116
             "result": ""
@@ -158,7 +158,7 @@ class TestParameterWorkflows(utils.TestCommand):
158 158
 
159 159
     def test_check_deprecated_params_no_output(self):
160 160
         self.websocket.wait_for_messages.return_value = iter([{
161
-            "execution": {"id": "IDID"},
161
+            "execution_id": "IDID",
162 162
             "status": "SUCCESS",
163 163
         }])
164 164
 
@@ -176,7 +176,7 @@ class TestParameterWorkflows(utils.TestCommand):
176 176
                               'deprecated': True,
177 177
                               'user_defined': True}]
178 178
         self.websocket.wait_for_messages.return_value = iter([{
179
-            "execution": {"id": "IDID"},
179
+            "execution_id": "IDID",
180 180
             "status": "SUCCESS",
181 181
             "deprecated": deprecated_params
182 182
         }])
@@ -197,7 +197,7 @@ class TestParameterWorkflows(utils.TestCommand):
197 197
         deprecated_params = [{'parameter': 'TestParameter1',
198 198
                               'deprecated': True}]
199 199
         self.websocket.wait_for_messages.return_value = iter([{
200
-            "execution": {"id": "IDID"},
200
+            "execution_id": "IDID",
201 201
             "status": "SUCCESS",
202 202
             "deprecated": deprecated_params
203 203
         }])

+ 2
- 2
tripleoclient/tests/workflows/test_plan_management.py View File

@@ -35,7 +35,7 @@ class TestPlanCreationWorkflows(utils.TestCommand):
35 35
         self.app.client_manager.tripleoclient = self.tripleoclient
36 36
 
37 37
         self.message_success = iter([{
38
-            "execution": {"id": "IDID"},
38
+            "execution_id": "IDID",
39 39
             "status": "SUCCESS",
40 40
         }])
41 41
 
@@ -255,7 +255,7 @@ class TestPlanUpdateWorkflows(base.TestCommand):
255 255
         self.workflow.action_executions.create.return_value = output
256 256
         self.workflow.executions.create.return_value = output
257 257
         self.message_success = iter([{
258
-            "execution": {"id": "IDID"},
258
+            "execution_id": "IDID",
259 259
             "status": "SUCCESS",
260 260
         }])
261 261
         self.websocket.wait_for_messages.return_value = self.message_success

+ 19
- 6
tripleoclient/workflows/base.py View File

@@ -60,19 +60,32 @@ def wait_for_messages(mistral, websocket, execution, timeout=None):
60 60
     try:
61 61
         for payload in websocket.wait_for_messages(timeout=timeout):
62 62
             # Ignore messages whose root_execution_id does not match the
63
-            # id of the execution for which we are waiting.
64
-            if payload['execution']['id'] != execution.id and \
65
-                payload['execution'].get('root_execution_id', '') != \
66
-                    execution.id:
63
+            # id of the execution for which we are waiting
64
+
65
+            # New versions of tripleo-common don't sent the execution anymore
66
+            # but keeping the old way ot getting it is important to keep
67
+            # backwards compatibility.
68
+
69
+            # TODO(apetrich) payload.execution is deprecated and will be
70
+            # removed from stein. We should keep this until payload.execution
71
+            #  is removed from the LTS
72
+            payload_exec_id = payload.get('execution_id') or \
73
+                payload.get('execution', {}).get('id')
74
+
75
+            payload_root_exec_id = payload.get('root_execution_id', '') or \
76
+                payload.get('execution', {}).get('root_execution_id', '')
77
+
78
+            if payload_exec_id != execution.id and \
79
+                    payload_root_exec_id != execution.id:
67 80
 
68 81
                     LOG.debug("Ignoring message from execution %s"
69
-                              % payload['execution']['id'])
82
+                              % payload_exec_id)
70 83
             else:
71 84
                 yield payload
72 85
             # If the message is from a sub-workflow, we just need to pass it
73 86
             # on to be displayed. This should never be the last message - so
74 87
             # continue and wait for the next.
75
-            if payload['execution']['id'] != execution.id:
88
+            if payload_exec_id != execution.id:
76 89
                 continue
77 90
             # Check the status of the payload, if we are not given one
78 91
             # default to running and assume it is just an "in progress"

Loading…
Cancel
Save