e87d6eb409f3047d42f2ebe12701a543387206e3
[kvmfornfv.git] / ci / test_kvmfornfv.sh
1 #!/bin/bash
2
3 ############################################################
4 ## This script  is an interface to trigger the
5 ## cyclicTestTrigger.sh for test type like patch verification,
6 ## daily testing.
7 ## Releng will trigger this script by passing test type as
8 ## verify/daily and test name as idle_idle/stress_idle/
9 ## packet_forward as arguments.
10 ## Verify Job runs idle_idle,packet_forward test
11 ## daily job runs base on the test name parameter
12 ############################################################
13
14 test_type=$1
15 test_name=$2
16 ftrace_enable=0
17 cyclictest_env_verify=("idle_idle" "cpustress_idle" "memorystress_idle" "iostress_idle") #cyclictest environment
18 cyclictest_env_daily=("idle_idle" "cpustress_idle" "memorystress_idle" "iostress_idle")
19 cyclictest_result=0 #exit code of cyclictest
20 packetforward_result=0 #exit code of packet forward
21 source $WORKSPACE/ci/envs/host-config
22
23 function packetForward {
24 #   source $WORKSPACE/ci/packet_forward_test.sh $HOST_IP
25    echo "Packetforwarding need to be implemented"
26    packetforward_result=$?
27    if [ ${packetforward_result} -ne 0 ];then
28       echo "Packet Forwarding test case execution FAILED"
29    else
30       echo "Packet Forwarding test case executed SUCCESSFULLY"
31    fi
32    host_clean
33 }
34
35 function cyclictest {
36    test_case=$1
37    source $WORKSPACE/ci/cyclicTestTrigger.sh $HOST_IP $test_time $test_type $test_case
38    #calculating and verifying sha512sum of the guestimage.
39    if ! verifyGuestImage;then
40       exit 1
41    fi
42    #Update kvmfornfv_cyclictest_${testName}.yaml with test_time and pod.yaml with IP
43    updateYaml
44    #Cleaning up the test environment before running cyclictest through yardstick.
45    env_clean
46    #Creating a docker image with yardstick installed and launching ubuntu docker to run yardstick cyclic testcase
47    if runCyclicTest;then
48       cyclictest_result=`expr ${cyclictest_result} + 0`
49    else
50       echo "Test case execution FAILED for ${test_case} environment"
51       cyclictest_result=`expr ${cyclictest_result} + 1`
52    fi
53 }
54
55 function ftrace_disable {
56    sudo ssh root@${HOST_IP} "sh /root/workspace/scripts/disbale-trace.sh"
57    sudo ssh root@${HOST_IP} "cd /tmp ; a=\$(ls -rt | tail -1) ; echo \$a ; mv \$a cyclictest_${env}.txt"
58    sudo mkdir -p $WORKSPACE/build_output/log/kernel_trace
59    sudo scp root@${HOST_IP}:/tmp/cyclictest_${env}.txt $WORKSPACE/build_output/log/kernel_trace/
60 }
61
62 #Execution of testcases based on test type and test name from releng.
63 if [ ${test_type} == "verify" ];then
64    HOST_IP="10.10.100.21"
65    test_time=120000 # 2m
66    if [ ${ftrace_enable} -eq '1' ]; then
67       for env in ${cyclictest_env_verify[@]}
68       do
69          #Enabling ftrace for kernel debugging.
70          sed -i '/host-setup1.sh/a\    \- \"enable-trace.sh\"' kvmfornfv_cyclictest_hostenv_guestenv.yaml
71          #Executing cyclictest through yardstick.
72          cyclictest ${env}
73          #disabling ftrace and collecting the logs to upload to artifact repository.
74          ftrace_disable
75          sleep 10
76       done
77       #Execution of packet forwarding test cases.
78       packetForward
79    else
80       for env in ${cyclictest_env_verify[@]}
81       do
82          #Executing cyclictest through yardstick.
83          cyclictest ${env}
84          sleep 10
85       done
86       #Execution of packet forwarding test cases.
87       packetForward
88    fi
89       if [ ${cyclictest_result} -ne 0 ] ||  [ ${packetforward_result} -ne 0 ];then
90          echo "Test case FAILED"
91          err_exit 1
92       else
93          err_exit 0
94       fi
95 elif [ ${test_type} == "daily" ];then
96    HOST_IP="10.10.100.22"
97    test_time=3600000 #1h
98    if [ ${test_name} == "packet_forward" ];then
99       packetForward
100       if [ ${packetforward_result} -ne 0 ] ; then
101          err_exit 1
102       else
103          err_exit 0
104       fi
105    elif [ ${test_name} == "cyclictest" ];then
106       if [ ${ftrace_enable} -eq '1' ]; then
107          for env in ${cyclictest_env_daily[@]}
108          do
109             #Enabling ftrace for kernel debugging.
110             sed -i '/host-setup1.sh/a\    \- \"enable-trace.sh\"' kvmfornfv_cyclictest_hostenv_guestenv.yaml
111             #Executing cyclictest through yardstick.
112             cyclictest ${env}
113             #disabling ftrace and collecting the logs to upload to artifact repository. 
114             ftrace_disable
115             sleep 5
116          done
117       else
118          for env in ${cyclictest_env_daily[@]}
119          do
120          #Executing cyclictest through yardstick.
121          cyclictest ${env}
122          sleep 5
123          done
124       fi
125          if [ ${cyclictest_result} -ne 0 ] ; then
126             echo "Cyclictest case execution FAILED"
127             err_exit 1
128          else
129             echo "Cyclictest case executed SUCCESSFULLY"
130             err_exit 0
131          fi
132    fi
133 elif [ ${test_type} == "merge" ];then
134    echo "Test is not enabled for ${test_type}"
135    exit 0
136 else
137    echo "Incorrect test type ${test_type}"
138 fi