Debian Codegraph @

glanceclient/tests/functional/v2/test_http_headers.py

raw symbols SCIP
1 # Licensed under the Apache License, Version 2.0 (the "License"); you may
2 # not use this file except in compliance with the License. You may obtain
3 # a copy of the License at
4 #
5 # http://www.apache.org/licenses/LICENSE-2.0
6 #
7 # Unless required by applicable law or agreed to in writing, software
8 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10 # License for the specific language governing permissions and limitations
11 # under the License.
12
13 from glanceclient.tests.functional import base
14 import time
15
16
17 IMAGE = {"protected": False,
18 "disk_format": "qcow2",
19 "name": "glance_functional_test_image.img",
20 "visibility": "private",
21 "container_format": "bare"}
22
23
24 class HttpHeadersTest(base.ClientTestBase):
25 def test_encode_headers_python(self):
26 """Test proper handling of Content-Type headers.
27
28 encode_headers() must be called as late as possible before a
29 request is sent. If this principle is violated, and if any
30 changes are made to the headers between encode_headers() and the
31 actual request (for instance a call to
32 _set_common_request_kwargs()), and if you're trying to set a
33 Content-Type that is not equal to application/octet-stream (the
34 default), it is entirely possible that you'll end up with two
35 Content-Type headers defined (yours plus
36 application/octet-stream). The request will go out the door with
37 only one of them chosen seemingly at random.
38
39 This test uses a call to update() because it sets a header such
40 as the following (this example may be subject to change):
41 Content-Type: application/openstack-images-v2.1-json-patch
42
43 This situation only occurs in python3. This test will never fail
44 in python2.
45
46 There is no test against the CLI because it swallows the error.
47 """
48 # the failure is intermittent - try up to 6 times
49 for attempt in range(0, 6):
50 glanceclient = self.glance_pyclient()
51 image = glanceclient.find(IMAGE["name"])
52 if image:
53 glanceclient.glance.images.delete(image.id)
54 image = glanceclient.glance.images.create(name=IMAGE["name"])
55 self.assertTrue(image.status == "queued")
56 try:
57 image = glanceclient.glance.images.update(image.id,
58 disk_format="qcow2")
59 except Exception as e:
60 self.assertNotIn("415 Unsupported Media Type", e.details)
61 time.sleep(5)