summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordjkonro <konraddjimeli@gmail.com>2018-01-14 16:19:05 +0100
committerdjkonro <konraddjimeli@gmail.com>2018-01-24 10:06:08 +0100
commit2a36556281b2d95f6d24da9bd02baa611724faf1 (patch)
treeea123cf60c25368635ef88dd042469f4cd62c77a
parentad86868d3740c6ec4a7da0a7a6126fc0385d6d1b (diff)
Add initial python class for kubernetes testing
JIRA: FUNCTEST-904 Co-Authored-By: Cédric Ollivier <cedric.ollivier@orange.com> Change-Id: I9007e4e6f58118d1b09774d0acbb2a315437e09a Signed-off-by: djkonro <konraddjimeli@gmail.com> Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
-rw-r--r--docker/Dockerfile8
-rw-r--r--docker/testcases.yaml24
-rw-r--r--functest_kubernetes/__init__.py0
-rw-r--r--functest_kubernetes/k8stest.py96
-rw-r--r--requirements.txt5
-rw-r--r--setup.cfg7
-rw-r--r--setup.py29
-rw-r--r--test-requirements.txt10
-rw-r--r--tox.ini27
9 files changed, 205 insertions, 1 deletions
diff --git a/docker/Dockerfile b/docker/Dockerfile
index 4b9ddd4e..b8b504b0 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -1,5 +1,6 @@
FROM opnfv/functest-core
+ARG BRANCH=master
ARG K8S_TAG=v1.7.3
RUN apk --no-cache add --update make bash go \
@@ -9,4 +10,9 @@ RUN apk --no-cache add --update make bash go \
(cd /src/k8s.io/kubernetes && \
make kubectl ginkgo && \
make WHAT=test/e2e/e2e.test) && \
- rm -rf /src/k8s.io/kubernetes/.git
+ git clone https://gerrit.opnfv.org/gerrit/functest-kubernetes /src/functest-kubernetes && \
+ (cd /src/functest-kubernetes && git fetch origin $BRANCH && git checkout FETCH_HEAD) && \
+ pip install /src/functest-kubernetes && \
+ rm -rf /src/k8s.io/kubernetes/.git /src/functest-kubernetes
+COPY testcases.yaml /usr/lib/python2.7/site-packages/functest/ci/testcases.yaml
+CMD ["run_tests", "-t", "all"]
diff --git a/docker/testcases.yaml b/docker/testcases.yaml
new file mode 100644
index 00000000..2eed64c1
--- /dev/null
+++ b/docker/testcases.yaml
@@ -0,0 +1,24 @@
+---
+tiers:
+ -
+ name: k8s_e2e
+ order: 1
+ ci_loop: '(daily)|(weekly)'
+ description: >-
+ A set of e2e tests integrated from kubernetes project.
+ testcases:
+ -
+ case_name: k8s_smoke
+ project_name: functest
+ criteria: 100
+ blocking: false
+ description: >-
+ Smoke Tests a running Kubernetes cluster, which
+ validates the deployed cluster is accessible, and
+ at least satisfies minimal functional requirements.
+ dependencies:
+ installer: '(compass)|(joid)'
+ scenario: 'k8-*'
+ run:
+ module: 'functest_kubernetes.k8stest'
+ class: 'K8sSmokeTest'
diff --git a/functest_kubernetes/__init__.py b/functest_kubernetes/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/functest_kubernetes/__init__.py
diff --git a/functest_kubernetes/k8stest.py b/functest_kubernetes/k8stest.py
new file mode 100644
index 00000000..3be56d6c
--- /dev/null
+++ b/functest_kubernetes/k8stest.py
@@ -0,0 +1,96 @@
+#!/usr/bin/env python
+#
+# Copyright (c) 2018 All rights reserved
+# This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+
+"""
+Define the parent for Kubernetes testing.
+"""
+
+from __future__ import division
+
+import logging
+import os
+import subprocess
+import time
+
+from functest.core import testcase
+
+
+LOGGER = logging.getLogger(__name__)
+
+
+class K8sTesting(testcase.TestCase):
+ """Kubernetes test runner"""
+
+ def __init__(self, **kwargs):
+ super(K8sTesting, self).__init__(**kwargs)
+ self.cmd = []
+ self.result = 0
+ self.start_time = 0
+ self.stop_time = 0
+
+ def run_kubetest(self):
+ """Run the test suites"""
+ cmd_line = self.cmd
+ LOGGER.info("Starting k8s test: '%s'.", cmd_line)
+
+ process = subprocess.Popen(cmd_line, stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT)
+ remark = []
+ lines = process.stdout.readlines()
+ for i in range(len(lines) - 1, -1, -1):
+ new_line = str(lines[i])
+
+ if 'SUCCESS!' in new_line or 'FAIL!' in new_line:
+ remark = new_line.replace('--', '|').split('|')
+ break
+
+ if remark and 'SUCCESS!' in remark[0]:
+ self.result = 100
+
+ def run(self):
+
+ if not os.path.isfile(os.getenv('KUBECONFIG')):
+ LOGGER.error("Cannot run k8s testcases. Config file not found ")
+ return self.EX_RUN_ERROR
+
+ self.start_time = time.time()
+ try:
+ self.run_kubetest()
+ res = self.EX_OK
+ except Exception as ex: # pylint: disable=broad-except
+ LOGGER.error("Error with running %s", str(ex))
+ res = self.EX_RUN_ERROR
+
+ self.stop_time = time.time()
+ return res
+
+ def check_envs(self): # pylint: disable=no-self-use
+ """Check if required environment variables are set"""
+ try:
+ assert 'DEPLOY_SCENARIO' in os.environ
+ assert 'KUBECONFIG' in os.environ
+ assert 'KUBE_MASTER' in os.environ
+ assert 'KUBE_MASTER_IP' in os.environ
+ assert 'KUBERNETES_PROVIDER' in os.environ
+ assert 'KUBE_MASTER_URL' in os.environ
+ except Exception as ex:
+ raise Exception("Cannot run k8s testcases. "
+ "Please check env var: %s" % str(ex))
+
+
+class K8sSmokeTest(K8sTesting):
+ """Kubernetes smoke test suite"""
+ def __init__(self, **kwargs):
+ if "case_name" not in kwargs:
+ kwargs.get("case_name", 'k8s_smoke')
+ super(K8sSmokeTest, self).__init__(**kwargs)
+ self.check_envs()
+ self.cmd = ['/src/k8s.io/kubernetes/cluster/test-smoke.sh', '--host',
+ os.getenv('KUBE_MASTER_URL')]
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 00000000..05b476e6
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,5 @@
+# The order of packages is significant, because pip processes them in the order
+# of appearance. Changing the order has an impact on the overall integration
+# process, which may cause wedges in the gate later.
+pbr!=2.1.0,>=2.0.0 # Apache-2.0
+functest
diff --git a/setup.cfg b/setup.cfg
new file mode 100644
index 00000000..1215a3b7
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,7 @@
+[metadata]
+name = functest.kubernetes
+version = 6
+home-page = https://wiki.opnfv.org/display/functest
+
+[files]
+packages = functest_kubernetes
diff --git a/setup.py b/setup.py
new file mode 100644
index 00000000..566d8443
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,29 @@
+# Copyright (c) 2013 Hewlett-Packard Development Company, L.P.
+#
+# 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.
+
+# THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT
+import setuptools
+
+# In python < 2.7.4, a lazy loading of package `pbr` will break
+# setuptools if some other modules registered functions in `atexit`.
+# solution from: http://bugs.python.org/issue15881#msg170215
+try:
+ import multiprocessing # noqa
+except ImportError:
+ pass
+
+setuptools.setup(
+ setup_requires=['pbr>=2.0.0'],
+ pbr=True)
diff --git a/test-requirements.txt b/test-requirements.txt
new file mode 100644
index 00000000..cce6dc25
--- /dev/null
+++ b/test-requirements.txt
@@ -0,0 +1,10 @@
+# The order of packages is significant, because pip processes them in the order
+# of appearance. Changing the order has an impact on the overall integration
+# process, which may cause wedges in the gate later.
+git+https://gerrit.opnfv.org/gerrit/functest#egg=functest
+coverage!=4.4,>=4.0 # Apache-2.0
+mock>=2.0 # BSD
+nose # LGPL
+flake8<2.6.0,>=2.5.4 # MIT
+pylint==1.4.5 # GPLv2
+yamllint
diff --git a/tox.ini b/tox.ini
new file mode 100644
index 00000000..34f8a756
--- /dev/null
+++ b/tox.ini
@@ -0,0 +1,27 @@
+[tox]
+envlist = pep8,pylint,yamllint,py27,py35
+
+[testenv]
+usedevelop = True
+deps =
+ -r{toxinidir}/test-requirements.txt
+install_command = pip install {opts} {packages}
+
+[testenv:pep8]
+basepython = python2.7
+commands = flake8
+
+[testenv:pylint]
+basepython = python2.7
+whitelist_externals = bash
+modules =
+ functest_kubernetes
+commands =
+ pylint --disable=locally-disabled --reports=n {[testenv:pylint]modules}
+
+[testenv:yamllint]
+basepython = python2.7
+files =
+ docker
+commands =
+ yamllint {[testenv:yamllint]files}