python/kubernetes/e2e_test/base.py
Davanum Srinivas 353e8ccdc8 Switch to minikube/localkube
* Drop the old Kubernetes on docker containers method as it
  did not have a SSL enabled port
* Use localkube component from minikube instead. This enables
  us to drop the hitch TLS proxy as well.
* E2E tests should be easy to run locally and pick up configuration
  from ~/.kube/config
* Consolidate the urls in one spot (base.py), also consolidate the
  SkipTest in one spot.
* For local testing, just run minikube and run the py27 or py34 tox
  target, that should run all the tests including the e2e tests.
* Fix the connect_post_namespaced_pod_exec and add a e2e test for it

Fixes #122
2017-02-09 15:49:04 -05:00

46 lines
1.6 KiB
Python

# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import copy
import os
import unittest
import urllib3
from kubernetes.client.configuration import configuration
from kubernetes.config import kube_config
DEFAULT_E2E_HOST = '127.0.0.1'
def get_e2e_configuration():
config = copy.copy(configuration)
config.host = None
if os.path.exists(
os.path.expanduser(kube_config.KUBE_CONFIG_DEFAULT_LOCATION)):
kube_config.load_kube_config(client_configuration=config)
else:
print('Unable to load config from %s' %
kube_config.KUBE_CONFIG_DEFAULT_LOCATION)
for url in ['https://%s:8443' % DEFAULT_E2E_HOST,
'http://%s:8080' % DEFAULT_E2E_HOST]:
try:
urllib3.PoolManager().request('GET', url)
config.host = url
config.verify_ssl = False
break
except urllib3.exceptions.HTTPError:
pass
if config.host is None:
raise unittest.SkipTest('Unable to find a running Kubernetes instance')
print('Running test against : %s' % config.host)
return config