3 # Copyright (c) 2018 All rights reserved
4 # This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
12 Define the parent for Kubernetes testing.
15 from __future__ import division
23 from xtesting.core import testcase
26 class E2ETesting(testcase.TestCase):
27 """Kubernetes test runner"""
28 # pylint: disable=too-many-instance-attributes
30 __logger = logging.getLogger(__name__)
32 config = '/root/.kube/config'
34 def __init__(self, **kwargs):
35 super(E2ETesting, self).__init__(**kwargs)
37 self.dir_results = "/home/opnfv/functest/results"
38 self.res_dir = os.path.join(self.dir_results, self.case_name)
42 self.output_log_name = 'functest-kubernetes.log'
43 self.output_debug_log_name = 'functest-kubernetes.debug.log'
45 def run_kubetest(self, **kwargs): # pylint: disable=too-many-branches
46 """Run the test suites"""
47 cmd_line = ['e2e.test', '-ginkgo.noColor', '-kubeconfig', self.config,
48 '-provider', 'local', '-report-dir', self.res_dir]
50 cmd_line.extend(['-ginkgo.{}'.format(arg), kwargs.get(arg)])
51 if "NON_BLOCKING_TAINTS" in os.environ:
53 ['-non-blocking-taints', os.environ["NON_BLOCKING_TAINTS"]])
54 cmd_line.extend(['-disable-log-dump', 'true'])
55 self.__logger.info("Starting k8s test: '%s'.", cmd_line)
56 process = subprocess.Popen(cmd_line, stdout=subprocess.PIPE,
57 stderr=subprocess.STDOUT)
58 boutput = process.stdout.read()
59 with open(os.path.join(self.res_dir, 'e2e.log'), 'wb') as foutput:
60 foutput.write(boutput)
62 r'^(FAIL|SUCCESS)!.* ([0-9]+) Passed \| ([0-9]+) Failed \|'
63 r' ([0-9]+) Pending \| ([0-9]+) Skipped',
64 boutput.decode("utf-8", errors="ignore"),
65 re.MULTILINE | re.DOTALL)
67 self.details['passed'] = int(grp.group(2))
68 self.details['failed'] = int(grp.group(3))
69 self.details['pending'] = int(grp.group(4))
70 self.details['skipped'] = int(grp.group(5))
71 self.__logger.debug("details: %s", self.details)
72 self.result = self.details['passed'] * 100 / (
73 self.details['passed'] + self.details['failed'] +
74 self.details['pending'])
75 self.__logger.debug("result: %s", self.result)
76 if grp.group(1) == 'FAIL':
78 r'^(Summarizing [0-9]+ Failure.*)Ran',
79 boutput.decode("utf-8", errors="ignore"),
80 re.MULTILINE | re.DOTALL)
82 self.__logger.error(grp2.group(1))
84 def run(self, **kwargs):
85 if not os.path.isfile(self.config):
87 "Cannot run k8s testcases. Config file not found")
88 return self.EX_RUN_ERROR
89 self.start_time = time.time()
91 self.run_kubetest(**kwargs)
93 except Exception: # pylint: disable=broad-except
94 self.__logger.exception("Error with running kubetest:")
95 res = self.EX_RUN_ERROR
96 self.stop_time = time.time()