adf0aa3ce5bdd669248454a242b73c008b7bff8c
[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" "cpustress_idle" "memorystress_idle" "iostress_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 #   source $WORKSPACE/ci/packet_forward_test.sh $HOST_IP
25    echo "Packetforwarding need to be implemented"
26    packetforward_result=$?
27    if [ ${packetforward_result} -ne 0 ];then
28       echo "Packet Forwarding test case execution FAILED"
29    else
30       echo "Packet Forwarding test case executed SUCCESSFULLY"
31    fi
32 }
33
34 function cyclictest {
35    test_case=$1
36    source $WORKSPACE/ci/cyclicTestTrigger.sh $HOST_IP $test_time $test_type $test_case
37    #Verifying whether the test node is up and running
38    connect_host
39    #Waiting for ssh to be available for the host machine.
40    sleep 20
41    #calculating and verifying sha512sum of the guestimage.
42    if ! verifyGuestImage;then
43       exit 1
44    fi
45    #Update kvmfornfv_cyclictest_${testName}.yaml with test_time and pod.yaml with IP
46    updateYaml
47    #Running PCM utility
48    collect_MBWInfo $test_type
49    #Checking which test cases will be executed first and last from the list to perform cleaning operations.
50    first_test_case=cyclictest_env_$test_type[0]
51    last_test_case=cyclictest_env_$test_type[-1]
52    #Cleaning the environment before running cyclictest through yardstick
53    if [ ${test_case} == "${!first_test_case}" ];then
54       env_clean
55    else
56       sudo ssh root@${HOST_IP} "pid=\$(ps aux | grep 'qemu' | awk '{print \$2}' | head -1); echo \$pid |xargs kill"
57    fi
58    #Creating a docker image with yardstick installed and launching ubuntu docker to run yardstick cyclic testcase
59    if runCyclicTest;then
60       cyclictest_result=`expr ${cyclictest_result} + 0`
61    else
62       echo "Test case execution FAILED for ${test_case} environment"
63       cyclictest_result=`expr ${cyclictest_result} + 1`
64    fi
65    echo "Terminating PCM Process"
66    sudo ssh root@${HOST_IP} "pid=\$(ps aux | grep 'pcm' | awk '{print \$2}' | head -1); echo \$pid |xargs kill -SIGTERM"
67    if [ ${test_case} != "${!last_test_case}" ];then
68       sudo ssh root@${HOST_IP} "reboot"
69    fi
70 }
71 function collect_MBWInfo {
72    #Collecting the Memory Bandwidth Information using pcm-memory utility
73    source $WORKSPACE/ci/envs/host-config
74    testType=$1
75    timeStamp=$(date +%Y%m%d%H%M%S)
76    echo "Running PCM memory to collect memory bandwidth"
77    sudo ssh root@${HOST_IP} "mkdir -p /root/MBWInfo"
78    sudo ssh root@${HOST_IP} "${pcm_memory} 60 &>/root/MBWInfo/MBWInfo_${testType}_${timeStamp} &disown"
79 }
80 function install_pcm {
81    source $WORKSPACE/ci/envs/host-config
82    sudo ssh root@${HOST_IP} '
83    modelName=`cat /proc/cpuinfo | grep -i "model name" | uniq`
84    if echo "$modelName" | grep -i "xeon" ;then
85       echo "pcm utility supports $modelName processor"
86    else
87       echo "check for the pcm utility supported processors"
88       exit 1
89    fi
90    cd /root
91    if [ ! -d "pcm" ]; then
92      `git clone https://github.com/opcm/pcm`
93       cd pcm
94       make
95       echo "Disabling NMI Watchdog"
96       echo 0 > /proc/sys/kernel/nmi_watchdog
97       echo "To Access MSR registers installing msr-tools"
98       sudo yum install msr-tools
99       sudo modprobe msr
100    fi
101    '
102 }
103
104 function ftrace_disable {
105    sudo ssh root@${HOST_IP} "sh /root/workspace/scripts/disbale-trace.sh"
106    sudo ssh root@${HOST_IP} "cd /tmp ; a=\$(ls -rt | tail -1) ; echo \$a ; mv \$a cyclictest_${env}.txt"
107    sudo mkdir -p $WORKSPACE/build_output/log/kernel_trace
108    sudo scp root@${HOST_IP}:/tmp/cyclictest_${env}.txt $WORKSPACE/build_output/log/kernel_trace/
109 }
110
111 #Execution of testcases based on test type and test name from releng.
112 if [ ${test_type} == "verify" ];then
113    HOST_IP="10.10.100.21"
114    test_time=1000 # 1s
115    install_pcm
116    if [ ${ftrace_enable} -eq '1' ]; then
117       for env in ${cyclictest_env_verify[@]}
118       do
119          #Enabling ftrace for kernel debugging.
120          sed -i '/host-setup1.sh/a\    \- \"enable-trace.sh\"' kvmfornfv_cyclictest_hostenv_guestenv.yaml
121          #Executing cyclictest through yardstick.
122          cyclictest ${env}
123          #disabling ftrace and collecting the logs to upload to artifact repository.
124          ftrace_disable
125          sleep 10
126       done
127       #Execution of packet forwarding test cases.
128       packetForward
129    else
130       for env in ${cyclictest_env_verify[@]}
131       do
132          #Executing cyclictest through yardstick.
133          cyclictest ${env}
134          sleep 10
135       done
136       env_clean
137       host_clean
138       #Execution of packet forwarding test cases.
139       packetForward
140    fi
141       if [ ${cyclictest_result} -ne 0 ] ||  [ ${packetforward_result} -ne 0 ];then
142          echo "Test case FAILED"
143          test_exit 1
144       else
145          test_exit 0
146       fi
147 elif [ ${test_type} == "daily" ];then
148    HOST_IP="10.10.100.22"
149    test_time=3600000 #1h
150    install_pcm
151    if [ ${test_name} == "packet_forward" ];then
152       packetForward
153       if [ ${packetforward_result} -ne 0 ] ; then
154          test_exit 1
155       else
156          test_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             #disabling ftrace and collecting the logs to upload to artifact repository. 
167             ftrace_disable
168             sleep 5
169          done
170       else
171          for env in ${cyclictest_env_daily[@]}
172          do
173          #Executing cyclictest through yardstick.
174          cyclictest ${env}
175          sleep 5
176          done
177          env_clean
178          host_clean
179       fi
180          if [ ${cyclictest_result} -ne 0 ] ; then
181             echo "Cyclictest case execution FAILED"
182             test_exit 1
183          else
184             echo "Cyclictest case executed SUCCESSFULLY"
185             test_exit 0
186          fi
187    fi
188 elif [ ${test_type} == "merge" ];then
189    echo "Test is not enabled for ${test_type}"
190    exit 0
191 else
192    echo "Incorrect test type ${test_type}"
193 fi