Ejemplo n.º 1
0
    def test_set_draining_with_cache(self, mock_logger, mock_session,
                                     event_no_cache):
        cid = ContainerInstanceDrainer(event_no_cache, None)
        cid.cache = dict(InstanceIsDraining=True)

        cid.set_draining('SomeCluster', 'SomeCiArn')
        cid.ecs_client.update_container_instances_state.assert_not_called()
Ejemplo n.º 2
0
    def test_set_draining_no_cache(self, mock_logger, mock_session,
                                   event_no_cache):
        cid = ContainerInstanceDrainer(event_no_cache, None)
        cid.cache = {}

        cid.set_draining('SomeCluster', 'SomeCiArn')
        cid.ecs_client.update_container_instances_state.assert_called_with(
            cluster='SomeCluster',
            containerInstances=['SomeCiArn'],
            status='DRAINING')
Ejemplo n.º 3
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()
Ejemplo n.º 4
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')
Ejemplo n.º 5
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()