aboutsummaryrefslogtreecommitdiffstats
path: root/functest_kubernetes/ims/ims.py
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2020-09-15 23:18:16 +0200
committerCédric Ollivier <cedric.ollivier@orange.com>2020-09-16 10:31:25 +0200
commit6a94f3af61529257cea8ec71fe728f28541a9dba (patch)
treec6670267e9625188fbc84f212e0b05c9852a5c9d /functest_kubernetes/ims/ims.py
parentaa4a7102926c5b71f9249a770b17ef917b928f71 (diff)
Publish helm_vims also based on clearwater-docker
It leverages helm rather than kubectl as proposed by k8s_vims. A new abstract class Vims is added to factorize code between both testcases. Change-Id: Ie5de8d62e25e74f73f8e32167228a08e82989abd Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com> (cherry picked from commit 32dfc10f56ead9abea8798e1ce16fe87652ca480)
Diffstat (limited to 'functest_kubernetes/ims/ims.py')
-rw-r--r--functest_kubernetes/ims/ims.py142
1 files changed, 106 insertions, 36 deletions
diff --git a/functest_kubernetes/ims/ims.py b/functest_kubernetes/ims/ims.py
index 0d059550..14097c8f 100644
--- a/functest_kubernetes/ims/ims.py
+++ b/functest_kubernetes/ims/ims.py
@@ -11,8 +11,10 @@
from __future__ import division
+import abc
import logging
import time
+import subprocess
import re
import yaml
@@ -53,48 +55,40 @@ class Vims(testcase.TestCase): # pylint: disable=too-many-instance-attributes
self.namespace = ""
self.zone = ""
- def deploy_vnf(self):
- """Deploy vIMS as proposed by clearwater-docker
+ def prepare_vnf(self):
+ """Prepare vIMS as proposed by clearwater-live-test
- It leverages on unofficial Clearwater dockers as proposed in the
- documentation.
+ It creates a dedicated namespace and the configmap needed.
- See https://github.com/Metaswitch/clearwater-docker for more details
+ See https://github.com/Metaswitch/clearwater-live-test 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)
+ self.zone = '{}.svc.cluster.local'.format(self.namespace)
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})
api_response = self.corev1.create_namespaced_config_map(
self.namespace, body=body)
self.__logger.debug("create_namespaced_config_map: %s", api_response)
- for deployment in self.deployment_list:
- with open(pkg_resources.resource_filename(
- 'functest_kubernetes',
- 'ims/{}-depl.yaml'.format(deployment))) as yfile:
- body = yaml.safe_load(yfile)
- resp = self.appsv1.create_namespaced_deployment(
- body=body, namespace=self.namespace)
- self.__logger.info("Deployment %s created", resp.metadata.name)
- self.__logger.debug(
- "create_namespaced_deployment: %s", api_response)
- for service in self.deployment_list:
- with open(pkg_resources.resource_filename(
- 'functest_kubernetes',
- 'ims/{}-svc.yaml'.format(service))) as yfile:
- body = yaml.safe_load(yfile)
- resp = self.corev1.create_namespaced_service(
- body=body, namespace=self.namespace)
- self.__logger.info("Service %s created", resp.metadata.name)
- self.__logger.debug(
- "create_namespaced_service: %s", api_response)
+
+ @abc.abstractmethod
+ def deploy_vnf(self):
+ """Deploy vIMS as proposed by clearwater-docker
+
+ It must be overriden on purpose.
+
+ See https://github.com/Metaswitch/clearwater-docker for more details
+ """
+
+ def wait_vnf(self):
+ """Wait vIMS is up and running"""
+ assert self.namespace
status = self.deployment_list.copy()
watch_deployment = watch.Watch()
for event in watch_deployment.stream(
@@ -119,12 +113,14 @@ class Vims(testcase.TestCase): # pylint: disable=too-many-instance-attributes
def test_vnf(self):
"""Test vIMS as proposed by clearwater-live-test
- It leverages on an unofficial Clearwater docker to allow testing from
+ It leverages an unofficial Clearwater docker to allow testing from
the Kubernetes cluster.
See https://github.com/Metaswitch/clearwater-live-test for more details
"""
time.sleep(120)
+ assert self.namespace
+ assert self.zone
container = client.V1Container(
name=self.test_container_name, image=self.test_image_name,
command=["rake", "test[{}]".format(self.zone),
@@ -171,7 +167,9 @@ class Vims(testcase.TestCase): # pylint: disable=too-many-instance-attributes
def run(self, **kwargs):
self.start_time = time.time()
try:
- if self.deploy_vnf():
+ self.prepare_vnf()
+ self.deploy_vnf()
+ if self.wait_vnf():
self.test_vnf()
except client.rest.ApiException:
self.__logger.exception("Cannot deploy and test vIms")
@@ -179,6 +177,12 @@ class Vims(testcase.TestCase): # pylint: disable=too-many-instance-attributes
def clean(self):
try:
+ api_response = self.corev1.delete_namespaced_pod(
+ name=self.test_container_name, namespace=self.namespace)
+ self.__logger.debug("delete_namespaced_pod: %s", api_response)
+ except client.rest.ApiException:
+ pass
+ try:
api_response = self.corev1.delete_namespaced_config_map(
name=self.metadata_name, namespace=self.namespace)
self.__logger.debug(
@@ -186,11 +190,51 @@ class Vims(testcase.TestCase): # pylint: disable=too-many-instance-attributes
except client.rest.ApiException:
pass
try:
- api_response = self.corev1.delete_namespaced_pod(
- name=self.test_container_name, namespace=self.namespace)
- self.__logger.debug("delete_namespaced_pod: %s", api_response)
+ api_response = self.corev1.delete_namespace(self.namespace)
+ self.__logger.debug("delete_namespace: %s", self.namespace)
except client.rest.ApiException:
pass
+
+
+class K8sVims(Vims):
+ """Deploy vIMS via kubectl as proposed by clearwater-docker
+
+ It leverages unofficial Clearwater dockers as proposed in the
+ documentation.
+
+ See https://github.com/Metaswitch/clearwater-docker for more details
+ """
+
+ __logger = logging.getLogger(__name__)
+
+ def deploy_vnf(self):
+ """Deploy vIMS via kubectl as proposed by clearwater-docker
+
+ See https://github.com/Metaswitch/clearwater-docker for more details
+ """
+ assert self.namespace
+ for deployment in self.deployment_list:
+ with open(pkg_resources.resource_filename(
+ 'functest_kubernetes',
+ 'ims/{}-depl.yaml'.format(deployment))) as yfile:
+ body = yaml.safe_load(yfile)
+ resp = self.appsv1.create_namespaced_deployment(
+ body=body, namespace=self.namespace)
+ self.__logger.info("Deployment %s created", resp.metadata.name)
+ self.__logger.debug(
+ "create_namespaced_deployment: %s", resp)
+ for service in self.deployment_list:
+ with open(pkg_resources.resource_filename(
+ 'functest_kubernetes',
+ 'ims/{}-svc.yaml'.format(service))) as yfile:
+ body = yaml.safe_load(yfile)
+ resp = self.corev1.create_namespaced_service(
+ body=body, namespace=self.namespace)
+ self.__logger.info("Service %s created", resp.metadata.name)
+ self.__logger.debug(
+ "create_namespaced_service: %s", resp)
+
+ def clean(self):
for deployment in self.deployment_list:
try:
api_response = self.appsv1.delete_namespaced_deployment(
@@ -206,8 +250,34 @@ class Vims(testcase.TestCase): # pylint: disable=too-many-instance-attributes
"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
+ super(K8sVims, self).clean()
+
+
+class HelmVims(Vims):
+ """Deploy vIMS via Helm as proposed by clearwater-docker
+
+ It leverages unofficial Clearwater dockers as proposed in the
+ documentation.
+
+ See https://github.com/Metaswitch/clearwater-docker for more details
+ """
+
+ __logger = logging.getLogger(__name__)
+
+ def deploy_vnf(self):
+ """Deploy vIMS via Helm as proposed by clearwater-docker
+
+ See https://github.com/Metaswitch/clearwater-docker for more details
+ """
+ cmd = [
+ "helm", "install", "clearwater",
+ pkg_resources.resource_filename("functest_kubernetes", "ims/helm"),
+ "-n", self.namespace]
+ output = subprocess.check_output(cmd)
+ self.__logger.debug(output.decode("utf-8"))
+
+ def clean(self):
+ cmd = ["helm", "uninstall", "clearwater", "-n", self.namespace]
+ output = subprocess.check_output(cmd)
+ self.__logger.debug(output.decode("utf-8"))
+ super(HelmVims, self).clean()