Add tempo waiting for ellis account
[functest-kubernetes.git] / functest_kubernetes / ims / ims.py
index 9a37a02..8c6cf2d 100644 (file)
@@ -7,7 +7,9 @@
 # which accompanies this distribution, and is available at
 # http://www.apache.org/licenses/LICENSE-2.0
 
-"""Deploy and Test Clearwater vIMS using Kubernetes"""
+"""Deploy and test Clearwater vIMS using Kubernetes"""
+
+from __future__ import division
 
 import logging
 import time
@@ -22,16 +24,14 @@ import pkg_resources
 from xtesting.core import testcase
 
 
-class Vims(testcase.TestCase):
-    """Deploy and Test Clearwater vIMS using Kubernetes
+class Vims(testcase.TestCase):  # pylint: disable=too-many-instance-attributes
+    """Deploy and test Clearwater vIMS using Kubernetes
 
     It leverage on the Python kubernetes client to apply operation proposed by
     clearwater-docker.
 
     See https://github.com/Metaswitch/clearwater-docker for more details
     """
-    namespace = 'default'
-    zone = 'default.svc.cluster.local'
     watch_timeout = 1200
     metadata_name = "env-vars"
     test_image_name = "ollivier/clearwater-live-test:latest"
@@ -48,6 +48,10 @@ class Vims(testcase.TestCase):
         config.load_kube_config()
         self.corev1 = client.CoreV1Api()
         self.appsv1 = client.AppsV1Api()
+        self.output_log_name = 'functest-kubernetes.log'
+        self.output_debug_log_name = 'functest-kubernetes.debug.log'
+        self.namespace = ""
+        self.zone = ""
 
     def deploy_vnf(self):
         """Deploy vIMS as proposed by clearwater-docker
@@ -57,8 +61,14 @@ class Vims(testcase.TestCase):
 
         See https://github.com/Metaswitch/clearwater-docker for more details
         """
+        api_response = self.corev1.create_namespace(
+            client.V1Namespace(metadata=client.V1ObjectMeta(
+                generate_name="ims-")))
+        self.namespace = api_response.metadata.name
+        self.__logger.debug("create_namespace: %s", api_response)
         metadata = client.V1ObjectMeta(
             name=self.metadata_name, namespace=self.namespace)
+        self.zone = '{}.svc.cluster.local'.format(self.namespace)
         body = client.V1ConfigMap(
             metadata=metadata,
             data={"ADDITIONAL_SHARED_CONFIG": "", "ZONE": self.zone})
@@ -71,7 +81,7 @@ class Vims(testcase.TestCase):
                     'ims/{}-depl.yaml'.format(deployment))) as yfile:
                 body = yaml.safe_load(yfile)
                 resp = self.appsv1.create_namespaced_deployment(
-                    body=body, namespace="default")
+                    body=body, namespace=self.namespace)
                 self.__logger.info("Deployment %s created", resp.metadata.name)
                 self.__logger.debug(
                     "create_namespaced_deployment: %s", api_response)
@@ -81,7 +91,7 @@ class Vims(testcase.TestCase):
                     'ims/{}-svc.yaml'.format(service))) as yfile:
                 body = yaml.safe_load(yfile)
                 resp = self.corev1.create_namespaced_service(
-                    body=body, namespace="default")
+                    body=body, namespace=self.namespace)
                 self.__logger.info("Service %s created", resp.metadata.name)
                 self.__logger.debug(
                     "create_namespaced_service: %s", api_response)
@@ -90,6 +100,7 @@ class Vims(testcase.TestCase):
         for event in watch_deployment.stream(
                 func=self.appsv1.list_namespaced_deployment,
                 namespace=self.namespace, timeout_seconds=self.watch_timeout):
+            self.__logger.debug(event)
             if event["object"].status.ready_replicas == 1:
                 if event['object'].metadata.name in status:
                     status.remove(event['object'].metadata.name)
@@ -97,7 +108,7 @@ class Vims(testcase.TestCase):
                         "%s started in %0.2f sec",
                         event['object'].metadata.name,
                         time.time()-self.start_time)
-            if len(status) == 0:
+            if not status:
                 watch_deployment.stop()
         self.result = 1/2 * 100
 
@@ -109,8 +120,13 @@ class Vims(testcase.TestCase):
 
         See https://github.com/Metaswitch/clearwater-live-test for more details
         """
+        time.sleep(60)
         container = client.V1Container(
-            name=self.test_container_name, image=self.test_image_name)
+            name=self.test_container_name, image=self.test_image_name,
+            command=["rake", "test[{}]".format(self.zone),
+                     "PROXY=bono.{}".format(self.zone),
+                     "ELLIS=ellis.{}".format(self.zone),
+                     "SIGNUP_CODE=secret", "--trace"])
         spec = client.V1PodSpec(containers=[container], restart_policy="Never")
         metadata = client.V1ObjectMeta(name=self.test_container_name)
         body = client.V1Pod(metadata=metadata, spec=spec)
@@ -119,9 +135,10 @@ class Vims(testcase.TestCase):
         for event in watch_deployment.stream(
                 func=self.corev1.list_namespaced_pod,
                 namespace=self.namespace, timeout_seconds=self.watch_timeout):
+            self.__logger.debug(event)
             if event["object"].metadata.name == self.test_container_name:
                 if (event["object"].status.phase == 'Succeeded'
-                        or event["object"].status.phase == 'Error'):
+                        or event["object"].status.phase == 'Failed'):
                     watch_deployment.stop()
         api_response = self.corev1.read_namespaced_pod_log(
             name=self.test_container_name, namespace=self.namespace)
@@ -185,3 +202,8 @@ class Vims(testcase.TestCase):
                     "delete_namespaced_service: %s", api_response)
             except client.rest.ApiException:
                 pass
+        try:
+            api_response = self.corev1.delete_namespace(self.namespace)
+            self.__logger.debug("delete_namespace: %s", self.namespace)
+        except client.rest.ApiException:
+            pass