2
2
import os
3
3
4
4
import requests
5
+ sess = requests .Session ()
6
+ adapter = requests .adapters .HTTPAdapter (pool_connections = 100 , pool_maxsize = 100 )
7
+ sess .mount ('https://' , adapter )
8
+ requests = sess
5
9
6
10
from docker_registry .lib import checksums
7
11
from docker_registry .lib import config
15
19
16
20
cfg = config .load ()
17
21
22
+ ua = 'docker/1.0.0 registry test pretending to be docker'
23
+
18
24
19
25
class TestWorkflow (base .TestCase ):
20
26
@@ -32,7 +38,7 @@ class TestWorkflow(base.TestCase):
32
38
33
39
def generate_chunk (self , data ):
34
40
bufsize = 1024
35
- io = StringIO . StringIO (data )
41
+ io = StringIO (data )
36
42
while True :
37
43
buf = io .read (bufsize )
38
44
if not buf :
@@ -60,14 +66,16 @@ def upload_image(self, image_id, parent_id, token):
60
66
self .registry_endpoint , image_id ),
61
67
data = json_data ,
62
68
headers = {'Authorization' : 'Token ' + token ,
69
+ 'User-Agent' : ua ,
63
70
'X-Docker-Checksum' : layer_checksum },
64
71
cookies = self .cookies )
65
72
self .assertEqual (resp .status_code , 200 , resp .text )
66
73
self .update_cookies (resp )
67
74
resp = requests .put ('{0}/v1/images/{1}/layer' .format (
68
75
self .registry_endpoint , image_id ),
69
76
data = self .generate_chunk (layer ),
70
- headers = {'Authorization' : 'Token ' + token },
77
+ headers = {'Authorization' : 'Token ' + token ,
78
+ 'User-Agent' : ua },
71
79
cookies = self .cookies )
72
80
self .assertEqual (resp .status_code , 200 , resp .text )
73
81
self .update_cookies (resp )
@@ -94,7 +102,8 @@ def docker_push(self):
94
102
resp = requests .put ('{0}/v1/repositories/{1}/{2}/' .format (
95
103
self .index_endpoint , namespace , repos ),
96
104
auth = tuple (self .user_credentials ),
97
- headers = {'X-Docker-Token' : 'true' },
105
+ headers = {'X-Docker-Token' : 'true' ,
106
+ 'User-Agent' : ua },
98
107
data = images_json )
99
108
self .assertEqual (resp .status_code , 200 , resp .text )
100
109
token = resp .headers .get ('x-docker-token' )
@@ -108,7 +117,8 @@ def docker_push(self):
108
117
resp = requests .put ('{0}/v1/repositories/{1}/{2}/images' .format (
109
118
self .index_endpoint , namespace , repos ),
110
119
auth = tuple (self .user_credentials ),
111
- headers = {'X-Endpoints' : self .registry_endpoint },
120
+ headers = {'X-Endpoints' : self .registry_endpoint ,
121
+ 'User-Agent' : ua },
112
122
data = json .dumps (images_json ))
113
123
self .assertEqual (resp .status_code , 204 )
114
124
return (namespace , repos )
@@ -160,7 +170,7 @@ def docker_pull(self, namespace, repos):
160
170
json_data , checksum , blob = self .fetch_image (image_id )
161
171
# check queried checksum and local computed checksum from the image
162
172
# are the same
163
- tmpfile = StringIO . StringIO ()
173
+ tmpfile = StringIO ()
164
174
tmpfile .write (blob )
165
175
tmpfile .seek (0 )
166
176
computed_checksum = checksums .compute_simple (tmpfile , json_data )
0 commit comments