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