Skip to content

Commit 96cfceb

Browse files
committed
Run e2e tests against against https url
Use hitch tls proxy to listen on 8443 port and forward the traffic to 8080. Add a configuration option to ignore any issues with host names as we don't generate the cert on the fly.
1 parent 1d3cd13 commit 96cfceb

File tree

9 files changed

+135
-18
lines changed

9 files changed

+135
-18
lines changed

.travis.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@ env:
1313
- TOXENV=docs
1414
- TOXENV=coverage,codecov
1515

16+
before_install:
17+
- sudo add-apt-repository ppa:0k53d-karl-f830m/hitch -y
18+
- sudo apt-get -qq update
19+
- sudo apt-get install hitch
20+
1621
install:
1722
- pip install tox
23+
- hitch --frontend=[*]:8443 --backend=[localhost]:8080 --daemon $TRAVIS_BUILD_DIR/scripts/example.pem
1824

1925
script:
2026
- tox

kubernetes/client/configuration.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ def __init__(self):
8585
self.cert_file = None
8686
# client key file
8787
self.key_file = None
88+
# check host name
89+
# Set this to True/False to enable/disable SSL hostname verification.
90+
self.assert_hostname = None
8891

8992
@property
9093
def logger_file(self):

kubernetes/client/rest.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,20 @@ def __init__(self, pools_size=4, config=configuration):
9595
# key file
9696
key_file = config.key_file
9797

98+
kwargs = {
99+
'num_pools': pools_size,
100+
'cert_reqs': cert_reqs,
101+
'ca_certs': ca_certs,
102+
'cert_file': cert_file,
103+
'key_file': key_file,
104+
}
105+
106+
if config.assert_hostname is not None:
107+
kwargs['assert_hostname'] = config.assert_hostname
108+
98109
# https pool manager
99110
self.pool_manager = urllib3.PoolManager(
100-
num_pools=pools_size,
101-
cert_reqs=cert_reqs,
102-
ca_certs=ca_certs,
103-
cert_file=cert_file,
104-
key_file=key_file
111+
**kwargs
105112
)
106113

107114
def request(self, method, url, query_params=None, headers=None,

kubernetes/e2e_test/base.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,23 @@
1010
# License for the specific language governing permissions and limitations
1111
# under the License.
1212

13+
import copy
14+
import os
1315
import urllib3
1416

17+
from kubernetes.client.configuration import configuration
1518

1619
def is_k8s_running():
1720
try:
1821
urllib3.PoolManager().request('GET', '127.0.0.1:8080')
1922
return True
2023
except urllib3.exceptions.HTTPError:
2124
return False
25+
26+
27+
def setSSLConfiguration():
28+
config = copy.copy(configuration)
29+
config.verify_ssl = True
30+
config.ssl_ca_cert = os.path.dirname(__file__) + '/../../scripts/example.pem'
31+
config.assert_hostname = False
32+
return config

kubernetes/e2e_test/test_batch.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,21 @@
1717

1818
from kubernetes.client import api_client
1919
from kubernetes.client.apis import batch_v1_api
20+
from kubernetes.client.configuration import configuration
2021
from kubernetes.e2e_test import base
2122

2223

2324
class TestClientBatch(unittest.TestCase):
25+
26+
@classmethod
27+
def setUpClass(cls):
28+
cls.API_URL = 'http://127.0.0.1:8080/'
29+
cls.config = configuration
30+
2431
@unittest.skipUnless(
2532
base.is_k8s_running(), "Kubernetes is not available")
2633
def test_job_apis(self):
27-
client = api_client.ApiClient('http://127.0.0.1:8080/')
34+
client = api_client.ApiClient(self.API_URL, config=self.config)
2835
api = batch_v1_api.BatchV1Api(client)
2936

3037
name = 'test-job-' + str(uuid.uuid4())
@@ -52,4 +59,12 @@ def test_job_apis(self):
5259
self.assertEqual(name, resp.metadata.name)
5360

5461
resp = api.delete_namespaced_job(
55-
name=name, body={}, namespace='default')
62+
name=name, body={}, namespace='default')
63+
64+
65+
class TestClientBatchSSL(TestClientBatch):
66+
67+
@classmethod
68+
def setUpClass(cls):
69+
cls.API_URL = 'https://127.0.0.1:8443/'
70+
cls.config = base.setSSLConfiguration()

kubernetes/e2e_test/test_client.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,21 @@
1717

1818
from kubernetes.client import api_client
1919
from kubernetes.client.apis import core_v1_api
20+
from kubernetes.client.configuration import configuration
2021
from kubernetes.e2e_test import base
2122

2223

2324
class TestClient(unittest.TestCase):
25+
26+
@classmethod
27+
def setUpClass(cls):
28+
cls.API_URL = 'http://127.0.0.1:8080/'
29+
cls.config = configuration
30+
2431
@unittest.skipUnless(
2532
base.is_k8s_running(), "Kubernetes is not available")
2633
def test_pod_apis(self):
27-
client = api_client.ApiClient('http://127.0.0.1:8080/')
34+
client = api_client.ApiClient(self.API_URL, config=self.config)
2835
api = core_v1_api.CoreV1Api(client)
2936

3037
name = 'test-' + str(uuid.uuid4())
@@ -53,7 +60,7 @@ def test_pod_apis(self):
5360
@unittest.skipUnless(
5461
base.is_k8s_running(), "Kubernetes is not available")
5562
def test_service_apis(self):
56-
client = api_client.ApiClient('http://127.0.0.1:8080/')
63+
client = api_client.ApiClient(self.API_URL, config=self.config)
5764
api = core_v1_api.CoreV1Api(client)
5865

5966
name = 'frontend-' + str(uuid.uuid4())
@@ -94,7 +101,7 @@ def test_service_apis(self):
94101
@unittest.skipUnless(
95102
base.is_k8s_running(), "Kubernetes is not available")
96103
def test_replication_controller_apis(self):
97-
client = api_client.ApiClient('http://127.0.0.1:8080/')
104+
client = api_client.ApiClient(self.API_URL, config=self.config)
98105
api = core_v1_api.CoreV1Api(client)
99106

100107
name = 'frontend-' + str(uuid.uuid4())
@@ -129,7 +136,7 @@ def test_replication_controller_apis(self):
129136
@unittest.skipUnless(
130137
base.is_k8s_running(), "Kubernetes is not available")
131138
def test_configmap_apis(self):
132-
client = api_client.ApiClient('http://127.0.0.1:8080/')
139+
client = api_client.ApiClient(self.API_URL, config=self.config)
133140
api = core_v1_api.CoreV1Api(client)
134141

135142
name = 'test-configmap-' + str(uuid.uuid4())
@@ -167,10 +174,18 @@ def test_configmap_apis(self):
167174
@unittest.skipUnless(
168175
base.is_k8s_running(), "Kubernetes is not available")
169176
def test_node_apis(self):
170-
client = api_client.ApiClient('http://127.0.0.1:8080/')
177+
client = api_client.ApiClient(self.API_URL, config=self.config)
171178
api = core_v1_api.CoreV1Api(client)
172179

173180
for item in api.list_node().items:
174181
node = api.read_node(name=item.metadata.name)
175182
self.assertTrue(len(node.metadata.labels) > 0)
176-
self.assertTrue(isinstance(node.metadata.labels, dict))
183+
self.assertTrue(isinstance(node.metadata.labels, dict))
184+
185+
186+
class TestClientSSL(TestClient):
187+
188+
@classmethod
189+
def setUpClass(cls):
190+
cls.API_URL = 'https://127.0.0.1:8443/'
191+
cls.config = base.setSSLConfiguration()

kubernetes/e2e_test/test_extensions.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,22 @@
1818

1919
from kubernetes.client import api_client
2020
from kubernetes.client.apis import extensions_v1beta1_api
21+
from kubernetes.client.configuration import configuration
2122
from kubernetes.client.models import v1_delete_options
2223
from kubernetes.e2e_test import base
2324

2425

2526
class TestClientExtensions(unittest.TestCase):
27+
28+
@classmethod
29+
def setUpClass(cls):
30+
cls.API_URL = 'http://127.0.0.1:8080/'
31+
cls.config = configuration
32+
2633
@unittest.skipUnless(
2734
base.is_k8s_running(), "Kubernetes is not available")
2835
def test_create_deployment(self):
29-
client = api_client.ApiClient('http://127.0.0.1:8080/')
36+
client = api_client.ApiClient(self.API_URL, config=self.config)
3037
api = extensions_v1beta1_api.ExtensionsV1beta1Api(client)
3138
name = 'nginx-deployment-' + str(uuid.uuid4())
3239
deployment = '''apiVersion: extensions/v1beta1
@@ -58,7 +65,7 @@ def test_create_deployment(self):
5865
@unittest.skipUnless(
5966
base.is_k8s_running(), "Kubernetes is not available")
6067
def test_create_daemonset(self):
61-
client = api_client.ApiClient('http://127.0.0.1:8080/')
68+
client = api_client.ApiClient(self.API_URL, config=self.config)
6269
api = extensions_v1beta1_api.ExtensionsV1beta1Api(client)
6370
name = 'nginx-app-' + str(uuid.uuid4())
6471
daemonset = {
@@ -90,4 +97,12 @@ def test_create_daemonset(self):
9097
self.assertIsNotNone(resp)
9198

9299
options = v1_delete_options.V1DeleteOptions()
93-
resp = api.delete_namespaced_daemon_set(name, 'default', body=options)
100+
resp = api.delete_namespaced_daemon_set(name, 'default', body=options)
101+
102+
103+
class TestClientExtensionsSSL(TestClientExtensions):
104+
105+
@classmethod
106+
def setUpClass(cls):
107+
cls.API_URL = 'https://127.0.0.1:8443/'
108+
cls.config = base.setSSLConfiguration()

scripts/example.pem

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
-----BEGIN PRIVATE KEY-----
2+
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQC322Zo7ETx0bAw
3+
0kJytMDPa76VT+TRgZj6AzS8xm+kRXeqLDJ+6ZmDvZkNKwbwIKAmccWvY/OJNv/0
4+
c5f1Hd6Y+vK9Qxi4f62ZbavKJpcxIFepa/hmrkRN0Iw9ZahzRZy07jw9SFxZTKEK
5+
GTj/sb+SCUMwaJFZN0D6zhtqR70NjdHp14JWJsUtarBBtoGzEtINJgRkTS9ej6Fj
6+
bh2RGz6HKiWQgX9W7v5P7zFek9IUDEczBr/aQlFXwE0tNUMjbZyMM4TfgITcx+mj
7+
FbR3+hoZLJg0NMKT2wSiKvp1DU0KR5xF8S4q4OUC5yyvV2ylHPdvWldh+6LXcrx/
8+
oSxhpYDhAgMBAAECggEAUNZfhbx0Z9ppXF3mJ2b/63MVHbM+CTuxFiP4uROKnLCK
9+
d8DtBs4Q2FKxi4+igkvl/mFBqOcKegc7rLByXKygZaTYu4xXvy8sFeyZfs1O5qOw
10+
x2YYlpUCpTAPqSMcWGqABzFEPTGmoQDHQZhrbkkp0LzP1OX1GkPoBx4+AZG/Nsin
11+
aWrTgfPNOtK2RGyLuS3rNn+NWh1jlm/37AVayKxSTirL5XXZUOW3Yye5ROZDWddr
12+
rKzkhIsF/zcUxsQvFtMtjFPRFhKlasAx6MgPB2ptzj5Ykq29jumVfBd9O6voqDMW
13+
Z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CSqGSIb3DQEBCwUAMBQxEjAQBgNV
31+
BAMMCWxvY2FsaG9zdDAeFw0xNzAyMDIyMTQ0MTVaFw0yNzAxMzEyMTQ0MTVaMBQx
32+
EjAQBgNVBAMMCWxvY2FsaG9zdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
33+
ggEBALfbZmjsRPHRsDDSQnK0wM9rvpVP5NGBmPoDNLzGb6RFd6osMn7pmYO9mQ0r
34+
BvAgoCZxxa9j84k2//Rzl/Ud3pj68r1DGLh/rZltq8omlzEgV6lr+GauRE3QjD1l
35+
qHNFnLTuPD1IXFlMoQoZOP+xv5IJQzBokVk3QPrOG2pHvQ2N0enXglYmxS1qsEG2
36+
gbMS0g0mBGRNL16PoWNuHZEbPocqJZCBf1bu/k/vMV6T0hQMRzMGv9pCUVfATS01
37+
QyNtnIwzhN+AhNzH6aMVtHf6GhksmDQ0wpPbBKIq+nUNTQpHnEXxLirg5QLnLK9X
38+
bKUc929aV2H7otdyvH+hLGGlgOECAwEAAaMNMAswCQYDVR0TBAIwADANBgkqhkiG
39+
9w0BAQsFAAOCAQEABblz/REaCmzZq/wlRN3NdwRuLvSz1peAVQNmuEfpIsYDxHIU
40+
ognnm+afEo6O18PjBXFSP4r1vsc/TTGk1T3xP4FgPJ9xLsUNQk9Kch05vQIwJtcQ
41+
iIdMRhGVdxSg8V29KTFImfcbS/VkV9Ev/FKHifs+PL9rJMBpE/r6xe6D6p+d9jw5
42+
cpCw+kgGHZVWA+8GEjyCGZIHyMAL6YwC246N6uTPuDHyvQZZHqh9r602bp5zpMbw
43+
ZW4+YD7+PEAhFmTRYiqUPTyBPRBKcIZdkKtND/CQ4IwtHJ+ApjwQuXBjKUpPJroh
44+
s5cwhxeaimBe9C9axIuuUd8LAVTXLFVwL0wEYw==
45+
-----END CERTIFICATE-----

tox.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ commands =
2121
[testenv:py27-functional]
2222
commands =
2323
python -V
24-
{toxinidir}/scripts/kube-init.sh nosetests []
24+
{toxinidir}/scripts/kube-init.sh nosetests -v []
2525

2626
[testenv:py35-functional]
2727
commands =
2828
python -V
29-
{toxinidir}/scripts/kube-init.sh nosetests []
29+
{toxinidir}/scripts/kube-init.sh nosetests -v []
3030

3131
[testenv:coverage]
3232
commands =

0 commit comments

Comments
 (0)