This patch contains scripts to update the measurement name as
[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 #calculating and verifying sha512sum of the guestimage.
23 function verifyGuestImage {
24    scp $WORKSPACE/build_output/guest1.sha512 root@${HOST_IP}:/root/images
25    checksum=$(sudo ssh root@${HOST_IP} "cd /root/images/ && sha512sum -c guest1.sha512 | awk '{print \$2}'")
26    if [ "$checksum" != "OK" ]; then
27       echo "Something wrong with the image, please verify"
28       return 1
29    fi
30 }
31
32 #Updating the pod.yaml file with HOST_IP,kvmfornfv_cyclictest_idle_idle.yaml with loops and interval
33 function updateYaml {
34    cd $WORKSPACE/tests/
35    sed -ri "s/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/${HOST_IP}/" pod.yaml
36    sed -ri "s/loops: [0-9]*/loops: ${testTime}/"  kvmfornfv_cyclictest_idle_idle.yaml
37    sed -ri "0,/interval: [0-9]*/s//interval: 1000/"  kvmfornfv_cyclictest_idle_idle.yaml
38 }
39
40 #cleaning the environment after executing the test through yardstick.
41 function env_clean {
42     container_id=`sudo docker ps -a | grep kvmfornfv_${testType} |awk '{print \$1}'|sed -e 's/\r//g'`
43     sudo docker stop ${container_id}
44     sudo docker rm ${container_id}
45     sudo ssh root@${HOST_IP} "rm -rf /root/workspace/*"
46     sudo ssh root@${HOST_IP} "pid=\$(ps aux | grep 'qemu' | awk '{print \$2}' | head -1); echo \$pid |xargs kill"
47     sudo rm -rf /tmp/kvmtest-${testType}*
48 }
49
50 #Cleaning the latest kernel changes on host after executing the test.
51 function host_clean {
52     sudo ssh root@${HOST_IP} "rpm=\$(rpm -qa | grep 'kernel-${KERNELRPM_VERSION}' | awk '{print \$1}'); rpm -ev \$rpm"
53     sudo ssh root@${HOST_IP} "rm -rf /boot/initramfs-${KERNELRPM_VERSION}*.img"
54     sudo ssh root@${HOST_IP} "grub2-mkconfig -o /boot/grub2/grub.cfg"
55     sudo ssh root@${HOST_IP} "reboot"
56 }
57
58 function cleanup {
59    output=$1
60    env_clean
61    host_clean
62    if [ $output != 0 ];then
63       echo "Yardstick Failed.Please check cyclictest.sh"
64       return 1
65    else
66       return 0
67    fi
68 }
69
70 #Creating a docker image with yardstick installed and Verify the results of cyclictest
71 function runCyclicTest {
72    docker_image_dir=$WORKSPACE/docker_image_build
73    ( cd ${docker_image_dir}; sudo docker build  -t kvmfornfv:latest --no-cache=true . )
74    if [ ${?} -ne 0 ] ; then
75       echo  "Docker image build failed"
76       id=$(sudo docker ps -a  | head  -2 | tail -1 | awk '{print $1}'); sudo docker rm -f $id
77       exit 1
78    fi
79    time_stamp=$(date +%Y%m%d%H%M%S)
80    volume=/tmp/kvmtest-${testType}-${time_stamp}
81    mkdir -p $volume/{image,rpm,scripts}
82
83    #copying required files to run yardstick cyclic testcase
84    mv $WORKSPACE/build_output/kernel-${KERNELRPM_VERSION}*.rpm ${volume}/rpm
85    cp -r $WORKSPACE/ci/envs/* ${volume}/scripts
86    cp -r $WORKSPACE/tests/kvmfornfv_cyclictest_idle_idle.yaml ${volume}
87    cp -r $WORKSPACE/tests/pod.yaml ${volume}/scripts
88
89    #Launching ubuntu docker container to run yardstick
90    sudo docker run -i -v ${volume}:/opt --net=host --name kvmfornfv_${testType} \
91    kvmfornfv:latest  /bin/bash -c "cd /opt/scripts && ls; ./cyclictest.sh $testType"
92    cyclictest_output=$?
93    #Verifying the results of cyclictest
94
95    if [ "$testType" == "verify" ];then
96       result=`grep -o '"errors":[^,]*' ${volume}/yardstick.out | awk -F '"' '{print $4}'`
97
98       if [ -z "${result}" ]; then
99          echo "####################################################"
100          echo ""
101          echo `grep -o '"data":[^}]*' ${volume}/yardstick.out | awk -F '{' '{print $2}'`
102          echo ""
103          echo "####################################################"
104          cleanup $cyclictest_output
105       else
106          echo "Testcase failed"
107          echo `grep -o '"errors":[^,]*' ${volume}/yardstick.out | awk -F '"' '{print $4}'`
108          env_clean
109          host_clean
110          return 1
111       fi
112    else
113       cleanup $cyclictest_output
114    fi
115 }