3535else :
3636 import httplib
3737
38+
3839def short_uuid ():
3940 id = str (uuid .uuid4 ())
4041 return id [- 12 :]
@@ -60,6 +61,7 @@ def manifest_with_command(name, command):
6061 }
6162 }
6263
64+
6365class TestClient (unittest .TestCase ):
6466
6567 @classmethod
@@ -71,7 +73,8 @@ def test_pod_apis(self):
7173 api = core_v1_api .CoreV1Api (client )
7274
7375 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" )
7578
7679 # wait for the default service account to be created
7780 timeout = time .time () + 30
@@ -84,9 +87,10 @@ def test_pod_apis(self):
8487 namespace = 'default' )
8588 except ApiException as e :
8689 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 ):
8891 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" )
9094 print ('default service not found yet: %s' % e )
9195 time .sleep (1 )
9296 continue
@@ -111,25 +115,25 @@ def test_pod_apis(self):
111115 '-c' ,
112116 'for i in $(seq 1 3); do date; done' ]
113117 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 )
117121 print ('EXEC response : %s' % resp )
118122 self .assertEqual (3 , len (resp .splitlines ()))
119123
120124 exec_command = 'uptime'
121125 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 )
125129 print ('EXEC response : %s' % resp )
126130 self .assertEqual (1 , len (resp .splitlines ()))
127131
128132 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 )
133137 resp .write_stdin ("echo test string 1\n " )
134138 line = resp .readline_stdout (timeout = 5 )
135139 self .assertFalse (resp .peek_stderr ())
@@ -157,7 +161,8 @@ def test_exit_code(self):
157161 api = core_v1_api .CoreV1Api (client )
158162
159163 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" )
161166
162167 # wait for the default service account to be created
163168 timeout = time .time () + 30
@@ -171,9 +176,10 @@ def test_exit_code(self):
171176 namespace = 'default' )
172177 except ApiException as e :
173178 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 ):
175180 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" )
177183 print ('default service not found yet: %s' % e )
178184 time .sleep (1 )
179185 continue
@@ -201,11 +207,16 @@ def test_exit_code(self):
201207 (["/bin/sh" , "-c" , "ls /" ], 0 )
202208 )
203209 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 )
209220
210221 self .assertIsNone (client .returncode )
211222 client .run_forever (timeout = 10 )
@@ -337,7 +348,8 @@ def test_portforward_raw(self):
337348
338349 for sock in (sock1234 , sock1235 ):
339350 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 ()
341353 sock .sendall (sent )
342354 reply = b''
343355 while True :
@@ -361,7 +373,7 @@ def test_portforward_http(self):
361373 client = api_client .ApiClient (configuration = self .config )
362374 api = core_v1_api .CoreV1Api (client )
363375
364- name = 'portforward-http-' + short_uuid ()
376+ name = 'portforward-http-' + short_uuid ()
365377 pod_manifest = {
366378 'apiVersion' : 'v1' ,
367379 'kind' : 'Pod' ,
@@ -404,7 +416,8 @@ def kubernetes_create_connection(address, *args, **kwargs):
404416 socket_create_connection = socket .create_connection
405417 try :
406418 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 )
408421 html = response .read ().decode ('utf-8' )
409422 finally :
410423 socket .create_connection = socket_create_connection
@@ -485,7 +498,7 @@ def test_replication_controller_apis(self):
485498 self .assertEqual (2 , resp .spec .replicas )
486499
487500 resp = api .delete_namespaced_replication_controller (
488- name = name , body = {}, namespace = 'default ' )
501+ name = name , namespace = 'default' , propagation_policy = 'Background ' )
489502
490503 def test_configmap_apis (self ):
491504 client = api_client .ApiClient (configuration = self .config )
@@ -521,7 +534,8 @@ def test_configmap_apis(self):
521534 resp = api .delete_namespaced_config_map (
522535 name = name , body = {}, namespace = 'default' )
523536
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" )
525539 self .assertEqual ([], resp .items )
526540
527541 def test_node_apis (self ):
0 commit comments