Exemplo n.º 1
0
def test_generate_start_end_time_invalid():
    # Try giving a start time that's later than the end time
    try:
        logs.generate_start_end_time("2016-06-06T20:26:49+00:00", "2016-06-06T20:25:49+00:00")
        assert False
    except ValueError:
        assert True
Exemplo n.º 2
0
def test_scribereader_print_logs_by_time():
    service = 'fake_service'
    levels = ['fake_level1', 'fake_level2']
    clusters = ['fake_cluster1', 'fake_cluster2']
    components = ['build', 'deploy', 'monitoring', 'marathon', 'chronos', 'stdout', 'stderr']

    with mock.patch('paasta_tools.cli.cmds.logs.scribereader', autospec=True) as mock_scribereader, \
            mock.patch('paasta_tools.cli.cmds.logs.ScribeLogReader.determine_scribereader_envs', autospec=True) \
            as determine_scribereader_envs_patch:

        determine_scribereader_envs_patch.return_value = ['env1', 'env2']
        fake_iter = mock.MagicMock()
        fake_iter.__iter__.return_value = ["""{"cluster":"fake_cluster1","component":"stderr","instance":"main",
                                           "level":"debug","message":"testing",
                                           "timestamp":"2016-06-08T06:31:52.706609135Z"}"""] * 100
        mock_scribereader.get_stream_tailer.return_value = fake_iter
        mock_scribereader.get_stream_reader.return_value = fake_iter

        start_time, end_time = logs.generate_start_end_time()
        logs.ScribeLogReader(cluster_map={}).print_logs_by_time(service, start_time, end_time,
                                                                levels, components, clusters,
                                                                raw_mode=False)

        # Please see comment in test_scribereader_print_last_n_logs for where this number comes from
        assert mock_scribereader.get_stream_tailer.call_count == 14

        start_time, end_time = logs.generate_start_end_time("3d", "2d")
        logs.ScribeLogReader(cluster_map={}).print_logs_by_time(service, start_time, end_time,
                                                                levels, components, clusters,
                                                                raw_mode=False)

        # Please see comment in test_scribereader_print_last_n_logs for where this number comes from
        assert mock_scribereader.get_stream_reader.call_count == 14
Exemplo n.º 3
0
def test_generate_start_end_time_human_durations():
    start_time, end_time = logs.generate_start_end_time("35m", "25m")

    time_delta = end_time - start_time

    actual_time = time_delta.total_seconds()
    ideal_time = 10 * 60

    # See note on the test above why this is not a simple == comparison
    assert abs(actual_time - ideal_time) < 0.1
Exemplo n.º 4
0
def test_generate_start_end_time():
    start_time, end_time = logs.generate_start_end_time()

    # Default for no args, test that there's a 30 minute difference
    time_delta = end_time - start_time

    # Do a loose comparison to make this test less time sensitive.
    # On slower systems, doing a datetime.datetime.utcnow() might
    # take a few milliseconds itself, doing a straight up == comparison
    # would not work
    actual_time = time_delta.total_seconds()
    ideal_time = 30 * 60

    assert abs(actual_time - ideal_time) < 0.1
Exemplo n.º 5
0
def test_paasta_log_line_passes_filter_false_when_invalid_time():
    service = 'fake_service'
    levels = ['fake_level1', 'fake_level2']
    clusters = ['fake_cluster1', 'fake_cluster2']
    instance = 'fake_instance'
    components = ['build', 'deploy']
    line = 'fake_line'
    formatted_line = format_log_line(levels[0], clusters[0], service, instance, components[0], line,
                                     timestamp=isodate.datetime_isoformat(datetime.datetime.utcnow()))

    start_time, end_time = logs.generate_start_end_time(from_string="5m", to_string="3m")

    assert logs.paasta_log_line_passes_filter(formatted_line, levels, service, components, clusters,
                                              start_time=start_time, end_time=end_time) is False
Exemplo n.º 6
0
def test_generate_start_end_time_invalid_to():
    try:
        logs.generate_start_end_time("2016-06-06T20:25:49+00:00", "invalid")
        assert False
    except ValueError:
        assert True
Exemplo n.º 7
0
def test_check_timestamp_in_range_false():
    timestamp = datetime.datetime.utcnow()
    start_time, end_time = logs.generate_start_end_time("10m", "5m")

    assert logs.check_timestamp_in_range(timestamp, start_time, end_time) is False
Exemplo n.º 8
0
def test_check_timestamp_in_range_false():
    timestamp = datetime.datetime.utcnow()
    start_time, end_time = logs.generate_start_end_time("10m", "5m")

    assert logs.check_timestamp_in_range(timestamp, start_time,
                                         end_time) is False
Exemplo n.º 9
0
def test_generate_start_end_time_invalid_to():
    try:
        logs.generate_start_end_time("2016-06-06T20:25:49+00:00", "invalid")
        assert False
    except ValueError:
        assert True
Exemplo n.º 10
0
def test_generate_start_end_time_invalid_to():
    with pytest.raises(ValueError):
        logs.generate_start_end_time("2016-06-06T20:25:49+00:00", "invalid")
Exemplo n.º 11
0
def test_generate_start_end_time_invalid():
    # Try giving a start time that's later than the end time
    with pytest.raises(ValueError):
        logs.generate_start_end_time("2016-06-06T20:26:49+00:00",
                                     "2016-06-06T20:25:49+00:00")