This file is indexed.

/usr/lib/python2.7/dist-packages/tempest_lib/tests/services/compute/test_images_client.py is in python-tempest-lib 0.14.0-2.

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
# Copyright 2015 NEC Corporation.  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 copy

from oslotest import mockpatch

from tempest_lib import exceptions as lib_exc
from tempest_lib.services.compute import images_client
from tempest_lib.tests import fake_auth_provider
from tempest_lib.tests.services.compute import base


class TestImagesClient(base.BaseComputeServiceTest):
    # Data Dictionaries used for testing #
    FAKE_IMAGE_METADATA = {
        "list":
            {"metadata": {
             "auto_disk_config": "True",
             "Label": "Changed"
             }},
        "set_item":
            {"meta": {
             "auto_disk_config": "True"
             }},
        "show_item":
            {"meta": {
             "kernel_id": "nokernel",
             }},
        "update":
            {"metadata": {
             "kernel_id": "False",
             "Label": "UpdatedImage"
             }},
        "set":
            {"metadata": {
             "Label": "Changed",
             "auto_disk_config": "True"
             }},
        "delete_item": {}
        }

    FAKE_IMAGE_DATA = {
        "list":
            {"images": [
             {"id": "70a599e0-31e7-49b7-b260-868f441e862b",
              "links": [
                    {"href": "http://openstack.example.com/v2/openstack" +
                             "/images/70a599e0-31e7-49b7-b260-868f441e862b",
                     "rel": "self"
                     }
              ],
              "name": "fakeimage7"
              }]},
        "show": {"image": {
            "created": "2011-01-01T01:02:03Z",
            "id": "70a599e0-31e7-49b7-b260-868f441e862b",
            "links": [
                {
                    "href": "http://openstack.example.com/v2/openstack" +
                            "/images/70a599e0-31e7-49b7-b260-868f441e862b",
                    "rel": "self"
                },
            ],
            "metadata": {
                "architecture": "x86_64",
                "auto_disk_config": "True",
                "kernel_id": "nokernel",
                "ramdisk_id": "nokernel"
            },
            "minDisk": 0,
            "minRam": 0,
            "name": "fakeimage7",
            "progress": 100,
            "status": "ACTIVE",
            "updated": "2011-01-01T01:02:03Z"}},
        "create": {},
        "delete": {}
        }
    func2mock = {
        'get': 'tempest_lib.common.rest_client.RestClient.get',
        'post': 'tempest_lib.common.rest_client.RestClient.post',
        'put': 'tempest_lib.common.rest_client.RestClient.put',
        'delete': 'tempest_lib.common.rest_client.RestClient.delete'}
    # Variable definition
    FAKE_IMAGE_ID = FAKE_IMAGE_DATA['show']['image']['id']
    FAKE_SERVER_ID = "80a599e0-31e7-49b7-b260-868f441e343f"
    FAKE_CREATE_INFO = {'location': 'None'}
    FAKE_METADATA = FAKE_IMAGE_METADATA['show_item']['meta']

    def setUp(self):
        super(TestImagesClient, self).setUp()
        fake_auth = fake_auth_provider.FakeAuthProvider()
        self.client = images_client.ImagesClient(fake_auth,
                                                 "compute", "regionOne")

    def _test_image_operation(self, operation="delete", bytes_body=False):
        response_code = 200
        mock_operation = self.func2mock['get']
        expected_op = self.FAKE_IMAGE_DATA[operation]
        params = {"image_id": self.FAKE_IMAGE_ID}
        headers = None
        if operation == 'list':
            function = self.client.list_images
        elif operation == 'show':
            function = self.client.show_image
        elif operation == 'create':
            function = self.client.create_image
            mock_operation = self.func2mock['post']
            params = {"server_id": self.FAKE_SERVER_ID}
            response_code = 202
            headers = {
                'connection': 'keep-alive',
                'content-length': '0',
                'content-type': 'application/json',
                'status': '202',
                'x-compute-request-id': 'req-fake',
                'vary': 'accept-encoding',
                'x-openstack-nova-api-version': 'v2.1',
                'date': '13 Oct 2015 05:55:36 GMT',
                'location': 'http://fake.com/images/fake'
            }
        else:
            function = self.client.delete_image
            mock_operation = self.func2mock['delete']
            response_code = 204

        self.check_service_client_function(
            function, mock_operation, expected_op,
            bytes_body, response_code, headers, **params)

    def _test_image_metadata(self, operation="set_item", bytes_body=False):
        response_code = 200
        expected_op = self.FAKE_IMAGE_METADATA[operation]
        if operation == 'list':
            function = self.client.list_image_metadata
            mock_operation = self.func2mock['get']
            params = {"image_id": self.FAKE_IMAGE_ID}

        elif operation == 'set':
            function = self.client.set_image_metadata
            mock_operation = self.func2mock['put']
            params = {"image_id": "_dummy_data",
                      "meta": self.FAKE_METADATA}

        elif operation == 'update':
            function = self.client.update_image_metadata
            mock_operation = self.func2mock['post']
            params = {"image_id": self.FAKE_IMAGE_ID,
                      "meta": self.FAKE_METADATA}

        elif operation == 'show_item':
            mock_operation = self.func2mock['get']
            function = self.client.show_image_metadata_item
            params = {"image_id": self.FAKE_IMAGE_ID,
                      "key": "123"}

        elif operation == 'delete_item':
            function = self.client.delete_image_metadata_item
            mock_operation = self.func2mock['delete']
            response_code = 204
            params = {"image_id": self.FAKE_IMAGE_ID,
                      "key": "123"}

        else:
            function = self.client.set_image_metadata_item
            mock_operation = self.func2mock['put']
            params = {"image_id": self.FAKE_IMAGE_ID,
                      "key": "123",
                      "meta": self.FAKE_METADATA}

        self.check_service_client_function(
            function, mock_operation, expected_op,
            bytes_body, response_code, **params)

    def _test_resource_deleted(self, bytes_body=False):
        params = {"id": self.FAKE_IMAGE_ID}
        expected_op = self.FAKE_IMAGE_DATA['show']['image']
        self.useFixture(mockpatch.Patch('tempest_lib.services.compute'
                        '.images_client.ImagesClient.show_image',
                                        side_effect=lib_exc.NotFound))
        self.assertEqual(True, self.client.is_resource_deleted(**params))
        tempdata = copy.deepcopy(self.FAKE_IMAGE_DATA['show'])
        tempdata['image']['id'] = None
        self.useFixture(mockpatch.Patch('tempest_lib.services.compute'
                        '.images_client.ImagesClient.show_image',
                                        return_value=expected_op))
        self.assertEqual(False, self.client.is_resource_deleted(**params))

    def test_list_images_with_str_body(self):
        self._test_image_operation('list')

    def test_list_images_with_bytes_body(self):
        self._test_image_operation('list', True)

    def test_show_image_with_str_body(self):
        self._test_image_operation('show')

    def test_show_image_with_bytes_body(self):
        self._test_image_operation('show', True)

    def test_create_image_with_str_body(self):
        self._test_image_operation('create')

    def test_create_image_with_bytes_body(self):
        self._test_image_operation('create', True)

    def test_delete_image_with_str_body(self):
        self._test_image_operation('delete')

    def test_delete_image_with_bytes_body(self):
        self._test_image_operation('delete', True)

    def test_list_image_metadata_with_str_body(self):
        self._test_image_metadata('list')

    def test_list_image_metadata_with_bytes_body(self):
        self._test_image_metadata('list', True)

    def test_set_image_metadata_with_str_body(self):
        self._test_image_metadata('set')

    def test_set_image_metadata_with_bytes_body(self):
        self._test_image_metadata('set', True)

    def test_update_image_metadata_with_str_body(self):
        self._test_image_metadata('update')

    def test_update_image_metadata_with_bytes_body(self):
        self._test_image_metadata('update', True)

    def test_set_image_metadata_item_with_str_body(self):
        self._test_image_metadata()

    def test_set_image_metadata_item_with_bytes_body(self):
        self._test_image_metadata(bytes_body=True)

    def test_show_image_metadata_item_with_str_body(self):
        self._test_image_metadata('show_item')

    def test_show_image_metadata_item_with_bytes_body(self):
        self._test_image_metadata('show_item', True)

    def test_delete_image_metadata_item_with_str_body(self):
        self._test_image_metadata('delete_item')

    def test_delete_image_metadata_item_with_bytes_body(self):
        self._test_image_metadata('delete_item', True)

    def test_resource_delete_with_str_body(self):
        self._test_resource_deleted()

    def test_resource_delete_with_bytes_body(self):
        self._test_resource_deleted(True)