CSIT-841 Optimize cheking k8s POD state 49/8849/2
authorPeter Mikus <pmikus@cisco.com>
Tue, 17 Oct 2017 06:13:14 +0000 (08:13 +0200)
committerPeter Mikus <pmikus@cisco.com>
Tue, 17 Oct 2017 06:57:19 +0000 (06:57 +0000)
Change-Id: Ie1725c0017b78945e431f493743f9a01a66e83c2
Signed-off-by: Peter Mikus <pmikus@cisco.com>
resources/libraries/python/KubernetesUtils.py
resources/libraries/python/VppConfigGenerator.py

index 77628b6..69e7e83 100644 (file)
@@ -50,6 +50,9 @@ class KubernetesUtils(object):
             raise RuntimeError('Failed to setup Kubernetes on {node}.'
                                .format(node=node['host']))
 
+        KubernetesUtils.wait_for_kubernetes_pods_on_node(node,
+                                                         nspace='kube-system')
+
     @staticmethod
     def setup_kubernetes_on_all_duts(nodes):
         """Set up Kubernetes on all DUTs.
@@ -244,34 +247,34 @@ class KubernetesUtils(object):
                                                                      rtype)
 
     @staticmethod
-    def get_kubernetes_logs_on_node(node, namespace='csit'):
+    def get_kubernetes_logs_on_node(node, nspace='csit'):
         """Get Kubernetes logs on node.
 
         :param node: DUT node.
-        :param namespace: Kubernetes namespace.
+        :param nspace: Kubernetes namespace.
         :type node: dict
-        :type namespace: str
+        :type nspace: str
         """
         ssh = SSH()
         ssh.connect(node)
 
         cmd = "for p in $(kubectl get pods -n {namespace} --no-headers"\
             " | cut -f 1 -d ' '); do echo $p; kubectl logs -n {namespace} $p; "\
-            "done".format(namespace=namespace)
+            "done".format(namespace=nspace)
         ssh.exec_command(cmd, timeout=120)
 
     @staticmethod
-    def get_kubernetes_logs_on_all_duts(nodes, namespace='csit'):
+    def get_kubernetes_logs_on_all_duts(nodes, nspace='csit'):
         """Get Kubernetes logs on all DUTs.
 
         :param nodes: Topology nodes.
-        :param namespace: Kubernetes namespace.
+        :param nspace: Kubernetes namespace.
         :type nodes: dict
-        :type namespace: str
+        :type nspace: str
         """
         for node in nodes.values():
             if node['type'] == NodeType.DUT:
-                KubernetesUtils.get_kubernetes_logs_on_node(node, namespace)
+                KubernetesUtils.get_kubernetes_logs_on_node(node, nspace)
 
     @staticmethod
     def reset_kubernetes_on_node(node):
@@ -302,25 +305,30 @@ class KubernetesUtils(object):
                 KubernetesUtils.reset_kubernetes_on_node(node)
 
     @staticmethod
-    def wait_for_kubernetes_pods_on_node(node):
+    def wait_for_kubernetes_pods_on_node(node, nspace='csit'):
         """Wait for Kubernetes PODs to become in 'Running' state on node.
 
         :param node: DUT node.
+        :param nspace: Kubernetes namespace.
         :type node: dict
+        :type nspace: str
         :raises RuntimeError: If Kubernetes PODs are not ready.
         """
         ssh = SSH()
         ssh.connect(node)
 
-        cmd = 'kubectl get -n csit pods --no-headers'
+        cmd = 'kubectl get -n {namespace} pods --no-headers'\
+            .format(namespace=nspace)
         for _ in range(48):
             (ret_code, stdout, _) = ssh.exec_command_sudo(cmd, timeout=120)
             if int(ret_code) == 0:
                 ready = True
                 for line in stdout.splitlines():
-                    if 'Running' in line and '1/1' in line:
-                        ready = True
-                    else:
+                    try:
+                        state = line.split()[1].split('/')
+                        ready = True if 'Running' in line and\
+                            state == state[::-1] else False
+                    except ValueError, IndexError:
                         ready = False
                 if ready:
                     break
@@ -330,15 +338,17 @@ class KubernetesUtils(object):
                                .format(node=node['host']))
 
     @staticmethod
-    def wait_for_kubernetes_pods_on_all_duts(nodes):
+    def wait_for_kubernetes_pods_on_all_duts(nodes, nspace='csit'):
         """Wait for Kubernetes PODs to become in Running state on all DUTs.
 
         :param nodes: Topology nodes.
+        :param nspace: Kubernetes namespace.
         :type nodes: dict
+        :type nspace: str
         """
         for node in nodes.values():
             if node['type'] == NodeType.DUT:
-                KubernetesUtils.wait_for_kubernetes_pods_on_node(node)
+                KubernetesUtils.wait_for_kubernetes_pods_on_node(node, nspace)
 
     @staticmethod
     def create_kubernetes_vswitch_startup_config(**kwargs):
index 6909649..2586202 100644 (file)
@@ -128,6 +128,11 @@ class VppConfigGenerator(object):
         path = ['unix', 'nodaemon']
         self.add_config_item(self._nodeconfig, '', path)
 
+    def add_unix_coredump(self):
+        """Add UNIX full-coredump configuration."""
+        path = ['unix', 'full-coredump']
+        self.add_config_item(self._nodeconfig, '', path)
+
     def add_unix_exec(self, value):
         """Add UNIX exec configuration."""
         path = ['unix', 'exec']