This patch includes scripts and configuration files for
[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    #executing packet forwarding test cases based on the job type.
25    if [ ${test_type} == "verify" ];then
26       echo "packet forwarding test cases are not yet implemented for verify job"
27       packetforward_result=0
28    elif [ ${test_type} == "daily" ];then
29       source $WORKSPACE/ci/cyclicTestTrigger.sh $HOST_IP
30       connect_host
31       #Waiting for ssh to be available for the host machine.
32       sleep 20
33       # copy files and rpms and setup environment required for executing test cases
34       setUpPacketForwarding
35       sleep 1
36       #Verifying whether the test node is up and running
37       connect_host
38       sleep 20
39       #Install and Execute packet forwarding test cases
40       runPacketForwarding $test_type
41       packetforward_result=$?
42    else
43       echo "Incorrect test type ${test_type}"
44       exit 1
45    fi
46 }
47
48 function cyclictest {
49    test_case=$1
50    source $WORKSPACE/ci/cyclicTestTrigger.sh $HOST_IP $test_time $test_type $test_case
51    #Verifying whether the test node is up and running
52    connect_host
53    #Waiting for ssh to be available for the host machine.
54    sleep 20
55    #calculating and verifying sha512sum of the guestimage.
56    if ! verifyGuestImage;then
57       exit 1
58    fi
59    #Update kvmfornfv_cyclictest_${testName}.yaml with test_time and pod.yaml with IP
60    updateYaml
61    #Running PCM utility
62    collect_MBWInfo $test_type
63    #Checking which test cases will be executed first and last from the list to perform cleaning operations.
64    first_test_case=cyclictest_env_$test_type[0]
65    last_test_case=cyclictest_env_$test_type[-1]
66    #Cleaning the environment before running cyclictest through yardstick
67    if [ ${test_case} == "${!first_test_case}" ];then
68       env_clean
69    else
70       sudo ssh root@${HOST_IP} "pid=\$(ps aux | grep 'qemu' | awk '{print \$2}' | head -1); echo \$pid |xargs kill"
71    fi
72    #Creating a docker image with yardstick installed and launching ubuntu docker to run yardstick cyclic testcase
73    if runCyclicTest;then
74       cyclictest_result=`expr ${cyclictest_result} + 0`
75    else
76       echo "Test case execution FAILED for ${test_case} environment"
77       cyclictest_result=`expr ${cyclictest_result} + 1`
78    fi
79    echo "Terminating PCM Process"
80    sudo ssh root@${HOST_IP} "pid=\$(ps aux | grep 'pcm' | awk '{print \$2}' | head -1); echo \$pid |xargs kill -SIGTERM"
81    if [ ${test_case} != "${!last_test_case}" ];then
82       sudo ssh root@${HOST_IP} "reboot"
83    fi
84 }
85 function collect_MBWInfo {
86    #Collecting the Memory Bandwidth Information using pcm-memory utility
87    source $WORKSPACE/ci/envs/host-config
88    testType=$1
89    timeStamp=$(date +%Y%m%d%H%M%S)
90    echo "Running PCM memory to collect memory bandwidth"
91    sudo ssh root@${HOST_IP} "mkdir -p /root/MBWInfo"
92    sudo ssh root@${HOST_IP} "${pcm_memory} 60 &>/root/MBWInfo/MBWInfo_${testType}_${timeStamp} &disown"
93 }
94 function install_pcm {
95    source $WORKSPACE/ci/envs/host-config
96    sudo ssh root@${HOST_IP} '
97    modelName=`cat /proc/cpuinfo | grep -i "model name" | uniq`
98    if echo "$modelName" | grep -i "xeon" ;then
99       echo "pcm utility supports $modelName processor"
100    else
101       echo "check for the pcm utility supported processors"
102       exit 1
103    fi
104    cd /root
105    if [ ! -d "pcm" ]; then
106      `git clone https://github.com/opcm/pcm`
107       cd pcm
108       make
109       echo "Disabling NMI Watchdog"
110       echo 0 > /proc/sys/kernel/nmi_watchdog
111       echo "To Access MSR registers installing msr-tools"
112       sudo yum install msr-tools
113       sudo modprobe msr
114    fi
115    '
116 }
117
118 function ftrace_disable {
119    sudo ssh root@${HOST_IP} "sh /root/workspace/scripts/disbale-trace.sh"
120    sudo ssh root@${HOST_IP} "cd /tmp ; a=\$(ls -rt | tail -1) ; echo \$a ; mv \$a cyclictest_${env}.txt"
121    sudo mkdir -p $WORKSPACE/build_output/log/kernel_trace
122    sudo scp root@${HOST_IP}:/tmp/cyclictest_${env}.txt $WORKSPACE/build_output/log/kernel_trace/
123 }
124
125 #Execution of testcases based on test type and test name from releng.
126 if [ ${test_type} == "verify" ];then
127    HOST_IP="10.10.100.21"
128    test_time=1000 # 1s
129    install_pcm
130    if [ ${ftrace_enable} -eq '1' ]; then
131       for env in ${cyclictest_env_verify[@]}
132       do
133          #Enabling ftrace for kernel debugging.
134          sed -i '/host-setup1.sh/a\    \- \"enable-trace.sh\"' kvmfornfv_cyclictest_hostenv_guestenv.yaml
135          #Executing cyclictest through yardstick.
136          cyclictest ${env}
137          #disabling ftrace and collecting the logs to upload to artifact repository.
138          ftrace_disable
139          sleep 10
140       done
141       #Execution of packet forwarding test cases.
142       packetForward
143    else
144       for env in ${cyclictest_env_verify[@]}
145       do
146          #Executing cyclictest through yardstick.
147          cyclictest ${env}
148          sleep 10
149       done
150       env_clean
151       host_clean
152       #Execution of packet forwarding test cases.
153       packetForward
154    fi
155    if [ ${cyclictest_result} -ne 0 ] ||  [ ${packetforward_result} -ne 0 ];then
156       echo "Test case FAILED"
157       test_exit 1
158    else
159       test_exit 0
160    fi
161 elif [ ${test_type} == "daily" ];then
162    HOST_IP="10.10.100.22"
163    test_time=3600000 #1h
164    install_pcm
165    if [ ${test_name} == "packet_forward" ];then
166       packetForward
167       packet_fwd_logs
168       #clean the test environment after the test case execution.
169       sudo ssh root@${HOST_IP} "rm -rf /root/workspace/*"
170       host_clean
171       if [ ${packetforward_result} -ne 0 ] ; then
172          echo "Execution of packet forwarding test cases FAILED"
173          packet_fwd_exit 1
174       else
175          echo "Executed packet forwarding test cases SUCCESSFULLY"
176          packet_fwd_exit 0
177       fi
178    elif [ ${test_name} == "cyclictest" ];then
179       if [ ${ftrace_enable} -eq '1' ]; then
180          for env in ${cyclictest_env_daily[@]}
181          do
182             #Enabling ftrace for kernel debugging.
183             sed -i '/host-setup1.sh/a\    \- \"enable-trace.sh\"' kvmfornfv_cyclictest_hostenv_guestenv.yaml
184             #Executing cyclictest through yardstick.
185             cyclictest ${env}
186             #disabling ftrace and collecting the logs to upload to artifact repository. 
187             ftrace_disable
188             sleep 5
189          done
190       else
191          for env in ${cyclictest_env_daily[@]}
192          do
193          #Executing cyclictest through yardstick.
194          cyclictest ${env}
195          sleep 5
196          done
197          env_clean
198          host_clean
199       fi
200          if [ ${cyclictest_result} -ne 0 ] ; then
201             echo "Cyclictest case execution FAILED"
202             test_exit 1
203          else
204             echo "Cyclictest case executed SUCCESSFULLY"
205             test_exit 0
206          fi
207    fi
208 elif [ ${test_type} == "merge" ];then
209    echo "Test is not enabled for ${test_type}"
210    exit 0
211 else
212    echo "Incorrect test type ${test_type}"
213 fi