From 4a0e013cb6e8fd3f3d4b8b595486193f5baa4aec Mon Sep 17 00:00:00 2001 From: Fabian von Feilitzsch Date: Wed, 13 Sep 2017 17:02:52 -0400 Subject: [PATCH] Update to test running - Make tests pass for now - Add stages to testing procedure - Add pypi deployment mechanism to travis - Test openshift container now runs on random port instead of 8443 make test output more verbose skip latest for route as well experimenting with travis build stages fix broken if for stage fix lint and script add default script for testing move all script parameters to outside for now add latest environment fix skip_latest try being real specific with environment remove unnecessary test stage spec order an issue? debug output reverting some changes Run on free port instead of 8443 Readd output capturing Add pypi deployment config --- .travis.yml | 69 +++++++++++-------- conftest.py | 2 +- .../examples/openshift_v1_route.yml | 5 ++ test/functional/conftest.py | 44 +++++++----- tox.ini | 2 +- 5 files changed, 77 insertions(+), 45 deletions(-) diff --git a/.travis.yml b/.travis.yml index fbdf59e9..acb924dd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,35 +1,50 @@ ---- sudo: required - services: - - docker - +- docker cache: - - pip - +- pip language: python - python: - - "2.7" - - "3.5" - +- '2.7' +- '3.5' env: - - TEST_SUITE=lint - - TEST_SUITE=functional OPENSHIFT_VERSION=latest - - TEST_SUITE=functional OPENSHIFT_VERSION=3.7 - - TEST_SUITE=functional OPENSHIFT_VERSION=3.6 - - TEST_SUITE=functional OPENSHIFT_VERSION=1.5 - - TEST_SUITE=functional OPENSHIFT_VERSION=1.4 - - TEST_SUITE=functional OPENSHIFT_VERSION=1.3 - +- TEST_SUITE=functional OPENSHIFT_VERSION=latest +- TEST_SUITE=functional OPENSHIFT_VERSION=3.7 +- TEST_SUITE=functional OPENSHIFT_VERSION=3.6 +- TEST_SUITE=functional OPENSHIFT_VERSION=1.5 +- TEST_SUITE=functional OPENSHIFT_VERSION=1.4 +- TEST_SUITE=functional OPENSHIFT_VERSION=1.3 +script: tox install: - - pip install tox-travis coveralls - -script: - - tox - +- pip install tox-travis coveralls after_success: - - coveralls - -before_cache: - - rm ~/.cache/pip/log/debug.log +- coveralls +jobs: + include: + - stage: lint + python: '2.7' + install: + - pip install tox-travis + script: tox -e py27-lint + env: + - TEST_SUITE=lint OPENSHIFT_VERSION=latest + - python: '3.5' + install: + - pip install tox-travis + script: tox -e py35-lint + env: + - TEST_SUITE=lint OPENSHIFT_VERSION=latest + - stage: deploy + script: skip + deploy: + provider: pypi + user: openshift + password: + secure: OtT8BL3rmSlag7H+jLNuPl52UOD8HVuohK0d4OQNMTiejZ1ali/fT4K1yCqteLLTalode1KnG/YpqQuOeEEVJCZNqbAeG3VuD4o3sx0hn1ATMwu5RDngovSSVojhKAOMSh/w3TycRysV+x/L5twntGycNUmtDiRGSJFmXGgq0EPLbE6DUv8IMwlhq/ncNz7/RU5KU852kwc6TDHZloHdhOH5ibibi7VCKUlkK/JnAT/OX0uw/j4v6Dvs6CzJ2lrSozUtjP5OxWPh6XRcXNxlxYuTSy7rjqBd05pk3YUAOQt/cEa4581Qu9hSEvhWFSJBjxpggWunTAbeSjqpdY+iqHcoKg+J3ErscIQnsLOwo8nCIKzyn4GMGx/jQYNfWuXGJiOqHFFCyYR16BajQ/gWk78K5MpUDlf2zoyq3NjTp7edY9lWWL7BEgZdd5EY6wI3V7tlGFeNG/iWw2gL3jR+FfUqzEnBnA+EfPUcowLD6rVCsKoxuLs1YyNiOJLzI1lX3FXvntEkVjPH7w5yju2GXWuw/Szgd0MK2HSedV/tp526V/GOkhD1sbQngEVdrIwPI1QbiMX/1pcSvkCvJrKq5EpShZ9iD/D0T92/01x5X3HSx+R3yV3zhB8L3H7RDL/F3HGNbqVPaj9rHAfTJaxWhy6Y3nWpfwQI43cKFCNwF28= + on: + tags: true + repo: openshift/openshift-restclient-python +stages: +- lint +- test +- deploy diff --git a/conftest.py b/conftest.py index 8a663760..580f1a5d 100644 --- a/conftest.py +++ b/conftest.py @@ -4,4 +4,4 @@ def pytest_addoption(parser): def pytest_report_header(config): - return "OpenShift verison: {}".format(config.getoption('--openshift-version')) + return "OpenShift version: {}".format(config.getoption('--openshift-version')) diff --git a/openshift/ansiblegen/examples/openshift_v1_route.yml b/openshift/ansiblegen/examples/openshift_v1_route.yml index 3fac9fb7..d6e5c73e 100644 --- a/openshift/ansiblegen/examples/openshift_v1_route.yml +++ b/openshift/ansiblegen/examples/openshift_v1_route.yml @@ -1,6 +1,11 @@ # v1_route.yml --- +# TODO(fabianvf): remove this limit when 3.6+ builds are working. +version_limits: + max: '1.5' + skip_latest: yes + tasks: - create: name: myroute diff --git a/test/functional/conftest.py b/test/functional/conftest.py index 2fc0b2fd..2f977c76 100644 --- a/test/functional/conftest.py +++ b/test/functional/conftest.py @@ -3,18 +3,20 @@ from __future__ import print_function import re -import copy import io import os -import tarfile +import copy import time import uuid import yaml +import socket +import tarfile +from contextlib import closing +import json import docker import pytest import requests -import json from pkg_resources import parse_version @@ -26,17 +28,27 @@ os.remove(os.path.join(os.getcwd(), 'KubeObjHelper.log')) + +@pytest.fixture(scope='session') +def port(): + with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as s: + s.bind(('', 0)) + return s.getsockname()[1] + + @pytest.fixture(scope='session') -def openshift_container(request): +def openshift_container(request, port): client = docker.from_env() - # TODO: bind to a random host port openshift_version = request.config.getoption('--openshift-version') if openshift_version is None: yield None else: - image_name = 'openshift/origin:{}'.format(openshift_version) - container = client.containers.run(image_name, 'start master', detach=True, - ports={'8443/tcp': 8443}) + container = client.containers.run( + 'openshift/origin:{}'.format(openshift_version), + 'start master --listen=0.0.0.0:{}'.format(port), + detach=True, + ports={port: port} + ) try: # Wait for the container to no longer be in the created state before @@ -48,7 +60,7 @@ def openshift_container(request): # Wait for the api server to be ready before continuing for _ in range(10): try: - requests.head("https://127.0.0.1:8443/healthz/ready", verify=False) + requests.head("https://127.0.0.1:{}/healthz/ready".format(port), verify=False) except requests.RequestException: pass time.sleep(1) @@ -105,7 +117,7 @@ def parse_test_name(name): @pytest.fixture(scope='class') -def ansible_helper(request, kubeconfig, admin_kubeconfig): +def ansible_helper(request, kubeconfig, admin_kubeconfig, port): api_version, resource = parse_test_name(request.node.name) needs_admin = request.node.cls.tasks.get('admin') config = admin_kubeconfig if needs_admin else kubeconfig @@ -113,7 +125,7 @@ def ansible_helper(request, kubeconfig, admin_kubeconfig): if kubeconfig is not None: auth = { 'kubeconfig': str(config), - 'host': 'https://localhost:8443', + 'host': 'https://localhost:{}'.format(port), 'verify_ssl': False } try: @@ -157,14 +169,14 @@ def compare_func(ansible_helper, k8s_obj, parameters): @pytest.fixture(scope='class') -def namespace(kubeconfig): +def namespace(kubeconfig, port): name = "test-{}".format(uuid.uuid4()) auth = {} if kubeconfig is not None: auth = { 'kubeconfig': str(kubeconfig), - 'host': 'https://localhost:8443', + 'host': 'https://localhost:{}'.format(port), 'verify_ssl': False } helper = KubernetesAnsibleModuleHelper('v1', 'namespace', debug=True, reset_logfile=False, **auth) @@ -184,13 +196,13 @@ def object_name(request): @pytest.fixture(scope='class') -def project(kubeconfig): +def project(kubeconfig, port): name = "test-{}".format(uuid.uuid4()) auth = {} if kubeconfig is not None: auth = { 'kubeconfig': str(kubeconfig), - 'host': 'https://localhost:8443', + 'host': 'https://localhost:{}'.format(port), 'verify_ssl': False } helper = OpenShiftAnsibleModuleHelper('v1', 'project', debug=True, reset_logfile=False, **auth) @@ -222,7 +234,7 @@ def skip_by_version(request, openshift_version): if request.node.cls.tasks.get('version_limits') and openshift_version: lowest_version = request.node.cls.tasks['version_limits'].get('min') highest_version = request.node.cls.tasks['version_limits'].get('max') - skip_latest = request.node.cls.tasks['version_limits'].get('latest') + skip_latest = request.node.cls.tasks['version_limits'].get('skip_latest') too_low = lowest_version and parse_version(lowest_version) > parse_version(openshift_version) too_high = highest_version and parse_version(highest_version) < parse_version(openshift_version) diff --git a/tox.ini b/tox.ini index 92a2e712..331859ee 100644 --- a/tox.ini +++ b/tox.ini @@ -21,7 +21,7 @@ commands = docs: python setup.py build_sphinx lint: flake8 unit: pytest openshift/test - functional: pytest test --openshift-version={env:openshift_version:latest} + functional: pytest test -v -r s --openshift-version={env:openshift_version:latest} [testenv:update_client] changedir = {toxinidir}/scripts