@@ -230,10 +230,6 @@ def test_exit_code(self):
230
230
resp = api .delete_namespaced_pod (name = name , body = {},
231
231
namespace = 'default' )
232
232
233
- # Skipping this test as this flakes a lot
234
- # See: https://github.com/kubernetes-client/python/issues/1300
235
- # Re-enable the test once the flakiness is investigated
236
- @unittest .skip ("skipping due to extreme flakiness" )
237
233
def test_portforward_raw (self ):
238
234
client = api_client .ApiClient (configuration = self .config )
239
235
api = core_v1_api .CoreV1Api (client )
@@ -267,7 +263,7 @@ def test_portforward_raw(self):
267
263
'name' : 'port-server' ,
268
264
'image' : 'python' ,
269
265
'command' : [
270
- '/opt/port-server.py' , '1234' , '1235' ,
266
+ 'python' , '-u' , ' /opt/port-server.py' , '1234' , '1235' ,
271
267
],
272
268
'volumeMounts' : [
273
269
{
@@ -278,17 +274,19 @@ def test_portforward_raw(self):
278
274
],
279
275
'startupProbe' : {
280
276
'tcpSocket' : {
281
- 'port' : 1234 ,
277
+ 'port' : 1235 ,
282
278
},
279
+ 'periodSeconds' : 1 ,
280
+ 'failureThreshold' : 30 ,
283
281
},
284
282
},
285
283
],
284
+ 'restartPolicy' : 'Never' ,
286
285
'volumes' : [
287
286
{
288
287
'name' : 'port-server' ,
289
288
'configMap' : {
290
289
'name' : name ,
291
- 'defaultMode' : 0o777 ,
292
290
},
293
291
},
294
292
],
@@ -299,77 +297,79 @@ def test_portforward_raw(self):
299
297
self .assertEqual (name , resp .metadata .name )
300
298
self .assertTrue (resp .status .phase )
301
299
300
+ timeout = time .time () + 60
302
301
while True :
303
302
resp = api .read_namespaced_pod (name = name ,
304
303
namespace = 'default' )
305
304
self .assertEqual (name , resp .metadata .name )
306
- self .assertTrue (resp .status .phase )
307
- if resp .status .phase != 'Pending' :
308
- break
305
+ if resp .status .phase == 'Running' :
306
+ if resp .status .container_statuses [0 ].ready :
307
+ break
308
+ else :
309
+ self .assertEqual (resp .status .phase , 'Pending' )
310
+ self .assertTrue (time .time () < timeout )
309
311
time .sleep (1 )
310
- self .assertEqual (resp .status .phase , 'Running' )
311
-
312
- pf = portforward (api .connect_get_namespaced_pod_portforward ,
313
- name , 'default' ,
314
- ports = '1234,1235,1236' )
315
- self .assertTrue (pf .connected )
316
- sock1234 = pf .socket (1234 )
317
- sock1235 = pf .socket (1235 )
318
- sock1234 .setblocking (True )
319
- sock1235 .setblocking (True )
320
- sent1234 = b'Test port 1234 forwarding...'
321
- sent1235 = b'Test port 1235 forwarding...'
322
- sock1234 .sendall (sent1234 )
323
- sock1235 .sendall (sent1235 )
324
- reply1234 = b''
325
- reply1235 = b''
326
- while True :
327
- rlist = []
328
- if sock1234 .fileno () != - 1 :
329
- rlist .append (sock1234 )
330
- if sock1235 .fileno () != - 1 :
331
- rlist .append (sock1235 )
332
- if not rlist :
333
- break
334
- r , _w , _x = select .select (rlist , [], [], 1 )
335
- if not r :
336
- break
337
- if sock1234 in r :
338
- data = sock1234 .recv (1024 )
339
- self .assertNotEqual (data , b'' , "Unexpected socket close" )
340
- reply1234 += data
341
- if sock1235 in r :
342
- data = sock1235 .recv (1024 )
343
- self .assertNotEqual (data , b'' , "Unexpected socket close" )
344
- reply1235 += data
345
- self .assertEqual (reply1234 , sent1234 )
346
- self .assertEqual (reply1235 , sent1235 )
347
- self .assertTrue (pf .connected )
348
-
349
- sock = pf .socket (1236 )
350
- self .assertRaises (socket .error , sock .sendall , b'This should fail...' )
351
- self .assertIsNotNone (pf .error (1236 ))
352
- sock .close ()
353
-
354
- for sock in (sock1234 , sock1235 ):
312
+
313
+ for ix in range (10 ):
314
+ ix = str (ix + 1 ).encode ()
315
+ pf = portforward (api .connect_get_namespaced_pod_portforward ,
316
+ name , 'default' ,
317
+ ports = '1234,1235,1236' )
355
318
self .assertTrue (pf .connected )
356
- sent = b'Another test using fileno %s' % str (
357
- sock .fileno ()).encode ()
358
- sock .sendall (sent )
359
- reply = b''
360
- while True :
361
- r , _w , _x = select .select ([sock ], [], [], 1 )
362
- if not r :
363
- break
364
- data = sock .recv (1024 )
365
- self .assertNotEqual (data , b'' , "Unexpected socket close" )
366
- reply += data
367
- self .assertEqual (reply , sent )
319
+ sock1234 = pf .socket (1234 )
320
+ sock1235 = pf .socket (1235 )
321
+ sock1234 .setblocking (True )
322
+ sock1235 .setblocking (True )
323
+ sent1234 = b'Test ' + ix + b' port 1234 forwarding'
324
+ sent1235 = b'Test ' + ix + b' port 1235 forwarding'
325
+ sock1234 .sendall (sent1234 )
326
+ sock1235 .sendall (sent1235 )
327
+ reply1234 = b''
328
+ reply1235 = b''
329
+ timeout = time .time () + 60
330
+ while reply1234 != sent1234 or reply1235 != sent1235 :
331
+ self .assertNotEqual (sock1234 .fileno (), - 1 )
332
+ self .assertNotEqual (sock1235 .fileno (), - 1 )
333
+ self .assertTrue (time .time () < timeout )
334
+ r , _w , _x = select .select ([sock1234 , sock1235 ], [], [], 1 )
335
+ if sock1234 in r :
336
+ data = sock1234 .recv (1024 )
337
+ self .assertNotEqual (data , b'' , 'Unexpected socket close' )
338
+ reply1234 += data
339
+ self .assertTrue (sent1234 .startswith (reply1234 ))
340
+ if sock1235 in r :
341
+ data = sock1235 .recv (1024 )
342
+ self .assertNotEqual (data , b'' , 'Unexpected socket close' )
343
+ reply1235 += data
344
+ self .assertTrue (sent1235 .startswith (reply1235 ))
345
+ self .assertTrue (pf .connected )
346
+
347
+ sock = pf .socket (1236 )
348
+ sock .setblocking (True )
349
+ self .assertEqual (sock .recv (1024 ), b'' )
350
+ self .assertIsNotNone (pf .error (1236 ))
368
351
sock .close ()
369
- time .sleep (1 )
370
- self .assertFalse (pf .connected )
371
- self .assertIsNone (pf .error (1234 ))
372
- self .assertIsNone (pf .error (1235 ))
352
+
353
+ for sock in (sock1234 , sock1235 ):
354
+ self .assertTrue (pf .connected )
355
+ sent = b'Another test ' + ix + b' using fileno ' + str (sock .fileno ()).encode ()
356
+ sock .sendall (sent )
357
+ reply = b''
358
+ timeout = time .time () + 60
359
+ while reply != sent :
360
+ self .assertNotEqual (sock .fileno (), - 1 )
361
+ self .assertTrue (time .time () < timeout )
362
+ r , _w , _x = select .select ([sock ], [], [], 1 )
363
+ if r :
364
+ data = sock .recv (1024 )
365
+ self .assertNotEqual (data , b'' , 'Unexpected socket close' )
366
+ reply += data
367
+ self .assertTrue (sent .startswith (reply ))
368
+ sock .close ()
369
+ time .sleep (1 )
370
+ self .assertFalse (pf .connected )
371
+ self .assertIsNone (pf .error (1234 ))
372
+ self .assertIsNone (pf .error (1235 ))
373
373
374
374
resp = api .delete_namespaced_pod (name = name , namespace = 'default' )
375
375
resp = api .delete_namespaced_config_map (name = name , namespace = 'default' )
0 commit comments