1
+ # -*- coding: utf-8 -*-
2
+
3
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may
4
+ # not use this file except in compliance with the License. You may obtain
5
+ # a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12
+ # License for the specific language governing permissions and limitations
13
+ # under the License.
14
+
15
+ import unittest
16
+
17
+ from kubernetes import utils , client
18
+ from kubernetes .e2e_test import base
19
+
20
+ class TestUtils (unittest .TestCase ):
21
+
22
+ @classmethod
23
+ def setUpClass (cls ):
24
+ cls .config = base .get_e2e_configuration ()
25
+
26
+ def test_app_yaml (self ):
27
+ k8s_client = client .api_client .ApiClient (configuration = self .config )
28
+ k8s_api = utils .create_from_yaml (k8s_client ,
29
+ "kubernetes/e2e_test/test_yaml/apps-deployment.yaml" )
30
+ self .assertEqual ("apps/v1beta1" ,
31
+ k8s_api .get_api_resources ().group_version )
32
+ dep = k8s_api .read_namespaced_deployment (name = "nginx-app" ,
33
+ namespace = "default" )
34
+ self .assertIsNotNone (dep )
35
+ resp = k8s_api .delete_namespaced_deployment (
36
+ name = "nginx-app" , namespace = "default" ,
37
+ body = {})
38
+
39
+ def test_extension_yaml (self ):
40
+ k8s_client = client .api_client .ApiClient (configuration = self .config )
41
+ k8s_api = utils .create_from_yaml (k8s_client ,
42
+ "kubernetes/e2e_test/test_yaml/extensions-deployment.yaml" )
43
+ self .assertEqual ("extensions/v1beta1" ,
44
+ k8s_api .get_api_resources ().group_version )
45
+ dep = k8s_api .read_namespaced_deployment (name = "nginx-deployment" ,
46
+ namespace = "default" )
47
+ self .assertIsNotNone (dep )
48
+ resp = k8s_api .delete_namespaced_deployment (
49
+ name = "nginx-deployment" , namespace = "default" ,
50
+ body = {})
51
+
52
+ def test_core_pod_yaml (self ):
53
+ k8s_client = client .api_client .ApiClient (configuration = self .config )
54
+ k8s_api = utils .create_from_yaml (k8s_client ,
55
+ "kubernetes/e2e_test/test_yaml/core-pod.yaml" )
56
+ self .assertEqual ("v1" ,
57
+ k8s_api .get_api_resources ().group_version )
58
+ pod = k8s_api .read_namespaced_pod (name = "myapp-pod" ,
59
+ namespace = "default" )
60
+ self .assertIsNotNone (pod )
61
+ resp = k8s_api .delete_namespaced_pod (
62
+ name = "myapp-pod" , namespace = "default" ,
63
+ body = {})
64
+
65
+ def test_core_service_yaml (self ):
66
+ k8s_client = client .api_client .ApiClient (configuration = self .config )
67
+ k8s_api = utils .create_from_yaml (k8s_client ,
68
+ "kubernetes/e2e_test/test_yaml/core-service.yaml" )
69
+ self .assertEqual ("v1" ,
70
+ k8s_api .get_api_resources ().group_version )
71
+ svc = k8s_api .read_namespaced_service (name = "my-service" ,
72
+ namespace = "default" )
73
+ self .assertIsNotNone (svc )
74
+ resp = k8s_api .delete_namespaced_service (
75
+ name = "my-service" , namespace = "default" ,
76
+ body = {})
77
+
78
+ def test_core_namespace_yaml (self ):
79
+ k8s_client = client .api_client .ApiClient (configuration = self .config )
80
+ k8s_api = utils .create_from_yaml (k8s_client ,
81
+ "kubernetes/e2e_test/test_yaml/core-namespace.yaml" )
82
+ self .assertEqual ("v1" ,
83
+ k8s_api .get_api_resources ().group_version )
84
+ nmsp = k8s_api .read_namespace (name = "development" )
85
+ self .assertIsNotNone (nmsp )
86
+ resp = k8s_api .delete_namespace (name = "development" , body = {})
87
+
88
+ def test_deployment_in_namespace (self ):
89
+ k8s_client = client .ApiClient (configuration = self .config )
90
+ core_api = utils .create_from_yaml (k8s_client ,
91
+ "kubernetes/e2e_test/test_yaml/core-namespace-dep.yaml" )
92
+ self .assertEqual ("v1" ,
93
+ core_api .get_api_resources ().group_version )
94
+ nmsp = core_api .read_namespace (name = "dep" )
95
+ self .assertIsNotNone (nmsp )
96
+ dep_api = utils .create_from_yaml (k8s_client ,
97
+ "kubernetes/e2e_test/test_yaml/extensions-deployment-dep.yaml" )
98
+ dep = dep_api .read_namespaced_deployment (name = "nginx-deployment" ,
99
+ namespace = "dep" )
100
+ self .assertIsNotNone (dep )
101
+ resp = dep_api .delete_namespaced_deployment (
102
+ name = "nginx-deployment" , namespace = "dep" ,
103
+ body = {})
104
+ resp = core_api .delete_namespace (name = "dep" , body = {})
105
+
106
+ def test_api_service (self ):
107
+ k8s_client = client .api_client .ApiClient (configuration = self .config )
108
+ k8s_api = utils .create_from_yaml (k8s_client ,
109
+ "kubernetes/e2e_test/test_yaml/api-service.yaml" )
110
+ self .assertEqual ("apiregistration.k8s.io/v1beta1" ,
111
+ k8s_api .get_api_resources ().group_version )
112
+ svc = k8s_api .read_api_service (
113
+ name = "v1alpha1.wardle.k8s.io" )
114
+ self .assertIsNotNone (svc )
115
+ resp = k8s_api .delete_api_service (
116
+ name = "v1alpha1.wardle.k8s.io" , body = {})
0 commit comments