This file is indexed.

/usr/lib/python2.7/dist-packages/aodh/tests/mocks.py is in python-aodh 2.0.0-0ubuntu1.

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
# 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 os

import happybase


class MockHBaseTable(happybase.Table):

    def __init__(self, name, connection, data_prefix):
        # data_prefix is added to all rows which are written
        # in this test. It allows to divide data from different tests
        self.data_prefix = data_prefix
        # We create happybase Table with prefix from
        # AODH_TEST_HBASE_TABLE_PREFIX
        prefix = os.getenv("AODH_TEST_HBASE_TABLE_PREFIX", 'test')
        super(MockHBaseTable, self).__init__(
            "%s_%s" % (prefix, name),
            connection)

    def put(self, row, *args, **kwargs):
        row = self.data_prefix + row
        return super(MockHBaseTable, self).put(row, *args,
                                               **kwargs)

    def scan(self, row_start=None, row_stop=None, row_prefix=None,
             columns=None, filter=None, timestamp=None,
             include_timestamp=False, batch_size=10, scan_batching=None,
             limit=None, sorted_columns=False):
        # Add data prefix for row parameters
        # row_prefix could not be combined with row_start or row_stop
        if not row_start and not row_stop:
            row_prefix = self.data_prefix + (row_prefix or "")
            row_start = None
            row_stop = None
        elif row_start and not row_stop:
            # Adding data_prefix to row_start and row_stop does not work
            # if it looks like row_start = %data_prefix%foo,
            # row_stop = %data_prefix, because row_start > row_stop
            filter = self._update_filter_row(filter)
            row_start = self.data_prefix + row_start
        else:
            row_start = self.data_prefix + (row_start or "")
            row_stop = self.data_prefix + (row_stop or "")
        gen = super(MockHBaseTable, self).scan(row_start, row_stop,
                                               row_prefix, columns,
                                               filter, timestamp,
                                               include_timestamp, batch_size,
                                               scan_batching, limit,
                                               sorted_columns)
        data_prefix_len = len(self.data_prefix)
        # Restore original row format
        for row, data in gen:
            yield (row[data_prefix_len:], data)

    def row(self, row, *args, **kwargs):
        row = self.data_prefix + row
        return super(MockHBaseTable, self).row(row, *args, **kwargs)

    def delete(self, row, *args, **kwargs):
        row = self.data_prefix + row
        return super(MockHBaseTable, self).delete(row, *args, **kwargs)

    def _update_filter_row(self, filter):
        if filter:
            return "PrefixFilter(%s) AND %s" % (self.data_prefix, filter)
        else:
            return "PrefixFilter(%s)" % self.data_prefix