Add initial Istio validation testcase for CI 11/63311/10
authorJingLu5 <lvjing5@huawei.com>
Tue, 9 Oct 2018 06:34:45 +0000 (14:34 +0800)
committerJingLu5 <lvjing5@huawei.com>
Fri, 19 Oct 2018 00:34:49 +0000 (08:34 +0800)
This work adds testcase for validating Istio installation

Change-Id: Ie895b27eb4b3fbec23cf9519699f5fe37236153c
Signed-off-by: JingLu5 <lvjing5@huawei.com>
ci/deploy.sh
ci/sdc_setup.sh [new file with mode: 0755]
ci/test.sh [deleted file]
clover/functest/clover_k8s.py
clover/servicemesh/validate.py [new file with mode: 0644]

index 2580dbc..4bdce89 100755 (executable)
@@ -15,7 +15,7 @@ MASTER_NODE_NAME="master"
 SSH_OPTIONS="-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
 K8S_ISTIO_DEPLOY_TIMEOUT=3600
 
-FUNCTEST_IMAGE="opnfv/functest-kubernetes:latest"
+FUNCTEST_IMAGE="opnfv/functest-kubernetes-features:amd64-gambia"
 INSTALLER_TYPE="container4nfv"
 DEPLOY_SCENARIO="k8-istio-clover"
 
@@ -42,8 +42,8 @@ MASTER_NODE_KEY=$(vagrant ssh-config $MASTER_NODE_NAME | awk '/IdentityFile /{pr
 ssh $SSH_OPTIONS -i $MASTER_NODE_KEY ${MASTER_NODE_USER}@${MASTER_NODE_HOST} rm -rf clover
 scp $SSH_OPTIONS -i $MASTER_NODE_KEY -r $CLOVER_BASE_DIR ${MASTER_NODE_USER}@${MASTER_NODE_HOST}:clover
 
-# Run test
-ssh $SSH_OPTIONS -i $MASTER_NODE_KEY ${MASTER_NODE_USER}@${MASTER_NODE_HOST} ./clover/ci/test.sh
+# Deploy SDC sample for Functest test
+ssh $SSH_OPTIONS -i $MASTER_NODE_KEY ${MASTER_NODE_USER}@${MASTER_NODE_HOST} ./clover/ci/sdc_setup.sh
 
 echo "Clover deploy complete!"
 
@@ -63,6 +63,9 @@ echo "export KUBE_MASTER_URL=$KUBE_MASTER_URL" >> $RC_FILE
 KUBE_MASTER_IP=$(echo $KUBE_MASTER_URL | awk -F'https://|:[0-9]+' '$0=$2')
 echo "export KUBE_MASTER_IP=$KUBE_MASTER_IP" >> $RC_FILE
 
+# Restart docker service in case Container4NFV CI job delete docker0 bridge
+systemctl restart docker
+
 # Run functest
 sudo docker pull $FUNCTEST_IMAGE
 sudo docker run --rm \
diff --git a/ci/sdc_setup.sh b/ci/sdc_setup.sh
new file mode 100755 (executable)
index 0000000..f4d82f5
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/bash
+#
+# Copyright (c) Authors of Clover
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+set -ex
+
+# Deploy Clover SDC sample
+kubectl apply -f <(istioctl kube-inject -f ~/clover/samples/scenarios/service_delivery_controller_opnfv.yaml)
+
+# Wait for SDC sample deployed
+kubectl get services
+kubectl get pods
+
+r="0"
+while [ $r -ne "10" ]
+do
+   sleep 30
+   kubectl get pods
+   r=$(kubectl get pods | grep Running | wc -l)
+done
+
+echo "Set up Clover SDC sample complete!"
diff --git a/ci/test.sh b/ci/test.sh
deleted file mode 100755 (executable)
index 4e0ccc5..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/bash
-#
-# Copyright (c) Authors of Clover
-#
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-set -ex
-
-echo "Clover test complete!"
index 654c8e5..b79ac90 100644 (file)
@@ -7,6 +7,7 @@
 
 import functest_kubernetes.k8stest as k8stest
 
+import clover.servicemesh.validate as istio_validate
 
 class K8sCloverTest(k8stest.K8sTesting):
     """Clover test suite"""
@@ -18,9 +19,9 @@ class K8sCloverTest(k8stest.K8sTesting):
         self.check_envs()
 
     def run_kubetest(self):
-        success = True
+        success = istio_validate.validateDeploy()
         if success:
             self.result = 100
-        elif failure:
+        else:
             self.result = 0
 
diff --git a/clover/servicemesh/validate.py b/clover/servicemesh/validate.py
new file mode 100644 (file)
index 0000000..0e2e59a
--- /dev/null
@@ -0,0 +1,47 @@
+#!/usr/bin/env python
+
+# Copyright (c) Authors of Clover
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Apache License, Version 2.0
+# which accompanies this distribution, and is available at
+# http://www.apache.org/licenses/LICENSE-2.0
+
+from kubernetes import client, config
+
+ISTIO_NAMESPACE = "istio-system"
+ISTIO_DEPLOYMENT = "istio-pilot"
+
+
+def validateDeploy():
+    config.load_kube_config()
+    appsv1 = client.AppsV1Api()
+    corev1 = client.CoreV1Api()
+    find_flag = False
+
+    # check deploytment
+    ret = appsv1.list_deployment_for_all_namespaces(watch=False)
+    for i in ret.items:
+        if ISTIO_DEPLOYMENT == i.metadata.name and \
+           ISTIO_NAMESPACE == i.metadata.namespace:
+           find_flag = True
+           break
+    if find_flag == False:
+        print("ERROR: Deployment: {} doesn't present in {} namespace".format(
+                        ISTIO_DEPLOYMENT, ISTIO_NAMESPACE))
+        return False
+
+    return True
+
+
+def main():
+    if validateDeploy():
+        print"Istio install validation has passed"
+        return True
+    else:
+        print"ERROR: Istio install validation has failed"
+        return False
+
+
+if __name__ == '__main__':
+    main()