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