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