This file is indexed.

/usr/lib/python3/dist-packages/gnocchi/tests/test_archive_policy.py is in python3-gnocchi 4.2.0-0ubuntu5.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
# -*- encoding: utf-8 -*-
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import numpy

from gnocchi import archive_policy
from gnocchi import service
from gnocchi.tests import base


class TestArchivePolicy(base.BaseTestCase):

    def test_several_equal_granularities(self):
        self.assertRaises(ValueError,
                          archive_policy.ArchivePolicy,
                          "foobar",
                          0,
                          [(10, 12), (20, 30), (20, 30)],
                          ["*"])

    def test_aggregation_methods(self):
        conf = service.prepare_service([],
                                       default_config_files=[])

        ap = archive_policy.ArchivePolicy("foobar",
                                          0,
                                          [],
                                          ["*"])
        self.assertEqual(
            archive_policy.ArchivePolicy.VALID_AGGREGATION_METHODS,
            ap.aggregation_methods)

        ap = archive_policy.ArchivePolicy("foobar",
                                          0,
                                          [],
                                          ["last"])
        self.assertEqual(
            set(["last"]),
            ap.aggregation_methods)

        ap = archive_policy.ArchivePolicy("foobar",
                                          0,
                                          [],
                                          ["*", "-mean"])
        self.assertEqual(
            (archive_policy.ArchivePolicy.VALID_AGGREGATION_METHODS
             - set(["mean"])),
            ap.aggregation_methods)

        ap = archive_policy.ArchivePolicy("foobar",
                                          0,
                                          [],
                                          ["-mean", "-last"])
        self.assertEqual(
            (set(conf.archive_policy.default_aggregation_methods)
             - set(["mean", "last"])),
            ap.aggregation_methods)

        ap = archive_policy.ArchivePolicy("foobar",
                                          0,
                                          [],
                                          ["+12pct"])
        self.assertEqual(
            (set(conf.archive_policy.default_aggregation_methods)
             .union(set(["12pct"]))),
            ap.aggregation_methods)

        ap = archive_policy.ArchivePolicy("foobar",
                                          0,
                                          [],
                                          ["+rate:last"])
        self.assertEqual(
            (set(conf.archive_policy.default_aggregation_methods)
             .union(set(["rate:last"]))),
            ap.aggregation_methods)

    def test_max_block_size(self):
        ap = archive_policy.ArchivePolicy("foobar",
                                          0,
                                          [(20, 60), (10, 300), (10, 5)],
                                          ["-mean", "-last"])
        self.assertEqual(ap.max_block_size, numpy.timedelta64(300, 's'))


class TestArchivePolicyItem(base.BaseTestCase):
    def test_zero_size(self):
        self.assertRaises(ValueError,
                          archive_policy.ArchivePolicyItem,
                          0, 1)
        self.assertRaises(ValueError,
                          archive_policy.ArchivePolicyItem,
                          1, 0)
        self.assertRaises(ValueError,
                          archive_policy.ArchivePolicyItem,
                          -1, 1)
        self.assertRaises(ValueError,
                          archive_policy.ArchivePolicyItem,
                          1, -1)
        self.assertRaises(ValueError,
                          archive_policy.ArchivePolicyItem,
                          2, None, 1)