@@ -172,8 +172,10 @@ def test_wait_end_tasks(self):
172
172
173
173
self .ecs ._wait_for_task_ended ()
174
174
client_mock .get_waiter .assert_called_once_with ('tasks_stopped' )
175
- client_mock .get_waiter .return_value .wait .assert_called_once_with (cluster = 'c' , tasks = ['arn' ])
176
- self .assertEquals (sys .maxsize , client_mock .get_waiter .return_value .config .max_attempts )
175
+ client_mock .get_waiter .return_value .wait .assert_called_once_with (
176
+ cluster = 'c' , tasks = ['arn' ])
177
+ self .assertEquals (
178
+ sys .maxsize , client_mock .get_waiter .return_value .config .max_attempts )
177
179
178
180
def test_check_success_tasks_raises (self ):
179
181
client_mock = mock .Mock ()
@@ -197,7 +199,8 @@ def test_check_success_tasks_raises(self):
197
199
self .assertIn ("'name': 'foo'" , str (e .exception ))
198
200
self .assertIn ("'lastStatus': 'STOPPED'" , str (e .exception ))
199
201
self .assertIn ("'exitCode': 1" , str (e .exception ))
200
- client_mock .describe_tasks .assert_called_once_with (cluster = 'c' , tasks = ['arn' ])
202
+ client_mock .describe_tasks .assert_called_once_with (
203
+ cluster = 'c' , tasks = ['arn' ])
201
204
202
205
def test_check_success_tasks_raises_pending (self ):
203
206
client_mock = mock .Mock ()
@@ -217,7 +220,8 @@ def test_check_success_tasks_raises_pending(self):
217
220
self .assertIn ("This task is still pending " , str (e .exception ))
218
221
self .assertIn ("'name': 'container-name'" , str (e .exception ))
219
222
self .assertIn ("'lastStatus': 'PENDING'" , str (e .exception ))
220
- client_mock .describe_tasks .assert_called_once_with (cluster = 'c' , tasks = ['arn' ])
223
+ client_mock .describe_tasks .assert_called_once_with (
224
+ cluster = 'c' , tasks = ['arn' ])
221
225
222
226
def test_check_success_tasks_raises_multiple (self ):
223
227
client_mock = mock .Mock ()
@@ -236,7 +240,42 @@ def test_check_success_tasks_raises_multiple(self):
236
240
}]
237
241
}
238
242
self .ecs ._check_success_task ()
239
- client_mock .describe_tasks .assert_called_once_with (cluster = 'c' , tasks = ['arn' ])
243
+ client_mock .describe_tasks .assert_called_once_with (
244
+ cluster = 'c' , tasks = ['arn' ])
245
+
246
+ def test_host_terminated_raises (self ):
247
+ client_mock = mock .Mock ()
248
+ self .ecs .client = client_mock
249
+ self .ecs .arn = 'arn'
250
+ client_mock .describe_tasks .return_value = {
251
+ 'tasks' : [{
252
+ 'stoppedReason' : 'Host EC2 (instance i-1234567890abcdef) terminated.' ,
253
+ "containers" : [
254
+ {
255
+ "containerArn" : "arn:aws:ecs:us-east-1:012345678910:container/e1ed7aac-d9b2-4315-8726-d2432bf11868" , # noqa: E501
256
+ "lastStatus" : "RUNNING" ,
257
+ "name" : "wordpress" ,
258
+ "taskArn" : "arn:aws:ecs:us-east-1:012345678910:task/d8c67b3c-ac87-4ffe-a847-4785bc3a8b55" # noqa: E501
259
+ }
260
+ ],
261
+ "desiredStatus" : "STOPPED" ,
262
+ "lastStatus" : "STOPPED" ,
263
+ "taskArn" : "arn:aws:ecs:us-east-1:012345678910:task/d8c67b3c-ac87-4ffe-a847-4785bc3a8b55" , # noqa: E501
264
+ "taskDefinitionArn" : "arn:aws:ecs:us-east-1:012345678910:task-definition/hello_world:11" # noqa: E501
265
+
266
+ }]
267
+ }
268
+
269
+ with self .assertRaises (AirflowException ) as e :
270
+ self .ecs ._check_success_task ()
271
+
272
+ self .assertIn (
273
+ "The task was stopped because the host instance terminated:" ,
274
+ str (e .exception ))
275
+ self .assertIn ("Host EC2 (" , str (e .exception ))
276
+ self .assertIn (") terminated" , str (e .exception ))
277
+ client_mock .describe_tasks .assert_called_once_with (
278
+ cluster = 'c' , tasks = ['arn' ])
240
279
241
280
def test_check_success_task_not_raises (self ):
242
281
client_mock = mock .Mock ()
@@ -252,7 +291,8 @@ def test_check_success_task_not_raises(self):
252
291
}]
253
292
}
254
293
self .ecs ._check_success_task ()
255
- client_mock .describe_tasks .assert_called_once_with (cluster = 'c' , tasks = ['arn' ])
294
+ client_mock .describe_tasks .assert_called_once_with (
295
+ cluster = 'c' , tasks = ['arn' ])
256
296
257
297
258
298
if __name__ == '__main__' :
0 commit comments