Пример #1
0
def test_follow_logs_single_pages_only():
    sleep = mock.Mock(spec=time.sleep)
    client = mock.Mock(spec=TypedAWSClient)
    client.filter_log_events.side_effect = [
        {
            'events': [{
                'eventId': '1',
                'timestamp': 1
            }]
        },
        {
            'events': [{
                'eventId': '2',
                'timestamp': 2
            }]
        },
        {
            'events': [{
                'eventId': '3',
                'timestamp': 3
            }]
        },
        KeyboardInterrupt(),
    ]
    event_gen = logs.FollowLogEventGenerator(client, sleep)
    assert list(
        event_gen.iter_log_events(log_group_name='mygroup',
                                  options=NO_OPTIONS)) == [
                                      {
                                          'eventId': '1',
                                          'timestamp': 1
                                      },
                                      {
                                          'eventId': '2',
                                          'timestamp': 2
                                      },
                                      {
                                          'eventId': '3',
                                          'timestamp': 3
                                      },
                                  ]
Пример #2
0
def test_follow_logs_all_pages_empty_with_pagination():
    sleep = mock.Mock(spec=time.sleep)
    client = mock.Mock(spec=TypedAWSClient)
    client.filter_log_events.side_effect = [
        {
            'events': [],
            'nextToken': 'nextToken1'
        },
        {
            'events': [],
            'nextToken': 'nextToken2'
        },
        {
            'events': [],
            'nextToken': 'nextToken3'
        },
        {
            'events': []
        },
        KeyboardInterrupt(),
    ]
    event_gen = logs.FollowLogEventGenerator(client, sleep)
    options = logs.LogRetrieveOptions(start_time=1)
    assert list(
        event_gen.iter_log_events(log_group_name='mygroup',
                                  options=options)) == []
    assert client.filter_log_events.call_args_list == [
        mock.call(log_group_name='mygroup', start_time=1),
        mock.call(log_group_name='mygroup',
                  start_time=1,
                  next_token='nextToken1'),
        mock.call(log_group_name='mygroup',
                  start_time=1,
                  next_token='nextToken2'),
        mock.call(log_group_name='mygroup',
                  start_time=1,
                  next_token='nextToken3'),
        # The last call should not use a next token.
        mock.call(log_group_name='mygroup', start_time=1)
    ]
Пример #3
0
def test_follow_logs_last_page_empty():
    sleep = mock.Mock(spec=time.sleep)
    client = mock.Mock(spec=TypedAWSClient)
    client.filter_log_events.side_effect = [
        {
            'events': [{
                'eventId': '1',
                'timestamp': 1
            }, {
                'eventId': '2',
                'timestamp': 2
            }, {
                'eventId': '3',
                'timestamp': 3
            }],
            'nextToken':
            'nextToken1'
        },
        {
            'events': [{
                'eventId': '4',
                'timestamp': 4
            }, {
                'eventId': '6',
                'timestamp': 6
            }, {
                'eventId': '5',
                'timestamp': 5
            }],
            'nextToken':
            'nextToken2'
        },
        # You can sometimes get a next token but with no events.
        {
            'events': [],
            'nextToken': 'nextToken3'
        },
        {
            'events': []
        },
        {
            'events': [{
                'eventId': '7',
                'timestamp': 7
            }]
        },
        KeyboardInterrupt(),
    ]
    event_gen = logs.FollowLogEventGenerator(client, sleep)
    options = logs.LogRetrieveOptions(start_time=1)
    assert list(
        event_gen.iter_log_events(log_group_name='mygroup',
                                  options=options)) == [
                                      {
                                          'eventId': '1',
                                          'timestamp': 1
                                      },
                                      {
                                          'eventId': '2',
                                          'timestamp': 2
                                      },
                                      {
                                          'eventId': '3',
                                          'timestamp': 3
                                      },
                                      {
                                          'eventId': '4',
                                          'timestamp': 4
                                      },
                                      {
                                          'eventId': '6',
                                          'timestamp': 6
                                      },
                                      {
                                          'eventId': '5',
                                          'timestamp': 5
                                      },
                                      {
                                          'eventId': '7',
                                          'timestamp': 7
                                      },
                                  ]
    assert client.filter_log_events.call_args_list == [
        mock.call(log_group_name='mygroup', start_time=1),
        mock.call(log_group_name='mygroup',
                  start_time=1,
                  next_token='nextToken1'),
        mock.call(log_group_name='mygroup',
                  start_time=1,
                  next_token='nextToken2'),
        mock.call(log_group_name='mygroup',
                  start_time=1,
                  next_token='nextToken3'),
        mock.call(log_group_name='mygroup', start_time=6),
        mock.call(log_group_name='mygroup', start_time=7),
    ]
Пример #4
0
def test_can_follow_log_events():
    sleep = mock.Mock(spec=time.sleep)
    client = mock.Mock(spec=TypedAWSClient)
    client.filter_log_events.side_effect = [
        # First page of results has nextToken indicating there's
        # more results.
        {
            'events': [{
                'eventId': '1',
                'timestamp': 1
            }, {
                'eventId': '2',
                'timestamp': 2
            }, {
                'eventId': '3',
                'timestamp': 3
            }],
            'nextToken':
            'nextToken1'
        },
        # Second page with no more results, also note the
        # timestamps are out of order.
        {
            'events': [{
                'eventId': '4',
                'timestamp': 4
            }, {
                'eventId': '6',
                'timestamp': 6
            }, {
                'eventId': '5',
                'timestamp': 5
            }]
        },
        # We then poll again with no new results for timestamp=6.
        {
            'events': [{
                'eventId': '6',
                'timestamp': 6
            }]
        },
        # And now we get new results.
        {
            'events': [
                {
                    'eventId': '6',
                    'timestamp': 6
                },
                # Same timestamp we're querying (6) but a new event.
                {
                    'eventId': '6NEW',
                    'timestamp': 6
                },
                {
                    'eventId': '7',
                    'timestamp': 7
                },
                {
                    'eventId': '8',
                    'timestamp': 8
                }
            ]
        },
        KeyboardInterrupt(),
    ]
    event_gen = logs.FollowLogEventGenerator(client, sleep)
    options = logs.LogRetrieveOptions(start_time=1)
    assert list(
        event_gen.iter_log_events(
            log_group_name='mygroup', options=options)) == [
                {
                    'eventId': '1',
                    'timestamp': 1
                },
                {
                    'eventId': '2',
                    'timestamp': 2
                },
                {
                    'eventId': '3',
                    'timestamp': 3
                },
                {
                    'eventId': '4',
                    'timestamp': 4
                },
                # Note we don't try to sort these entries.
                {
                    'eventId': '6',
                    'timestamp': 6
                },
                {
                    'eventId': '5',
                    'timestamp': 5
                },
                {
                    'eventId': '6NEW',
                    'timestamp': 6
                },
                {
                    'eventId': '7',
                    'timestamp': 7
                },
                {
                    'eventId': '8',
                    'timestamp': 8
                },
            ]
    assert client.filter_log_events.call_args_list == [
        mock.call(log_group_name='mygroup', start_time=1),
        mock.call(log_group_name='mygroup',
                  start_time=1,
                  next_token='nextToken1'),
        mock.call(log_group_name='mygroup', start_time=6),
        mock.call(log_group_name='mygroup', start_time=6),
        mock.call(log_group_name='mygroup', start_time=8),
    ]