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,27 @@ 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
+ timeout = time .time () + 30
78
+ while True :
79
+ if time .time () > timeout :
80
+ print ('timeout waiting for default service account creation' )
81
+ break
82
+ try :
83
+ resp = api .read_namespaced_service_account (name = 'default' ,
84
+ namespace = 'default' )
85
+ except ApiException as e :
86
+ if (six .PY3 and e .status != HTTPStatus .NOT_FOUND ) or (
87
+ six .PY3 is False and e .status != httplib .NOT_FOUND ):
88
+ print ('error: %s' % e )
89
+ self .fail (msg = "unexpected error getting default service account" )
90
+ print ('default service not found yet: %s' % e )
91
+ time .sleep (1 )
92
+ continue
93
+ self .assertEqual ('default' , resp .metadata .name )
94
+ break
95
+
68
96
resp = api .create_namespaced_pod (body = pod_manifest ,
69
97
namespace = 'default' )
70
98
self .assertEqual (name , resp .metadata .name )
@@ -130,6 +158,28 @@ def test_exit_code(self):
130
158
131
159
name = 'busybox-test-' + short_uuid ()
132
160
pod_manifest = manifest_with_command (name , "while true;do date;sleep 5; done" )
161
+
162
+ # wait for the default service account to be created
163
+ timeout = time .time () + 30
164
+ while True :
165
+ if time .time () > timeout :
166
+ print ('timeout waiting for default service account creation' )
167
+ break
168
+
169
+ try :
170
+ resp = api .read_namespaced_service_account (name = 'default' ,
171
+ namespace = 'default' )
172
+ except ApiException as e :
173
+ if (six .PY3 and e .status != HTTPStatus .NOT_FOUND ) or (
174
+ six .PY3 is False and e .status != httplib .NOT_FOUND ):
175
+ print ('error: %s' % e )
176
+ self .fail (msg = "unexpected error getting default service account" )
177
+ print ('default service not found yet: %s' % e )
178
+ time .sleep (1 )
179
+ continue
180
+ self .assertEqual ('default' , resp .metadata .name )
181
+ break
182
+
133
183
resp = api .create_namespaced_pod (body = pod_manifest ,
134
184
namespace = 'default' )
135
185
self .assertEqual (name , resp .metadata .name )
@@ -443,6 +493,7 @@ def test_configmap_apis(self):
443
493
"apiVersion" : "v1" ,
444
494
"metadata" : {
445
495
"name" : name ,
496
+ "labels" : {"e2e-tests" : "true" },
446
497
},
447
498
"data" : {
448
499
"config.json" : "{\" command\" :\" /usr/bin/mysqld_safe\" }" ,
@@ -466,7 +517,7 @@ def test_configmap_apis(self):
466
517
resp = api .delete_namespaced_config_map (
467
518
name = name , body = {}, namespace = 'default' )
468
519
469
- resp = api .list_namespaced_config_map ('default' , pretty = True )
520
+ resp = api .list_namespaced_config_map ('default' , pretty = True , label_selector = "e2e-tests=true" )
470
521
self .assertEqual ([], resp .items )
471
522
472
523
def test_node_apis (self ):
0 commit comments