def test_get_running_tasks(self, mock_logger, mock_session, event_no_cache): cid = ContainerInstanceDrainer(event_no_cache, None) expected_tasks = ['task1', 'task2'] cid.ecs_client.list_tasks = Mock( return_value={'taskArns': expected_tasks}) rv = cid.get_running_tasks('SomeCluster', 'SomeCiArn') cid.ecs_client.list_tasks.assert_called_with( cluster='SomeCluster', containerInstance='SomeCiArn') assert rv == expected_tasks
def test_run_with_no_tasks_running(self, mock_logger, mock_session, event_no_cache): cid = ContainerInstanceDrainer(event_no_cache, None) cid._sleep = Mock() cid.get_ecs_details = Mock(return_value=('SomeCluster', 'SomeCiArn')) cid.set_draining = Mock() cid.get_running_tasks = Mock(return_value=[]) cid.complete_hook = Mock() cid.run() cid.get_ecs_details.assert_called_with('EC2InstanceIdFromMessage') cid.set_draining.assert_called_with('SomeCluster', 'SomeCiArn') cid.get_running_tasks.assert_called_with('SomeCluster', 'SomeCiArn') cid.complete_hook.assert_called()
def test_run_sad_ecs_details(self, mock_logger, mock_session, event_no_cache): cid = ContainerInstanceDrainer(event_no_cache, None) cid._sleep = Mock() cid.get_ecs_details = Mock(return_value=('SomeCluster', 'SomeCiArn')) cid.set_draining = Mock() cid.complete_hook = Mock() cid.get_running_tasks = Mock(return_value=['task1', 'task2']) cid.get_ecs_details = Mock(return_value=()) cid.run() cid.logger.error.assert_called_with( "Unable to find cluster or container instance matching ec2 instance-id: %s", 'EC2InstanceIdFromMessage')
def test_run_with_tasks_still_running(self, mock_logger, mock_session, event_no_cache): cid = ContainerInstanceDrainer(event_no_cache, None) cid._sleep = Mock() cid.get_ecs_details = Mock(return_value=('SomeCluster', 'SomeCiArn')) cid.set_draining = Mock() cid.complete_hook = Mock() cid.get_running_tasks = Mock(return_value=['task1', 'task2']) cid.run() cid.get_ecs_details.assert_called_with('EC2InstanceIdFromMessage') cid.set_draining.assert_called_with('SomeCluster', 'SomeCiArn') cid.get_running_tasks.assert_called_with('SomeCluster', 'SomeCiArn') cid._sleep.assert_called_once_with(cid.reinvocation_delay) cid.sns_client.publish.assert_called_once() cid.complete_hook.assert_not_called()