35
35
else :
36
36
import httplib
37
37
38
+
38
39
def short_uuid ():
39
40
id = str (uuid .uuid4 ())
40
41
return id [- 12 :]
@@ -60,6 +61,7 @@ def manifest_with_command(name, command):
60
61
}
61
62
}
62
63
64
+
63
65
class TestClient (unittest .TestCase ):
64
66
65
67
@classmethod
@@ -71,7 +73,8 @@ def test_pod_apis(self):
71
73
api = core_v1_api .CoreV1Api (client )
72
74
73
75
name = 'busybox-test-' + short_uuid ()
74
- pod_manifest = manifest_with_command (name , "while true;do date;sleep 5; done" )
76
+ pod_manifest = manifest_with_command (
77
+ name , "while true;do date;sleep 5; done" )
75
78
76
79
# wait for the default service account to be created
77
80
timeout = time .time () + 30
@@ -84,9 +87,10 @@ def test_pod_apis(self):
84
87
namespace = 'default' )
85
88
except ApiException as e :
86
89
if (six .PY3 and e .status != HTTPStatus .NOT_FOUND ) or (
87
- six .PY3 is False and e .status != httplib .NOT_FOUND ):
90
+ six .PY3 is False and e .status != httplib .NOT_FOUND ):
88
91
print ('error: %s' % e )
89
- self .fail (msg = "unexpected error getting default service account" )
92
+ self .fail (
93
+ msg = "unexpected error getting default service account" )
90
94
print ('default service not found yet: %s' % e )
91
95
time .sleep (1 )
92
96
continue
@@ -111,25 +115,25 @@ def test_pod_apis(self):
111
115
'-c' ,
112
116
'for i in $(seq 1 3); do date; done' ]
113
117
resp = stream (api .connect_get_namespaced_pod_exec , name , 'default' ,
114
- command = exec_command ,
115
- stderr = False , stdin = False ,
116
- stdout = True , tty = False )
118
+ command = exec_command ,
119
+ stderr = False , stdin = False ,
120
+ stdout = True , tty = False )
117
121
print ('EXEC response : %s' % resp )
118
122
self .assertEqual (3 , len (resp .splitlines ()))
119
123
120
124
exec_command = 'uptime'
121
125
resp = stream (api .connect_post_namespaced_pod_exec , name , 'default' ,
122
- command = exec_command ,
123
- stderr = False , stdin = False ,
124
- stdout = True , tty = False )
126
+ command = exec_command ,
127
+ stderr = False , stdin = False ,
128
+ stdout = True , tty = False )
125
129
print ('EXEC response : %s' % resp )
126
130
self .assertEqual (1 , len (resp .splitlines ()))
127
131
128
132
resp = stream (api .connect_post_namespaced_pod_exec , name , 'default' ,
129
- command = '/bin/sh' ,
130
- stderr = True , stdin = True ,
131
- stdout = True , tty = False ,
132
- _preload_content = False )
133
+ command = '/bin/sh' ,
134
+ stderr = True , stdin = True ,
135
+ stdout =True , tty = False ,
136
+ _preload_content = False )
133
137
resp .write_stdin ("echo test string 1\n " )
134
138
line = resp .readline_stdout (timeout = 5 )
135
139
self .assertFalse (resp .peek_stderr ())
@@ -157,7 +161,8 @@ def test_exit_code(self):
157
161
api = core_v1_api .CoreV1Api (client )
158
162
159
163
name = 'busybox-test-' + short_uuid ()
160
- pod_manifest = manifest_with_command (name , "while true;do date;sleep 5; done" )
164
+ pod_manifest = manifest_with_command (
165
+ name , "while true;do date;sleep 5; done" )
161
166
162
167
# wait for the default service account to be created
163
168
timeout = time .time () + 30
@@ -171,9 +176,10 @@ def test_exit_code(self):
171
176
namespace = 'default' )
172
177
except ApiException as e :
173
178
if (six .PY3 and e .status != HTTPStatus .NOT_FOUND ) or (
174
- six .PY3 is False and e .status != httplib .NOT_FOUND ):
179
+ six .PY3 is False and e .status != httplib .NOT_FOUND ):
175
180
print ('error: %s' % e )
176
- self .fail (msg = "unexpected error getting default service account" )
181
+ self .fail (
182
+ msg = "unexpected error getting default service account" )
177
183
print ('default service not found yet: %s' % e )
178
184
time .sleep (1 )
179
185
continue
@@ -201,11 +207,16 @@ def test_exit_code(self):
201
207
(["/bin/sh" , "-c" , "ls /" ], 0 )
202
208
)
203
209
for command , value in commands_expected_values :
204
- client = stream (api .connect_get_namespaced_pod_exec , name , 'default' ,
205
- command = command ,
206
- stderr = True , stdin = False ,
207
- stdout = True , tty = False ,
208
- _preload_content = False )
210
+ client = stream (
211
+ api .connect_get_namespaced_pod_exec ,
212
+ name ,
213
+ 'default' ,
214
+ command = command ,
215
+ stderr = True ,
216
+ stdin = False ,
217
+ stdout = True ,
218
+ tty = False ,
219
+ _preload_content = False )
209
220
210
221
self .assertIsNone (client .returncode )
211
222
client .run_forever (timeout = 10 )
@@ -337,7 +348,8 @@ def test_portforward_raw(self):
337
348
338
349
for sock in (sock1234 , sock1235 ):
339
350
self .assertTrue (pf .connected )
340
- sent = b'Another test using fileno %s' % str (sock .fileno ()).encode ()
351
+ sent = b'Another test using fileno %s' % str (
352
+ sock .fileno ()).encode ()
341
353
sock .sendall (sent )
342
354
reply = b''
343
355
while True :
@@ -361,7 +373,7 @@ def test_portforward_http(self):
361
373
client = api_client .ApiClient (configuration = self .config )
362
374
api = core_v1_api .CoreV1Api (client )
363
375
364
- name = 'portforward-http-' + short_uuid ()
376
+ name = 'portforward-http-' + short_uuid ()
365
377
pod_manifest = {
366
378
'apiVersion' : 'v1' ,
367
379
'kind' : 'Pod' ,
@@ -404,7 +416,8 @@ def kubernetes_create_connection(address, *args, **kwargs):
404
416
socket_create_connection = socket .create_connection
405
417
try :
406
418
socket .create_connection = kubernetes_create_connection
407
- response = urllib_request .urlopen ('http://%s.default.kubernetes/' % name )
419
+ response = urllib_request .urlopen (
420
+ 'http://%s.default.kubernetes/' % name )
408
421
html = response .read ().decode ('utf-8' )
409
422
finally :
410
423
socket .create_connection = socket_create_connection
@@ -485,7 +498,7 @@ def test_replication_controller_apis(self):
485
498
self .assertEqual (2 , resp .spec .replicas )
486
499
487
500
resp = api .delete_namespaced_replication_controller (
488
- name = name , body = {}, namespace = 'default ' )
501
+ name = name , namespace = 'default' , propagation_policy = 'Background ' )
489
502
490
503
def test_configmap_apis (self ):
491
504
client = api_client .ApiClient (configuration = self .config )
@@ -521,7 +534,8 @@ def test_configmap_apis(self):
521
534
resp = api .delete_namespaced_config_map (
522
535
name = name , body = {}, namespace = 'default' )
523
536
524
- resp = api .list_namespaced_config_map ('default' , pretty = True , label_selector = "e2e-tests=true" )
537
+ resp = api .list_namespaced_config_map (
538
+ 'default' , pretty = True , label_selector = "e2e-tests=true" )
525
539
self .assertEqual ([], resp .items )
526
540
527
541
def test_node_apis (self ):
0 commit comments