MCPcopy Index your code
hub / github.com/kubernetes-client/python / test_exit_code

Method test_exit_code

kubernetes/e2e_test/test_client.py:250–317  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

248 api.delete_namespaced_pod(name=name, body={}, namespace='default')
249
250 def test_exit_code(self):
251 client = api_client.ApiClient(configuration=self.config)
252 api = core_v1_api.CoreV1Api(client)
253
254 name = 'busybox-test-' + short_uuid()
255 pod_manifest = manifest_with_command(
256 name, "while true;do date;sleep 5; done")
257
258 # wait for the default service account to be created
259 timeout = time.time() + 30
260 while True:
261 if time.time() > timeout:
262 print('timeout waiting for default service account creation')
263 break
264
265 try:
266 resp = api.read_namespaced_service_account(name='default',
267 namespace='default')
268 except ApiException as e:
269 if e.status != HTTPStatus.NOT_FOUND:
270 print('error: %s' % e)
271 self.fail(
272 msg="unexpected error getting default service account")
273 print('default service not found yet: %s' % e)
274 time.sleep(1)
275 continue
276 self.assertEqual('default', resp.metadata.name)
277 break
278
279 resp = api.create_namespaced_pod(body=pod_manifest,
280 namespace='default')
281 self.assertEqual(name, resp.metadata.name)
282 self.assertTrue(resp.status.phase)
283
284 while True:
285 resp = api.read_namespaced_pod(name=name,
286 namespace='default')
287 self.assertEqual(name, resp.metadata.name)
288 self.assertTrue(resp.status.phase)
289 if resp.status.phase == 'Running':
290 break
291 time.sleep(1)
292
293 commands_expected_values = (
294 (["false", 1]),
295 (["/bin/sh", "-c", "sleep 1; exit 3"], 3),
296 (["true", 0]),
297 (["/bin/sh", "-c", "ls /"], 0)
298 )
299 for command, value in commands_expected_values:
300 client = stream(
301 api.connect_get_namespaced_pod_exec,
302 name,
303 'default',
304 command=command,
305 stderr=True,
306 stdin=False,
307 stdout=True,

Callers

nothing calls this directly

Calls 9

create_namespaced_podMethod · 0.95
read_namespaced_podMethod · 0.95
delete_namespaced_podMethod · 0.95
manifest_with_commandFunction · 0.85
run_foreverMethod · 0.80
short_uuidFunction · 0.70
timeMethod · 0.45
sleepMethod · 0.45

Tested by

no test coverage detected