aboutsummaryrefslogtreecommitdiffstats
path: root/functest_kubernetes
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 /functest_kubernetes
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>
Diffstat (limited to 'functest_kubernetes')
-rw-r--r--functest_kubernetes/__init__.py0
-rw-r--r--functest_kubernetes/k8stest.py96
2 files changed, 96 insertions, 0 deletions
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')]