@@ -70,137 +70,6 @@ class TestClient(unittest.TestCase):
7070 def setUpClass (cls ):
7171 cls .config = base .get_e2e_configuration ()
7272
73- def test_pod_apis (self ):
74- client = api_client .ApiClient (configuration = self .config )
75- api = core_v1_api .CoreV1Api (client )
76-
77- name = 'busybox-test-' + short_uuid ()
78- pod_manifest = manifest_with_command (
79- name , "while true;do date;sleep 5; done" )
80-
81- # wait for the default service account to be created
82- timeout = time .time () + 30
83- while True :
84- if time .time () > timeout :
85- print ('timeout waiting for default service account creation' )
86- break
87- try :
88- resp = api .read_namespaced_service_account (name = 'default' ,
89- namespace = 'default' )
90- except ApiException as e :
91- if (six .PY3 and e .status != HTTPStatus .NOT_FOUND ) or (
92- six .PY3 is False and e .status != httplib .NOT_FOUND ):
93- print ('error: %s' % e )
94- self .fail (
95- msg = "unexpected error getting default service account" )
96- print ('default service not found yet: %s' % e )
97- time .sleep (1 )
98- continue
99- self .assertEqual ('default' , resp .metadata .name )
100- break
101-
102- resp = api .create_namespaced_pod (body = pod_manifest ,
103- namespace = 'default' )
104- self .assertEqual (name , resp .metadata .name )
105- self .assertTrue (resp .status .phase )
106-
107- while True :
108- resp = api .read_namespaced_pod (name = name ,
109- namespace = 'default' )
110- self .assertEqual (name , resp .metadata .name )
111- self .assertTrue (resp .status .phase )
112- if resp .status .phase != 'Pending' :
113- break
114- time .sleep (1 )
115-
116- exec_command = ['/bin/sh' ,
117- '-c' ,
118- 'for i in $(seq 1 3); do date; done' ]
119- resp = stream (api .connect_get_namespaced_pod_exec , name , 'default' ,
120- command = exec_command ,
121- stderr = False , stdin = False ,
122- stdout = True , tty = False )
123- print ('EXEC response : %s (%s)' % (repr (resp ), type (resp )))
124- self .assertIsInstance (resp , str )
125- self .assertEqual (3 , len (resp .splitlines ()))
126-
127- exec_command = ['/bin/sh' ,
128- '-c' ,
129- 'echo -n "This is a test string" | gzip' ]
130- resp = stream (api .connect_get_namespaced_pod_exec , name , 'default' ,
131- command = exec_command ,
132- stderr = False , stdin = False ,
133- stdout = True , tty = False ,
134- binary = True )
135- print ('EXEC response : %s (%s)' % (repr (resp ), type (resp )))
136- self .assertIsInstance (resp , bytes )
137- self .assertEqual ("This is a test string" , gzip .decompress (resp ).decode ('utf-8' ))
138-
139- exec_command = 'uptime'
140- resp = stream (api .connect_post_namespaced_pod_exec , name , 'default' ,
141- command = exec_command ,
142- stderr = False , stdin = False ,
143- stdout = True , tty = False )
144- print ('EXEC response : %s' % repr (resp ))
145- self .assertEqual (1 , len (resp .splitlines ()))
146-
147- resp = stream (api .connect_post_namespaced_pod_exec , name , 'default' ,
148- command = '/bin/sh' ,
149- stderr = True , stdin = True ,
150- stdout = True , tty = False ,
151- _preload_content = False )
152- resp .write_stdin ("echo test string 1\n " )
153- line = resp .readline_stdout (timeout = 5 )
154- self .assertFalse (resp .peek_stderr ())
155- self .assertEqual ("test string 1" , line )
156- resp .write_stdin ("echo test string 2 >&2\n " )
157- line = resp .readline_stderr (timeout = 5 )
158- self .assertFalse (resp .peek_stdout ())
159- self .assertEqual ("test string 2" , line )
160- resp .write_stdin ("exit\n " )
161- resp .update (timeout = 5 )
162- while True :
163- line = resp .read_channel (ERROR_CHANNEL )
164- if line != '' :
165- break
166- time .sleep (1 )
167- status = json .loads (line )
168- self .assertEqual (status ['status' ], 'Success' )
169- resp .update (timeout = 5 )
170- self .assertFalse (resp .is_open ())
171-
172- resp = stream (api .connect_post_namespaced_pod_exec , name , 'default' ,
173- command = '/bin/sh' ,
174- stderr = True , stdin = True ,
175- stdout = True , tty = False ,
176- binary = True ,
177- _preload_content = False )
178- resp .write_stdin (b"echo test string 1\n " )
179- line = resp .readline_stdout (timeout = 5 )
180- self .assertFalse (resp .peek_stderr ())
181- self .assertEqual (b"test string 1" , line )
182- resp .write_stdin (b"echo test string 2 >&2\n " )
183- line = resp .readline_stderr (timeout = 5 )
184- self .assertFalse (resp .peek_stdout ())
185- self .assertEqual (b"test string 2" , line )
186- resp .write_stdin (b"exit\n " )
187- resp .update (timeout = 5 )
188- while True :
189- line = resp .read_channel (ERROR_CHANNEL )
190- if len (line ) != 0 :
191- break
192- time .sleep (1 )
193- status = json .loads (line )
194- self .assertEqual (status ['status' ], 'Success' )
195- resp .update (timeout = 5 )
196- self .assertFalse (resp .is_open ())
197-
198- number_of_pods = len (api .list_pod_for_all_namespaces ().items )
199- self .assertTrue (number_of_pods > 0 )
200-
201- resp = api .delete_namespaced_pod (name = name , body = {},
202- namespace = 'default' )
203-
20473 def test_exit_code (self ):
20574 client = api_client .ApiClient (configuration = self .config )
20675 api = core_v1_api .CoreV1Api (client )
0 commit comments