-
-
Notifications
You must be signed in to change notification settings - Fork 150
/
Copy pathtest_ecs.py
1630 lines (1278 loc) · 66.8 KB
/
test_ecs.py
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
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
from copy import deepcopy
from datetime import datetime, timedelta
import pytest
import tempfile
import os
import logging
from boto3.session import Session
from botocore.exceptions import ClientError, NoCredentialsError
from dateutil.tz import tzlocal
from mock.mock import patch
from ecs_deploy.ecs import EcsService, EcsTaskDefinition, \
UnknownContainerError, EcsTaskDefinitionDiff, EcsClient, \
EcsAction, EcsConnectionError, DeployAction, ScaleAction, RunAction, \
EcsTaskDefinitionCommandError, UnknownTaskDefinitionError, LAUNCH_TYPE_EC2, read_env_file, EcsDeployment, \
EcsDeploymentError
CLUSTER_NAME = u'test-cluster'
CLUSTER_ARN = u'arn:aws:ecs:eu-central-1:123456789012:cluster/%s' % CLUSTER_NAME
SERVICE_NAME = u'test-service'
SERVICE_ARN = u'ecs-svc/12345678901234567890'
DESIRED_COUNT = 2
TASK_DEFINITION_FAMILY_1 = u'test-task'
TASK_DEFINITION_REVISION_1 = 1
TASK_DEFINITION_ROLE_ARN_1 = u'arn:test:role:1'
TASK_DEFINITION_ARN_1 = u'arn:aws:ecs:eu-central-1:123456789012:task-definition/%s:%s' % (TASK_DEFINITION_FAMILY_1,
TASK_DEFINITION_REVISION_1)
TASK_DEFINITION_RUNTIME_PLATFORM_1 = {u'cpuArchitecture': u'X86_64', u'operatingSystemFamily': u'LINUX'}
TASK_DEFINITION_VOLUMES_1 = []
TASK_DEFINITION_CONTAINERS_1 = [
{u'name': u'webserver', u'image': u'webserver:123', u'command': u'run',
u'environment': ({"name": "foo", "value": "bar"}, {"name": "lorem", "value": "ipsum"}, {"name": "empty", "value": ""}),
u'environmentFiles': [{'value': 'arn:aws:s3:::myS3bucket/myApp/.env', 'type': 's3'}, {'value': 'arn:aws:s3:::coolBuckets/dev/.env', 'type': 's3'}],
u'secrets': ({"name": "baz", "valueFrom": "qux"}, {"name": "dolor", "valueFrom": "sit"}),
u'dockerLabels': {"foo": "bar", "lorem": "ipsum", "empty": ""},
u'logConfiguration': {},
u'ulimits': [{'name': 'memlock', 'softLimit': 256, 'hardLimit': 256}],
u'systemControls': [{'namespace': 'net.core.somaxconn', 'value': '511'}],
u'portMappings': [{'containerPort': 8080, 'hostPort': 8080}],
u'mountPoints': [{'sourceVolume': 'volume', 'containerPath': '/container/path', 'readOnly': False}]},
{u'name': u'application', u'image': u'application:123', u'command': u'run', u'environment': (),
u'logConfiguration': {}, u'dockerLabels': {},
u'ulimits': [{'name': 'memlock', 'softLimit': 256, 'hardLimit': 256}],
u'systemControls': [{'namespace': 'net.core.somaxconn', 'value': '511'}],
u'portMappings': [{'containerPort': 8080, 'hostPort': 8080}],
u'mountPoints': [{'sourceVolume': 'volume', 'containerPath': '/container/path', 'readOnly': False}]}
]
TASK_DEFINITION_FAMILY_2 = u'test-task'
TASK_DEFINITION_REVISION_2 = 2
TASK_DEFINITION_ARN_2 = u'arn:aws:ecs:eu-central-1:123456789012:task-definition/%s:%s' % (TASK_DEFINITION_FAMILY_2,
TASK_DEFINITION_REVISION_2)
TASK_DEFINITION_VOLUMES_2 = []
TASK_DEFINITION_CONTAINERS_2 = [
{u'name': u'webserver', u'image': u'webserver:123', u'command': u'run',
u'environment': ({"name": "foo", "value": "bar"}, {"name": "lorem", "value": "ipsum"}, {"name": "empty", "value": ""}),
u'environmentFiles': [{'value': 'arn:aws:s3:::myS3bucket/myApp/.env', 'type': 's3'}, {'value': 'arn:aws:s3:::coolBuckets/dev/.env', 'type': 's3'}],
u'secrets': ({"name": "baz", "valueFrom": "qux"}, {"name": "dolor", "valueFrom": "sit"}),
u'dockerLabels': {"foo": "bar", "lorem": "ipsum", "empty": ""},
u'logConfiguration': {},
u'ulimits': [{'name': 'memlock', 'softLimit': 256, 'hardLimit': 256}],
u'systemControls': [{'namespace': 'net.core.somaxconn', 'value': '511'}],
u'portMappings': [{'containerPort': 8080, 'hostPort': 8080}],
u'mountPoints': [{'sourceVolume': 'volume', 'containerPath': '/container/path', 'readOnly': False}]},
{u'name': u'application', u'image': u'application:123', u'command': u'run', u'environment': (),
u'logConfiguration': {}, u'dockerLabels': {},
u'ulimits': [{'name': 'memlock', 'softLimit': 256, 'hardLimit': 256}],
u'systemControls': [{'namespace': 'net.core.somaxconn', 'value': '511'}],
u'portMappings': [{'containerPort': 8080, 'hostPort': 8080}],
u'mountPoints': [{'sourceVolume': 'volume', 'containerPath': '/container/path', 'readOnly': False}]},
]
TASK_DEFINITION_REVISION_3 = 3
TASK_DEFINITION_ARN_3 = u'arn:aws:ecs:eu-central-1:123456789012:task-definition/%s:%s' % (TASK_DEFINITION_FAMILY_1,
TASK_DEFINITION_REVISION_3)
TASK_DEFINITION_VOLUMES_3 = []
TASK_DEFINITION_CONTAINERS_3 = [
{u'name': u'webserver', u'image': u'webserver:456', u'command': u'execute',
u'environment': ({"name": "foo", "value": "foobar"}, {"name": "newvar", "value": "new value"}),
u'secrets': ({"name": "baz", "valueFrom": "foobaz"}, {"name": "dolor", "valueFrom": "loremdolor"}),
u'dockerLabels': {"foo": "foobar", "newlabel": "new value"}},
{u'name': u'application', u'image': u'application:123', u'command': u'run', u'environment': ()}
]
TASK_DEFINITION_ROLE_ARN_3 = u'arn:test:another-role:1'
PAYLOAD_TASK_DEFINITION_1 = {
u'taskDefinitionArn': TASK_DEFINITION_ARN_1,
u'runtimePlatform': deepcopy(TASK_DEFINITION_RUNTIME_PLATFORM_1),
u'family': TASK_DEFINITION_FAMILY_1,
u'revision': TASK_DEFINITION_REVISION_1,
u'taskRoleArn': TASK_DEFINITION_ROLE_ARN_1,
u'executionRoleArn': TASK_DEFINITION_ROLE_ARN_1,
u'volumes': deepcopy(TASK_DEFINITION_VOLUMES_1),
u'containerDefinitions': deepcopy(TASK_DEFINITION_CONTAINERS_1),
u'status': u'active',
u'requiresAttributes': {},
u'networkMode': u'host',
u'placementConstraints': {},
u'registeredBy': 'foobar',
u'registeredAt': '2021-01-20T14:33:44Z',
u'deregisteredAt': '2021-01-20T14:33:44Z',
u'unknownProperty': u'lorem-ipsum',
u'compatibilities': [u'EC2'],
}
PAYLOAD_TASK_DEFINITION_2 = {
u'taskDefinitionArn': TASK_DEFINITION_ARN_2,
u'family': TASK_DEFINITION_FAMILY_2,
u'revision': TASK_DEFINITION_REVISION_2,
u'volumes': deepcopy(TASK_DEFINITION_VOLUMES_2),
u'containerDefinitions': deepcopy(TASK_DEFINITION_CONTAINERS_2),
u'status': u'active',
u'unknownProperty': u'lorem-ipsum',
u'compatibilities': [u'EC2'],
}
PAYLOAD_TASK_DEFINITION_3 = {
u'taskDefinitionArn': TASK_DEFINITION_ARN_3,
u'family': TASK_DEFINITION_FAMILY_1,
u'revision': TASK_DEFINITION_REVISION_3,
u'taskRoleArn': TASK_DEFINITION_ROLE_ARN_3,
u'executionRoleArn': TASK_DEFINITION_ROLE_ARN_3,
u'volumes': deepcopy(TASK_DEFINITION_VOLUMES_3),
u'containerDefinitions': deepcopy(TASK_DEFINITION_CONTAINERS_3),
u'status': u'active',
u'requiresAttributes': {},
u'networkMode': u'host',
u'placementConstraints': {},
u'unknownProperty': u'lorem-ipsum',
u'compatibilities': [u'EC2'],
}
TASK_ARN_1 = u'arn:aws:ecs:eu-central-1:123456789012:task/12345678-1234-1234-1234-123456789011'
TASK_ARN_2 = u'arn:aws:ecs:eu-central-1:123456789012:task/12345678-1234-1234-1234-123456789012'
PAYLOAD_TASK_1 = {
u'taskArn': TASK_ARN_1,
u'clusterArn': CLUSTER_ARN,
u'taskDefinitionArn': TASK_DEFINITION_ARN_1,
u'containerInstanceArn': u'arn:aws:ecs:eu-central-1:123456789012:container-instance/12345678-123456-123456-123456',
u'overrides': {u'containerOverrides': []},
u'lastStatus': u'RUNNING',
u'desiredStatus': u'RUNNING',
u'containers': TASK_DEFINITION_CONTAINERS_1,
u'startedBy': SERVICE_ARN
}
PAYLOAD_TASK_2 = {
u'taskArn': TASK_ARN_2,
u'clusterArn': CLUSTER_ARN,
u'taskDefinitionArn': TASK_DEFINITION_ARN_1,
u'containerInstanceArn': u'arn:aws:ecs:eu-central-1:123456789012:container-instance/12345678-123456-123456-123456',
u'overrides': {u'containerOverrides': []},
u'lastStatus': u'RUNNING',
u'desiredStatus': u'RUNNING',
u'containers': TASK_DEFINITION_CONTAINERS_1,
u'startedBy': SERVICE_ARN
}
PAYLOAD_DEPLOYMENTS = [
{
u'status': u'PRIMARY',
u'pendingCount': 0,
u'desiredCount': DESIRED_COUNT,
u'runningCount': DESIRED_COUNT,
u'taskDefinition': TASK_DEFINITION_ARN_1,
u'createdAt': datetime(2016, 3, 11, 12, 0, 0, 000000, tzinfo=tzlocal()),
u'updatedAt': datetime(2016, 3, 11, 12, 5, 0, 000000, tzinfo=tzlocal()),
u'id': u'ecs-svc/0000000000000000002',
u'rolloutState': u'COMPLETED',
u'rolloutStateReason': u'ECS deployment ecs-svc/5169280574093855189 completed.',
u'failedTasks': 0,
}
]
PAYLOAD_DEPLOYMENTS_IN_PROGRESS = [
{
u'status': u'PRIMARY',
u'pendingCount': 0,
u'desiredCount': DESIRED_COUNT,
u'runningCount': DESIRED_COUNT,
u'taskDefinition': TASK_DEFINITION_ARN_1,
u'createdAt': datetime(2016, 3, 11, 12, 0, 0, 000000, tzinfo=tzlocal()),
u'updatedAt': datetime(2016, 3, 11, 12, 5, 0, 000000, tzinfo=tzlocal()),
u'id': u'ecs-svc/0000000000000000002',
u'rolloutState': u'IN_PROGRESS',
u'rolloutStateReason': u'ECS deployment ecs-svc/5169280574093855189 in progress.',
u'failedTasks': 0,
},
{
u'status': u'ACTIVE',
u'pendingCount': 0,
u'desiredCount': DESIRED_COUNT,
u'runningCount': DESIRED_COUNT,
u'taskDefinition': TASK_DEFINITION_ARN_1,
u'createdAt': datetime(2016, 3, 11, 12, 0, 0, 000000, tzinfo=tzlocal()),
u'updatedAt': datetime(2016, 3, 11, 12, 5, 0, 000000, tzinfo=tzlocal()),
u'id': u'ecs-svc/0000000000000000002',
u'rolloutState': u'COMPLETED',
u'rolloutStateReason': u'ECS deployment ecs-svc/5169280574093855189 completed.',
u'failedTasks': 0,
}
]
PAYLOAD_DEPLOYMENTS_IN_PROGRESS_FAILED_TASKS = [
{
u'status': u'PRIMARY',
u'pendingCount': 0,
u'desiredCount': DESIRED_COUNT,
u'runningCount': DESIRED_COUNT,
u'taskDefinition': TASK_DEFINITION_ARN_1,
u'createdAt': datetime(2016, 3, 11, 12, 0, 0, 000000, tzinfo=tzlocal()),
u'updatedAt': datetime(2016, 3, 11, 12, 5, 0, 000000, tzinfo=tzlocal()),
u'id': u'ecs-svc/0000000000000000002',
u'rolloutState': u'IN_PROGRESS',
u'rolloutStateReason': u'ECS deployment ecs-svc/5169280574093855189 in progress.',
u'failedTasks': 3,
},
{
u'status': u'ACTIVE',
u'pendingCount': 0,
u'desiredCount': DESIRED_COUNT,
u'runningCount': DESIRED_COUNT,
u'taskDefinition': TASK_DEFINITION_ARN_1,
u'createdAt': datetime(2016, 3, 11, 12, 0, 0, 000000, tzinfo=tzlocal()),
u'updatedAt': datetime(2016, 3, 11, 12, 5, 0, 000000, tzinfo=tzlocal()),
u'id': u'ecs-svc/0000000000000000002',
u'rolloutState': u'COMPLETED',
u'rolloutStateReason': u'ECS deployment ecs-svc/5169280574093855189 completed.',
u'failedTasks': 0,
}
]
PAYLOAD_DEPLOYMENTS_FAILED = [
{
u'status': u'PRIMARY',
u'pendingCount': 0,
u'desiredCount': DESIRED_COUNT,
u'runningCount': DESIRED_COUNT,
u'taskDefinition': TASK_DEFINITION_ARN_1,
u'createdAt': datetime(2016, 3, 11, 12, 0, 0, 000000, tzinfo=tzlocal()),
u'updatedAt': datetime(2016, 3, 11, 12, 5, 0, 000000, tzinfo=tzlocal()),
u'id': u'ecs-svc/0000000000000000002',
u'rolloutState': u'FAILED',
u'rolloutStateReason': u'ECS deployment circuit breaker: tasks failed to start.',
u'failedTasks': 10,
},
{
u'status': u'ACTIVE',
u'pendingCount': 0,
u'desiredCount': DESIRED_COUNT,
u'runningCount': DESIRED_COUNT,
u'taskDefinition': TASK_DEFINITION_ARN_1,
u'createdAt': datetime(2016, 3, 11, 12, 0, 0, 000000, tzinfo=tzlocal()),
u'updatedAt': datetime(2016, 3, 11, 12, 5, 0, 000000, tzinfo=tzlocal()),
u'id': u'ecs-svc/0000000000000000002',
u'rolloutState': u'COMPLETED',
u'rolloutStateReason': u'ECS deployment ecs-svc/5169280574093855189 completed.',
u'failedTasks': 0,
}
]
PAYLOAD_DEPLOYMENTS_FAILED_ROLLBACK = [
{
u'status': u'PRIMARY',
u'pendingCount': 0,
u'desiredCount': DESIRED_COUNT,
u'runningCount': DESIRED_COUNT,
u'taskDefinition': TASK_DEFINITION_ARN_1,
u'createdAt': datetime(2016, 3, 11, 12, 0, 0, 000000, tzinfo=tzlocal()),
u'updatedAt': datetime(2016, 3, 11, 12, 5, 0, 000000, tzinfo=tzlocal()),
u'id': u'ecs-svc/0000000000000000002',
u'rolloutState': u'IN_PROGRESS',
u'rolloutStateReason': u'ECS deployment circuit breaker: rolling back to deploymentId ecs-svc/123456789012345',
},
{
u'status': u'ACTIVE',
u'pendingCount': 0,
u'desiredCount': DESIRED_COUNT,
u'runningCount': DESIRED_COUNT,
u'taskDefinition': TASK_DEFINITION_ARN_1,
u'createdAt': datetime(2016, 3, 11, 12, 0, 0, 000000, tzinfo=tzlocal()),
u'updatedAt': datetime(2016, 3, 11, 12, 5, 0, 000000, tzinfo=tzlocal()),
u'id': u'ecs-svc/0000000000000000002',
u'rolloutState': u'FAILED',
u'rolloutStateReason': u'ECS deployment circuit breaker: tasks failed to start.',
}
]
PAYLOAD_EVENTS = [
{
u'id': u'error',
u'createdAt': datetime.now(tz=tzlocal()),
u'message': u'Service was unable to Lorem Ipsum'
},
{
u'id': u'older_error',
u'createdAt': datetime(2016, 3, 11, 12, 0, 10, 000000, tzinfo=tzlocal()),
u'message': u'Service was unable to Lorem Ipsum'
}
]
PAYLOAD_SERVICE = {
u'serviceName': SERVICE_NAME,
u'desiredCount': DESIRED_COUNT,
u'taskDefinition': TASK_DEFINITION_ARN_1,
u'deployments': PAYLOAD_DEPLOYMENTS,
u'events': []
}
PAYLOAD_SERVICE_WITH_ERRORS = {
u'serviceName': SERVICE_NAME,
u'desiredCount': DESIRED_COUNT,
u'taskDefinition': TASK_DEFINITION_ARN_1,
u'deployments': PAYLOAD_DEPLOYMENTS,
u'events': PAYLOAD_EVENTS
}
PAYLOAD_SERVICE_WITHOUT_DEPLOYMENTS = {
u'serviceName': SERVICE_NAME,
u'desiredCount': DESIRED_COUNT,
u'taskDefinition': TASK_DEFINITION_ARN_1,
u'deployments': [],
u'events': []
}
PAYLOAD_SERVICE_WITHOUT_DEPLOYMENT_IN_PROGRESS = {
u'serviceName': SERVICE_NAME,
u'desiredCount': DESIRED_COUNT,
u'taskDefinition': TASK_DEFINITION_ARN_1,
u'deployments': PAYLOAD_DEPLOYMENTS_IN_PROGRESS,
u'events': []
}
PAYLOAD_SERVICE_WITHOUT_DEPLOYMENT_IN_PROGRESS_FAILED_TASKS = {
u'serviceName': SERVICE_NAME,
u'desiredCount': DESIRED_COUNT,
u'taskDefinition': TASK_DEFINITION_ARN_1,
u'deployments': PAYLOAD_DEPLOYMENTS_IN_PROGRESS_FAILED_TASKS,
u'events': []
}
PAYLOAD_SERVICE_WITHOUT_DEPLOYMENT_FAILED_NO_ROLLBACK = {
u'serviceName': SERVICE_NAME,
u'desiredCount': DESIRED_COUNT,
u'taskDefinition': TASK_DEFINITION_ARN_1,
u'deployments': PAYLOAD_DEPLOYMENTS_FAILED,
u'events': []
}
PAYLOAD_SERVICE_WITHOUT_DEPLOYMENT_FAILED_WITH_ROLLBACK = {
u'serviceName': SERVICE_NAME,
u'desiredCount': DESIRED_COUNT,
u'taskDefinition': TASK_DEFINITION_ARN_1,
u'deployments': PAYLOAD_DEPLOYMENTS_FAILED_ROLLBACK,
u'events': []
}
RESPONSE_SERVICE = {
u"service": PAYLOAD_SERVICE
}
RESPONSE_SERVICE_WITH_ERRORS = {
u"service": PAYLOAD_SERVICE_WITH_ERRORS
}
RESPONSE_DESCRIBE_SERVICES = {
u"services": [PAYLOAD_SERVICE]
}
RESPONSE_TASK_DEFINITION = {
u"taskDefinition": PAYLOAD_TASK_DEFINITION_1
}
RESPONSE_TASK_DEFINITION_2 = {
u"taskDefinition": PAYLOAD_TASK_DEFINITION_2
}
RESPONSE_TASK_DEFINITION_3 = {
u"taskDefinition": PAYLOAD_TASK_DEFINITION_3
}
RESPONSE_TASK_DEFINITIONS = {
TASK_DEFINITION_ARN_1: RESPONSE_TASK_DEFINITION,
TASK_DEFINITION_ARN_2: RESPONSE_TASK_DEFINITION_2,
TASK_DEFINITION_ARN_3: RESPONSE_TASK_DEFINITION_3,
u'test-task:1': RESPONSE_TASK_DEFINITION,
u'test-task:2': RESPONSE_TASK_DEFINITION_2,
u'test-task:3': RESPONSE_TASK_DEFINITION_3,
u'test-task': RESPONSE_TASK_DEFINITION_2,
}
RESPONSE_LIST_TASKS_2 = [TASK_ARN_1, TASK_ARN_2]
RESPONSE_LIST_TASKS_1 = [TASK_ARN_1]
RESPONSE_LIST_TASKS_0 = []
RESPONSE_DESCRIBE_TASKS = [PAYLOAD_TASK_1, PAYLOAD_TASK_2]
@pytest.fixture()
def task_definition():
return EcsTaskDefinition(**deepcopy(PAYLOAD_TASK_DEFINITION_1))
@pytest.fixture
def task_definition_revision_2():
return EcsTaskDefinition(**deepcopy(PAYLOAD_TASK_DEFINITION_2))
@pytest.fixture
def service():
return EcsService(CLUSTER_NAME, deepcopy(PAYLOAD_SERVICE))
@pytest.fixture
def service_with_errors():
return EcsService(CLUSTER_NAME, deepcopy(PAYLOAD_SERVICE_WITH_ERRORS))
@pytest.fixture
def service_without_deployments():
return EcsService(CLUSTER_NAME, deepcopy(PAYLOAD_SERVICE_WITHOUT_DEPLOYMENTS))
@pytest.fixture
def service_with_failed_deployment():
return EcsService(CLUSTER_NAME, deepcopy(PAYLOAD_SERVICE_WITHOUT_DEPLOYMENT_FAILED_NO_ROLLBACK))
@pytest.fixture
def service_with_failed_tasks():
return EcsService(CLUSTER_NAME, deepcopy(PAYLOAD_SERVICE_WITHOUT_DEPLOYMENT_IN_PROGRESS_FAILED_TASKS))
def test_service_init(service):
assert isinstance(service, dict)
assert service.cluster == CLUSTER_NAME
assert service[u'desiredCount'] == DESIRED_COUNT
assert service[u'taskDefinition'] == TASK_DEFINITION_ARN_1
def test_service_set_task_definition(service, task_definition):
assert service.task_definition == TASK_DEFINITION_ARN_1
service.set_task_definition(task_definition)
assert service.task_definition == task_definition.arn
def test_service_name(service):
assert service.name == SERVICE_NAME
def test_service_deployment_created_at(service):
assert service.deployment_created_at == datetime(2016, 3, 11, 12, 00, 00, 000000, tzinfo=tzlocal())
def test_service_deployment_updated_at(service):
assert service.deployment_updated_at == datetime(2016, 3, 11, 12, 5, 00, 000000, tzinfo=tzlocal())
def test_service_deployment_created_at_without_deployments(service_without_deployments):
now = datetime.now()
assert service_without_deployments.deployment_created_at >= now
assert service_without_deployments.deployment_created_at <= datetime.now()
def test_service_deployment_updated_at_without_deployments(service_without_deployments):
now = datetime.now()
assert service_without_deployments.deployment_updated_at >= now
assert service_without_deployments.deployment_updated_at <= datetime.now()
def test_service_errors(service_with_errors):
assert len(service_with_errors.errors) == 1
def test_service_older_errors(service_with_errors):
assert len(service_with_errors.older_errors) == 1
def test_task_family(task_definition):
assert task_definition.family == TASK_DEFINITION_FAMILY_1
def test_task_containers(task_definition):
assert task_definition.containers == TASK_DEFINITION_CONTAINERS_2
def test_task_container_names(task_definition):
assert u'webserver' in task_definition.container_names
assert u'application' in task_definition.container_names
assert u'foobar' not in task_definition.container_names
def test_task_volumes(task_definition):
assert task_definition.volumes == TASK_DEFINITION_VOLUMES_2
def test_task_revision(task_definition):
assert task_definition.revision == TASK_DEFINITION_REVISION_1
def test_task_no_diff(task_definition):
assert task_definition.diff == []
def test_task_image_diff(task_definition):
task_definition.set_images(u'foobar')
assert len(task_definition.diff) == 2
for diff in task_definition.diff:
assert isinstance(diff, EcsTaskDefinitionDiff)
def test_task_set_tag(task_definition):
task_definition.set_images(u'foobar')
for container in task_definition.containers:
assert container[u'image'].endswith(u':foobar')
def test_task_set_image(task_definition):
task_definition.set_images(webserver=u'new-image:123', application=u'app-image:latest')
for container in task_definition.containers:
if container[u'name'] == u'webserver':
assert container[u'image'] == u'new-image:123'
if container[u'name'] == u'application':
assert container[u'image'] == u'app-image:latest'
def test_task_set_cpu(task_definition):
task_definition.set_cpu(webserver=10, application=0)
for container in task_definition.containers:
if container[u'name'] == u'webserver':
assert container[u'cpu'] == 10
if container[u'name'] == u'application':
assert container[u'cpu'] == 0
def test_task_set_memory(task_definition):
task_definition.set_memory(webserver=256, application=128)
for container in task_definition.containers:
if container[u'name'] == u'webserver':
assert container[u'memory'] == 256
if container[u'name'] == u'application':
assert container[u'memory'] == 128
def test_task_set_memoryreservation(task_definition):
task_definition.set_memoryreservation(webserver=128, application=64)
for container in task_definition.containers:
if container[u'name'] == u'webserver':
assert container[u'memoryReservation'] == 128
if container[u'name'] == u'application':
assert container[u'memoryReservation'] == 64
def test_task_set_privileged(task_definition):
task_definition.set_privileged(webserver=False, application=True)
for container in task_definition.containers:
if container[u'name'] == u'webserver':
assert container[u'privileged'] == False
if container[u'name'] == u'application':
assert container[u'privileged'] == True
def test_task_set_log_configurations(task_definition):
assert len(task_definition.containers[0]['logConfiguration']) == 0
task_definition.set_log_configurations(((u'webserver', u'awslogs', u'awslogs-group', u'service_logs'), (u'webserver', u'awslogs', u'awslogs-region', u'eu-central-1')))
assert len(task_definition.containers[0]['logConfiguration']) > 0
assert('logDriver' in task_definition.containers[0]['logConfiguration'])
assert 'awslogs' == task_definition.containers[0]['logConfiguration']['logDriver']
assert 'options' in task_definition.containers[0]['logConfiguration']
assert 'awslogs-group' in task_definition.containers[0]['logConfiguration']['options']
assert 'service_logs' == task_definition.containers[0]['logConfiguration']['options']['awslogs-group']
assert 'awslogs-region' in task_definition.containers[0]['logConfiguration']['options']
assert 'eu-central-1' == task_definition.containers[0]['logConfiguration']['options']['awslogs-region']
def test_task_set_log_configurations_no_changes(task_definition):
assert len(task_definition.containers[0]['logConfiguration']) == 0
task_definition.set_log_configurations(((u'webserver', u'awslogs', u'awslogs-group', u'service_logs'), (u'webserver', u'awslogs', u'awslogs-region', u'eu-central-1')))
# deploy without log configurations does not change the previous configuration
# needs to be actively changed
task_definition.set_log_configurations(())
assert len(task_definition.containers[0]['logConfiguration']) > 0
assert('logDriver' in task_definition.containers[0]['logConfiguration'])
assert 'awslogs' == task_definition.containers[0]['logConfiguration']['logDriver']
assert 'options' in task_definition.containers[0]['logConfiguration']
assert 'awslogs-group' in task_definition.containers[0]['logConfiguration']['options']
assert 'service_logs' == task_definition.containers[0]['logConfiguration']['options']['awslogs-group']
assert 'awslogs-region' in task_definition.containers[0]['logConfiguration']['options']
assert 'eu-central-1' == task_definition.containers[0]['logConfiguration']['options']['awslogs-region']
def test_task_set_environment(task_definition):
assert len(task_definition.containers[0]['environment']) == 3
task_definition.set_environment(((u'webserver', u'foo', u'baz'), (u'webserver', u'some-name', u'some-value')))
assert len(task_definition.containers[0]['environment']) == 4
assert {'name': 'lorem', 'value': 'ipsum'} in task_definition.containers[0]['environment']
assert {'name': 'foo', 'value': 'baz'} in task_definition.containers[0]['environment']
assert {'name': 'some-name', 'value': 'some-value'} in task_definition.containers[0]['environment']
def test_read_env_file_wrong_env_format():
tmp = tempfile.NamedTemporaryFile(delete=False)
tmp.write(b'#comment\n \nIncompleteDescription')
tmp.read()
l = read_env_file('webserver',tmp.name)
os.unlink(tmp.name)
tmp.close()
assert l == ()
def test_env_file_wrong_file_name():
with pytest.raises(EcsTaskDefinitionCommandError):
read_env_file('webserver','WrongFileName')
def test_task_set_environment_from_e_and_env_file(task_definition):
assert len(task_definition.containers[0]['environment']) == 3
tmp = tempfile.NamedTemporaryFile(delete=False)
tmp.write(b'some-name-from-env-file=some-value-from-env-file')
tmp.read()
task_definition.set_environment(((u'webserver', u'foo', u'baz'), (u'webserver', u'some-name', u'some-value')), env_file = ((u'webserver',tmp.name),))
os.unlink(tmp.name)
tmp.close()
assert len(task_definition.containers[0]['environment']) == 5
assert {'name': 'lorem', 'value': 'ipsum'} in task_definition.containers[0]['environment']
assert {'name': 'foo', 'value': 'baz'} in task_definition.containers[0]['environment']
assert {'name': 'some-name', 'value': 'some-value'} in task_definition.containers[0]['environment']
assert {'name': 'some-name-from-env-file', 'value': 'some-value-from-env-file'} in task_definition.containers[0]['environment']
def test_task_set_environment_from_env_file(task_definition):
assert len(task_definition.containers[0]['environment']) == 3
tmp = tempfile.NamedTemporaryFile(delete=False)
tmp.write(b'some-name-from-env-file=some-value-from-env-file')
tmp.read()
task_definition.set_environment((), env_file = ((u'webserver',tmp.name),))
os.unlink(tmp.name)
tmp.close()
assert len(task_definition.containers[0]['environment']) == 4
assert {'name': 'lorem', 'value': 'ipsum'} in task_definition.containers[0]['environment']
assert {'name': 'some-name-from-env-file', 'value': 'some-value-from-env-file'} in task_definition.containers[0]['environment']
def test_task_set_environment_exclusively(task_definition):
assert len(task_definition.containers[0]['environment']) == 3
assert len(task_definition.containers[1]['environment']) == 0
task_definition.set_environment(((u'application', u'foo', u'baz'), (u'application', u'new-var', u'new-value')), exclusive=True)
assert len(task_definition.containers[0]['environment']) == 0
assert len(task_definition.containers[1]['environment']) == 2
assert task_definition.containers[0]['environment'] == []
assert {'name': 'foo', 'value': 'baz'} in task_definition.containers[1]['environment']
assert {'name': 'new-var', 'value': 'new-value'} in task_definition.containers[1]['environment']
def test_task_set_docker_labels(task_definition):
assert len(task_definition.containers[0]['dockerLabels']) == 3
task_definition.set_docker_labels(((u'webserver', u'foo', u'baz'), (u'webserver', u'some-name', u'some-value')))
assert len(task_definition.containers[0]['dockerLabels']) == 4
assert 'foo' in task_definition.containers[0]['dockerLabels']
assert 'lorem' in task_definition.containers[0]['dockerLabels']
assert 'some-name' in task_definition.containers[0]['dockerLabels']
def test_task_set_docker_label_exclusively(task_definition):
assert len(task_definition.containers[0]['dockerLabels']) == 3
assert len(task_definition.containers[1]['dockerLabels']) == 0
task_definition.set_docker_labels(((u'application', u'foo', u'baz'), (u'application', u'new-var', u'new-value')), exclusive=True)
assert len(task_definition.containers[0]['dockerLabels']) == 0
assert len(task_definition.containers[1]['dockerLabels']) == 2
assert task_definition.containers[0]['dockerLabels'] == {}
assert 'foo' in task_definition.containers[1]['dockerLabels']
assert 'new-var' in task_definition.containers[1]['dockerLabels']
def test_task_set_s3_env_file_multiple_files(task_definition):
assert len(task_definition.containers[0]['environmentFiles']) == 2
task_definition.set_s3_env_file(((u'webserver', u'arn:aws:s3:::mycompany.domain.com/app/.env'), (u'webserver', u'arn:aws:s3:::melted.cheese.com/grilled/.env'), (u'proxyserver', u'arn:ars:s3:::pizza/dev/.env')))
assert len(task_definition.containers[0]['environmentFiles']) == 4
assert {'value': 'arn:aws:s3:::mycompany.domain.com/app/.env', 'type': 's3'} in task_definition.containers[0]['environmentFiles']
assert {'value': 'arn:aws:s3:::myS3bucket/myApp/.env', 'type': 's3'} in task_definition.containers[0]['environmentFiles']
assert {'value': 'arn:aws:s3:::coolBuckets/dev/.env', 'type': 's3'} in task_definition.containers[0]['environmentFiles']
assert {'value': 'arn:aws:s3:::melted.cheese.com/grilled/.env', 'type': 's3'} in task_definition.containers[0]['environmentFiles']
def test_task_set_s3_env_file_single_file(task_definition):
assert len(task_definition.containers[0]['environmentFiles']) == 2
task_definition.set_s3_env_file(((u'webserver', u'arn:aws:s3:::mycompany.domain.com/app/.env')))
assert len(task_definition.containers[0]['environmentFiles']) == 3
# assert {'value': 'arn:aws:s3:::mycompany.domain.com/app/.env', 'type': 's3'} in task_definition.containers[0]['environmentFiles']
def test_task_set_s3_env_file_exclusively(task_definition):
assert len(task_definition.containers[0]['environmentFiles']) == 2
task_definition.set_s3_env_file((u'webserver', u'arn:aws:s3:::mycompany.domain.com/app/.env'), exclusive=True)
assert len(task_definition.containers[0]['environmentFiles']) == 1
assert {'value': 'arn:aws:s3:::mycompany.domain.com/app/.env', 'type': 's3'} in task_definition.containers[0]['environmentFiles']
def test_task_set_secrets_exclusively(task_definition):
assert len(task_definition.containers[0]['secrets']) == 2
task_definition.set_secrets(((u'webserver', u'new-secret', u'another-place'), ), exclusive=True)
assert len(task_definition.containers[0]['secrets']) == 1
assert {'name': 'new-secret', 'valueFrom': 'another-place'} in task_definition.containers[0]['secrets']
def test_task_set_secrets(task_definition):
task_definition.set_secrets(((u'webserver', u'foo', u'baz'), (u'webserver', u'some-name', u'some-value')))
assert {'name': 'dolor', 'valueFrom': 'sit'} in task_definition.containers[0]['secrets']
assert {'name': 'foo', 'valueFrom': 'baz'} in task_definition.containers[0]['secrets']
assert {'name': 'some-name', 'valueFrom': 'some-value'} in task_definition.containers[0]['secrets']
def test_task_set_system_controls(task_definition):
assert len(task_definition.containers[0]['systemControls']) == 1
task_definition.set_system_controls(((u'webserver', u'net.core.somaxconn', u'511'), (u'webserver',u'net.ipv4.ip_forward', u'1')))
assert len(task_definition.containers[0]['systemControls']) == 2
assert {'namespace': 'net.core.somaxconn', 'value': '511'} in task_definition.containers[0]['systemControls']
assert {'namespace': 'net.ipv4.ip_forward', 'value': '1'} in task_definition.containers[0]['systemControls']
def test_task_set_system_controls_existing_not_set_again(task_definition):
assert len(task_definition.containers[0]['systemControls']) == 1
task_definition.set_system_controls(((u'webserver', u'net.ipv4.ip_forward', u'1'), ))
assert len(task_definition.containers[0]['systemControls']) == 2
assert {'namespace': 'net.core.somaxconn', 'value': '511'} in task_definition.containers[0]['systemControls']
assert {'namespace': 'net.ipv4.ip_forward', 'value': '1'} in task_definition.containers[0]['systemControls']
def test_task_set_system_controlsts_exclusively(task_definition):
assert len(task_definition.containers[0]['systemControls']) == 1
assert 'net.core.somaxconn' == task_definition.containers[0]['systemControls'][0]['namespace']
task_definition.set_system_controls(((u'webserver', u'net.ipv4.ip_forward', u'1'),), exclusive=True)
assert len(task_definition.containers[0]['systemControls']) == 1
assert 'net.ipv4.ip_forward' == task_definition.containers[0]['systemControls'][0]['namespace']
assert {'namespace': 'net.ipv4.ip_forward', 'value': '1'} in task_definition.containers[0]['systemControls']
def test_task_set_ulimits(task_definition):
assert len(task_definition.containers[0]['ulimits']) == 1
task_definition.set_ulimits(((u'webserver', u'memlock', 256, 257), (u'webserver', u'cpu', 80, 85)))
assert len(task_definition.containers[0]['ulimits']) == 2
assert {'name': 'memlock', 'softLimit': 256, 'hardLimit': 257} in task_definition.containers[0]['ulimits']
assert {'name': 'cpu', 'softLimit': 80, 'hardLimit': 85} in task_definition.containers[0]['ulimits']
def test_task_set_ulimits_existing_not_set_again(task_definition):
assert len(task_definition.containers[0]['ulimits']) == 1
task_definition.set_ulimits(((u'webserver', u'cpu', 80, 85), ))
assert len(task_definition.containers[0]['ulimits']) == 2
assert {'name': 'memlock', 'softLimit': 256, 'hardLimit': 256} in task_definition.containers[0]['ulimits']
assert {'name': 'cpu', 'softLimit': 80, 'hardLimit': 85} in task_definition.containers[0]['ulimits']
def test_task_set_ulimits_exclusively(task_definition):
assert len(task_definition.containers[0]['ulimits']) == 1
assert 'memlock' == task_definition.containers[0]['ulimits'][0]['name']
task_definition.set_ulimits(((u'webserver', u'cpu', 80, 85),), exclusive=True)
assert len(task_definition.containers[0]['ulimits']) == 1
assert 'cpu' == task_definition.containers[0]['ulimits'][0]['name']
assert {'name': 'cpu', 'softLimit': 80, 'hardLimit': 85} in task_definition.containers[0]['ulimits']
def test_task_set_port_mappings(task_definition):
assert len(task_definition.containers[0]['portMappings']) == 1
assert 8080 == task_definition.containers[0]['portMappings'][0]['containerPort']
task_definition.set_port_mappings(((u'webserver', 8080, 8080), (u'webserver', 81, 80)))
assert len(task_definition.containers[0]['portMappings']) == 2
assert {'containerPort': 8080, 'hostPort': 8080, 'protocol': 'tcp'} in task_definition.containers[0]['portMappings']
assert {'containerPort': 81, 'hostPort': 80, 'protocol': 'tcp'} in task_definition.containers[0]['portMappings']
def test_task_set_port_mappings_exclusively(task_definition):
assert len(task_definition.containers[0]['portMappings']) == 1
assert 8080 == task_definition.containers[0]['portMappings'][0]['containerPort']
task_definition.set_port_mappings(((u'webserver', 81, 80),), exclusive=True)
assert len(task_definition.containers[0]['portMappings']) == 1
assert 81 == task_definition.containers[0]['portMappings'][0]['containerPort']
assert {'containerPort': 81, 'hostPort': 80, 'protocol': 'tcp'} in task_definition.containers[0]['portMappings']
def test_task_set_mount_points(task_definition):
assert len(task_definition.containers[0]['mountPoints']) == 1
assert '/container/path' == task_definition.containers[0]['mountPoints'][0]['containerPath']
task_definition.set_mount_points(((u'webserver', u'volume', u'/data/path'), (u'webserver', u'another_volume', u'/logs/path')))
assert len(task_definition.containers[0]['mountPoints']) == 2
assert {'sourceVolume': 'volume', 'containerPath': '/data/path', 'readOnly': False} in task_definition.containers[0]['mountPoints']
assert {'sourceVolume': 'another_volume', 'containerPath': '/logs/path', 'readOnly': False} in task_definition.containers[0]['mountPoints']
def test_task_set_mount_points_exclusively(task_definition):
assert len(task_definition.containers[0]['mountPoints']) == 1
assert '/container/path' == task_definition.containers[0]['mountPoints'][0]['containerPath']
assert 'volume' == task_definition.containers[0]['mountPoints'][0]['sourceVolume']
task_definition.set_mount_points(((u'webserver', u'another_volume', u'/logs/path'),), exclusive=True)
assert len(task_definition.containers[0]['mountPoints']) == 1
assert '/logs/path' == task_definition.containers[0]['mountPoints'][0]['containerPath']
assert 'another_volume' == task_definition.containers[0]['mountPoints'][0]['sourceVolume']
assert {'sourceVolume': 'another_volume', 'containerPath': '/logs/path', 'readOnly': False} in task_definition.containers[0]['mountPoints']
def test_task_set_image_for_unknown_container(task_definition):
with pytest.raises(UnknownContainerError):
task_definition.set_images(foobar=u'new-image:123')
def test_task_set_command(task_definition):
task_definition.set_commands(webserver=u'run-webserver', application=u'run-application')
for container in task_definition.containers:
if container[u'name'] == u'webserver':
assert container[u'command'] == [u'run-webserver']
if container[u'name'] == u'application':
assert container[u'command'] == [u'run-application']
def test_task_set_command_with_multiple_arguments(task_definition):
task_definition.set_commands(webserver=u'run-webserver arg1 arg2', application=u'run-application arg1 arg2')
for container in task_definition.containers:
if container[u'name'] == u'webserver':
assert container[u'command'] == [u'run-webserver', u'arg1', u'arg2']
if container[u'name'] == u'application':
assert container[u'command'] == [u'run-application', u'arg1', u'arg2']
def test_task_set_command_with_empty_argument(task_definition):
empty_argument = " "
task_definition.set_commands(webserver=empty_argument + u'run-webserver arg1 arg2')
for container in task_definition.containers:
if container[u'name'] == u'webserver':
assert container[u'command'] == [u'run-webserver', u'arg1', u'arg2']
def test_task_set_command_as_json_list(task_definition):
task_definition.set_commands(webserver=u'["run-webserver", "arg1", "arg2"]', application=u'["run-application", "arg1", "arg2"]')
for container in task_definition.containers:
if container[u'name'] == u'webserver':
assert container[u'command'] == [u'run-webserver', u'arg1', u'arg2']
if container[u'name'] == u'application':
assert container[u'command'] == [u'run-application', u'arg1', u'arg2']
def test_task_set_command_as_invalid_json_list(task_definition):
with pytest.raises(EcsTaskDefinitionCommandError):
task_definition.set_commands(webserver=u'["run-webserver, "arg1" arg2"]', application=u'["run-application" "arg1 "arg2"]')
def test_task_set_command_for_unknown_container(task_definition):
with pytest.raises(UnknownContainerError):
task_definition.set_images(foobar=u'run-foobar')
class TestSetHealthChecks:
@pytest.mark.parametrize(
'webserver_health_check, application_health_check',
(
(
(u'webserver', u'curl -f http://webserver/alive/', 30, 5, 3, 0),
(u'application', u'curl -f http://application/alive/', 60, 10, 6, 5)
),
(
(u'webserver', u'curl -f http://webserver/alive/', 30, 5, 3, 0),
(u'application', u'curl -f http://application/alive/', 60, 10, 6, 5)
)
)
)
def test_success(self, webserver_health_check, application_health_check, task_definition):
task_definition.set_health_checks((
webserver_health_check,
application_health_check,
))
for container in task_definition.containers:
if container[u'name'] == u'webserver':
assert container[u'healthCheck'] == {
u'command': [u'CMD-SHELL', u'curl -f http://webserver/alive/'],
u'interval': 30,
u'timeout': 5,
u'retries': 3,
u'startPeriod': 0
}
if container[u'name'] == u'application':
assert container[u'healthCheck'] == {
u'command': [u'CMD-SHELL', u'curl -f http://application/alive/'],
u'interval': 60,
u'timeout': 10,
u'retries': 6,
u'startPeriod': 5
}
def test_unknown_container(self, task_definition):
with pytest.raises(UnknownContainerError):
task_definition.set_health_checks(((u'foobar', u'curl -f http://application/alive/', 60, 10, 6, 5),))
def test_task_get_overrides(task_definition):
assert task_definition.get_overrides() == []
def test_task_get_overrides_with_command(task_definition):
task_definition.set_commands(webserver='/usr/bin/python script.py')
overrides = task_definition.get_overrides()
assert len(overrides) == 1
assert overrides[0]['command'] == ['/usr/bin/python','script.py']
def test_task_get_overrides_with_environment(task_definition):
task_definition.set_environment((('webserver', 'foo', 'baz'),))
overrides = task_definition.get_overrides()
assert len(overrides) == 1
assert overrides[0]['name'] == 'webserver'
assert dict(name='foo', value='baz') in overrides[0]['environment']
def test_task_get_overrides_with_docker_labels(task_definition):
task_definition.set_docker_labels((('webserver', 'foo', 'baz'),))
overrides = task_definition.get_overrides()
assert len(overrides) == 1
assert overrides[0]['name'] == 'webserver'
#assert 'foo' in overrides[0]['dockerLabels']
assert overrides[0]['dockerLabels']['foo'] == 'baz'
def test_task_get_overrides_with_secrets(task_definition):
task_definition.set_secrets((('webserver', 'foo', 'baz'),))
overrides = task_definition.get_overrides()
assert len(overrides) == 1
assert overrides[0]['name'] == 'webserver'
assert dict(name='foo', valueFrom='baz') in overrides[0]['secrets']
def test_task_get_overrides_with_command_environment_and_secrets(task_definition):
task_definition.set_commands(webserver='/usr/bin/python script.py')
task_definition.set_environment((('webserver', 'foo', 'baz'),))
task_definition.set_secrets((('webserver', 'bar', 'qux'),))
overrides = task_definition.get_overrides()
assert len(overrides) == 1
assert overrides[0]['name'] == 'webserver'
assert overrides[0]['command'] == ['/usr/bin/python','script.py']
assert dict(name='foo', value='baz') in overrides[0]['environment']
assert dict(name='bar', valueFrom='qux') in overrides[0]['secrets']
def test_task_get_overrides_with_command_secrets_and_environment_for_multiple_containers(task_definition):
task_definition.set_commands(application='/usr/bin/python script.py')
task_definition.set_environment((('webserver', 'foo', 'baz'),))
task_definition.set_secrets((('webserver', 'bar', 'qux'),))
overrides = task_definition.get_overrides()
assert len(overrides) == 2
assert overrides[0]['name'] == 'application'
assert overrides[0]['command'] == ['/usr/bin/python','script.py']
assert overrides[1]['name'] == 'webserver'
assert dict(name='foo', value='baz') in overrides[1]['environment']
assert dict(name='bar', valueFrom='qux') in overrides[1]['secrets']
def test_task_get_overrides_command(task_definition):
command = task_definition.get_overrides_command('/usr/bin/python script.py')
assert isinstance(command, list)
assert command == ['/usr/bin/python','script.py']