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