|
19 | 19 | import time
|
20 | 20 | import unittest
|
21 | 21 | import uuid
|
| 22 | +import six |
22 | 23 |
|
23 | 24 | from kubernetes.client import api_client
|
24 | 25 | from kubernetes.client.api import core_v1_api
|
25 | 26 | from kubernetes.e2e_test import base
|
26 | 27 | from kubernetes.stream import stream, portforward
|
27 | 28 | from kubernetes.stream.ws_client import ERROR_CHANNEL
|
| 29 | +from kubernetes.client.rest import ApiException |
28 | 30 |
|
29 | 31 | import six.moves.urllib.request as urllib_request
|
30 | 32 |
|
| 33 | +if six.PY3: |
| 34 | + from http import HTTPStatus |
| 35 | +else: |
| 36 | + import httplib |
| 37 | + |
31 | 38 | def short_uuid():
|
32 | 39 | id = str(uuid.uuid4())
|
33 | 40 | return id[-12:]
|
@@ -65,6 +72,23 @@ def test_pod_apis(self):
|
65 | 72 |
|
66 | 73 | name = 'busybox-test-' + short_uuid()
|
67 | 74 | pod_manifest = manifest_with_command(name, "while true;do date;sleep 5; done")
|
| 75 | + |
| 76 | + # wait for the default service account to be created |
| 77 | + while True: |
| 78 | + try: |
| 79 | + resp = api.read_namespaced_service_account(name='default', |
| 80 | + namespace='default') |
| 81 | + except ApiException as e: |
| 82 | + if (six.PY3 and e.status != HTTPStatus.NOT_FOUND) or ( |
| 83 | + six.PY3 is False and e.status != httplib.NOT_FOUND): |
| 84 | + print('error: %s' % e) |
| 85 | + self.fail(msg="unexpected error getting default service account") |
| 86 | + print('default service not found yet: %s' % e) |
| 87 | + time.sleep(1) |
| 88 | + continue |
| 89 | + self.assertEqual('default', resp.metadata.name) |
| 90 | + break |
| 91 | + |
68 | 92 | resp = api.create_namespaced_pod(body=pod_manifest,
|
69 | 93 | namespace='default')
|
70 | 94 | self.assertEqual(name, resp.metadata.name)
|
@@ -130,6 +154,23 @@ def test_exit_code(self):
|
130 | 154 |
|
131 | 155 | name = 'busybox-test-' + short_uuid()
|
132 | 156 | pod_manifest = manifest_with_command(name, "while true;do date;sleep 5; done")
|
| 157 | + |
| 158 | + # wait for the default service account to be created |
| 159 | + while True: |
| 160 | + try: |
| 161 | + resp = api.read_namespaced_service_account(name='default', |
| 162 | + namespace='default') |
| 163 | + except ApiException as e: |
| 164 | + if (six.PY3 and e.status != HTTPStatus.NOT_FOUND) or ( |
| 165 | + six.PY3 is False and e.status != httplib.NOT_FOUND): |
| 166 | + print('error: %s' % e) |
| 167 | + self.fail(msg="unexpected error getting default service account") |
| 168 | + print('default service not found yet: %s' % e) |
| 169 | + time.sleep(1) |
| 170 | + continue |
| 171 | + self.assertEqual('default', resp.metadata.name) |
| 172 | + break |
| 173 | + |
133 | 174 | resp = api.create_namespaced_pod(body=pod_manifest,
|
134 | 175 | namespace='default')
|
135 | 176 | self.assertEqual(name, resp.metadata.name)
|
|
0 commit comments