@@ -270,6 +270,193 @@ def test_launch_workflow(self):
270
270
executions .ExecutionManager .create .assert_called_with (
271
271
WF1_NAME , workflow_input = workflow_input , env = env )
272
272
273
+ @mock .patch .object (
274
+ workflows .WorkflowManager , 'list' ,
275
+ mock .MagicMock (return_value = []))
276
+ @mock .patch .object (
277
+ workflows .WorkflowManager , 'get' ,
278
+ mock .MagicMock (return_value = WF1 ))
279
+ @mock .patch .object (
280
+ workflows .WorkflowManager , 'create' ,
281
+ mock .MagicMock (return_value = [WF1 ]))
282
+ @mock .patch .object (
283
+ executions .ExecutionManager , 'create' ,
284
+ mock .MagicMock (return_value = executions .Execution (None , WF1_EXEC )))
285
+ def test_launch_workflow_under_parent_chain_with_jinja_params (self ):
286
+ ac_ctx = {
287
+ 'chain' : {
288
+ 'params' : {
289
+ 'var1' : 'foobar' ,
290
+ 'var2' : '{{foobar}}' ,
291
+ 'var3' : ['{{foo}}' , '{{bar}}' ],
292
+ 'var4' : {
293
+ 'foobar' : '{{foobar}}'
294
+ },
295
+ 'var5' : {
296
+ 'foobar' : '{% for item in items %}foobar{% end for %}'
297
+ }
298
+ }
299
+ }
300
+ }
301
+
302
+ liveaction = LiveActionDB (action = WF1_NAME , parameters = ACTION_PARAMS , context = ac_ctx )
303
+ liveaction , execution = action_service .request (liveaction )
304
+ liveaction = LiveAction .get_by_id (str (liveaction .id ))
305
+ self .assertEqual (liveaction .status , action_constants .LIVEACTION_STATUS_RUNNING )
306
+
307
+ mistral_context = liveaction .context .get ('mistral' , None )
308
+ self .assertIsNotNone (mistral_context )
309
+ self .assertEqual (mistral_context ['execution_id' ], WF1_EXEC .get ('id' ))
310
+ self .assertEqual (mistral_context ['workflow_name' ], WF1_EXEC .get ('workflow_name' ))
311
+
312
+ workflow_input = copy .deepcopy (ACTION_PARAMS )
313
+ workflow_input .update ({'count' : '3' })
314
+
315
+ env = {
316
+ 'st2_execution_id' : str (execution .id ),
317
+ 'st2_liveaction_id' : str (liveaction .id ),
318
+ 'st2_action_api_url' : 'http://0.0.0.0:9101/v1' ,
319
+ '__actions' : {
320
+ 'st2.action' : {
321
+ 'st2_context' : {
322
+ 'api_url' : 'http://0.0.0.0:9101/v1' ,
323
+ 'endpoint' : 'http://0.0.0.0:9101/v1/actionexecutions' ,
324
+ 'parent' : {
325
+ 'execution_id' : str (execution .id ),
326
+ 'chain' : {
327
+ 'params' : {
328
+ 'var1' : 'foobar' ,
329
+ 'var2' : '{% raw %}{{foobar}}{% endraw %}' ,
330
+ 'var3' : [
331
+ '{% raw %}{{foo}}{% endraw %}' ,
332
+ '{% raw %}{{bar}}{% endraw %}'
333
+ ],
334
+ 'var4' : {
335
+ 'foobar' : '{% raw %}{{foobar}}{% endraw %}'
336
+ },
337
+ 'var5' : {
338
+ 'foobar' : (
339
+ '{% raw %}{% for item in items %}'
340
+ 'foobar{% end for %}{% endraw %}'
341
+ )
342
+ }
343
+ }
344
+ }
345
+ },
346
+ 'notify' : {},
347
+ 'skip_notify_tasks' : []
348
+ }
349
+ }
350
+ }
351
+ }
352
+
353
+ executions .ExecutionManager .create .assert_called_with (
354
+ WF1_NAME , workflow_input = workflow_input , env = env )
355
+
356
+ @mock .patch .object (
357
+ workflows .WorkflowManager , 'list' ,
358
+ mock .MagicMock (return_value = []))
359
+ @mock .patch .object (
360
+ workflows .WorkflowManager , 'get' ,
361
+ mock .MagicMock (return_value = WF1 ))
362
+ @mock .patch .object (
363
+ workflows .WorkflowManager , 'create' ,
364
+ mock .MagicMock (return_value = [WF1 ]))
365
+ @mock .patch .object (
366
+ executions .ExecutionManager , 'create' ,
367
+ mock .MagicMock (return_value = executions .Execution (None , WF1_EXEC )))
368
+ def test_launch_workflow_under_parent_chain_with_nonetype_in_chain_context (self ):
369
+ ac_ctx = {'chain' : None }
370
+
371
+ liveaction = LiveActionDB (action = WF1_NAME , parameters = ACTION_PARAMS , context = ac_ctx )
372
+ liveaction , execution = action_service .request (liveaction )
373
+ liveaction = LiveAction .get_by_id (str (liveaction .id ))
374
+ self .assertEqual (liveaction .status , action_constants .LIVEACTION_STATUS_RUNNING )
375
+
376
+ mistral_context = liveaction .context .get ('mistral' , None )
377
+ self .assertIsNotNone (mistral_context )
378
+ self .assertEqual (mistral_context ['execution_id' ], WF1_EXEC .get ('id' ))
379
+ self .assertEqual (mistral_context ['workflow_name' ], WF1_EXEC .get ('workflow_name' ))
380
+
381
+ workflow_input = copy .deepcopy (ACTION_PARAMS )
382
+ workflow_input .update ({'count' : '3' })
383
+
384
+ env = {
385
+ 'st2_execution_id' : str (execution .id ),
386
+ 'st2_liveaction_id' : str (liveaction .id ),
387
+ 'st2_action_api_url' : 'http://0.0.0.0:9101/v1' ,
388
+ '__actions' : {
389
+ 'st2.action' : {
390
+ 'st2_context' : {
391
+ 'api_url' : 'http://0.0.0.0:9101/v1' ,
392
+ 'endpoint' : 'http://0.0.0.0:9101/v1/actionexecutions' ,
393
+ 'parent' : {
394
+ 'execution_id' : str (execution .id ),
395
+ 'chain' : None
396
+ },
397
+ 'notify' : {},
398
+ 'skip_notify_tasks' : []
399
+ }
400
+ }
401
+ }
402
+ }
403
+
404
+ executions .ExecutionManager .create .assert_called_with (
405
+ WF1_NAME , workflow_input = workflow_input , env = env )
406
+
407
+ @mock .patch .object (
408
+ workflows .WorkflowManager , 'list' ,
409
+ mock .MagicMock (return_value = []))
410
+ @mock .patch .object (
411
+ workflows .WorkflowManager , 'get' ,
412
+ mock .MagicMock (return_value = WF1 ))
413
+ @mock .patch .object (
414
+ workflows .WorkflowManager , 'create' ,
415
+ mock .MagicMock (return_value = [WF1 ]))
416
+ @mock .patch .object (
417
+ executions .ExecutionManager , 'create' ,
418
+ mock .MagicMock (return_value = executions .Execution (None , WF1_EXEC )))
419
+ def test_launch_workflow_under_parent_chain_with_nonetype_in_params_context (self ):
420
+ ac_ctx = {'chain' : {'params' : None }}
421
+
422
+ liveaction = LiveActionDB (action = WF1_NAME , parameters = ACTION_PARAMS , context = ac_ctx )
423
+ liveaction , execution = action_service .request (liveaction )
424
+ liveaction = LiveAction .get_by_id (str (liveaction .id ))
425
+ self .assertEqual (liveaction .status , action_constants .LIVEACTION_STATUS_RUNNING )
426
+
427
+ mistral_context = liveaction .context .get ('mistral' , None )
428
+ self .assertIsNotNone (mistral_context )
429
+ self .assertEqual (mistral_context ['execution_id' ], WF1_EXEC .get ('id' ))
430
+ self .assertEqual (mistral_context ['workflow_name' ], WF1_EXEC .get ('workflow_name' ))
431
+
432
+ workflow_input = copy .deepcopy (ACTION_PARAMS )
433
+ workflow_input .update ({'count' : '3' })
434
+
435
+ env = {
436
+ 'st2_execution_id' : str (execution .id ),
437
+ 'st2_liveaction_id' : str (liveaction .id ),
438
+ 'st2_action_api_url' : 'http://0.0.0.0:9101/v1' ,
439
+ '__actions' : {
440
+ 'st2.action' : {
441
+ 'st2_context' : {
442
+ 'api_url' : 'http://0.0.0.0:9101/v1' ,
443
+ 'endpoint' : 'http://0.0.0.0:9101/v1/actionexecutions' ,
444
+ 'parent' : {
445
+ 'execution_id' : str (execution .id ),
446
+ 'chain' : {
447
+ 'params' : None
448
+ }
449
+ },
450
+ 'notify' : {},
451
+ 'skip_notify_tasks' : []
452
+ }
453
+ }
454
+ }
455
+ }
456
+
457
+ executions .ExecutionManager .create .assert_called_with (
458
+ WF1_NAME , workflow_input = workflow_input , env = env )
459
+
273
460
@mock .patch .object (
274
461
workflows .WorkflowManager , 'list' ,
275
462
mock .MagicMock (return_value = []))
0 commit comments