Execution of kvm4nfv cyclictest based on job type.
[kvmfornfv.git] / ci / cyclicTestTrigger.sh
1 #!/bin/bash
2
3 #############################################################
4 ## This script defines the functions present in
5 ## test_kvmfornfv.sh interface.These will launch ubuntu
6 ## docker container runs cyclictest through yardstick
7 ## and verifies the test results.
8 ############################################################
9
10 HOST_IP=$1
11 testTime=$2
12 testType=$3
13
14 source $WORKSPACE/ci/envs/utils.sh
15 KERNELRPM_VERSION=$( getKernelVersion )
16
17 if [ -z ${KERNELRPM_VERSION} ];then
18    echo "Kernel RPM not found in build_output Directory"
19    exit 1
20 fi
21
22 #Updating the pod.yaml file with HOST_IP,cyclictest-node-context.yaml with loops and interval
23 function updateYaml {
24    cd $WORKSPACE/tests/
25    sed -ri "s/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/${HOST_IP}/" pod.yaml
26    sed -ri "s/loops: [0-9]*/loops: ${testTime}/"  cyclictest-node-context.yaml
27    sed -ri "s/interval: [0-9]*/interval: 1000/"  cyclictest-node-context.yaml
28 }
29
30 #cleaning the environment after executing the test through yardstick.
31 function env_clean {
32     container_id=`sudo docker ps -a | grep kvmfornfv_${testType} |awk '{print \$1}'|sed -e 's/\r//g'`
33     sudo docker rm ${container_id}
34     sudo ssh root@${HOST_IP} "rm -rf /root/workspace/*"
35     sudo ssh root@${HOST_IP} "pid=\$(ps aux | grep 'qemu' | awk '{print \$2}' | head -1); echo \$pid |xargs kill"
36     sudo rm -rf /tmp/kvmtest-${testType}*
37 }
38
39 #Cleaning the latest kernel changes on host after executing the test.
40 function host_clean {
41     sudo ssh root@${HOST_IP} "rpm=\$(rpm -qa | grep 'kernel-${KERNELRPM_VERSION}' | awk '{print \$1}'); rpm -ev \$rpm"
42     sudo ssh root@${HOST_IP} "rm -rf /boot/initramfs-${KERNELRPM_VERSION}*.img"
43     sudo ssh root@${HOST_IP} "grub2-mkconfig -o /boot/grub2/grub.cfg"
44     sudo ssh root@${HOST_IP} "reboot"
45 }
46
47
48 #Creating a docker image with yardstick installed and Verify the results of cyclictest
49 function runCyclicTest {
50    docker_image_dir=$WORKSPACE/docker_image_build
51    ( cd ${docker_image_dir}; sudo docker build  -t kvmfornfv:latest --no-cache=true . )
52    if [ ${?} -ne 0 ] ; then
53       echo  "Docker image build failed"
54       id=$(sudo docker ps -a  | head  -2 | tail -1 | awk '{print $1}'); sudo docker rm -f $id
55       exit 1
56    fi
57    time_stamp=$(date +%Y%m%d%H%M%S)
58    volume=/tmp/kvmtest-${testType}-${time_stamp}
59    mkdir -p $volume/{image,rpm,scripts}
60
61    #copying required files to run yardstick cyclic testcase
62    mv $WORKSPACE/build_output/kernel-${KERNELRPM_VERSION}*.rpm ${volume}/rpm
63    cp -r $WORKSPACE/ci/envs/* ${volume}/scripts
64    cp -r $WORKSPACE/tests/cyclictest-node-context.yaml ${volume}
65    cp -r $WORKSPACE/tests/pod.yaml ${volume}
66
67    #Launching ubuntu docker container to run yardstick
68    sudo docker run -i -v ${volume}:/opt --net=host --name kvmfornfv_${testType} \
69    kvmfornfv:latest  /bin/bash -c "cd /opt/scripts && ls; ./cyclictest.sh"
70
71    #Verifying the results of cyclictest
72    result=`grep -o '"errors":[^,]*' ${volume}/yardstick.out | awk -F '"' '{print $4}'`
73
74    if [ -z "${result}" ]; then
75       echo "####################################################"
76       echo ""
77       echo `grep -o '"data":[^}]*' ${volume}/yardstick.out | awk -F '{' '{print $2}'`
78       echo ""
79       echo "####################################################"
80       env_clean
81       host_clean
82       exit 0
83    else
84       echo "Testcase failed"
85       echo `grep -o '"errors":[^,]*' ${volume}/yardstick.out | awk -F '"' '{print $4}'`
86       env_clean
87       host_clean
88       exit 1
89    fi
90 }