diff options
author | mrichomme <morgan.richomme@orange.com> | 2019-12-10 08:47:28 +0100 |
---|---|---|
committer | mrichomme <morgan.richomme@orange.com> | 2019-12-11 12:00:31 +0100 |
commit | 1f997a66f658ff11809f44f4630fc678eb091b83 (patch) | |
tree | d29e08adfc2a5d193310d9dfc640175b0cf76fc6 /infra-healthcheck/infra_healthcheck | |
parent | 78b4cdd2c5aa084ee6b8cc0f768187be907ae68c (diff) |
Move integration xtesting Dockerfile to ONAP
All the Dockerfiles and xtesting configurations were hosted in gitlab.com [1]
The goal of this patch is to host these assets in ONAP
A jenkins jjb shall be created to generated the docker and push them on the nexus
(today the built-in registry of ONAP was used)
These xtesting dockers are referencing integration categories [2] and integration
use cases [3]
These xtesting dockers shall also simplify the way to integrate new use cases in any
CI chain (jenkins or gitlab-ci based)
[1]: https://gitlab.com/Orange-OpenSource/lfn/onap/integration/xtesting
[2]: https://wiki.onap.org/pages/viewpage.action?pageId=71835330
[3]: http://testresults.opnfv.org/onap/api/v1/projects/integration/cases
Issue-ID: INT-1366
Signed-off-by: mrichomme <morgan.richomme@orange.com>
Change-Id: Iba0fc0b0415731a7a81ba0225a70ae16391dd129
Signed-off-by: mrichomme <morgan.richomme@orange.com>
Diffstat (limited to 'infra-healthcheck/infra_healthcheck')
-rw-r--r-- | infra-healthcheck/infra_healthcheck/__init__.py | 0 | ||||
-rw-r--r-- | infra-healthcheck/infra_healthcheck/k8stest.py | 121 | ||||
-rw-r--r-- | infra-healthcheck/infra_healthcheck/test_k8stest.py | 41 |
3 files changed, 162 insertions, 0 deletions
diff --git a/infra-healthcheck/infra_healthcheck/__init__.py b/infra-healthcheck/infra_healthcheck/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/infra-healthcheck/infra_healthcheck/__init__.py diff --git a/infra-healthcheck/infra_healthcheck/k8stest.py b/infra-healthcheck/infra_healthcheck/k8stest.py new file mode 100644 index 0000000..8bb7dde --- /dev/null +++ b/infra-healthcheck/infra_healthcheck/k8stest.py @@ -0,0 +1,121 @@ +#!/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 subprocess +import time + +from xtesting.core import testcase + + +class K8sTesting(testcase.TestCase): + """Kubernetes test runner""" + + __logger = logging.getLogger(__name__) + + def __init__(self, **kwargs): + super(K8sTesting, self).__init__(**kwargs) + self.cmd = [] + self.result = 0 + self.details = {} + self.start_time = 0 + self.stop_time = 0 + self.criteria_string = "" + + def run_kubetest(self): # pylint: disable=too-many-branches + """Run the test suites""" + cmd_line = self.cmd + self.__logger.info("Starting k8s test: '%s'.", cmd_line) + + process = subprocess.Popen(cmd_line, stdout=subprocess.PIPE, + stderr=subprocess.STDOUT) + output = process.stdout.read().decode("utf-8") + if ('Error loading client' in output or + 'Unexpected error' in output): + raise Exception(output) + + # create a log file + file_name = "/var/lib/xtesting/results/" + self.case_name + ".log" + log_file = open(file_name, "w") + log_file.write(output) + log_file.close() + + remarks = [] + details = {} + lines = output.split('\n') + success = False + + for log in lines: + if log.startswith(">>>"): + remarks.append(log.replace('>', '')) + for remark in remarks: + if ':' in remark: + # 2 possible Results + # * numeric nb pods, failed, duration + # * list of pods, charts,... + if '[' in remark: + # it is a list + str1 = remark.split(":", 1)[1].strip().replace( + ']', '').replace('[', '') + details[remark.split(":", 1)[0].strip()] = str1.split(",") + else: + details[remark.split(":", 1)[0].strip()] = int( + remark.split(":", 1)[1].strip()) + + # if 1 pod/helm chart if Failed, the testcase is failed + if int(details[self.criteria_string]) < 1: + success = True + + self.details = details + self.__logger.info("details: %s", details) + + if success: + self.result = 100 + else: + self.result = 0 + + def run(self, **kwargs): + + self.start_time = time.time() + try: + self.run_kubetest() + res = self.EX_OK + except Exception: # pylint: disable=broad-except + self.__logger.exception("Error with running kubetest:") + res = self.EX_RUN_ERROR + + self.stop_time = time.time() + return res + + +class OnapK8sTest(K8sTesting): + """Kubernetes smoke test suite""" + def __init__(self, **kwargs): + if "case_name" not in kwargs: + kwargs.get("case_name", 'onap-k8s') + super(OnapK8sTest, self).__init__(**kwargs) + self.cmd = ['/check_onap_k8s.sh'] + self.criteria_string = "Nb Failed Pods" + + +class OnapHelmTest(K8sTesting): + """Kubernetes conformance test suite""" + def __init__(self, **kwargs): + if "case_name" not in kwargs: + kwargs.get("case_name", 'onap-helm') + super(OnapHelmTest, self).__init__(**kwargs) + self.cmd = ['/check_onap_helm.sh'] + self.criteria_string = "Nb Failed Helm Charts" diff --git a/infra-healthcheck/infra_healthcheck/test_k8stest.py b/infra-healthcheck/infra_healthcheck/test_k8stest.py new file mode 100644 index 0000000..4e91279 --- /dev/null +++ b/infra-healthcheck/infra_healthcheck/test_k8stest.py @@ -0,0 +1,41 @@ +#!/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 classes required to fully cover k8s.""" + +import logging +import os +import unittest + + +from infra_healthcheck import k8stest + + +class K8sTests(unittest.TestCase): + + # pylint: disable=missing-docstring + + def setUp(self): + os.environ["DEPLOY_SCENARIO"] = "k8-test" + os.environ["KUBE_MASTER_IP"] = "127.0.0.1" + os.environ["KUBE_MASTER_URL"] = "https://127.0.0.1:6443" + os.environ["KUBERNETES_PROVIDER"] = "local" + + self.k8stesting = k8stest.K8sTesting() + + def test_run_kubetest_cmd_none(self): + self.k8stesting.cmd = None + with self.assertRaises(TypeError): + self.k8stesting.run_kubetest() + + +if __name__ == "__main__": + logging.disable(logging.CRITICAL) + unittest.main(verbosity=2) |