Update python3 to python3.6
[functest-kubernetes.git] / functest_kubernetes / k8stest.py
index d851d9e..59eb999 100644 (file)
@@ -28,9 +28,10 @@ class K8sTesting(testcase.TestCase):
 
     __logger = logging.getLogger(__name__)
 
+    config = '/root/.kube/config'
+
     def __init__(self, **kwargs):
         super(K8sTesting, self).__init__(**kwargs)
-        self.config = '/root/.kube/config'
         self.cmd = []
         self.result = 0
         self.start_time = 0
@@ -44,22 +45,28 @@ class K8sTesting(testcase.TestCase):
         process = subprocess.Popen(cmd_line, stdout=subprocess.PIPE,
                                    stderr=subprocess.STDOUT)
         output = process.stdout.read()
-        # Remove color code escape sequences
-        output = re.sub(r'\x1B\[[0-?]*[ -/]*[@-~]', '', str(output))
+        if ('Error loading client' in output or
+                'Unexpected error' in output):
+            raise Exception(output)
 
         remarks = []
         lines = output.split('\n')
+        success = False
+        failure = False
         i = 0
         while i < len(lines):
-            if '[k8s.io]' in lines[i]:
-                if i != 0 and 'seconds' in lines[i - 1]:
-                    self.__logger.debug(lines[i - 1])
-                while lines[i] != '-' * len(lines[i]):
+            if '[Fail]' in lines[i] or 'Failures:' in lines[i]:
+                self.__logger.error(lines[i])
+            if re.search(r'\[(.)*[0-9]+ seconds\]', lines[i]):
+                self.__logger.debug(lines[i])
+                i = i + 1
+                while i < len(lines) and lines[i] != '-' * len(lines[i]):
                     if lines[i].startswith('STEP:') or ('INFO:' in lines[i]):
                         break
                     self.__logger.debug(lines[i])
                     i = i + 1
-
+            if i >= len(lines):
+                break
             success = 'SUCCESS!' in lines[i]
             failure = 'FAIL!' in lines[i]
             if success or failure:
@@ -90,7 +97,7 @@ class K8sTesting(testcase.TestCase):
 
         if not os.path.isfile(self.config):
             self.__logger.error(
-                "Cannot run k8s testcases. Config file not found ")
+                "Cannot run k8s testcases. Config file not found")
             return self.EX_RUN_ERROR
 
         self.start_time = time.time()
@@ -104,17 +111,6 @@ class K8sTesting(testcase.TestCase):
         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 '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"""
@@ -122,9 +118,9 @@ class K8sSmokeTest(K8sTesting):
         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')]
+        self.cmd = ['e2e.test', '-ginkgo.focus', 'Guestbook.application',
+                    '-ginkgo.noColor', '-kubeconfig', self.config,
+                    '--provider', 'local']
 
 
 class K8sConformanceTest(K8sTesting):
@@ -133,7 +129,6 @@ class K8sConformanceTest(K8sTesting):
         if "case_name" not in kwargs:
             kwargs.get("case_name", 'k8s_conformance')
         super(K8sConformanceTest, self).__init__(**kwargs)
-        self.check_envs()
-        self.cmd = ['/src/k8s.io/kubernetes/_output/bin/e2e.test',
-                    '-ginkgo.focus', 'Conformance',
-                    '-kubeconfig', self.config]
+        self.cmd = ['e2e.test', '-ginkgo.focus', 'Conformance',
+                    '-ginkgo.noColor', '-kubeconfig', self.config,
+                    '--provider', 'local']