예제 #1
0
    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()
예제 #2
0
    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')
예제 #3
0
    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()