17
17
from kubernetes import utils , client
18
18
from kubernetes .e2e_test import base
19
19
20
+
20
21
class TestUtils (unittest .TestCase ):
21
22
22
23
@classmethod
23
24
def setUpClass (cls ):
24
25
cls .config = base .get_e2e_configuration ()
26
+ cls .test_namespace = "e2e-test-utils"
27
+ k8s_client = client .api_client .ApiClient (configuration = cls .config )
28
+ core_v1 = client .CoreV1Api (api_client = k8s_client )
29
+ body = client .V1Namespace (metadata = client .V1ObjectMeta (name = cls .test_namespace ))
30
+ core_v1 .create_namespace (body = body )
31
+
32
+ @classmethod
33
+ def tearDownClass (cls ):
34
+ k8s_client = client .api_client .ApiClient (configuration = cls .config )
35
+ core_v1 = client .CoreV1Api (api_client = k8s_client )
36
+ core_v1 .delete_namespace (name = cls .test_namespace )
25
37
26
38
def test_app_yaml (self ):
27
39
k8s_client = client .api_client .ApiClient (configuration = self .config )
28
- k8s_api = utils .create_from_yaml (k8s_client ,
40
+ k8s_api = utils .create_from_yaml (k8s_client ,
29
41
"kubernetes/e2e_test/test_yaml/apps-deployment.yaml" )
30
- self .assertEqual ("apps/v1beta1" ,
42
+ self .assertEqual ("apps/v1beta1" ,
31
43
k8s_api .get_api_resources ().group_version )
32
44
dep = k8s_api .read_namespaced_deployment (name = "nginx-app" ,
33
45
namespace = "default" )
34
46
self .assertIsNotNone (dep )
35
- resp = k8s_api .delete_namespaced_deployment (
36
- name = "nginx-app" , namespace = "default" ,
47
+ k8s_api .delete_namespaced_deployment (
48
+ name = "nginx-app" , namespace = "default" ,
37
49
body = {})
38
50
39
51
def test_extension_yaml (self ):
@@ -45,7 +57,7 @@ def test_extension_yaml(self):
45
57
dep = k8s_api .read_namespaced_deployment (name = "nginx-deployment" ,
46
58
namespace = "default" )
47
59
self .assertIsNotNone (dep )
48
- resp = k8s_api .delete_namespaced_deployment (
60
+ k8s_api .delete_namespaced_deployment (
49
61
name = "nginx-deployment" , namespace = "default" ,
50
62
body = {})
51
63
@@ -58,7 +70,7 @@ def test_core_pod_yaml(self):
58
70
pod = k8s_api .read_namespaced_pod (name = "myapp-pod" ,
59
71
namespace = "default" )
60
72
self .assertIsNotNone (pod )
61
- resp = k8s_api .delete_namespaced_pod (
73
+ k8s_api .delete_namespaced_pod (
62
74
name = "myapp-pod" , namespace = "default" ,
63
75
body = {})
64
76
@@ -71,7 +83,7 @@ def test_core_service_yaml(self):
71
83
svc = k8s_api .read_namespaced_service (name = "my-service" ,
72
84
namespace = "default" )
73
85
self .assertIsNotNone (svc )
74
- resp = k8s_api .delete_namespaced_service (
86
+ k8s_api .delete_namespaced_service (
75
87
name = "my-service" , namespace = "default" ,
76
88
body = {})
77
89
@@ -83,7 +95,7 @@ def test_core_namespace_yaml(self):
83
95
k8s_api .get_api_resources ().group_version )
84
96
nmsp = k8s_api .read_namespace (name = "development" )
85
97
self .assertIsNotNone (nmsp )
86
- resp = k8s_api .delete_namespace (name = "development" , body = {})
98
+ k8s_api .delete_namespace (name = "development" , body = {})
87
99
88
100
def test_deployment_in_namespace (self ):
89
101
k8s_client = client .ApiClient (configuration = self .config )
@@ -98,10 +110,10 @@ def test_deployment_in_namespace(self):
98
110
dep = dep_api .read_namespaced_deployment (name = "nginx-deployment" ,
99
111
namespace = "dep" )
100
112
self .assertIsNotNone (dep )
101
- resp = dep_api .delete_namespaced_deployment (
113
+ dep_api .delete_namespaced_deployment (
102
114
name = "nginx-deployment" , namespace = "dep" ,
103
115
body = {})
104
- resp = core_api .delete_namespace (name = "dep" , body = {})
116
+ core_api .delete_namespace (name = "dep" , body = {})
105
117
106
118
def test_api_service (self ):
107
119
k8s_client = client .api_client .ApiClient (configuration = self .config )
@@ -112,5 +124,61 @@ def test_api_service(self):
112
124
svc = k8s_api .read_api_service (
113
125
name = "v1alpha1.wardle.k8s.io" )
114
126
self .assertIsNotNone (svc )
115
- resp = k8s_api .delete_api_service (
116
- name = "v1alpha1.wardle.k8s.io" , body = {})
127
+ k8s_api .delete_api_service (
128
+ name = "v1alpha1.wardle.k8s.io" , body = {})
129
+
130
+ def test_namespaced_app_yaml (self ):
131
+ k8s_client = client .api_client .ApiClient (configuration = self .config )
132
+ k8s_api = utils .create_namespaced_from_yaml (k8s_client ,
133
+ "kubernetes/e2e_test/test_yaml/apps-deployment.yaml" ,
134
+ namespace = self .test_namespace )
135
+ self .assertEqual ("apps/v1beta1" ,
136
+ k8s_api .get_api_resources ().group_version )
137
+ dep = k8s_api .read_namespaced_deployment (name = "nginx-app" ,
138
+ namespace = self .test_namespace ,)
139
+ self .assertIsNotNone (dep )
140
+ k8s_api .delete_namespaced_deployment (
141
+ name = "nginx-app" , namespace = self .test_namespace ,
142
+ body = {})
143
+
144
+ def test_namespaced_extension_yaml (self ):
145
+ k8s_client = client .api_client .ApiClient (configuration = self .config )
146
+ k8s_api = utils .create_namespaced_from_yaml (k8s_client ,
147
+ "kubernetes/e2e_test/test_yaml/extensions-deployment.yaml" ,
148
+ namespace = self .test_namespace )
149
+ self .assertEqual ("extensions/v1beta1" ,
150
+ k8s_api .get_api_resources ().group_version )
151
+ dep = k8s_api .read_namespaced_deployment (name = "nginx-deployment" ,
152
+ namespace = self .test_namespace )
153
+ self .assertIsNotNone (dep )
154
+ k8s_api .delete_namespaced_deployment (
155
+ name = "nginx-deployment" , namespace = self .test_namespace ,
156
+ body = {})
157
+
158
+ def test_namespaced_core_pod_yaml (self ):
159
+ k8s_client = client .api_client .ApiClient (configuration = self .config )
160
+ k8s_api = utils .create_namespaced_from_yaml (k8s_client ,
161
+ "kubernetes/e2e_test/test_yaml/core-pod.yaml" ,
162
+ namespace = self .test_namespace )
163
+ self .assertEqual ("v1" ,
164
+ k8s_api .get_api_resources ().group_version )
165
+ pod = k8s_api .read_namespaced_pod (name = "myapp-pod" ,
166
+ namespace = self .test_namespace )
167
+ self .assertIsNotNone (pod )
168
+ k8s_api .delete_namespaced_pod (
169
+ name = "myapp-pod" , namespace = self .test_namespace ,
170
+ body = {})
171
+
172
+ def test_namespaced_core_service_yaml (self ):
173
+ k8s_client = client .api_client .ApiClient (configuration = self .config )
174
+ k8s_api = utils .create_namespaced_from_yaml (k8s_client ,
175
+ "kubernetes/e2e_test/test_yaml/core-service.yaml" ,
176
+ namespace = self .test_namespace )
177
+ self .assertEqual ("v1" ,
178
+ k8s_api .get_api_resources ().group_version )
179
+ svc = k8s_api .read_namespaced_service (name = "my-service" ,
180
+ namespace = self .test_namespace )
181
+ self .assertIsNotNone (svc )
182
+ k8s_api .delete_namespaced_service (
183
+ name = "my-service" , namespace = self .test_namespace ,
184
+ body = {})
0 commit comments