This patch includes updated scripts to use different docker containers
[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 testName=$4
14
15 source $WORKSPACE/ci/envs/utils.sh
16 source $WORKSPACE/ci/envs/host-config
17
18 checkRPMNames
19
20 KERNELRPM_VERSION=$( getKernelVersion )
21 QEMURPM_VERSION=$( getQemuVersion )
22
23 if [ -z ${KERNELRPM_VERSION} ];then
24    echo "Kernel RPM not found in build_output Directory"
25    exit 1
26 fi
27 if [ -z ${QEMURPM_VERSION} ];then
28    echo "QEMU RPM not found in build_output Directory"
29    exit 1
30 fi
31
32 #calculating and verifying sha512sum of the guestimage.
33 function verifyGuestImage {
34    scp $WORKSPACE/build_output/guest1.sha512 root@${HOST_IP}:/root/images
35    checksum=$(sudo ssh root@${HOST_IP} "cd /root/images/ && sha512sum -c guest1.sha512 | awk '{print \$2}'")
36    if [ "$checksum" != "OK" ]; then
37       echo "Something wrong with the image, please verify"
38       return 1
39    fi
40 }
41
42 #Verifying the availability of the host after reboot
43 function connect_host {
44    n=0
45    while [ $n -lt 25 ]; do
46       host_ping_test="ping -c 1 ${HOST_IP}"
47       eval $host_ping_test &> /dev/null
48       if [ ${?} -ne 0 ] ; then
49          sleep 10
50          echo "host machine is still under reboot..trying to connect...."
51          n=$(($n+1))
52       else
53          echo "resuming the execution of test cases....."
54          #Waiting for ssh to be available for the host machine.
55          sleep 30
56          break
57       fi
58       if [ $n == 24 ];then
59          echo "Host machine unable to boot-up!"
60          exit 1
61       fi
62    done
63 }
64
65 #Updating the pod.yaml file with HOST_IP,kvmfornfv_cyclictest_idle_idle.yaml with loops and interval
66 function updateYaml {
67    cd $WORKSPACE/tests/
68    sed -ri "s/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/${HOST_IP}/" pod.yaml
69    sed -ri "s/loops: [0-9]*/loops: ${testTime}/"  kvmfornfv_cyclictest_hostenv_guestenv.yaml
70    sed -ri "0,/interval: [0-9]*/s//interval: 1000/"  kvmfornfv_cyclictest_hostenv_guestenv.yaml
71    cp kvmfornfv_cyclictest_hostenv_guestenv.yaml kvmfornfv_cyclictest_${testName}.yaml
72    sed -ri "s/tc: \"kvmfornfv_cyclictest-node-context\"/tc: \"kvmfornfv_cyclictest_${testName}\"/" kvmfornfv_cyclictest_${testName}.yaml
73    case $testName in
74
75        idle_idle)
76                 ;;
77        cpustress_idle)
78                       sed -i '/host-run-qemu.sh/a\    \- \"stress_daily.sh cpu\"' kvmfornfv_cyclictest_${testName}.yaml
79                       ;;
80        memorystress_idle)
81                       sed -i '/host-run-qemu.sh/a\    \- \"stress_daily.sh memory\"' kvmfornfv_cyclictest_${testName}.yaml
82                       ;;
83        iostress_idle)
84                       sed -i '/host-run-qemu.sh/a\    \- \"stress_daily.sh io\"' kvmfornfv_cyclictest_${testName}.yaml
85                       ;;
86        idle_cpustress)
87                       sed -i '/guest-setup1.sh/a\    \- \"stress_daily.sh cpu\"' kvmfornfv_cyclictest_${testName}.yaml
88                       ;;
89        idle_memorystress)
90                       sed -i '/guest-setup1.sh/a\    \- \"stress_daily.sh memory\"' kvmfornfv_cyclictest_${testName}.yaml
91                       ;;
92        idle_iostress)
93                       sed -i '/guest-setup1.sh/a\    \- \"stress_daily.sh io\"' kvmfornfv_cyclictest_${testName}.yaml
94                       ;;
95         *)
96           echo "Incorrect test environment: $testName"
97           exit 1
98           ;;
99     esac
100 }
101
102 #cleaning the environment after executing the test through yardstick.
103 function env_clean {
104     container_id=`sudo docker ps -a | grep kvmfornfv_${testType} |awk '{print \$1}'|sed -e 's/\r//g'`
105     sudo docker stop ${container_id}
106     sudo docker rm ${container_id}
107     sudo ssh root@${HOST_IP} "rm -rf /root/workspace/*"
108     sudo ssh root@${HOST_IP} "pid=\$(ps aux | grep 'qemu' | awk '{print \$2}' | head -1); echo \$pid |xargs kill"
109     sudo rm -rf /tmp/kvmtest-${testType}*
110 }
111
112 #Cleaning the latest kernel changes on host after executing the test.
113 function host_clean {
114     sudo ssh root@${HOST_IP} "rpm=\$(rpm -qa | grep 'kernel-${KERNELRPM_VERSION}' | awk '{print \$1}'); rpm -ev \$rpm"
115     sudo ssh root@${HOST_IP} "rpm=\$(rpm -qa | grep 'kernel-devel-${KERNELRPM_VERSION}' | awk '{print \$1}'); rpm -ev \$rpm"
116     sudo ssh root@${HOST_IP} "rm -rf /boot/initramfs-${KERNELRPM_VERSION}*.img"
117     sudo ssh root@${HOST_IP} "grub2-mkconfig -o /boot/grub2/grub.cfg"
118     sudo ssh root@${HOST_IP} "rpm=\$(rpm -qa | grep 'qemu-${QEMURPM_VERSION}'| awk '{print \$1}'); rpm -ev \$rpm"
119     sudo ssh root@${HOST_IP} "reboot"
120 }
121
122 function cleanup {
123    output=$1
124    env_clean
125    host_clean
126    if [ $output != 0 ];then
127       echo "Yardstick Failed.Please check cyclictest.sh"
128       return 1
129    else
130       return 0
131    fi
132 }
133
134 #environment setup for executing packet forwarding test cases
135 function setUpPacketForwarding {
136    #copying required files to run packet forwarding test cases
137    ssh root@$HOST_IP "mkdir -p /root/workspace/image"
138    ssh root@$HOST_IP "mkdir -p /root/workspace/rpm"
139    ssh root@$HOST_IP "mkdir -p /root/workspace/scripts"
140    #Copying the host configuration scripts on to host
141    scp -r $WORKSPACE/ci/envs/* root@$HOST_IP:/root/workspace/scripts
142    scp -r $WORKSPACE/tests/vsperf.conf* root@$HOST_IP:/root/workspace/scripts
143    scp -r $WORKSPACE/build_output/kernel-${KERNELRPM_VERSION}*.rpm root@$HOST_IP:/root/workspace/rpm
144    scp -r $WORKSPACE/build_output/kernel-devel-${KERNELRPM_VERSION}*.rpm root@$HOST_IP:/root/workspace/rpm
145    scp -r $WORKSPACE/build_output/qemu-${QEMURPM_VERSION}*.rpm root@$HOST_IP:/root/workspace/rpm
146    #execute host configuration script for installing kvm built kernel.
147    ssh root@$HOST_IP "cd /root/workspace/scripts ; ./host-setup0.sh"
148    ssh root@$HOST_IP "cd /root/workspace/rpm ; rpm -ivh kernel-devel-${KERNELRPM_VERSION}*.rpm"
149    ssh root@$HOST_IP "reboot"
150    sleep 10
151 }
152
153 #executing packet forwarding test cases
154 function runPacketForwarding {
155    testType=$1
156    ssh -t -t root@$HOST_IP "cd /root/workspace/scripts ; sudo scl enable python33 'sh packet_forwarding.sh $testType $QEMURPM_VERSION'"
157 }
158
159 #Creating a docker image with yardstick installed and Verify the results of cyclictest
160 function runCyclicTest {
161    docker_image_dir=$WORKSPACE/docker_image_build
162    ( cd ${docker_image_dir}; sudo docker build  -t kvmfornfv:latest --no-cache=true . )
163    if [ ${?} -ne 0 ] ; then
164       echo  "Docker image build failed"
165       id=$(sudo docker ps -a  | head  -2 | tail -1 | awk '{print $1}'); sudo docker rm -f $id
166       exit 1
167    fi
168    time_stamp=$(date +%Y%m%d%H%M%S)
169    volume=/tmp/kvmtest-${testType}-${time_stamp}
170    mkdir -p $volume/{image,rpm,scripts}
171    #copying required files to run yardstick cyclic testcase
172    cp $WORKSPACE/build_output/kernel-${KERNELRPM_VERSION}*.rpm ${volume}/rpm
173    cp $WORKSPACE/build_output/qemu-${QEMURPM_VERSION}*.rpm ${volume}/rpm
174    cp -r $WORKSPACE/ci/envs/* ${volume}/scripts
175    cp -r $WORKSPACE/tests/kvmfornfv_cyclictest_${testName}.yaml ${volume}
176    cp -r $WORKSPACE/tests/pod.yaml ${volume}/scripts
177
178    #Launching ubuntu docker container to run yardstick
179    sudo docker run -i -v ${volume}:/opt --net=host --name kvmfornfv_${testType}_${testName} \
180    kvmfornfv:latest /bin/bash -c "cd /opt/scripts && ls; ./cyclictest.sh $testType $testName"
181    cyclictest_output=$?
182    if [ "$testName" == "iostress_idle" ];then
183       copyLogs
184    fi
185
186    #Verifying the results of cyclictest
187    if [ "$testType" == "verify" ];then
188       result=`grep -o '"errors":[^,]*' ${volume}/yardstick.out | awk -F '"' '{print $4}'`
189
190       if [ -z "${result}" ]; then
191          echo "####################################################"
192          echo " "
193          echo `grep -o '"data":[^}]*' ${volume}/yardstick.out | awk -F '{' '{print $2}'`
194          echo ""
195          echo "####################################################"
196          cleanup $cyclictest_output
197       else
198          echo "Testcase failed"
199          echo `grep -o '"errors":[^,]*' ${volume}/yardstick.out | awk -F '"' '{print $4}'`
200          env_clean
201          host_clean
202          return 1
203       fi
204    else
205       cleanup $cyclictest_output
206    fi
207 }