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