This file is indexed.

/usr/lib/python2.7/dist-packages/neutronclient/tests/unit/osc/v2/sfc/fakes.py is in python-neutronclient 1:6.7.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
 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
# Copyright (c) 2017 Huawei Technologies India Pvt.Limited.
# All Rights Reserved.
#
#   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 argparse
import copy

import mock

from osc_lib.tests import utils
from oslo_utils import uuidutils


class TestNeutronClientOSCV2(utils.TestCommand):

    def setUp(self):
        super(TestNeutronClientOSCV2, self).setUp()
        self.namespace = argparse.Namespace()
        self.app.client_manager.session = mock.Mock()
        self.app.client_manager.neutronclient = mock.Mock()
        self.neutronclient = self.app.client_manager.neutronclient
        self.neutronclient.find_resource = mock.Mock(
            side_effect=lambda resource, name_or_id, project_id=None,
            cmd_resource=None, parent_id=None, fields=None:
            {'id': name_or_id})


class FakeSfcPortPair(object):
    """Fake port pair attributes."""

    @staticmethod
    def create_port_pair(attrs=None):
        """Create a fake port pair.

        :param Dictionary attrs:
            A dictionary with all attributes
        :return:
            A Dictionary with id, name, description, ingress, egress,
            service-function-parameter, project_id
        """
        attrs = attrs or {}

        # Set default attributes.
        port_pair_attrs = {
            'description': 'description',
            'egress': uuidutils.generate_uuid(),
            'id': uuidutils.generate_uuid(),
            'ingress': uuidutils.generate_uuid(),
            'name': 'port-pair-name',
            'service_function_parameters': 'correlation=None,weight=1',
            'project_id': uuidutils.generate_uuid(),
        }

        # Overwrite default attributes.
        port_pair_attrs.update(attrs)
        return copy.deepcopy(port_pair_attrs)

    @staticmethod
    def create_port_pairs(attrs=None, count=1):
        """Create multiple port_pairs.

        :param Dictionary attrs:
            A dictionary with all attributes
        :param int count:
            The number of port_pairs to fake
        :return:
            A list of dictionaries faking the port_pairs
        """
        port_pairs = []
        for _ in range(count):
            port_pairs.append(FakeSfcPortPair.create_port_pair(attrs))

        return port_pairs


class FakeSfcPortPairGroup(object):
    """Fake port pair group attributes."""

    @staticmethod
    def create_port_pair_group(attrs=None):
        """Create a fake port pair group.

        :param Dictionary attrs:
            A dictionary with all attributes
        :return:
            A Dictionary with id, name, description, port_pairs, group_id
            port_pair_group_parameters, project_id
        """
        attrs = attrs or {}

        # Set default attributes.
        port_pair_group_attrs = {
            'id': uuidutils.generate_uuid(),
            'group_id': uuidutils.generate_uuid(),
            'name': 'port-pair-group-name',
            'description': 'description',
            'port_pairs': uuidutils.generate_uuid(),
            'port_pair_group_parameters': '{"lb_fields": []}',
            'project_id': uuidutils.generate_uuid(),
            'tap_enabled': False
        }

        # port_pair_group_attrs default attributes.
        port_pair_group_attrs.update(attrs)
        return copy.deepcopy(port_pair_group_attrs)

    @staticmethod
    def create_port_pair_groups(attrs=None, count=1):
        """Create multiple port pair groups.

        :param Dictionary attrs:
            A dictionary with all attributes
        :param int count:
            The number of port_pair_groups to fake
        :return:
            A list of dictionaries faking the port pair groups
        """
        port_pair_groups = []
        for _ in range(count):
            port_pair_groups.append(
                FakeSfcPortPairGroup.create_port_pair_group(attrs))

        return port_pair_groups


class FakeSfcFlowClassifier(object):
    """Fake flow classifier attributes."""

    @staticmethod
    def create_flow_classifier(attrs=None):
        """Create a fake flow classifier.

        :param Dictionary attrs:
            A dictionary with all attributes
        :return:
            A Dictionary with faking port chain attributes
        """
        attrs = attrs or {}

        # Set default attributes.
        flow_classifier_attrs = {
            'id': uuidutils.generate_uuid(),
            'destination_ip_prefix': '2.2.2.2/32',
            'destination_port_range_max': '90',
            'destination_port_range_min': '80',
            'ethertype': 'IPv4',
            'logical_destination_port': uuidutils.generate_uuid(),
            'logical_source_port': uuidutils.generate_uuid(),
            'name': 'flow-classifier-name',
            'description': 'fc_description',
            'protocol': 'tcp',
            'source_ip_prefix': '1.1.1.1/32',
            'source_port_range_max': '20',
            'source_port_range_min': '10',
            'project_id': uuidutils.generate_uuid(),
            'l7_parameters': '{}'
        }
        flow_classifier_attrs.update(attrs)
        return copy.deepcopy(flow_classifier_attrs)

    @staticmethod
    def create_flow_classifiers(attrs=None, count=1):
        """Create multiple flow classifiers.

        :param Dictionary attrs:
            A dictionary with all attributes
        :param int count:
            The number of flow classifiers to fake
        :return:
            A list of dictionaries faking the flow classifiers
        """
        flow_classifiers = []
        for _ in range(count):
            flow_classifiers.append(
                FakeSfcFlowClassifier.create_flow_classifier(attrs))

        return flow_classifiers


class FakeSfcPortChain(object):
    """Fake port chain attributes."""

    @staticmethod
    def create_port_chain(attrs=None):
        """Create a fake port chain.

        :param Dictionary attrs:
            A dictionary with all attributes
        :return:
            A Dictionary with faking port chain attributes
        """
        attrs = attrs or {}

        # Set default attributes.
        port_chain_attrs = {
            'id': uuidutils.generate_uuid(),
            'chain_id': uuidutils.generate_uuid(),
            'name': 'port-chain-name',
            'description': 'description',
            'port_pair_groups': uuidutils.generate_uuid(),
            'flow_classifiers': uuidutils.generate_uuid(),
            'chain_parameters': '{"correlation": mpls}',
            'project_id': uuidutils.generate_uuid(),
        }

        # port_pair_group_attrs default attributes.
        port_chain_attrs.update(attrs)
        return copy.deepcopy(port_chain_attrs)

    @staticmethod
    def create_port_chains(attrs=None, count=1):
        """Create multiple port chains.

        :param Dictionary attrs:
            A dictionary with all attributes
        :param int count:
            The number of port chains to fake
        :return:
            A list of dictionaries faking the port chains.
        """
        port_chains = []
        for _ in range(count):
            port_chains.append(FakeSfcPortChain.create_port_chain(attrs))
        return port_chains


class FakeSfcServiceGraph(object):
    """Fake service graph attributes."""

    @staticmethod
    def create_sfc_service_graph(attrs=None):
        """Create a fake service graph.

        :param Dictionary attrs:
            A dictionary with all attributes
        :return:
            A Dictionary with faking service graph attributes
        """
        attrs = attrs or {}

        # Set default attributes.
        service_graph_attrs = {
            'id': uuidutils.generate_uuid(),
            'name': 'port-pair-group-name',
            'description': 'description',
            'port_chains': {uuidutils.generate_uuid(): [
                uuidutils.generate_uuid()]},
            'project_id': uuidutils.generate_uuid(),
        }

        service_graph_attrs.update(attrs)
        return copy.deepcopy(service_graph_attrs)

    @staticmethod
    def create_sfc_service_graphs(attrs=None, count=1):
        """Create multiple service graphs.

        :param Dictionary attrs:
            A dictionary with all attributes
        :param int count:
            The number of service graphs to fake
        :return:
            A list of dictionaries faking the service graphs.
        """
        service_graphs = []
        for _ in range(count):
            service_graphs.append(
                FakeSfcServiceGraph.create_sfc_service_graph(attrs))
        return service_graphs