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