forked from openmsa/python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_orchestration.py
More file actions
632 lines (492 loc) · 26.2 KB
/
test_orchestration.py
File metadata and controls
632 lines (492 loc) · 26.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
"""
Test Orchestration
"""
from unittest.mock import patch
from util import _is_valid_json
from util import orchestration_fixture # pylint: disable=unused-import
# pylint: disable=redefined-outer-name
def test_list_service_instances(orchestration_fixture):
"""
Test List Service Instances
"""
device_info = (
'[{"name":"Process/Reference/Customer/Kibana/kibana_dashboard",'
'"id":2102,"serviceExternalReference":"MSASID2102","state":"ACTIVE"},'
'{"name":"Process/Reference/Customer/Kibana/kibana_dashboard",'
'"id":2258,"serviceExternalReference":"MSASID2258","state":"ACTIVE"},'
'{"name":"Process/Reference/Customer/Kibana/kibana_dashboard",'
'"id":2231,"serviceExternalReference":"MSASID2231","state":"ACTIVE"},'
'{"name":"Process/Reference/Device_Management/Device_Management_List",'
'"id":1536,"serviceExternalReference":"MSASID1536","state":"ACTIVE"}]')
with patch('requests.get') as mock_call_get:
mock_call_get.return_value.text = device_info
orch = orchestration_fixture
orch.list_service_instances()
assert orch.path == '/orchestration/MSAA19224/service/instance'
assert _is_valid_json(orch.response.text)
def test_get_service_variables_by_service_id(orchestration_fixture):
"""
Test Get Service variables by Service ID
"""
device_info = ('[{"comment":"","name":"SERVICEINSTANCEID",'
'"value":"205710"},'
'{"comment":"","name":"service_id",'
'"value":"205710"}]')
with patch('requests.get') as mock_call_get:
mock_call_get.return_value.text = device_info
orch = orchestration_fixture
orch.get_service_variables('1234')
assert orch.path == '/orchestration/service/variables/1234'
assert _is_valid_json(orch.response.text)
def test_get_list_service_by_status(orchestration_fixture):
"""
Test Get list of services by status
"""
response = (
'{"Process/IP_CONTROLLER/Fulfilment_Dispatcher/Fulfilment_Dispatcher":'
'{"RUNNING":0,"ENDED":0,"WARNING":0,"FAIL":0},"Process/IP_CONTROLLER/'
'Fulfilment_Handler/Fulfilment_Handler":{"RUNNING":0,"ENDED":0,'
'"WARNING":0,"FAIL":0}}')
with patch('requests.get') as mock_call_get:
mock_call_get.return_value.text = response
orch = orchestration_fixture
orch.get_list_service_by_status(1)
assert orch.path == '/orchestration/v1/services?ubiqubeId=MSAA19224&range=1'
assert _is_valid_json(orch.response.text)
def test_get_service_status_by_id(orchestration_fixture):
"""
Test Get service status by ID
"""
import json
response = (
'[{"serviceId":{"name":"Process/IP_CONTROLLER/Cleaner/Cleaner","id":398,'
'"serviceExternalReference":"FSTSID398","state":null},"processId":'
'{"name":"Process/IP_CONTROLLER/Cleaner/Cleaner","id":448,"lastExecNumber":1,'
'"submissionType":"RUN"},"status":{"status":"ENDED","details":"Cleanerhasbeenfinished",'
'"startingDate":"2021-01-2911:33:23.865242","endingDate":"2021-01-2911:33:29.19334",'
'"execNumber":1,"processTaskStatus":[{"status":"ENDED","order":1,"processInstanceId":448,'
'"scriptName":"Cleaner","details":"Cleanerhasbeenfinished",'
'"startingDate":"2021-01-2911:33:23.878261","endingDate":"2021-01-2911:33:29.19334",'
'"newParameters":[]}]},"executorUsername":"ncroot"}]')
with patch('requests.get') as mock_call_get:
mock_call_get.return_value.text = response
orch = orchestration_fixture
assert orch.get_service_status_by_id(398) == 'ENDED'
assert orch.path == '/orchestration/v1/service/process-instance/398'
response_fail = ('[]')
with patch('requests.get') as mock_call_get:
mock_call_get.return_value.text = response_fail
orch = orchestration_fixture
assert orch.get_service_status_by_id(398) is None
assert orch.path == '/orchestration/v1/service/process-instance/398'
def test_get_process_status_by_id(orchestration_fixture):
"""
Test Get service status by ID
"""
import json
response = (
'{ "serviceId": { "name": "Process/workflows/TestConPy/TestConPy", "id": 187201, '
'"serviceExternalReference": "IOSSID187201", "state": null }, '
'"processId": { "name": "Process/workflows/TestConPy/Process_Test", '
'"id": 189406, "lastExecNumber": 1, "submissionType": "RUN" }, '
'"status": { "status": "ENDED", "details": "Task OK", "startingDate": "2021-06-21 11:42:34.731975", '
'"endingDate": "2021-06-21 11:42:35.108229", "execNumber": 1, "processReference": null, '
'"processTaskStatus": [ { "status": "ENDED", "order": 1, "processInstanceId": 189406, '
'"scriptName": "test1", "details": "Task OK", "startingDate": "2021-06-21 11:42:34.795359", '
'"endingDate": "2021-06-21 11:42:35.108229", "newParameters": [] } ] }, "executorUsername": null }')
with patch('requests.get') as mock_call_get:
mock_call_get.return_value.text = response
orch = orchestration_fixture
assert orch.get_process_status_by_id(189406) == 'ENDED'
assert orch.path == '/orchestration/v1/process-instance/189406'
response_fail = ('[]')
with patch('requests.get') as mock_call_get:
mock_call_get.return_value.text = response_fail
orch = orchestration_fixture
assert orch.get_process_status_by_id(189406) is None
assert orch.path == '/orchestration/v1/process-instance/189406'
def test_get_service_variable_by_name(orchestration_fixture):
"""
Test Get Service Variables by Variable Name
"""
device_info = ('{"TASKINSTANCEID":"353763"}')
with patch('requests.get') as mock_call_get:
mock_call_get.return_value.text = device_info
orch = orchestration_fixture
orch.get_service_variable_by_name('1234', 'TASKINSTANCEID')
assert orch.path == \
'/orchestration/service/variables/1234/TASKINSTANCEID'
assert _is_valid_json(orch.response.text)
def test_update_service_variable(orchestration_fixture):
"""
Update service variable
"""
with patch('msa_sdk.msa_api.MSA_API._call_post') as mock_call_post:
orch = orchestration_fixture
orch.update_service_variable('1234', 'TASKINSTANCEID', 'NewValue')
assert orch.path == \
'/orchestration/service/variables/1234/TASKINSTANCEID?value=NewValue'
mock_call_post.assert_called_once()
def test_delete_service_by_id(orchestration_fixture):
"""
Delete service by ID
"""
with patch('msa_sdk.msa_api.MSA_API._call_delete') as mock_call_delete:
orch = orchestration_fixture
orch.delete_service('1234')
assert orch.path == '/orchestration/MSAA19224/service/instance/1234'
mock_call_delete.assert_called_once()
def test_list_process_instances(orchestration_fixture):
"""
Test list process instances
"""
device_info = (
'[{"processId":{"id":208606,"lastExecNumber":1,'
'"name":"Fortigate_Ping_Execution/Process_Execute_Ping/Process_Execute_Ping",'
'"submissionType":"RUN"},"serviceId":{"id":205732,'
'"name":"Fortigate_Ping_Execution","serviceExternalReference":"FGT_PING",'
'"state":null},"status":{"details":"Mandatory parameter device_id is not'
'present","endingDate":"2017-06-04 15:18:00.0",'
'"execNumber":1,'
'"processTaskStatus":[{"details":"Mandatory parameter device_id is not present",'
'"endingDate":"2017-06-04'
'15:18:00.0","newParameter":[],"order":1,"processInstanceId":208606,'
'"scriptName":"Execute Ping","startingDate":"2017-06-04 15:18:00.0","status":"FAIL"}],'
'"startingDate":"2017-06-04 15:18:00.0","status":"FAIL"}}]')
local_path = '/orchestration/process/instances/{}'.format(1234)
with patch('msa_sdk.msa_api.MSA_API._call_get') as mock_call_get:
mock_call_get.return_value.text = device_info
orch = orchestration_fixture
orch.list_process_instances_by_service(1234)
assert orch.path == local_path
mock_call_get.assert_called_once()
def test_launch_process_instance(orchestration_fixture):
"""
Test launch process instance
"""
local_path = '/orchestration/process/execute/{}'
local_path += '/{}?processName={}'
with patch('msa_sdk.msa_api.MSA_API._call_post') as mock_call_post:
orch = orchestration_fixture
orch.execute_launch_process_instance('1234', 'Process',
{"var1": 1, "var2": 2})
assert orch.path == local_path.format('MSAA19224', '1234',
'Process')
mock_call_post.assert_called_once()
def test_execute_service(orchestration_fixture):
"""
Test execute service
"""
local_path = '/orchestration/service/execute/{}'
local_path += '?serviceName={}&processName={}&serviceInstance=0'
with patch('msa_sdk.msa_api.MSA_API._call_post') as mock_call_post:
orch = orchestration_fixture
orch.execute_service('1234', 'ProcessName',
{"var1": 1, "var2": 2})
assert orch.path == local_path.format('MSAA19224', '1234',
'ProcessName')
mock_call_post.assert_called_once_with({"var1": 1, "var2": 2})
def test_execute_service_process(orchestration_fixture):
"""
Test execute service process
"""
local_path = '/orchestration/service/execute/{}'
local_path += '?serviceName={}&processName={}&serviceInstance=0'
result = ('{"serviceId": {'
'"name": "Process/workflows/TestConPy/TestConPy",'
'"id": 187201,'
'"serviceExternalReference": "IOSSID187201",'
'"state": null'
'}, "processId": {'
'"id": 189406, '
'"name": "Process/workflows/TestConPy/Process_Test",'
'"lastExecNumber": 1,'
'"submissionType": "RUN"'
'}}')
with patch('requests.post') as mock_post:
orch = orchestration_fixture
mock_post.return_value.text = result
assert orch.execute_service_process('1234', 'ProcessName',
{"var1": 1, "var2": 2}) == (187201,
189406)
assert orch.path == local_path.format('MSAA19224', '1234',
'ProcessName')
def test_execute_service_process_no_service_id(orchestration_fixture):
"""
Test execute service process no service id
"""
local_path = '/orchestration/service/execute/{}'
local_path += '?serviceName={}&processName={}&serviceInstance=0'
result = ('{"processId": {'
'"id": 189406, '
'"name": "Process/workflows/TestConPy/Process_Test",'
'"lastExecNumber": 1,'
'"submissionType": "RUN"'
'}}')
with patch('requests.post') as mock_post:
orch = orchestration_fixture
mock_post.return_value.text = result
assert orch.execute_service_process('1234', 'ProcessName',
{"var1": 1, "var2": 2}) == (-1,
189406)
assert orch.path == local_path.format('MSAA19224', '1234',
'ProcessName')
def test_execute_service_process_no_process_id(orchestration_fixture):
"""
Test execute service process no process id
"""
local_path = '/orchestration/service/execute/{}'
local_path += '?serviceName={}&processName={}&serviceInstance=0'
result = ('{"serviceId": {'
'"name": "Process/workflows/TestConPy/TestConPy",'
'"id": 187201,'
'"serviceExternalReference": "IOSSID187201",'
'"state": null'
'}}')
with patch('requests.post') as mock_post:
orch = orchestration_fixture
mock_post.return_value.text = result
assert orch.execute_service_process('1234', 'ProcessName',
{"var1": 1, "var2": 2}) == (187201,
-1)
assert orch.path == local_path.format('MSAA19224', '1234',
'ProcessName')
def test_execute_by_service(orchestration_fixture):
"""
Test execute by service
"""
local_path = '/orchestration/service/execute/{}'
local_path += '/{}?serviceName={}&processName={}'
with patch('msa_sdk.msa_api.MSA_API._call_post') as mock_call_post:
orch = orchestration_fixture
orch.execute_by_service('external_ref', 'service_ref', 'serviceName',
'ProcessName',
{"var1": 1, "var2": 2})
assert orch.path == local_path.format('external_ref', 'service_ref',
'serviceName', 'ProcessName')
mock_call_post.assert_called_once_with({"var1": 1, "var2": 2})
def test_execute_service_by_reference(orchestration_fixture):
"""
Test execute service by reference
"""
local_path = '/orchestration/service/execute/{}/{}'
local_path += '?serviceName={}&processName={}'
with patch('msa_sdk.msa_api.MSA_API._call_post') as mock_call_post:
orch = orchestration_fixture
orch.execute_service_by_reference('external_ref', 'servReference',
'servName', 'procName',
{"var1": 1, "var2": 2})
assert orch.path == local_path.format('external_ref', 'servReference',
'servName', 'procName')
mock_call_post.assert_called_once_with({"var1": 1, "var2": 2})
def test_wait_and_run_execute_service_by_reference(orchestration_fixture):
"""
Test wait_and_run_execute_service_by_reference, test part orch.get_process_status_by_id(service_instance_id)
"""
import json
result = ('[{"TASKINSTANCEID":"353763", "status": { "status": "ENDED"} }]')
with patch('msa_sdk.msa_api.MSA_API._call_post') as mock_call_post:
with patch('requests.get') as mock_call_get:
orch = orchestration_fixture
mock_call_get.return_value.text = result
orch = orchestration_fixture
orch.wait_and_run_execute_service_by_reference('NTTA14', 'NTTSID2867','Process/workflows/test_wait_and_run_execute_service_by_reference/test_wait_and_run_execute_service_by_reference', 'Process/workflows/test_wait_and_run_execute_service_by_reference/Process_very_long_task',{"var1": 1, "var2": 2}, 20, 5)
#assert orch.path == '/orchestration/service/execute/NTTA14/NTTSID2867?serviceName=Process/workflows/test_wait_and_run_execute_service_by_reference/test_wait_and_run_execute_service_by_reference&processName=Process/workflows/test_wait_and_run_execute_service_by_reference/Process_very_long_task'
assert orch.path == '/orchestration/v1/service/process-instance/2867'
response = ( '[{"serviceId":{"name":"Process/workflows/test_wait_and_run_execute_service_by_reference/test_wait_and_run_execute_service_by_reference","id":2867,'
'"serviceExternalReference":"NTTSID2867","state":null},"processId":'
'{"name":"Process/workflows/test_wait_and_run_execute_service_by_reference/Process_very_long_task","id":448,"lastExecNumber":1,'
'"submissionType":"RUN"},"status":{"status":"RUNNING","details":"Cleanerhasbeenfinished",'
'"startingDate":"2021-01-2911:33:23.865242","endingDate":"2021-01-2911:33:29.19334",'
'"execNumber":1,"processTaskStatus":[{"status":"ENDED","order":1,"processInstanceId":448,'
'"scriptName":"Cleaner","details":"Cleanerhasbeenfinished",'
'"startingDate":"2021-01-2911:33:23.878261","endingDate":"2021-01-2911:33:29.19334",'
'"newParameters":[]}]},"executorUsername":"ncroot"}]')
with patch('msa_sdk.variables.Variables.task_call') as mock_task_call:
with patch('requests.get') as mock_call_get:
context = {
"PROCESSINSTANCEID": 448,
"TASKID": 1,
"EXECNUMBER": 1
}
mock_task_call.return_value = context
with patch('requests.get') as mock_call_get:
mock_call_get.return_value.text = response
orch = orchestration_fixture
# assert orch.wait_and_run_execute_service_by_reference('NTTA14', 'NTTSID2867','Process/workflows/test_wait_and_run_execute_service_by_reference/test_wait_and_run_execute_service_by_reference', 'Process/workflows/test_wait_and_run_execute_service_by_reference/Process_very_long_task',{"var1": 1, "var2": 2}, 20, 5) == 'RUNNING'
assert orch.path == '/orchestration/v1/service/process-instance/2867'
def test_wait_and_run_execute_service_by_reference_running(orchestration_fixture):
"""
Test wait_and_run_execute_service_by_reference, test part orch.get_process_status_by_id(service_instance_id)
"""
import json
result = ('[{"TASKINSTANCEID":"2867", "status": { "status": "RUNNING"} } ]')
orch = orchestration_fixture
with patch('msa_sdk.variables.Variables.task_call') as mock_task_call:
with patch('requests.put') as mock_call_put:
context = {
"PROCESSINSTANCEID": "285",
"TASKID": "1",
"EXECNUMBER": "1"
}
mock_task_call.return_value.text = context
#overwrite method update_asynchronous_task_details
with patch.object(orch, 'update_asynchronous_task_details', return_value=None):
with patch('msa_sdk.msa_api.MSA_API._call_post') as mock_call_post:
with patch('requests.get') as mock_call_get:
mock_call_get.return_value.text = result
orch.wait_and_run_execute_service_by_reference('NTTA14', 'NTTSID2867','Process/workflows/test_wait_and_run_execute_service_by_reference/test_wait_and_run_execute_service_by_reference', 'Process/workflows/test_wait_and_run_execute_service_by_reference/Process_very_long_task',{"var1": 1, "var2": 2}, 20, 5)
assert orch.path == '/orchestration/v1/service/process-instance/2867'
def test_wait_and_run_execute_service_by_reference_timeout(orchestration_fixture):
"""
Test wait_and_run_execute_service_by_reference, test execute_service_by_reference part
"""
local_path = '/orchestration/service/execute/{}/{}'
local_path += '?serviceName={}&processName={}'
with patch('msa_sdk.msa_api.MSA_API._call_post') as mock_call_post:
orch = orchestration_fixture
#orch.wait_and_run_execute_service_by_reference('INV124', 'SDSSID1124', 'servName', 'procName', {"var1": 1, "var2": 2}, -20, 5)
orch.wait_and_run_execute_service_by_reference('NTTA14', 'NTTSID2867','Process/workflows/test_wait_and_run_execute_service_by_reference/test_wait_and_run_execute_service_by_reference', 'Process/workflows/test_wait_and_run_execute_service_by_reference/Process_very_long_task',{"var1": 1, "var2": 2}, -20, 5)
assert orch.path == local_path.format('NTTA14', 'NTTSID2867',
'Process/workflows/test_wait_and_run_execute_service_by_reference/test_wait_and_run_execute_service_by_reference', 'Process/workflows/test_wait_and_run_execute_service_by_reference/Process_very_long_task')
mock_call_post.assert_called_once_with({"var1": 1, "var2": 2})
def test_wait_end_get_process_instance(orchestration_fixture):
"""
Test wait_end_get_process_instance
"""
result = ('{"TASKINSTANCEID":"353763", "status": { "status": "RUNNING"} }')
with patch('msa_sdk.msa_api.MSA_API._call_post') as mock_call_post:
with patch('requests.get') as mock_call_get:
orch = orchestration_fixture
mock_call_get.return_value.text = result
orch.wait_end_get_process_instance(1124, 20, 5)
assert orch.path == '/orchestration/process/instance/1124'
def test_wait_end_get_process_instance_ended(orchestration_fixture):
"""
Test wait_end_get_process_instance proc ENDED
"""
result = ('{"TASKINSTANCEID":"353763", "status": { "status": "ENDED"} }')
with patch('msa_sdk.msa_api.MSA_API._call_post') as mock_call_post:
with patch('requests.get') as mock_call_get:
orch = orchestration_fixture
mock_call_get.return_value.text = result
orch.wait_end_get_process_instance(1124, 20, 5)
assert orch.path == '/orchestration/process/instance/1124'
def test_resume_failed_or_paused_process_instance(orchestration_fixture):
"""
Test resume_failed_or_paused_process_instance.
"""
local_path = '/orchestration/v2/process/{}/resume'.format(1234)
with patch('msa_sdk.msa_api.MSA_API._call_post') as mock_call_post:
orch = orchestration_fixture
orch.resume_failed_or_paused_process_instance(1234)
assert orch.path == local_path.format(1334)
mock_call_post.assert_called_once()
def test_list_process_instance_by_service_id(orchestration_fixture):
"""
Test List process instance by service id
"""
device_info = (
'[{"processId":{"id":208606,"lastExecNumber":1,'
'"name":"Fortigate_Ping_Execution/Process_Execute_Ping/Process_Execute_Ping",'
'"submissionType":"RUN"},"serviceId":{"id":205732,'
'"name":"Fortigate_Ping_Execution","serviceExternalReference":"FGT_PING",'
'"state":null},"status":{"details":"Mandatory parameter device_id is not'
'present","endingDate":"2017-06-04 15:18:00.0",'
'"execNumber":1,'
'"processTaskStatus":[{"details":"Mandatory parameter device_id is not present",'
'"endingDate":"2017-06-04'
'15:18:00.0","newParameter":[],"order":1,"processInstanceId":208606,'
'"scriptName":"Execute Ping","startingDate":"2017-06-04 15:18:00.0","status":"FAIL"}],'
'"startingDate":"2017-06-04 15:18:00.0","status":"FAIL"}}]')
local_path = '/orchestration/process/instances/{}'.format(1234)
with patch('msa_sdk.msa_api.MSA_API._call_get') as mock_call_get:
mock_call_get.return_value.text = device_info
orch = orchestration_fixture
orch.list_process_instances_by_service(1234)
assert orch.path == local_path
mock_call_get.assert_called_once()
def test_get_process_instance(orchestration_fixture):
"""
Test get process instance
"""
device_info = (
'[{"processId":{"id":208606,"lastExecNumber":1,'
'"name":"Fortigate_Ping_Execution/Process_Execute_Ping/Process_Execute_Ping",'
'"submissionType":"RUN"},"serviceId":{"id":205732,'
'"name":"Fortigate_Ping_Execution","serviceExternalReference":"FGT_PING",'
'"state":null},"status":{"details":"Mandatory parameter device_id is not'
'present","endingDate":"2017-06-04 15:18:00.0",'
'"execNumber":1,'
'"processTaskStatus":[{"details":"Mandatory parameter device_id is not present",'
'"endingDate":"2017-06-04'
'15:18:00.0","newParameter":[],"order":1,"processInstanceId":208606,'
'"scriptName":"Execute Ping","startingDate":"2017-06-04 15:18:00.0","status":"FAIL"}],'
'"startingDate":"2017-06-04 15:18:00.0","status":"FAIL"}}]')
local_path = '/orchestration/process/instance/{}'.format(1234)
with patch('msa_sdk.msa_api.MSA_API._call_get') as mock_call_get:
mock_call_get.return_value.text = device_info
orch = orchestration_fixture
orch.get_process_instance(1234)
assert orch.path == local_path
mock_call_get.assert_called_once()
def test_update_process_script_details(orchestration_fixture):
"""
Test update process script details
"""
local_path = ('/orchestration/process/instance/{}'
'/task/{}/execnumber/{}/update').format(1234, 'Task-ID',
'exec-number')
with patch('msa_sdk.msa_api.MSA_API._call_put') as mock_call_put:
orch = orchestration_fixture
orch.update_process_script_details(1234, 'Task-ID', 'exec-number')
assert orch.path == local_path
mock_call_put.assert_called_once()
def test_update_service_instance_ref(orchestration_fixture):
"""
Test update service instance reference
"""
local_path = ('/orchestration/{}/service/instance/update'
'/{}/?serviceReference={}').format('MSAA19224', 'ServID',
'Serv_Ref')
with patch('msa_sdk.msa_api.MSA_API._call_put') as mock_call_put:
orch = orchestration_fixture
orch.update_service_instance_reference('ServID', 'Serv_Ref')
assert orch.path == local_path
mock_call_put.assert_called_once()
def test_read_service_instance(orchestration_fixture):
"""
Test Read Service Instances
"""
device_info = (
'{"name":"Process/Reference/Customer/Kibana/kibana_dashboard",'
'"id":2231,"serviceExternalReference":"MSASID2231","state":"ACTIVE"}')
with patch('requests.get') as mock_call_get:
mock_call_get.return_value.text = device_info
orch = orchestration_fixture
orch.read_service_instance('2231')
assert orch.path == '/orchestration/MSAA19224/service/instance/2231'
assert _is_valid_json(orch.response.text)
def test_update_asynchronous_task_details(orchestration_fixture):
"""
Test update task async way
"""
argument_dict = {
'process_id': '1234',
'task_id': '42',
'exec_number': '4242',
'data': 'Lorem ipsum dolor sit amet'}
with patch('requests.put') as mock_call_put:
assert not orchestration_fixture.update_asynchronous_task_details(
**argument_dict)
def test_attach_wf_to_subtenant(orchestration_fixture):
"""
Test attach_wf_to_subtenant
"""
local_path = '/orchestration/service/attach'
local_path += '?ubiqubeIds={}&uri={}'
with patch('msa_sdk.msa_api.MSA_API._call_post') as mock_call_post:
orch = orchestration_fixture
orch.attach_wf_to_subtenant("UBIA234", "Process/workflows/AutoAttached/organizations.xml")
assert orch.path == local_path.format('UBIA234', 'Process/workflows/AutoAttached/organizations.xml')
mock_call_post.assert_called_once_with()